LLVM 24.0.0git
ARMAsmParser.cpp
Go to the documentation of this file.
1//===- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions -------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#include "ARMBaseInstrInfo.h"
10#include "ARMFeatures.h"
18#include "Utils/ARMBaseInfo.h"
19#include "llvm/ADT/APFloat.h"
20#include "llvm/ADT/APInt.h"
21#include "llvm/ADT/STLExtras.h"
23#include "llvm/ADT/SmallSet.h"
25#include "llvm/ADT/StringMap.h"
26#include "llvm/ADT/StringRef.h"
27#include "llvm/ADT/StringSet.h"
29#include "llvm/ADT/Twine.h"
30#include "llvm/MC/MCContext.h"
31#include "llvm/MC/MCExpr.h"
32#include "llvm/MC/MCInst.h"
33#include "llvm/MC/MCInstrDesc.h"
34#include "llvm/MC/MCInstrInfo.h"
42#include "llvm/MC/MCSection.h"
43#include "llvm/MC/MCStreamer.h"
45#include "llvm/MC/MCSymbol.h"
51#include "llvm/Support/Debug.h"
54#include "llvm/Support/SMLoc.h"
57#include <algorithm>
58#include <cassert>
59#include <cstddef>
60#include <cstdint>
61#include <iterator>
62#include <limits>
63#include <memory>
64#include <optional>
65#include <string>
66#include <utility>
67#include <vector>
68
69#define DEBUG_TYPE "asm-parser"
70
71using namespace llvm;
72
73namespace {
74class ARMOperand;
75
76enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
77
78static inline unsigned extractITMaskBit(unsigned Mask, unsigned Position) {
79 // Position==0 means we're not in an IT block at all. Position==1
80 // means we want the first state bit, which is always 0 (Then).
81 // Position==2 means we want the second state bit, stored at bit 3
82 // of Mask, and so on downwards. So (5 - Position) will shift the
83 // right bit down to bit 0, including the always-0 bit at bit 4 for
84 // the mandatory initial Then.
85 return (Mask >> (5 - Position) & 1);
86}
87
88class UnwindContext {
89 using Locs = SmallVector<SMLoc, 4>;
90
91 MCAsmParser &Parser;
92 Locs FnStartLocs;
93 Locs CantUnwindLocs;
94 Locs PersonalityLocs;
95 Locs PersonalityIndexLocs;
96 Locs HandlerDataLocs;
98
99public:
100 UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {}
101
102 bool hasFnStart() const { return !FnStartLocs.empty(); }
103 bool cantUnwind() const { return !CantUnwindLocs.empty(); }
104 bool hasHandlerData() const { return !HandlerDataLocs.empty(); }
105
106 bool hasPersonality() const {
107 return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty());
108 }
109
110 void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); }
111 void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); }
112 void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); }
113 void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); }
114 void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); }
115
116 void saveFPReg(MCRegister Reg) { FPReg = Reg; }
117 MCRegister getFPReg() const { return FPReg; }
118
119 void emitFnStartLocNotes() const {
120 for (SMLoc Loc : FnStartLocs)
121 Parser.Note(Loc, ".fnstart was specified here");
122 }
123
124 void emitCantUnwindLocNotes() const {
125 for (SMLoc Loc : CantUnwindLocs)
126 Parser.Note(Loc, ".cantunwind was specified here");
127 }
128
129 void emitHandlerDataLocNotes() const {
130 for (SMLoc Loc : HandlerDataLocs)
131 Parser.Note(Loc, ".handlerdata was specified here");
132 }
133
134 void emitPersonalityLocNotes() const {
135 for (Locs::const_iterator PI = PersonalityLocs.begin(),
136 PE = PersonalityLocs.end(),
137 PII = PersonalityIndexLocs.begin(),
138 PIE = PersonalityIndexLocs.end();
139 PI != PE || PII != PIE;) {
140 if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer()))
141 Parser.Note(*PI++, ".personality was specified here");
142 else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer()))
143 Parser.Note(*PII++, ".personalityindex was specified here");
144 else
145 llvm_unreachable(".personality and .personalityindex cannot be "
146 "at the same location");
147 }
148 }
149
150 void reset() {
151 FnStartLocs = Locs();
152 CantUnwindLocs = Locs();
153 PersonalityLocs = Locs();
154 HandlerDataLocs = Locs();
155 PersonalityIndexLocs = Locs();
156 FPReg = ARM::SP;
157 }
158};
159
160// Various sets of ARM instruction mnemonics which are used by the asm parser
161class ARMMnemonicSets {
162 StringSet<> CDE;
163 StringSet<> CDEWithVPTSuffix;
164public:
165 ARMMnemonicSets(const MCSubtargetInfo &STI);
166
167 /// Returns true iff a given mnemonic is a CDE instruction
168 bool isCDEInstr(StringRef Mnemonic) {
169 // Quick check before searching the set
170 if (!Mnemonic.starts_with("cx") && !Mnemonic.starts_with("vcx"))
171 return false;
172 return CDE.count(Mnemonic);
173 }
174
175 /// Returns true iff a given mnemonic is a VPT-predicable CDE instruction
176 /// (possibly with a predication suffix "e" or "t")
177 bool isVPTPredicableCDEInstr(StringRef Mnemonic) {
178 if (!Mnemonic.starts_with("vcx"))
179 return false;
180 return CDEWithVPTSuffix.count(Mnemonic);
181 }
182
183 /// Returns true iff a given mnemonic is an IT-predicable CDE instruction
184 /// (possibly with a condition suffix)
185 bool isITPredicableCDEInstr(StringRef Mnemonic) {
186 if (!Mnemonic.starts_with("cx"))
187 return false;
188 return Mnemonic.starts_with("cx1a") || Mnemonic.starts_with("cx1da") ||
189 Mnemonic.starts_with("cx2a") || Mnemonic.starts_with("cx2da") ||
190 Mnemonic.starts_with("cx3a") || Mnemonic.starts_with("cx3da");
191 }
192
193 /// Return true iff a given mnemonic is an integer CDE instruction with
194 /// dual-register destination
195 bool isCDEDualRegInstr(StringRef Mnemonic) {
196 if (!Mnemonic.starts_with("cx"))
197 return false;
198 return Mnemonic == "cx1d" || Mnemonic == "cx1da" ||
199 Mnemonic == "cx2d" || Mnemonic == "cx2da" ||
200 Mnemonic == "cx3d" || Mnemonic == "cx3da";
201 }
202};
203
204ARMMnemonicSets::ARMMnemonicSets(const MCSubtargetInfo &STI) {
205 for (StringRef Mnemonic: { "cx1", "cx1a", "cx1d", "cx1da",
206 "cx2", "cx2a", "cx2d", "cx2da",
207 "cx3", "cx3a", "cx3d", "cx3da", })
208 CDE.insert(Mnemonic);
209 for (StringRef Mnemonic :
210 {"vcx1", "vcx1a", "vcx2", "vcx2a", "vcx3", "vcx3a"}) {
211 CDE.insert(Mnemonic);
212 CDEWithVPTSuffix.insert(Mnemonic);
213 CDEWithVPTSuffix.insert(std::string(Mnemonic) + "t");
214 CDEWithVPTSuffix.insert(std::string(Mnemonic) + "e");
215 }
216}
217
218class ARMAsmParser : public MCTargetAsmParser {
219 const ARMMCOptions &CLOpts;
220 const MCRegisterInfo *MRI;
221 UnwindContext UC;
222 ARMMnemonicSets MS;
223
224 ARMTargetStreamer &getTargetStreamer() {
225 assert(getParser().getStreamer().getTargetStreamer() &&
226 "do not have a target streamer");
227 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
228 return static_cast<ARMTargetStreamer &>(TS);
229 }
230
231 // Map of register aliases registers via the .req directive.
232 StringMap<MCRegister> RegisterReqs;
233
234 bool NextSymbolIsThumb;
235
236 bool useImplicitITThumb() const {
237 return CLOpts.implicit_it == ImplicitItModeTy::Always ||
238 CLOpts.implicit_it == ImplicitItModeTy::ThumbOnly;
239 }
240
241 bool useImplicitITARM() const {
242 return CLOpts.implicit_it == ImplicitItModeTy::Always ||
243 CLOpts.implicit_it == ImplicitItModeTy::ARMOnly;
244 }
245
246 struct {
247 ARMCC::CondCodes Cond; // Condition for IT block.
248 unsigned Mask:4; // Condition mask for instructions.
249 // Starting at first 1 (from lsb).
250 // '1' condition as indicated in IT.
251 // '0' inverse of condition (else).
252 // Count of instructions in IT block is
253 // 4 - trailingzeroes(mask)
254 // Note that this does not have the same encoding
255 // as in the IT instruction, which also depends
256 // on the low bit of the condition code.
257
258 unsigned CurPosition; // Current position in parsing of IT
259 // block. In range [0,4], with 0 being the IT
260 // instruction itself. Initialized according to
261 // count of instructions in block. ~0U if no
262 // active IT block.
263
264 bool IsExplicit; // true - The IT instruction was present in the
265 // input, we should not modify it.
266 // false - The IT instruction was added
267 // implicitly, we can extend it if that
268 // would be legal.
269 } ITState;
270
271 SmallVector<MCInst, 4> PendingConditionalInsts;
272
273 void onEndOfFile() override {
274 flushPendingInstructions(getParser().getStreamer());
275 }
276
277 void flushPendingInstructions(MCStreamer &Out) override {
278 if (!inImplicitITBlock()) {
279 assert(PendingConditionalInsts.size() == 0);
280 return;
281 }
282
283 // Emit the IT instruction
284 MCInst ITInst;
285 ITInst.setOpcode(ARM::t2IT);
286 ITInst.addOperand(MCOperand::createImm(ITState.Cond));
287 ITInst.addOperand(MCOperand::createImm(ITState.Mask));
288 Out.emitInstruction(ITInst, getSTI());
289
290 // Emit the conditional instructions
291 assert(PendingConditionalInsts.size() <= 4);
292 for (const MCInst &Inst : PendingConditionalInsts) {
293 Out.emitInstruction(Inst, getSTI());
294 }
295 PendingConditionalInsts.clear();
296
297 // Clear the IT state
298 ITState.Mask = 0;
299 ITState.CurPosition = ~0U;
300 }
301
302 bool inITBlock() { return ITState.CurPosition != ~0U; }
303 bool inExplicitITBlock() { return inITBlock() && ITState.IsExplicit; }
304 bool inImplicitITBlock() { return inITBlock() && !ITState.IsExplicit; }
305
306 bool lastInITBlock() {
307 return ITState.CurPosition == 4 - (unsigned)llvm::countr_zero(ITState.Mask);
308 }
309
310 void forwardITPosition() {
311 if (!inITBlock()) return;
312 // Move to the next instruction in the IT block, if there is one. If not,
313 // mark the block as done, except for implicit IT blocks, which we leave
314 // open until we find an instruction that can't be added to it.
315 unsigned TZ = llvm::countr_zero(ITState.Mask);
316 if (++ITState.CurPosition == 5 - TZ && ITState.IsExplicit)
317 ITState.CurPosition = ~0U; // Done with the IT block after this.
318 }
319
320 // Rewind the state of the current IT block, removing the last slot from it.
321 void rewindImplicitITPosition() {
322 assert(inImplicitITBlock());
323 assert(ITState.CurPosition > 1);
324 ITState.CurPosition--;
325 unsigned TZ = llvm::countr_zero(ITState.Mask);
326 unsigned NewMask = 0;
327 NewMask |= ITState.Mask & (0xC << TZ);
328 NewMask |= 0x2 << TZ;
329 ITState.Mask = NewMask;
330 }
331
332 // Rewind the state of the current IT block, removing the last slot from it.
333 // If we were at the first slot, this closes the IT block.
334 void discardImplicitITBlock() {
335 assert(inImplicitITBlock());
336 assert(ITState.CurPosition == 1);
337 ITState.CurPosition = ~0U;
338 }
339
340 // Get the condition code corresponding to the current IT block slot.
341 ARMCC::CondCodes currentITCond() {
342 unsigned MaskBit = extractITMaskBit(ITState.Mask, ITState.CurPosition);
343 return MaskBit ? ARMCC::getOppositeCondition(ITState.Cond) : ITState.Cond;
344 }
345
346 // Invert the condition of the current IT block slot without changing any
347 // other slots in the same block.
348 void invertCurrentITCondition() {
349 if (ITState.CurPosition == 1) {
350 ITState.Cond = ARMCC::getOppositeCondition(ITState.Cond);
351 } else {
352 ITState.Mask ^= 1 << (5 - ITState.CurPosition);
353 }
354 }
355
356 // Returns true if the current IT block is full (all 4 slots used).
357 bool isITBlockFull() {
358 return inITBlock() && (ITState.Mask & 1);
359 }
360
361 // Extend the current implicit IT block to have one more slot with the given
362 // condition code.
363 void extendImplicitITBlock(ARMCC::CondCodes Cond) {
364 assert(inImplicitITBlock());
365 assert(!isITBlockFull());
366 assert(Cond == ITState.Cond ||
367 Cond == ARMCC::getOppositeCondition(ITState.Cond));
368 unsigned TZ = llvm::countr_zero(ITState.Mask);
369 unsigned NewMask = 0;
370 // Keep any existing condition bits.
371 NewMask |= ITState.Mask & (0xE << TZ);
372 // Insert the new condition bit.
373 NewMask |= (Cond != ITState.Cond) << TZ;
374 // Move the trailing 1 down one bit.
375 NewMask |= 1 << (TZ - 1);
376 ITState.Mask = NewMask;
377 }
378
379 // Create a new implicit IT block with a dummy condition code.
380 void startImplicitITBlock() {
381 assert(!inITBlock());
382 ITState.Cond = ARMCC::AL;
383 ITState.Mask = 8;
384 ITState.CurPosition = 1;
385 ITState.IsExplicit = false;
386 }
387
388 // Create a new explicit IT block with the given condition and mask.
389 // The mask should be in the format used in ARMOperand and
390 // MCOperand, with a 1 implying 'e', regardless of the low bit of
391 // the condition.
392 void startExplicitITBlock(ARMCC::CondCodes Cond, unsigned Mask) {
393 assert(!inITBlock());
394 ITState.Cond = Cond;
395 ITState.Mask = Mask;
396 ITState.CurPosition = 0;
397 ITState.IsExplicit = true;
398 }
399
400 struct {
401 unsigned Mask : 4;
402 unsigned CurPosition;
403 } VPTState;
404 bool inVPTBlock() { return VPTState.CurPosition != ~0U; }
405 void forwardVPTPosition() {
406 if (!inVPTBlock()) return;
407 unsigned TZ = llvm::countr_zero(VPTState.Mask);
408 if (++VPTState.CurPosition == 5 - TZ)
409 VPTState.CurPosition = ~0U;
410 }
411
412 void Note(SMLoc L, const Twine &Msg, SMRange Range = {}) {
413 return getParser().Note(L, Msg, Range);
414 }
415
416 bool Warning(SMLoc L, const Twine &Msg, SMRange Range = {}) {
417 return getParser().Warning(L, Msg, Range);
418 }
419
420 bool Error(SMLoc L, const Twine &Msg, SMRange Range = {}) {
421 return getParser().Error(L, Msg, Range);
422 }
423
424 bool validatetLDMRegList(const MCInst &Inst, const OperandVector &Operands,
425 unsigned MnemonicOpsEndInd, unsigned ListIndex,
426 bool IsARPop = false);
427 bool validatetSTMRegList(const MCInst &Inst, const OperandVector &Operands,
428 unsigned MnemonicOpsEndInd, unsigned ListIndex);
429
430 MCRegister tryParseRegister(bool AllowOutofBoundReg = false);
431 bool tryParseRegisterWithWriteBack(OperandVector &);
432 int tryParseShiftRegister(OperandVector &);
433 std::optional<ARM_AM::ShiftOpc> tryParseShiftToken();
434 bool parseRegisterList(OperandVector &, bool EnforceOrder = true,
435 bool AllowRAAC = false, bool IsLazyLoadStore = false,
436 bool IsVSCCLRM = false);
437 bool parseMemory(OperandVector &);
438 bool parseOperand(OperandVector &, StringRef Mnemonic);
439 bool parseImmExpr(int64_t &Out);
440 bool parsePrefix(ARM::Specifier &);
441 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
442 unsigned &ShiftAmount);
443 bool parseLiteralValues(unsigned Size, SMLoc L);
444 bool parseDirectiveThumb(SMLoc L);
445 bool parseDirectiveARM(SMLoc L);
446 bool parseDirectiveThumbFunc(SMLoc L);
447 bool parseDirectiveCode(SMLoc L);
448 bool parseDirectiveSyntax(SMLoc L);
449 bool parseDirectiveReq(StringRef Name, SMLoc L);
450 bool parseDirectiveUnreq(SMLoc L);
451 bool parseDirectiveArch(SMLoc L);
452 bool parseDirectiveEabiAttr(SMLoc L);
453 bool parseDirectiveCPU(SMLoc L);
454 bool parseDirectiveFPU(SMLoc L);
455 bool parseDirectiveFnStart(SMLoc L);
456 bool parseDirectiveFnEnd(SMLoc L);
457 bool parseDirectiveCantUnwind(SMLoc L);
458 bool parseDirectivePersonality(SMLoc L);
459 bool parseDirectiveHandlerData(SMLoc L);
460 bool parseDirectiveSetFP(SMLoc L);
461 bool parseDirectivePad(SMLoc L);
462 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
463 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
464 bool parseDirectiveLtorg(SMLoc L);
465 bool parseDirectiveEven(SMLoc L);
466 bool parseDirectivePersonalityIndex(SMLoc L);
467 bool parseDirectiveUnwindRaw(SMLoc L);
468 bool parseDirectiveTLSDescSeq(SMLoc L);
469 bool parseDirectiveMovSP(SMLoc L);
470 bool parseDirectiveObjectArch(SMLoc L);
471 bool parseDirectiveArchExtension(SMLoc L);
472 bool parseDirectiveAlign(SMLoc L);
473 bool parseDirectiveThumbSet(SMLoc L);
474
475 bool parseDirectiveSEHAllocStack(SMLoc L, bool Wide);
476 bool parseDirectiveSEHSaveRegs(SMLoc L, bool Wide);
477 bool parseDirectiveSEHSaveSP(SMLoc L);
478 bool parseDirectiveSEHSaveFRegs(SMLoc L);
479 bool parseDirectiveSEHSaveLR(SMLoc L);
480 bool parseDirectiveSEHPrologEnd(SMLoc L, bool Fragment);
481 bool parseDirectiveSEHNop(SMLoc L, bool Wide);
482 bool parseDirectiveSEHEpilogStart(SMLoc L, bool Condition);
483 bool parseDirectiveSEHEpilogEnd(SMLoc L);
484 bool parseDirectiveSEHCustom(SMLoc L);
485
486 std::unique_ptr<ARMOperand> defaultCondCodeOp();
487 std::unique_ptr<ARMOperand> defaultCCOutOp();
488 std::unique_ptr<ARMOperand> defaultVPTPredOp();
489
490 bool isMnemonicVPTPredicable(StringRef Mnemonic, StringRef ExtraToken);
491 StringRef splitMnemonic(StringRef Mnemonic, StringRef ExtraToken,
492 ARMCC::CondCodes &PredicationCode,
493 ARMVCC::VPTCodes &VPTPredicationCode,
494 bool &CarrySetting, unsigned &ProcessorIMod,
495 StringRef &ITMask);
496 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef ExtraToken,
497 StringRef FullInst, bool &CanAcceptCarrySet,
498 bool &CanAcceptPredicationCode,
499 bool &CanAcceptVPTPredicationCode);
500 bool enableArchExtFeature(StringRef Name, SMLoc &ExtLoc);
501
502 void tryConvertingToTwoOperandForm(StringRef Mnemonic,
503 ARMCC::CondCodes PredicationCode,
504 bool CarrySetting, OperandVector &Operands,
505 unsigned MnemonicOpsEndInd);
506
507 bool CDEConvertDualRegOperand(StringRef Mnemonic, OperandVector &Operands,
508 unsigned MnemonicOpsEndInd);
509
510 bool isThumb() const {
511 // FIXME: Can tablegen auto-generate this?
512 return getSTI().hasFeature(ARM::ModeThumb);
513 }
514
515 bool isThumbOne() const {
516 return isThumb() && !getSTI().hasFeature(ARM::FeatureThumb2);
517 }
518
519 bool isThumbTwo() const {
520 return isThumb() && getSTI().hasFeature(ARM::FeatureThumb2);
521 }
522
523 bool hasThumb() const {
524 return getSTI().hasFeature(ARM::HasV4TOps);
525 }
526
527 bool hasThumb2() const {
528 return getSTI().hasFeature(ARM::FeatureThumb2);
529 }
530
531 bool hasV6Ops() const {
532 return getSTI().hasFeature(ARM::HasV6Ops);
533 }
534
535 bool hasV6T2Ops() const {
536 return getSTI().hasFeature(ARM::HasV6T2Ops);
537 }
538
539 bool hasV6MOps() const {
540 return getSTI().hasFeature(ARM::HasV6MOps);
541 }
542
543 bool hasV7Ops() const {
544 return getSTI().hasFeature(ARM::HasV7Ops);
545 }
546
547 bool hasV8Ops() const {
548 return getSTI().hasFeature(ARM::HasV8Ops);
549 }
550
551 bool hasV8MBaseline() const {
552 return getSTI().hasFeature(ARM::HasV8MBaselineOps);
553 }
554
555 bool hasV8MMainline() const {
556 return getSTI().hasFeature(ARM::HasV8MMainlineOps);
557 }
558 bool hasV8_1MMainline() const {
559 return getSTI().hasFeature(ARM::HasV8_1MMainlineOps);
560 }
561 bool hasMVEFloat() const {
562 return getSTI().hasFeature(ARM::HasMVEFloatOps);
563 }
564 bool hasCDE() const {
565 return getSTI().hasFeature(ARM::HasCDEOps);
566 }
567 bool has8MSecExt() const {
568 return getSTI().hasFeature(ARM::Feature8MSecExt);
569 }
570
571 bool hasARM() const {
572 return !getSTI().hasFeature(ARM::FeatureNoARM);
573 }
574
575 bool hasDSP() const {
576 return getSTI().hasFeature(ARM::FeatureDSP);
577 }
578
579 bool hasD32() const {
580 return getSTI().hasFeature(ARM::FeatureD32);
581 }
582
583 bool hasV8_1aOps() const {
584 return getSTI().hasFeature(ARM::HasV8_1aOps);
585 }
586
587 bool hasRAS() const {
588 return getSTI().hasFeature(ARM::FeatureRAS);
589 }
590
591 void SwitchMode() {
592 MCSubtargetInfo &STI = copySTI();
593 auto FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
594 setAvailableFeatures(FB);
595 }
596
597 void FixModeAfterArchChange(bool WasThumb, SMLoc Loc);
598
599 bool isMClass() const {
600 return getSTI().hasFeature(ARM::FeatureMClass);
601 }
602
603 /// @name Auto-generated Match Functions
604 /// {
605
606#define GET_ASSEMBLER_HEADER
607#include "ARMGenAsmMatcher.inc"
608
609 /// }
610
611 ParseStatus parseITCondCode(OperandVector &);
612 ParseStatus parseCoprocNumOperand(OperandVector &);
613 ParseStatus parseCoprocRegOperand(OperandVector &);
614 ParseStatus parseCoprocOptionOperand(OperandVector &);
615 ParseStatus parseMemBarrierOptOperand(OperandVector &);
616 ParseStatus parseTraceSyncBarrierOptOperand(OperandVector &);
617 ParseStatus parseInstSyncBarrierOptOperand(OperandVector &);
618 ParseStatus parseProcIFlagsOperand(OperandVector &);
619 ParseStatus parseMSRMaskOperand(OperandVector &);
620 ParseStatus parseBankedRegOperand(OperandVector &);
621 ParseStatus parsePKHImm(OperandVector &O, ARM_AM::ShiftOpc, int Low,
622 int High);
623 ParseStatus parsePKHLSLImm(OperandVector &O) {
624 return parsePKHImm(O, ARM_AM::lsl, 0, 31);
625 }
626 ParseStatus parsePKHASRImm(OperandVector &O) {
627 return parsePKHImm(O, ARM_AM::asr, 1, 32);
628 }
629 ParseStatus parseSetEndImm(OperandVector &);
630 ParseStatus parseShifterImm(OperandVector &);
631 ParseStatus parseRotImm(OperandVector &);
632 ParseStatus parseModImm(OperandVector &);
633 ParseStatus parseBitfield(OperandVector &);
634 ParseStatus parsePostIdxReg(OperandVector &);
635 ParseStatus parseAM3Offset(OperandVector &);
636 ParseStatus parseFPImm(OperandVector &);
637 ParseStatus parseVectorList(OperandVector &);
638 ParseStatus parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
639 SMLoc &EndLoc);
640
641 // Asm Match Converter Methods
642 void cvtThumbMultiply(MCInst &Inst, const OperandVector &);
643 void cvtThumbBranches(MCInst &Inst, const OperandVector &);
644 void cvtMVEVMOVQtoDReg(MCInst &Inst, const OperandVector &);
645
646 bool validateInstruction(MCInst &Inst, const OperandVector &Ops,
647 unsigned MnemonicOpsEndInd);
648 bool processInstruction(MCInst &Inst, const OperandVector &Ops,
649 unsigned MnemonicOpsEndInd, MCStreamer &Out);
650 bool shouldOmitVectorPredicateOperand(StringRef Mnemonic,
652 unsigned MnemonicOpsEndInd);
653 bool isITBlockTerminator(MCInst &Inst) const;
654
655 void fixupGNULDRDAlias(StringRef Mnemonic, OperandVector &Operands,
656 unsigned MnemonicOpsEndInd);
657 bool validateLDRDSTRD(MCInst &Inst, const OperandVector &Operands, bool Load,
658 bool ARMMode, bool Writeback,
659 unsigned MnemonicOpsEndInd);
660
661public:
662 enum ARMMatchResultTy {
663 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
664 Match_RequiresNotITBlock,
665 Match_RequiresV6,
666 Match_RequiresThumb2,
667 Match_RequiresV8,
668 Match_RequiresFlagSetting,
669#define GET_OPERAND_DIAGNOSTIC_TYPES
670#include "ARMGenAsmMatcher.inc"
671
672 };
673
674 ARMAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser,
675 const MCInstrInfo &MII)
676 : MCTargetAsmParser(STI, MII),
677 CLOpts(ARM_MC::getCLOpts(Parser.getContext().getTargetOptions())),
678 UC(Parser), MS(STI) {
680
681 // Cache the MCRegisterInfo.
682 MRI = getContext().getRegisterInfo();
683
684 // Initialize the set of available features.
685 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
686
687 // Add build attributes based on the selected target.
688 if (CLOpts.add_build_attributes)
689 getTargetStreamer().emitTargetAttributes(STI);
690
691 // Not in an ITBlock to start with.
692 ITState.CurPosition = ~0U;
693
694 VPTState.CurPosition = ~0U;
695
696 NextSymbolIsThumb = false;
697 }
698
699 // Implementation of the MCTargetAsmParser interface:
700 bool parseRegister(MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc) override;
701 ParseStatus tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
702 SMLoc &EndLoc) override;
703 bool parseInstruction(ParseInstructionInfo &Info, StringRef Name,
704 SMLoc NameLoc, OperandVector &Operands) override;
705 bool ParseDirective(AsmToken DirectiveID) override;
706
707 unsigned validateTargetOperandClass(const MCParsedAsmOperand &Op,
708 unsigned Kind) override;
709 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
710 unsigned
711 checkEarlyTargetMatchPredicate(MCInst &Inst,
712 const OperandVector &Operands) override;
713
714 bool matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
715 OperandVector &Operands, MCStreamer &Out,
716 uint64_t &ErrorInfo,
717 bool MatchingInlineAsm) override;
718 unsigned MatchInstruction(OperandVector &Operands, MCInst &Inst,
719 SmallVectorImpl<NearMissInfo> &NearMisses,
720 bool MatchingInlineAsm, bool &EmitInITBlock,
721 MCStreamer &Out);
722
723 struct NearMissMessage {
724 SMLoc Loc;
725 SmallString<128> Message;
726 };
727
728 const char *getCustomOperandDiag(ARMMatchResultTy MatchError);
729
730 void FilterNearMisses(SmallVectorImpl<NearMissInfo> &NearMissesIn,
731 SmallVectorImpl<NearMissMessage> &NearMissesOut,
732 SMLoc IDLoc, OperandVector &Operands);
733 void ReportNearMisses(SmallVectorImpl<NearMissInfo> &NearMisses, SMLoc IDLoc,
735
736 void doBeforeLabelEmit(MCSymbol *Symbol, SMLoc IDLoc) override;
737
738 void onLabelParsed(MCSymbol *Symbol) override;
739
740 const MCInstrDesc &getInstrDesc(unsigned int Opcode) const {
741 return MII.get(Opcode);
742 }
743
744 bool hasMVE() const { return getSTI().hasFeature(ARM::HasMVEIntegerOps); }
745
746 // Return the low-subreg of a given Q register.
747 MCRegister getDRegFromQReg(MCRegister QReg) const {
748 return MRI->getSubReg(QReg, ARM::dsub_0);
749 }
750
751 const MCRegisterInfo *getMRI() const { return MRI; }
752};
753
754/// ARMOperand - Instances of this class represent a parsed ARM machine
755/// operand.
756class ARMOperand : public MCParsedAsmOperand {
757 enum KindTy {
758 k_CondCode,
759 k_VPTPred,
760 k_CCOut,
761 k_ITCondMask,
762 k_CoprocNum,
763 k_CoprocReg,
764 k_CoprocOption,
765 k_Immediate,
766 k_MemBarrierOpt,
767 k_InstSyncBarrierOpt,
768 k_TraceSyncBarrierOpt,
769 k_Memory,
770 k_PostIndexRegister,
771 k_MSRMask,
772 k_BankedReg,
773 k_ProcIFlags,
774 k_VectorIndex,
775 k_Register,
776 k_RegisterList,
777 k_RegisterListWithAPSR,
778 k_DPRRegisterList,
779 k_SPRRegisterList,
780 k_FPSRegisterListWithVPR,
781 k_FPDRegisterListWithVPR,
782 k_VectorList,
783 k_VectorListAllLanes,
784 k_VectorListIndexed,
785 k_ShiftedRegister,
786 k_ShiftedImmediate,
787 k_ShifterImmediate,
788 k_RotateImmediate,
789 k_ModifiedImmediate,
790 k_ConstantPoolImmediate,
791 k_BitfieldDescriptor,
792 k_Token,
793 } Kind;
794
795 SMLoc StartLoc, EndLoc, AlignmentLoc;
797
798 ARMAsmParser *Parser;
799
800 struct CCOp {
802 };
803
804 struct VCCOp {
806 };
807
808 struct CopOp {
809 unsigned Val;
810 };
811
812 struct CoprocOptionOp {
813 unsigned Val;
814 };
815
816 struct ITMaskOp {
817 unsigned Mask:4;
818 };
819
820 struct MBOptOp {
821 ARM_MB::MemBOpt Val;
822 };
823
824 struct ISBOptOp {
826 };
827
828 struct TSBOptOp {
830 };
831
832 struct IFlagsOp {
834 };
835
836 struct MMaskOp {
837 unsigned Val;
838 };
839
840 struct BankedRegOp {
841 unsigned Val;
842 };
843
844 struct TokOp {
845 const char *Data;
846 unsigned Length;
847 };
848
849 struct RegOp {
850 MCRegister RegNum;
851 };
852
853 // A vector register list is a sequential list of 1 to 4 registers.
854 struct VectorListOp {
855 MCRegister RegNum;
856 unsigned Count;
857 unsigned LaneIndex;
858 bool isDoubleSpaced;
859 };
860
861 struct VectorIndexOp {
862 unsigned Val;
863 };
864
865 struct ImmOp {
866 const MCExpr *Val;
867 };
868
869 /// Combined record for all forms of ARM address expressions.
870 struct MemoryOp {
871 MCRegister BaseRegNum;
872 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
873 // was specified.
874 const MCExpr *OffsetImm; // Offset immediate value
875 MCRegister OffsetRegNum; // Offset register num, when OffsetImm == NULL
876 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
877 unsigned ShiftImm; // shift for OffsetReg.
878 unsigned Alignment; // 0 = no alignment specified
879 // n = alignment in bytes (2, 4, 8, 16, or 32)
880 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
881 };
882
883 struct PostIdxRegOp {
884 MCRegister RegNum;
885 bool isAdd;
886 ARM_AM::ShiftOpc ShiftTy;
887 unsigned ShiftImm;
888 };
889
890 struct ShifterImmOp {
891 bool isASR;
892 unsigned Imm;
893 };
894
895 struct RegShiftedRegOp {
896 ARM_AM::ShiftOpc ShiftTy;
897 MCRegister SrcReg;
898 MCRegister ShiftReg;
899 unsigned ShiftImm;
900 };
901
902 struct RegShiftedImmOp {
903 ARM_AM::ShiftOpc ShiftTy;
904 MCRegister SrcReg;
905 unsigned ShiftImm;
906 };
907
908 struct RotImmOp {
909 unsigned Imm;
910 };
911
912 struct ModImmOp {
913 unsigned Bits;
914 unsigned Rot;
915 };
916
917 struct BitfieldOp {
918 unsigned LSB;
919 unsigned Width;
920 };
921
922 union {
923 struct CCOp CC;
924 struct VCCOp VCC;
925 struct CopOp Cop;
926 struct CoprocOptionOp CoprocOption;
927 struct MBOptOp MBOpt;
928 struct ISBOptOp ISBOpt;
929 struct TSBOptOp TSBOpt;
930 struct ITMaskOp ITMask;
931 struct IFlagsOp IFlags;
932 struct MMaskOp MMask;
933 struct BankedRegOp BankedReg;
934 struct TokOp Tok;
935 struct RegOp Reg;
936 struct VectorListOp VectorList;
937 struct VectorIndexOp VectorIndex;
938 struct ImmOp Imm;
939 struct MemoryOp Memory;
940 struct PostIdxRegOp PostIdxReg;
941 struct ShifterImmOp ShifterImm;
942 struct RegShiftedRegOp RegShiftedReg;
943 struct RegShiftedImmOp RegShiftedImm;
944 struct RotImmOp RotImm;
945 struct ModImmOp ModImm;
946 struct BitfieldOp Bitfield;
947 };
948
949public:
950 ARMOperand(KindTy K, ARMAsmParser &Parser) : Kind(K), Parser(&Parser) {}
951
952 /// getStartLoc - Get the location of the first token of this operand.
953 SMLoc getStartLoc() const override { return StartLoc; }
954
955 /// getEndLoc - Get the location of the last token of this operand.
956 SMLoc getEndLoc() const override { return EndLoc; }
957
958 /// getLocRange - Get the range between the first and last token of this
959 /// operand.
960 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
961
962 /// getAlignmentLoc - Get the location of the Alignment token of this operand.
963 SMLoc getAlignmentLoc() const {
964 assert(Kind == k_Memory && "Invalid access!");
965 return AlignmentLoc;
966 }
967
969 assert(Kind == k_CondCode && "Invalid access!");
970 return CC.Val;
971 }
972
973 ARMVCC::VPTCodes getVPTPred() const {
974 assert(isVPTPred() && "Invalid access!");
975 return VCC.Val;
976 }
977
978 unsigned getCoproc() const {
979 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
980 return Cop.Val;
981 }
982
983 StringRef getToken() const {
984 assert(Kind == k_Token && "Invalid access!");
985 return StringRef(Tok.Data, Tok.Length);
986 }
987
988 MCRegister getReg() const override {
989 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
990 return Reg.RegNum;
991 }
992
993 const SmallVectorImpl<MCRegister> &getRegList() const {
994 assert((Kind == k_RegisterList || Kind == k_RegisterListWithAPSR ||
995 Kind == k_DPRRegisterList || Kind == k_SPRRegisterList ||
996 Kind == k_FPSRegisterListWithVPR ||
997 Kind == k_FPDRegisterListWithVPR) &&
998 "Invalid access!");
999 return Registers;
1000 }
1001
1002 const MCExpr *getImm() const {
1003 assert(isImm() && "Invalid access!");
1004 return Imm.Val;
1005 }
1006
1007 const MCExpr *getConstantPoolImm() const {
1008 assert(isConstantPoolImm() && "Invalid access!");
1009 return Imm.Val;
1010 }
1011
1012 unsigned getVectorIndex() const {
1013 assert(Kind == k_VectorIndex && "Invalid access!");
1014 return VectorIndex.Val;
1015 }
1016
1017 ARM_MB::MemBOpt getMemBarrierOpt() const {
1018 assert(Kind == k_MemBarrierOpt && "Invalid access!");
1019 return MBOpt.Val;
1020 }
1021
1022 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
1023 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
1024 return ISBOpt.Val;
1025 }
1026
1027 ARM_TSB::TraceSyncBOpt getTraceSyncBarrierOpt() const {
1028 assert(Kind == k_TraceSyncBarrierOpt && "Invalid access!");
1029 return TSBOpt.Val;
1030 }
1031
1032 ARM_PROC::IFlags getProcIFlags() const {
1033 assert(Kind == k_ProcIFlags && "Invalid access!");
1034 return IFlags.Val;
1035 }
1036
1037 unsigned getMSRMask() const {
1038 assert(Kind == k_MSRMask && "Invalid access!");
1039 return MMask.Val;
1040 }
1041
1042 unsigned getBankedReg() const {
1043 assert(Kind == k_BankedReg && "Invalid access!");
1044 return BankedReg.Val;
1045 }
1046
1047 bool isCoprocNum() const { return Kind == k_CoprocNum; }
1048 bool isCoprocReg() const { return Kind == k_CoprocReg; }
1049 bool isCoprocOption() const { return Kind == k_CoprocOption; }
1050 bool isCondCode() const { return Kind == k_CondCode; }
1051 bool isVPTPred() const { return Kind == k_VPTPred; }
1052 bool isCCOut() const { return Kind == k_CCOut; }
1053 bool isITMask() const { return Kind == k_ITCondMask; }
1054 bool isITCondCode() const { return Kind == k_CondCode; }
1055 bool isImm() const override {
1056 return Kind == k_Immediate;
1057 }
1058
1059 bool isARMBranchTarget() const {
1060 if (!isImm()) return false;
1061
1062 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()))
1063 return CE->getValue() % 4 == 0;
1064 return true;
1065 }
1066
1067
1068 bool isThumbBranchTarget() const {
1069 if (!isImm()) return false;
1070
1071 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()))
1072 return CE->getValue() % 2 == 0;
1073 return true;
1074 }
1075
1076 // checks whether this operand is an unsigned offset which fits is a field
1077 // of specified width and scaled by a specific number of bits
1078 template<unsigned width, unsigned scale>
1079 bool isUnsignedOffset() const {
1080 if (!isImm()) return false;
1081 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
1082 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
1083 int64_t Val = CE->getValue();
1084 int64_t Align = 1LL << scale;
1085 int64_t Max = Align * ((1LL << width) - 1);
1086 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
1087 }
1088 return false;
1089 }
1090
1091 // checks whether this operand is an signed offset which fits is a field
1092 // of specified width and scaled by a specific number of bits
1093 template<unsigned width, unsigned scale>
1094 bool isSignedOffset() const {
1095 if (!isImm()) return false;
1096 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
1097 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
1098 int64_t Val = CE->getValue();
1099 int64_t Align = 1LL << scale;
1100 int64_t Max = Align * ((1LL << (width-1)) - 1);
1101 int64_t Min = -Align * (1LL << (width-1));
1102 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
1103 }
1104 return false;
1105 }
1106
1107 // checks whether this operand is an offset suitable for the LE /
1108 // LETP instructions in Arm v8.1M
1109 bool isLEOffset() const {
1110 if (!isImm()) return false;
1111 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
1112 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
1113 int64_t Val = CE->getValue();
1114 return Val < 0 && Val >= -4094 && (Val & 1) == 0;
1115 }
1116 return false;
1117 }
1118
1119 // checks whether this operand is a memory operand computed as an offset
1120 // applied to PC. the offset may have 8 bits of magnitude and is represented
1121 // with two bits of shift. textually it may be either [pc, #imm], #imm or
1122 // relocable expression...
1123 bool isThumbMemPC() const {
1124 int64_t Val = 0;
1125 if (isImm()) {
1126 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
1127 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
1128 if (!CE) return false;
1129 Val = CE->getValue();
1130 }
1131 else if (isGPRMem()) {
1132 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
1133 if(Memory.BaseRegNum != ARM::PC) return false;
1134 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
1135 Val = CE->getValue();
1136 else
1137 return false;
1138 }
1139 else return false;
1140 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
1141 }
1142
1143 bool isFPImm() const {
1144 if (!isImm()) return false;
1145 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1146 if (!CE || !isUInt<32>(CE->getValue()))
1147 return false;
1148 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1149 return Val != -1;
1150 }
1151
1152 template<int64_t N, int64_t M>
1153 bool isImmediate() const {
1154 if (!isImm()) return false;
1155 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1156 if (!CE) return false;
1157 int64_t Value = CE->getValue();
1158 return Value >= N && Value <= M;
1159 }
1160
1161 template<int64_t N, int64_t M>
1162 bool isImmediateS4() const {
1163 if (!isImm()) return false;
1164 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1165 if (!CE) return false;
1166 int64_t Value = CE->getValue();
1167 // ARM assembly uses #-0 to request the subtract-zero encoding,
1168 // which is distinct from the add-zero spelling even though both
1169 // have zero magnitude. The rather odd std::numeric_limits
1170 // invocation gives us this.
1171 return (((Value & 3) == 0) && Value >= N && Value <= M) ||
1172 Value == std::numeric_limits<int32_t>::min();
1173 }
1174 template<int64_t N, int64_t M>
1175 bool isImmediateS2() const {
1176 if (!isImm()) return false;
1177 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1178 if (!CE) return false;
1179 int64_t Value = CE->getValue();
1180 return ((Value & 1) == 0) && Value >= N && Value <= M;
1181 }
1182 bool isFBits16() const {
1183 return isImmediate<0, 17>();
1184 }
1185 bool isFBits32() const {
1186 return isImmediate<1, 33>();
1187 }
1188 bool isImm8s4() const {
1189 return isImmediateS4<-1020, 1020>();
1190 }
1191 bool isImm7s4() const {
1192 return isImmediateS4<-508, 508>();
1193 }
1194 bool isImm7Shift0() const {
1195 return isImmediate<-127, 127>();
1196 }
1197 bool isImm7Shift1() const {
1198 return isImmediateS2<-255, 255>();
1199 }
1200 bool isImm7Shift2() const {
1201 return isImmediateS4<-511, 511>();
1202 }
1203 bool isImm7() const {
1204 return isImmediate<-127, 127>();
1205 }
1206 bool isImm0_1020s4() const {
1207 return isImmediateS4<0, 1020>();
1208 }
1209 bool isImm0_508s4() const {
1210 return isImmediateS4<0, 508>();
1211 }
1212 bool isImm0_508s4Neg() const {
1213 if (!isImm()) return false;
1214 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1215 if (!CE) return false;
1216 int64_t Value = -CE->getValue();
1217 // explicitly exclude zero. we want that to use the normal 0_508 version.
1218 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
1219 }
1220
1221 bool isImm0_4095Neg() const {
1222 if (!isImm()) return false;
1223 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1224 if (!CE) return false;
1225 // isImm0_4095Neg is used with 32-bit immediates only.
1226 // 32-bit immediates are zero extended to 64-bit when parsed,
1227 // thus simple -CE->getValue() results in a big negative number,
1228 // not a small positive number as intended
1229 if ((CE->getValue() >> 32) > 0) return false;
1230 uint32_t Value = -static_cast<uint32_t>(CE->getValue());
1231 return Value > 0 && Value < 4096;
1232 }
1233
1234 bool isImm0_7() const {
1235 return isImmediate<0, 7>();
1236 }
1237
1238 bool isImm1_16() const {
1239 return isImmediate<1, 16>();
1240 }
1241
1242 bool isImm1_32() const {
1243 return isImmediate<1, 32>();
1244 }
1245
1246 bool isImm8_255() const {
1247 return isImmediate<8, 255>();
1248 }
1249
1250 bool isImm0_255Expr() const {
1251 if (!isImm())
1252 return false;
1253 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1254 // If it's not a constant expression, it'll generate a fixup and be
1255 // handled later.
1256 if (!CE)
1257 return true;
1258 int64_t Value = CE->getValue();
1259 return isUInt<8>(Value);
1260 }
1261
1262 bool isImm256_65535Expr() const {
1263 if (!isImm()) return false;
1264 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1265 // If it's not a constant expression, it'll generate a fixup and be
1266 // handled later.
1267 if (!CE) return true;
1268 int64_t Value = CE->getValue();
1269 return Value >= 256 && Value < 65536;
1270 }
1271
1272 bool isImm0_65535Expr() const {
1273 if (!isImm()) return false;
1274 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1275 // If it's not a constant expression, it'll generate a fixup and be
1276 // handled later.
1277 if (!CE) return true;
1278 int64_t Value = CE->getValue();
1279 return Value >= 0 && Value < 65536;
1280 }
1281
1282 bool isImm24bit() const {
1283 return isImmediate<0, 0xffffff + 1>();
1284 }
1285
1286 bool isImmThumbSR() const {
1287 return isImmediate<1, 33>();
1288 }
1289
1290 bool isPKHLSLImm() const {
1291 return isImmediate<0, 32>();
1292 }
1293
1294 bool isPKHASRImm() const {
1295 return isImmediate<0, 33>();
1296 }
1297
1298 bool isAdrLabel() const {
1299 // If we have an immediate that's not a constant, treat it as a label
1300 // reference needing a fixup.
1301 if (isImm() && !isa<MCConstantExpr>(getImm()))
1302 return true;
1303
1304 // If it is a constant, it must fit into a modified immediate encoding.
1305 if (!isImm()) return false;
1306 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1307 if (!CE) return false;
1308 int64_t Value = CE->getValue();
1309 return (ARM_AM::getSOImmVal(Value) != -1 ||
1310 ARM_AM::getSOImmVal(-Value) != -1);
1311 }
1312
1313 bool isT2SOImm() const {
1314 // If we have an immediate that's not a constant, treat it as an expression
1315 // needing a fixup.
1316 if (isImm() && !isa<MCConstantExpr>(getImm())) {
1317 // We want to avoid matching :upper16: and :lower16: as we want these
1318 // expressions to match in isImm0_65535Expr()
1319 auto *ARM16Expr = dyn_cast<MCSpecifierExpr>(getImm());
1320 return (!ARM16Expr || (ARM16Expr->getSpecifier() != ARM::S_HI16 &&
1321 ARM16Expr->getSpecifier() != ARM::S_LO16));
1322 }
1323 if (!isImm()) return false;
1324 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1325 if (!CE) return false;
1326 int64_t Value = CE->getValue();
1327 return ARM_AM::getT2SOImmVal(Value) != -1;
1328 }
1329
1330 bool isT2SOImmNot() 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 ARM_AM::getT2SOImmVal(Value) == -1 &&
1337 }
1338
1339 bool isT2SOImmNeg() const {
1340 if (!isImm()) return false;
1341 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1342 if (!CE) return false;
1343 int64_t Value = CE->getValue();
1344 // Only use this when not representable as a plain so_imm.
1345 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1347 }
1348
1349 bool isSetEndImm() const {
1350 if (!isImm()) return false;
1351 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1352 if (!CE) return false;
1353 int64_t Value = CE->getValue();
1354 return Value == 1 || Value == 0;
1355 }
1356
1357 bool isReg() const override { return Kind == k_Register; }
1358 bool isRegList() const { return Kind == k_RegisterList; }
1359 bool isRegListWithAPSR() const {
1360 return Kind == k_RegisterListWithAPSR || Kind == k_RegisterList;
1361 }
1362 bool isDReg() const {
1363 return isReg() &&
1364 getARMMCRegisterClass(ARM::DPRRegClassID).contains(Reg.RegNum);
1365 }
1366 bool isQReg() const {
1367 return isReg() &&
1368 getARMMCRegisterClass(ARM::QPRRegClassID).contains(Reg.RegNum);
1369 }
1370 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1371 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
1372 bool isFPSRegListWithVPR() const { return Kind == k_FPSRegisterListWithVPR; }
1373 bool isFPDRegListWithVPR() const { return Kind == k_FPDRegisterListWithVPR; }
1374 bool isToken() const override { return Kind == k_Token; }
1375 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
1376 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
1377 bool isTraceSyncBarrierOpt() const { return Kind == k_TraceSyncBarrierOpt; }
1378 bool isMem() const override {
1379 return isGPRMem() || isMVEMem();
1380 }
1381 bool isMVEMem() const {
1382 if (Kind != k_Memory)
1383 return false;
1384 if (Memory.BaseRegNum &&
1385 !getARMMCRegisterClass(ARM::GPRRegClassID)
1386 .contains(Memory.BaseRegNum) &&
1387 !getARMMCRegisterClass(ARM::MQPRRegClassID).contains(Memory.BaseRegNum))
1388 return false;
1389 if (Memory.OffsetRegNum && !getARMMCRegisterClass(ARM::MQPRRegClassID)
1390 .contains(Memory.OffsetRegNum))
1391 return false;
1392 return true;
1393 }
1394 bool isGPRMem() const {
1395 if (Kind != k_Memory)
1396 return false;
1397 if (Memory.BaseRegNum &&
1398 !getARMMCRegisterClass(ARM::GPRRegClassID).contains(Memory.BaseRegNum))
1399 return false;
1400 if (Memory.OffsetRegNum && !getARMMCRegisterClass(ARM::GPRRegClassID)
1401 .contains(Memory.OffsetRegNum))
1402 return false;
1403 return true;
1404 }
1405 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1406 bool isRegShiftedReg() const {
1407 return Kind == k_ShiftedRegister &&
1408 getARMMCRegisterClass(ARM::GPRRegClassID)
1409 .contains(RegShiftedReg.SrcReg) &&
1410 getARMMCRegisterClass(ARM::GPRRegClassID)
1411 .contains(RegShiftedReg.ShiftReg);
1412 }
1413 bool isRegShiftedImm() const {
1414 return Kind == k_ShiftedImmediate &&
1415 getARMMCRegisterClass(ARM::GPRRegClassID)
1416 .contains(RegShiftedImm.SrcReg);
1417 }
1418 bool isRotImm() const { return Kind == k_RotateImmediate; }
1419
1420 template<unsigned Min, unsigned Max>
1421 bool isPowerTwoInRange() const {
1422 if (!isImm()) return false;
1423 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1424 if (!CE) return false;
1425 int64_t Value = CE->getValue();
1426 return Value > 0 && llvm::popcount((uint64_t)Value) == 1 && Value >= Min &&
1427 Value <= Max;
1428 }
1429 bool isModImm() const { return Kind == k_ModifiedImmediate; }
1430
1431 bool isModImmNot() const {
1432 if (!isImm()) return false;
1433 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1434 if (!CE) return false;
1435 int64_t Value = CE->getValue();
1436 return ARM_AM::getSOImmVal(~Value) != -1;
1437 }
1438
1439 bool isModImmNeg() const {
1440 if (!isImm()) return false;
1441 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1442 if (!CE) return false;
1443 int64_t Value = CE->getValue();
1444 return ARM_AM::getSOImmVal(Value) == -1 &&
1445 ARM_AM::getSOImmVal(-Value) != -1;
1446 }
1447
1448 bool isThumbModImmNeg1_7() const {
1449 if (!isImm()) return false;
1450 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1451 if (!CE) return false;
1452 int32_t Value = -(int32_t)CE->getValue();
1453 return 0 < Value && Value < 8;
1454 }
1455
1456 bool isThumbModImmNeg8_255() const {
1457 if (!isImm()) return false;
1458 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1459 if (!CE) return false;
1460 int32_t Value = -(int32_t)CE->getValue();
1461 return 7 < Value && Value < 256;
1462 }
1463
1464 bool isConstantPoolImm() const { return Kind == k_ConstantPoolImmediate; }
1465 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1466 bool isPostIdxRegShifted() const {
1467 return Kind == k_PostIndexRegister &&
1468 getARMMCRegisterClass(ARM::GPRRegClassID)
1469 .contains(PostIdxReg.RegNum);
1470 }
1471 bool isPostIdxReg() const {
1472 return isPostIdxRegShifted() && PostIdxReg.ShiftTy == ARM_AM::no_shift;
1473 }
1474 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const {
1475 if (!isGPRMem())
1476 return false;
1477 // No offset of any kind.
1478 return !Memory.OffsetRegNum && Memory.OffsetImm == nullptr &&
1479 (alignOK || Memory.Alignment == Alignment);
1480 }
1481 bool isMemNoOffsetT2(bool alignOK = false, unsigned Alignment = 0) const {
1482 if (!isGPRMem())
1483 return false;
1484
1485 if (!getARMMCRegisterClass(ARM::GPRnopcRegClassID)
1486 .contains(Memory.BaseRegNum))
1487 return false;
1488
1489 // No offset of any kind.
1490 return !Memory.OffsetRegNum && Memory.OffsetImm == nullptr &&
1491 (alignOK || Memory.Alignment == Alignment);
1492 }
1493 bool isMemNoOffsetT2NoSp(bool alignOK = false, unsigned Alignment = 0) const {
1494 if (!isGPRMem())
1495 return false;
1496
1497 if (!getARMMCRegisterClass(ARM::rGPRRegClassID).contains(Memory.BaseRegNum))
1498 return false;
1499
1500 // No offset of any kind.
1501 return !Memory.OffsetRegNum && Memory.OffsetImm == nullptr &&
1502 (alignOK || Memory.Alignment == Alignment);
1503 }
1504 bool isMemNoOffsetT(bool alignOK = false, unsigned Alignment = 0) const {
1505 if (!isGPRMem())
1506 return false;
1507
1508 if (!getARMMCRegisterClass(ARM::tGPRRegClassID).contains(Memory.BaseRegNum))
1509 return false;
1510
1511 // No offset of any kind.
1512 return !Memory.OffsetRegNum && Memory.OffsetImm == nullptr &&
1513 (alignOK || Memory.Alignment == Alignment);
1514 }
1515 bool isMemPCRelImm12() const {
1516 if (!isGPRMem() || Memory.OffsetRegNum || Memory.Alignment != 0)
1517 return false;
1518 // Base register must be PC.
1519 if (Memory.BaseRegNum != ARM::PC)
1520 return false;
1521 // Immediate offset in range [-4095, 4095].
1522 if (!Memory.OffsetImm) return true;
1523 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1524 int64_t Val = CE->getValue();
1525 return (Val > -4096 && Val < 4096) ||
1526 (Val == std::numeric_limits<int32_t>::min());
1527 }
1528 return false;
1529 }
1530
1531 bool isAlignedMemory() const {
1532 return isMemNoOffset(true);
1533 }
1534
1535 bool isAlignedMemoryNone() const {
1536 return isMemNoOffset(false, 0);
1537 }
1538
1539 bool isDupAlignedMemoryNone() const {
1540 return isMemNoOffset(false, 0);
1541 }
1542
1543 bool isAlignedMemory16() const {
1544 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1545 return true;
1546 return isMemNoOffset(false, 0);
1547 }
1548
1549 bool isDupAlignedMemory16() const {
1550 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1551 return true;
1552 return isMemNoOffset(false, 0);
1553 }
1554
1555 bool isAlignedMemory32() const {
1556 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1557 return true;
1558 return isMemNoOffset(false, 0);
1559 }
1560
1561 bool isDupAlignedMemory32() const {
1562 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1563 return true;
1564 return isMemNoOffset(false, 0);
1565 }
1566
1567 bool isAlignedMemory64() const {
1568 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1569 return true;
1570 return isMemNoOffset(false, 0);
1571 }
1572
1573 bool isDupAlignedMemory64() const {
1574 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1575 return true;
1576 return isMemNoOffset(false, 0);
1577 }
1578
1579 bool isAlignedMemory64or128() const {
1580 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1581 return true;
1582 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1583 return true;
1584 return isMemNoOffset(false, 0);
1585 }
1586
1587 bool isDupAlignedMemory64or128() const {
1588 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1589 return true;
1590 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1591 return true;
1592 return isMemNoOffset(false, 0);
1593 }
1594
1595 bool isAlignedMemory64or128or256() const {
1596 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1597 return true;
1598 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1599 return true;
1600 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
1601 return true;
1602 return isMemNoOffset(false, 0);
1603 }
1604
1605 bool isAddrMode2() const {
1606 if (!isGPRMem() || Memory.Alignment != 0) return false;
1607 // Check for register offset.
1608 if (Memory.OffsetRegNum) return true;
1609 // Immediate offset in range [-4095, 4095].
1610 if (!Memory.OffsetImm) return true;
1611 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1612 int64_t Val = CE->getValue();
1613 return Val > -4096 && Val < 4096;
1614 }
1615 return false;
1616 }
1617
1618 bool isAM2OffsetImm() const {
1619 if (!isImm()) return false;
1620 // Immediate offset in range [-4095, 4095].
1621 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1622 if (!CE) return false;
1623 int64_t Val = CE->getValue();
1624 return (Val == std::numeric_limits<int32_t>::min()) ||
1625 (Val > -4096 && Val < 4096);
1626 }
1627
1628 bool isAddrMode3() const {
1629 // If we have an immediate that's not a constant, treat it as a label
1630 // reference needing a fixup. If it is a constant, it's something else
1631 // and we reject it.
1632 if (isImm() && !isa<MCConstantExpr>(getImm()))
1633 return true;
1634 if (!isGPRMem() || Memory.Alignment != 0) return false;
1635 // No shifts are legal for AM3.
1636 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1637 // Check for register offset.
1638 if (Memory.OffsetRegNum) return true;
1639 // Immediate offset in range [-255, 255].
1640 if (!Memory.OffsetImm) return true;
1641 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1642 int64_t Val = CE->getValue();
1643 // The #-0 offset is encoded as std::numeric_limits<int32_t>::min(), and
1644 // we have to check for this too.
1645 return (Val > -256 && Val < 256) ||
1646 Val == std::numeric_limits<int32_t>::min();
1647 }
1648 return false;
1649 }
1650
1651 bool isAM3Offset() const {
1652 if (isPostIdxReg())
1653 return true;
1654 if (!isImm())
1655 return false;
1656 // Immediate offset in range [-255, 255].
1657 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1658 if (!CE) return false;
1659 int64_t Val = CE->getValue();
1660 // Special case, #-0 is std::numeric_limits<int32_t>::min().
1661 return (Val > -256 && Val < 256) ||
1662 Val == std::numeric_limits<int32_t>::min();
1663 }
1664
1665 bool isAddrMode5() const {
1666 // If we have an immediate that's not a constant, treat it as a label
1667 // reference needing a fixup. If it is a constant, it's something else
1668 // and we reject it.
1669 if (isImm() && !isa<MCConstantExpr>(getImm()))
1670 return true;
1671 if (!isGPRMem() || Memory.Alignment != 0) return false;
1672 // Check for register offset.
1673 if (Memory.OffsetRegNum) return false;
1674 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1675 if (!Memory.OffsetImm) return true;
1676 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1677 int64_t Val = CE->getValue();
1678 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1679 Val == std::numeric_limits<int32_t>::min();
1680 }
1681 return false;
1682 }
1683
1684 bool isAddrMode5FP16() const {
1685 // If we have an immediate that's not a constant, treat it as a label
1686 // reference needing a fixup. If it is a constant, it's something else
1687 // and we reject it.
1688 if (isImm() && !isa<MCConstantExpr>(getImm()))
1689 return true;
1690 if (!isGPRMem() || Memory.Alignment != 0) return false;
1691 // Check for register offset.
1692 if (Memory.OffsetRegNum) return false;
1693 // Immediate offset in range [-510, 510] and a multiple of 2.
1694 if (!Memory.OffsetImm) return true;
1695 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1696 int64_t Val = CE->getValue();
1697 return (Val >= -510 && Val <= 510 && ((Val & 1) == 0)) ||
1698 Val == std::numeric_limits<int32_t>::min();
1699 }
1700 return false;
1701 }
1702
1703 bool isMemTBB() const {
1704 if (!isGPRMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1705 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1706 return false;
1707 return true;
1708 }
1709
1710 bool isMemTBH() const {
1711 if (!isGPRMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1712 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1713 Memory.Alignment != 0 )
1714 return false;
1715 return true;
1716 }
1717
1718 bool isMemRegOffset() const {
1719 if (!isGPRMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1720 return false;
1721 return true;
1722 }
1723
1724 bool isT2MemRegOffset() const {
1725 if (!isGPRMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1726 Memory.Alignment != 0 || Memory.BaseRegNum == ARM::PC)
1727 return false;
1728 // Only lsl #{0, 1, 2, 3} allowed.
1729 if (Memory.ShiftType == ARM_AM::no_shift)
1730 return true;
1731 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1732 return false;
1733 return true;
1734 }
1735
1736 bool isMemThumbRR() const {
1737 // Thumb reg+reg addressing is simple. Just two registers, a base and
1738 // an offset. No shifts, negations or any other complicating factors.
1739 if (!isGPRMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1740 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1741 return false;
1742 return isARMLowRegister(Memory.BaseRegNum) &&
1743 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1744 }
1745
1746 bool isMemThumbRIs4() const {
1747 if (!isGPRMem() || Memory.OffsetRegNum ||
1748 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1749 return false;
1750 // Immediate offset, multiple of 4 in range [0, 124].
1751 if (!Memory.OffsetImm) return true;
1752 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1753 int64_t Val = CE->getValue();
1754 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1755 }
1756 return false;
1757 }
1758
1759 bool isMemThumbRIs2() const {
1760 if (!isGPRMem() || Memory.OffsetRegNum ||
1761 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1762 return false;
1763 // Immediate offset, multiple of 4 in range [0, 62].
1764 if (!Memory.OffsetImm) return true;
1765 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1766 int64_t Val = CE->getValue();
1767 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1768 }
1769 return false;
1770 }
1771
1772 bool isMemThumbRIs1() const {
1773 if (!isGPRMem() || Memory.OffsetRegNum ||
1774 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1775 return false;
1776 // Immediate offset in range [0, 31].
1777 if (!Memory.OffsetImm) return true;
1778 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1779 int64_t Val = CE->getValue();
1780 return Val >= 0 && Val <= 31;
1781 }
1782 return false;
1783 }
1784
1785 bool isMemThumbSPI() const {
1786 if (!isGPRMem() || Memory.OffsetRegNum || Memory.BaseRegNum != ARM::SP ||
1787 Memory.Alignment != 0)
1788 return false;
1789 // Immediate offset, multiple of 4 in range [0, 1020].
1790 if (!Memory.OffsetImm) return true;
1791 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1792 int64_t Val = CE->getValue();
1793 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1794 }
1795 return false;
1796 }
1797
1798 bool isMemImm8s4Offset() const {
1799 // If we have an immediate that's not a constant, treat it as a label
1800 // reference needing a fixup. If it is a constant, it's something else
1801 // and we reject it.
1802 if (isImm() && !isa<MCConstantExpr>(getImm()))
1803 return true;
1804 if (!isGPRMem() || Memory.OffsetRegNum || Memory.Alignment != 0)
1805 return false;
1806 // Immediate offset a multiple of 4 in range [-1020, 1020].
1807 if (!Memory.OffsetImm) return true;
1808 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1809 int64_t Val = CE->getValue();
1810 // Special case, #-0 is std::numeric_limits<int32_t>::min().
1811 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) ||
1812 Val == std::numeric_limits<int32_t>::min();
1813 }
1814 return false;
1815 }
1816
1817 bool isMemImm7s4Offset() const {
1818 // If we have an immediate that's not a constant, treat it as a label
1819 // reference needing a fixup. If it is a constant, it's something else
1820 // and we reject it.
1821 if (isImm() && !isa<MCConstantExpr>(getImm()))
1822 return true;
1823 if (!isGPRMem() || Memory.OffsetRegNum || Memory.Alignment != 0 ||
1824 !getARMMCRegisterClass(ARM::GPRnopcRegClassID)
1825 .contains(Memory.BaseRegNum))
1826 return false;
1827 // Immediate offset a multiple of 4 in range [-508, 508].
1828 if (!Memory.OffsetImm) return true;
1829 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1830 int64_t Val = CE->getValue();
1831 // Special case, #-0 is INT32_MIN.
1832 return (Val >= -508 && Val <= 508 && (Val & 3) == 0) || Val == INT32_MIN;
1833 }
1834 return false;
1835 }
1836
1837 bool isMemImm0_1020s4Offset() const {
1838 if (!isGPRMem() || Memory.OffsetRegNum || Memory.Alignment != 0)
1839 return false;
1840 // Immediate offset a multiple of 4 in range [0, 1020].
1841 if (!Memory.OffsetImm) return true;
1842 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1843 int64_t Val = CE->getValue();
1844 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1845 }
1846 return false;
1847 }
1848
1849 bool isMemImm8Offset() const {
1850 if (!isGPRMem() || Memory.OffsetRegNum || Memory.Alignment != 0)
1851 return false;
1852 // Base reg of PC isn't allowed for these encodings.
1853 if (Memory.BaseRegNum == ARM::PC) return false;
1854 // Immediate offset in range [-255, 255].
1855 if (!Memory.OffsetImm) return true;
1856 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1857 int64_t Val = CE->getValue();
1858 return (Val == std::numeric_limits<int32_t>::min()) ||
1859 (Val > -256 && Val < 256);
1860 }
1861 return false;
1862 }
1863
1864 template<unsigned Bits, unsigned RegClassID>
1865 bool isMemImm7ShiftedOffset() const {
1866 if (!isGPRMem() || Memory.OffsetRegNum || Memory.Alignment != 0 ||
1867 !getARMMCRegisterClass(RegClassID).contains(Memory.BaseRegNum))
1868 return false;
1869
1870 // Expect an immediate offset equal to an element of the range
1871 // [-127, 127], shifted left by Bits.
1872
1873 if (!Memory.OffsetImm) return true;
1874 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1875 int64_t Val = CE->getValue();
1876
1877 // INT32_MIN is a special-case value (indicating the encoding with
1878 // zero offset and the subtract bit set)
1879 if (Val == INT32_MIN)
1880 return true;
1881
1882 unsigned Divisor = 1U << Bits;
1883
1884 // Check that the low bits are zero
1885 if (Val % Divisor != 0)
1886 return false;
1887
1888 // Check that the remaining offset is within range.
1889 Val /= Divisor;
1890 return (Val >= -127 && Val <= 127);
1891 }
1892 return false;
1893 }
1894
1895 template <int shift> bool isMemRegRQOffset() const {
1896 if (!isMVEMem() || Memory.OffsetImm != nullptr || Memory.Alignment != 0)
1897 return false;
1898
1899 if (!getARMMCRegisterClass(ARM::GPRnopcRegClassID)
1900 .contains(Memory.BaseRegNum))
1901 return false;
1902 if (!getARMMCRegisterClass(ARM::MQPRRegClassID)
1903 .contains(Memory.OffsetRegNum))
1904 return false;
1905
1906 if (shift == 0 && Memory.ShiftType != ARM_AM::no_shift)
1907 return false;
1908
1909 if (shift > 0 &&
1910 (Memory.ShiftType != ARM_AM::uxtw || Memory.ShiftImm != shift))
1911 return false;
1912
1913 return true;
1914 }
1915
1916 template <int shift> bool isMemRegQOffset() const {
1917 if (!isMVEMem() || Memory.OffsetRegNum || Memory.Alignment != 0)
1918 return false;
1919
1920 if (!getARMMCRegisterClass(ARM::MQPRRegClassID).contains(Memory.BaseRegNum))
1921 return false;
1922
1923 if (!Memory.OffsetImm)
1924 return true;
1925 static_assert(shift < 56,
1926 "Such that we dont shift by a value higher than 62");
1927 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1928 int64_t Val = CE->getValue();
1929
1930 // The value must be a multiple of (1 << shift)
1931 if ((Val & ((1U << shift) - 1)) != 0)
1932 return false;
1933
1934 // And be in the right range, depending on the amount that it is shifted
1935 // by. Shift 0, is equal to 7 unsigned bits, the sign bit is set
1936 // separately.
1937 int64_t Range = (1U << (7 + shift)) - 1;
1938 return (Val == INT32_MIN) || (Val > -Range && Val < Range);
1939 }
1940 return false;
1941 }
1942
1943 bool isMemPosImm8Offset() const {
1944 if (!isGPRMem() || Memory.OffsetRegNum || Memory.Alignment != 0)
1945 return false;
1946 // Immediate offset in range [0, 255].
1947 if (!Memory.OffsetImm) return true;
1948 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1949 int64_t Val = CE->getValue();
1950 return Val >= 0 && Val < 256;
1951 }
1952 return false;
1953 }
1954
1955 bool isMemNegImm8Offset() const {
1956 if (!isGPRMem() || Memory.OffsetRegNum || Memory.Alignment != 0)
1957 return false;
1958 // Base reg of PC isn't allowed for these encodings.
1959 if (Memory.BaseRegNum == ARM::PC) return false;
1960 // Immediate offset in range [-255, -1].
1961 if (!Memory.OffsetImm) return false;
1962 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1963 int64_t Val = CE->getValue();
1964 return (Val == std::numeric_limits<int32_t>::min()) ||
1965 (Val > -256 && Val < 0);
1966 }
1967 return false;
1968 }
1969
1970 bool isMemUImm12Offset() const {
1971 if (!isGPRMem() || Memory.OffsetRegNum || Memory.Alignment != 0)
1972 return false;
1973 // Immediate offset in range [0, 4095].
1974 if (!Memory.OffsetImm) return true;
1975 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1976 int64_t Val = CE->getValue();
1977 return (Val >= 0 && Val < 4096);
1978 }
1979 return false;
1980 }
1981
1982 bool isMemImm12Offset() const {
1983 // If we have an immediate that's not a constant, treat it as a label
1984 // reference needing a fixup. If it is a constant, it's something else
1985 // and we reject it.
1986
1987 if (isImm() && !isa<MCConstantExpr>(getImm()))
1988 return true;
1989
1990 if (!isGPRMem() || Memory.OffsetRegNum || Memory.Alignment != 0)
1991 return false;
1992 // Immediate offset in range [-4095, 4095].
1993 if (!Memory.OffsetImm) return true;
1994 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
1995 int64_t Val = CE->getValue();
1996 return (Val > -4096 && Val < 4096) ||
1997 (Val == std::numeric_limits<int32_t>::min());
1998 }
1999 // If we have an immediate that's not a constant, treat it as a
2000 // symbolic expression needing a fixup.
2001 return true;
2002 }
2003
2004 bool isConstPoolAsmImm() const {
2005 // Delay processing of Constant Pool Immediate, this will turn into
2006 // a constant. Match no other operand
2007 return (isConstantPoolImm());
2008 }
2009
2010 bool isPostIdxImm8() const {
2011 if (!isImm()) return false;
2012 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2013 if (!CE) return false;
2014 int64_t Val = CE->getValue();
2015 return (Val > -256 && Val < 256) ||
2016 (Val == std::numeric_limits<int32_t>::min());
2017 }
2018
2019 bool isPostIdxImm8s4() const {
2020 if (!isImm()) return false;
2021 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2022 if (!CE) return false;
2023 int64_t Val = CE->getValue();
2024 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
2025 (Val == std::numeric_limits<int32_t>::min());
2026 }
2027
2028 bool isMSRMask() const { return Kind == k_MSRMask; }
2029 bool isBankedReg() const { return Kind == k_BankedReg; }
2030 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
2031
2032 // NEON operands.
2033 bool isAnyVectorList() const {
2034 return Kind == k_VectorList || Kind == k_VectorListAllLanes ||
2035 Kind == k_VectorListIndexed;
2036 }
2037
2038 bool isVectorList() const { return Kind == k_VectorList; }
2039
2040 bool isSingleSpacedVectorList() const {
2041 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
2042 }
2043
2044 bool isDoubleSpacedVectorList() const {
2045 return Kind == k_VectorList && VectorList.isDoubleSpaced;
2046 }
2047
2048 bool isVecListOneD() const {
2049 // We convert a single D reg to a list containing a D reg
2050 if (isDReg() && !Parser->hasMVE())
2051 return true;
2052 if (!isSingleSpacedVectorList()) return false;
2053 return VectorList.Count == 1;
2054 }
2055
2056 bool isVecListTwoMQ() const {
2057 return isSingleSpacedVectorList() && VectorList.Count == 2 &&
2058 getARMMCRegisterClass(ARM::MQPRRegClassID)
2059 .contains(VectorList.RegNum);
2060 }
2061
2062 bool isVecListDPair() const {
2063 // We convert a single Q reg to a list with the two corresponding D
2064 // registers
2065 if (isQReg() && !Parser->hasMVE())
2066 return true;
2067 if (!isSingleSpacedVectorList()) return false;
2068 return (getARMMCRegisterClass(ARM::DPairRegClassID)
2069 .contains(VectorList.RegNum));
2070 }
2071
2072 bool isVecListThreeD() const {
2073 if (!isSingleSpacedVectorList()) return false;
2074 return VectorList.Count == 3;
2075 }
2076
2077 bool isVecListFourD() const {
2078 if (!isSingleSpacedVectorList()) return false;
2079 return VectorList.Count == 4;
2080 }
2081
2082 bool isVecListDPairSpaced() const {
2083 if (Kind != k_VectorList) return false;
2084 if (isSingleSpacedVectorList()) return false;
2085 return (getARMMCRegisterClass(ARM::DPairSpcRegClassID)
2086 .contains(VectorList.RegNum));
2087 }
2088
2089 bool isVecListThreeQ() const {
2090 if (!isDoubleSpacedVectorList()) return false;
2091 return VectorList.Count == 3;
2092 }
2093
2094 bool isVecListFourQ() const {
2095 if (!isDoubleSpacedVectorList()) return false;
2096 return VectorList.Count == 4;
2097 }
2098
2099 bool isVecListFourMQ() const {
2100 return isSingleSpacedVectorList() && VectorList.Count == 4 &&
2101 getARMMCRegisterClass(ARM::MQPRRegClassID)
2102 .contains(VectorList.RegNum);
2103 }
2104
2105 bool isSingleSpacedVectorAllLanes() const {
2106 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
2107 }
2108
2109 bool isDoubleSpacedVectorAllLanes() const {
2110 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
2111 }
2112
2113 bool isVecListOneDAllLanes() const {
2114 if (!isSingleSpacedVectorAllLanes()) return false;
2115 return VectorList.Count == 1;
2116 }
2117
2118 bool isVecListDPairAllLanes() const {
2119 if (!isSingleSpacedVectorAllLanes()) return false;
2120 return (getARMMCRegisterClass(ARM::DPairRegClassID)
2121 .contains(VectorList.RegNum));
2122 }
2123
2124 bool isVecListDPairSpacedAllLanes() const {
2125 if (!isDoubleSpacedVectorAllLanes()) return false;
2126 return VectorList.Count == 2;
2127 }
2128
2129 bool isVecListThreeDAllLanes() const {
2130 if (!isSingleSpacedVectorAllLanes()) return false;
2131 return VectorList.Count == 3;
2132 }
2133
2134 bool isVecListThreeQAllLanes() const {
2135 if (!isDoubleSpacedVectorAllLanes()) return false;
2136 return VectorList.Count == 3;
2137 }
2138
2139 bool isVecListFourDAllLanes() const {
2140 if (!isSingleSpacedVectorAllLanes()) return false;
2141 return VectorList.Count == 4;
2142 }
2143
2144 bool isVecListFourQAllLanes() const {
2145 if (!isDoubleSpacedVectorAllLanes()) return false;
2146 return VectorList.Count == 4;
2147 }
2148
2149 bool isSingleSpacedVectorIndexed() const {
2150 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
2151 }
2152
2153 bool isDoubleSpacedVectorIndexed() const {
2154 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
2155 }
2156
2157 bool isVecListOneDByteIndexed() const {
2158 if (!isSingleSpacedVectorIndexed()) return false;
2159 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
2160 }
2161
2162 bool isVecListOneDHWordIndexed() const {
2163 if (!isSingleSpacedVectorIndexed()) return false;
2164 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
2165 }
2166
2167 bool isVecListOneDWordIndexed() const {
2168 if (!isSingleSpacedVectorIndexed()) return false;
2169 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
2170 }
2171
2172 bool isVecListTwoDByteIndexed() const {
2173 if (!isSingleSpacedVectorIndexed()) return false;
2174 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
2175 }
2176
2177 bool isVecListTwoDHWordIndexed() const {
2178 if (!isSingleSpacedVectorIndexed()) return false;
2179 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
2180 }
2181
2182 bool isVecListTwoQWordIndexed() const {
2183 if (!isDoubleSpacedVectorIndexed()) return false;
2184 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
2185 }
2186
2187 bool isVecListTwoQHWordIndexed() const {
2188 if (!isDoubleSpacedVectorIndexed()) return false;
2189 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
2190 }
2191
2192 bool isVecListTwoDWordIndexed() const {
2193 if (!isSingleSpacedVectorIndexed()) return false;
2194 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
2195 }
2196
2197 bool isVecListThreeDByteIndexed() const {
2198 if (!isSingleSpacedVectorIndexed()) return false;
2199 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
2200 }
2201
2202 bool isVecListThreeDHWordIndexed() const {
2203 if (!isSingleSpacedVectorIndexed()) return false;
2204 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
2205 }
2206
2207 bool isVecListThreeQWordIndexed() const {
2208 if (!isDoubleSpacedVectorIndexed()) return false;
2209 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
2210 }
2211
2212 bool isVecListThreeQHWordIndexed() const {
2213 if (!isDoubleSpacedVectorIndexed()) return false;
2214 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
2215 }
2216
2217 bool isVecListThreeDWordIndexed() const {
2218 if (!isSingleSpacedVectorIndexed()) return false;
2219 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
2220 }
2221
2222 bool isVecListFourDByteIndexed() const {
2223 if (!isSingleSpacedVectorIndexed()) return false;
2224 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
2225 }
2226
2227 bool isVecListFourDHWordIndexed() const {
2228 if (!isSingleSpacedVectorIndexed()) return false;
2229 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
2230 }
2231
2232 bool isVecListFourQWordIndexed() const {
2233 if (!isDoubleSpacedVectorIndexed()) return false;
2234 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
2235 }
2236
2237 bool isVecListFourQHWordIndexed() const {
2238 if (!isDoubleSpacedVectorIndexed()) return false;
2239 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
2240 }
2241
2242 bool isVecListFourDWordIndexed() const {
2243 if (!isSingleSpacedVectorIndexed()) return false;
2244 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
2245 }
2246
2247 bool isVectorIndex() const { return Kind == k_VectorIndex; }
2248
2249 template <unsigned NumLanes>
2250 bool isVectorIndexInRange() const {
2251 if (Kind != k_VectorIndex) return false;
2252 return VectorIndex.Val < NumLanes;
2253 }
2254
2255 bool isVectorIndex8() const { return isVectorIndexInRange<8>(); }
2256 bool isVectorIndex16() const { return isVectorIndexInRange<4>(); }
2257 bool isVectorIndex32() const { return isVectorIndexInRange<2>(); }
2258 bool isVectorIndex64() const { return isVectorIndexInRange<1>(); }
2259
2260 template<int PermittedValue, int OtherPermittedValue>
2261 bool isMVEPairVectorIndex() const {
2262 if (Kind != k_VectorIndex) return false;
2263 return VectorIndex.Val == PermittedValue ||
2264 VectorIndex.Val == OtherPermittedValue;
2265 }
2266
2267 bool isNEONi8splat() const {
2268 if (!isImm()) return false;
2269 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2270 // Must be a constant.
2271 if (!CE) return false;
2272 int64_t Value = CE->getValue();
2273 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
2274 // value.
2275 return Value >= 0 && Value < 256;
2276 }
2277
2278 bool isNEONi16splat() const {
2279 if (isNEONByteReplicate(2))
2280 return false; // Leave that for bytes replication and forbid by default.
2281 if (!isImm())
2282 return false;
2283 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2284 // Must be a constant.
2285 if (!CE) return false;
2286 unsigned Value = CE->getValue();
2288 }
2289
2290 bool isNEONi16splatNot() const {
2291 if (!isImm())
2292 return false;
2293 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2294 // Must be a constant.
2295 if (!CE) return false;
2296 unsigned Value = CE->getValue();
2297 return ARM_AM::isNEONi16splat(~Value & 0xffff);
2298 }
2299
2300 bool isNEONi32splat() const {
2301 if (isNEONByteReplicate(4))
2302 return false; // Leave that for bytes replication and forbid by default.
2303 if (!isImm())
2304 return false;
2305 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2306 // Must be a constant.
2307 if (!CE) return false;
2308 unsigned Value = CE->getValue();
2310 }
2311
2312 bool isNEONi32splatNot() const {
2313 if (!isImm())
2314 return false;
2315 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2316 // Must be a constant.
2317 if (!CE) return false;
2318 unsigned Value = CE->getValue();
2320 }
2321
2322 static bool isValidNEONi32vmovImm(int64_t Value) {
2323 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
2324 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
2325 return ((Value & 0xffffffffffffff00) == 0) ||
2326 ((Value & 0xffffffffffff00ff) == 0) ||
2327 ((Value & 0xffffffffff00ffff) == 0) ||
2328 ((Value & 0xffffffff00ffffff) == 0) ||
2329 ((Value & 0xffffffffffff00ff) == 0xff) ||
2330 ((Value & 0xffffffffff00ffff) == 0xffff);
2331 }
2332
2333 bool isNEONReplicate(unsigned Width, unsigned NumElems, bool Inv) const {
2334 assert((Width == 8 || Width == 16 || Width == 32) &&
2335 "Invalid element width");
2336 assert(NumElems * Width <= 64 && "Invalid result width");
2337
2338 if (!isImm())
2339 return false;
2340 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2341 // Must be a constant.
2342 if (!CE)
2343 return false;
2344 int64_t Value = CE->getValue();
2345 if (!Value)
2346 return false; // Don't bother with zero.
2347 if (Inv)
2348 Value = ~Value;
2349
2350 uint64_t Mask = (1ull << Width) - 1;
2351 uint64_t Elem = Value & Mask;
2352 if (Width == 16 && (Elem & 0x00ff) != 0 && (Elem & 0xff00) != 0)
2353 return false;
2354 if (Width == 32 && !isValidNEONi32vmovImm(Elem))
2355 return false;
2356
2357 for (unsigned i = 1; i < NumElems; ++i) {
2358 Value >>= Width;
2359 if ((Value & Mask) != Elem)
2360 return false;
2361 }
2362 return true;
2363 }
2364
2365 bool isNEONByteReplicate(unsigned NumBytes) const {
2366 return isNEONReplicate(8, NumBytes, false);
2367 }
2368
2369 static void checkNeonReplicateArgs(unsigned FromW, unsigned ToW) {
2370 assert((FromW == 8 || FromW == 16 || FromW == 32) &&
2371 "Invalid source width");
2372 assert((ToW == 16 || ToW == 32 || ToW == 64) &&
2373 "Invalid destination width");
2374 assert(FromW < ToW && "ToW is not less than FromW");
2375 }
2376
2377 template<unsigned FromW, unsigned ToW>
2378 bool isNEONmovReplicate() const {
2379 checkNeonReplicateArgs(FromW, ToW);
2380 if (ToW == 64 && isNEONi64splat())
2381 return false;
2382 return isNEONReplicate(FromW, ToW / FromW, false);
2383 }
2384
2385 template<unsigned FromW, unsigned ToW>
2386 bool isNEONinvReplicate() const {
2387 checkNeonReplicateArgs(FromW, ToW);
2388 return isNEONReplicate(FromW, ToW / FromW, true);
2389 }
2390
2391 bool isNEONi32vmov() const {
2392 if (isNEONByteReplicate(4))
2393 return false; // Let it to be classified as byte-replicate case.
2394 if (!isImm())
2395 return false;
2396 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2397 // Must be a constant.
2398 if (!CE)
2399 return false;
2400 return isValidNEONi32vmovImm(CE->getValue());
2401 }
2402
2403 bool isNEONi32vmovNeg() const {
2404 if (!isImm()) return false;
2405 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2406 // Must be a constant.
2407 if (!CE) return false;
2408 return isValidNEONi32vmovImm(~CE->getValue());
2409 }
2410
2411 bool isNEONi64splat() const {
2412 if (!isImm()) return false;
2413 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2414 // Must be a constant.
2415 if (!CE) return false;
2416 uint64_t Value = CE->getValue();
2417 // i64 value with each byte being either 0 or 0xff.
2418 for (unsigned i = 0; i < 8; ++i, Value >>= 8)
2419 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
2420 return true;
2421 }
2422
2423 template<int64_t Angle, int64_t Remainder>
2424 bool isComplexRotation() const {
2425 if (!isImm()) return false;
2426
2427 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2428 if (!CE) return false;
2429 uint64_t Value = CE->getValue();
2430
2431 return (Value % Angle == Remainder && Value <= 270);
2432 }
2433
2434 bool isMVELongShift() const {
2435 if (!isImm()) return false;
2436 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2437 // Must be a constant.
2438 if (!CE) return false;
2439 uint64_t Value = CE->getValue();
2440 return Value >= 1 && Value <= 32;
2441 }
2442
2443 bool isMveSaturateOp() const {
2444 if (!isImm()) return false;
2445 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2446 if (!CE) return false;
2447 uint64_t Value = CE->getValue();
2448 return Value == 48 || Value == 64;
2449 }
2450
2451 bool isITCondCodeNoAL() const {
2452 if (!isITCondCode()) return false;
2454 return CC != ARMCC::AL;
2455 }
2456
2457 bool isITCondCodeRestrictedI() const {
2458 if (!isITCondCode())
2459 return false;
2461 return CC == ARMCC::EQ || CC == ARMCC::NE;
2462 }
2463
2464 bool isITCondCodeRestrictedS() const {
2465 if (!isITCondCode())
2466 return false;
2468 return CC == ARMCC::LT || CC == ARMCC::GT || CC == ARMCC::LE ||
2469 CC == ARMCC::GE;
2470 }
2471
2472 bool isITCondCodeRestrictedU() const {
2473 if (!isITCondCode())
2474 return false;
2476 return CC == ARMCC::HS || CC == ARMCC::HI;
2477 }
2478
2479 bool isITCondCodeRestrictedFP() const {
2480 if (!isITCondCode())
2481 return false;
2483 return CC == ARMCC::EQ || CC == ARMCC::NE || CC == ARMCC::LT ||
2484 CC == ARMCC::GT || CC == ARMCC::LE || CC == ARMCC::GE;
2485 }
2486
2487 void setVecListDPair(unsigned int DPair) {
2488 Kind = k_VectorList;
2489 VectorList.RegNum = DPair;
2490 VectorList.Count = 2;
2491 VectorList.isDoubleSpaced = false;
2492 }
2493
2494 void setVecListOneD(unsigned int DReg) {
2495 Kind = k_VectorList;
2496 VectorList.RegNum = DReg;
2497 VectorList.Count = 1;
2498 VectorList.isDoubleSpaced = false;
2499 }
2500
2501 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
2502 // Add as immediates when possible. Null MCExpr = 0.
2503 if (!Expr)
2505 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
2506 Inst.addOperand(MCOperand::createImm(CE->getValue()));
2507 else
2509 }
2510
2511 void addARMBranchTargetOperands(MCInst &Inst, unsigned N) const {
2512 assert(N == 1 && "Invalid number of operands!");
2513 addExpr(Inst, getImm());
2514 }
2515
2516 void addThumbBranchTargetOperands(MCInst &Inst, unsigned N) const {
2517 assert(N == 1 && "Invalid number of operands!");
2518 addExpr(Inst, getImm());
2519 }
2520
2521 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
2522 assert(N == 2 && "Invalid number of operands!");
2523 Inst.addOperand(MCOperand::createImm(unsigned(getCondCode())));
2524 unsigned RegNum = getCondCode() == ARMCC::AL ? ARM::NoRegister : ARM::CPSR;
2525 Inst.addOperand(MCOperand::createReg(RegNum));
2526 }
2527
2528 void addVPTPredNOperands(MCInst &Inst, unsigned N) const {
2529 assert(N == 3 && "Invalid number of operands!");
2530 Inst.addOperand(MCOperand::createImm(unsigned(getVPTPred())));
2531 unsigned RegNum = getVPTPred() == ARMVCC::None ? ARM::NoRegister : ARM::P0;
2532 Inst.addOperand(MCOperand::createReg(RegNum));
2534 }
2535
2536 void addVPTPredROperands(MCInst &Inst, unsigned N) const {
2537 assert(N == 4 && "Invalid number of operands!");
2538 addVPTPredNOperands(Inst, N-1);
2539 MCRegister RegNum;
2540 if (getVPTPred() == ARMVCC::None) {
2541 RegNum = ARM::NoRegister;
2542 } else {
2543 unsigned NextOpIndex = Inst.getNumOperands();
2544 auto &MCID = Parser->getInstrDesc(Inst.getOpcode());
2545 int TiedOp = MCID.getOperandConstraint(NextOpIndex, MCOI::TIED_TO);
2546 assert(TiedOp >= 0 &&
2547 "Inactive register in vpred_r is not tied to an output!");
2548 RegNum = Inst.getOperand(TiedOp).getReg();
2549 }
2550 Inst.addOperand(MCOperand::createReg(RegNum));
2551 }
2552
2553 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
2554 assert(N == 1 && "Invalid number of operands!");
2555 Inst.addOperand(MCOperand::createImm(getCoproc()));
2556 }
2557
2558 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
2559 assert(N == 1 && "Invalid number of operands!");
2560 Inst.addOperand(MCOperand::createImm(getCoproc()));
2561 }
2562
2563 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
2564 assert(N == 1 && "Invalid number of operands!");
2565 Inst.addOperand(MCOperand::createImm(CoprocOption.Val));
2566 }
2567
2568 void addITMaskOperands(MCInst &Inst, unsigned N) const {
2569 assert(N == 1 && "Invalid number of operands!");
2570 Inst.addOperand(MCOperand::createImm(ITMask.Mask));
2571 }
2572
2573 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
2574 assert(N == 1 && "Invalid number of operands!");
2575 Inst.addOperand(MCOperand::createImm(unsigned(getCondCode())));
2576 }
2577
2578 void addITCondCodeInvOperands(MCInst &Inst, unsigned N) const {
2579 assert(N == 1 && "Invalid number of operands!");
2581 }
2582
2583 void addCCOutOperands(MCInst &Inst, unsigned N) const {
2584 assert(N == 1 && "Invalid number of operands!");
2586 }
2587
2588 void addRegOperands(MCInst &Inst, unsigned N) const {
2589 assert(N == 1 && "Invalid number of operands!");
2591 }
2592
2593 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
2594 assert(N == 3 && "Invalid number of operands!");
2595 assert(isRegShiftedReg() &&
2596 "addRegShiftedRegOperands() on non-RegShiftedReg!");
2597 Inst.addOperand(MCOperand::createReg(RegShiftedReg.SrcReg));
2598 Inst.addOperand(MCOperand::createReg(RegShiftedReg.ShiftReg));
2600 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
2601 }
2602
2603 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
2604 assert(N == 2 && "Invalid number of operands!");
2605 assert(isRegShiftedImm() &&
2606 "addRegShiftedImmOperands() on non-RegShiftedImm!");
2607 Inst.addOperand(MCOperand::createReg(RegShiftedImm.SrcReg));
2608 // Shift of #32 is encoded as 0 where permitted
2609 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
2611 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
2612 }
2613
2614 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
2615 assert(N == 1 && "Invalid number of operands!");
2616 Inst.addOperand(MCOperand::createImm((ShifterImm.isASR << 5) |
2617 ShifterImm.Imm));
2618 }
2619
2620 void addRegListOperands(MCInst &Inst, unsigned N) const {
2621 assert(N == 1 && "Invalid number of operands!");
2622 const SmallVectorImpl<MCRegister> &RegList = getRegList();
2623 for (MCRegister Reg : RegList)
2625 }
2626
2627 void addRegListWithAPSROperands(MCInst &Inst, unsigned N) const {
2628 assert(N == 1 && "Invalid number of operands!");
2629 const SmallVectorImpl<MCRegister> &RegList = getRegList();
2630 for (MCRegister Reg : RegList)
2632 }
2633
2634 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
2635 addRegListOperands(Inst, N);
2636 }
2637
2638 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
2639 addRegListOperands(Inst, N);
2640 }
2641
2642 void addFPSRegListWithVPROperands(MCInst &Inst, unsigned N) const {
2643 addRegListOperands(Inst, N);
2644 }
2645
2646 void addFPDRegListWithVPROperands(MCInst &Inst, unsigned N) const {
2647 addRegListOperands(Inst, N);
2648 }
2649
2650 void addRotImmOperands(MCInst &Inst, unsigned N) const {
2651 assert(N == 1 && "Invalid number of operands!");
2652 // Encoded as val>>3. The printer handles display as 8, 16, 24.
2653 Inst.addOperand(MCOperand::createImm(RotImm.Imm >> 3));
2654 }
2655
2656 void addModImmOperands(MCInst &Inst, unsigned N) const {
2657 assert(N == 1 && "Invalid number of operands!");
2658
2659 // Support for fixups (MCFixup)
2660 if (isImm())
2661 return addImmOperands(Inst, N);
2662
2663 Inst.addOperand(MCOperand::createImm(ModImm.Bits | (ModImm.Rot << 7)));
2664 }
2665
2666 void addModImmNotOperands(MCInst &Inst, unsigned N) const {
2667 assert(N == 1 && "Invalid number of operands!");
2668 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2669 uint32_t Enc = ARM_AM::getSOImmVal(~CE->getValue());
2671 }
2672
2673 void addModImmNegOperands(MCInst &Inst, unsigned N) const {
2674 assert(N == 1 && "Invalid number of operands!");
2675 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2676 uint32_t Enc = ARM_AM::getSOImmVal(-CE->getValue());
2678 }
2679
2680 void addThumbModImmNeg8_255Operands(MCInst &Inst, unsigned N) const {
2681 assert(N == 1 && "Invalid number of operands!");
2682 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2683 uint32_t Val = -CE->getValue();
2685 }
2686
2687 void addThumbModImmNeg1_7Operands(MCInst &Inst, unsigned N) const {
2688 assert(N == 1 && "Invalid number of operands!");
2689 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2690 uint32_t Val = -CE->getValue();
2692 }
2693
2694 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
2695 assert(N == 1 && "Invalid number of operands!");
2696 // Munge the lsb/width into a bitfield mask.
2697 unsigned lsb = Bitfield.LSB;
2698 unsigned width = Bitfield.Width;
2699 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
2700 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
2701 (32 - (lsb + width)));
2702 Inst.addOperand(MCOperand::createImm(Mask));
2703 }
2704
2705 void addImmOperands(MCInst &Inst, unsigned N) const {
2706 assert(N == 1 && "Invalid number of operands!");
2707 addExpr(Inst, getImm());
2708 }
2709
2710 void addFBits16Operands(MCInst &Inst, unsigned N) const {
2711 assert(N == 1 && "Invalid number of operands!");
2712 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2713 Inst.addOperand(MCOperand::createImm(16 - CE->getValue()));
2714 }
2715
2716 void addFBits32Operands(MCInst &Inst, unsigned N) const {
2717 assert(N == 1 && "Invalid number of operands!");
2718 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2719 Inst.addOperand(MCOperand::createImm(32 - CE->getValue()));
2720 }
2721
2722 void addFPImmOperands(MCInst &Inst, unsigned N) const {
2723 assert(N == 1 && "Invalid number of operands!");
2724 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2725 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
2727 }
2728
2729 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
2730 assert(N == 1 && "Invalid number of operands!");
2731 // FIXME: We really want to scale the value here, but the LDRD/STRD
2732 // instruction don't encode operands that way yet.
2733 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2734 Inst.addOperand(MCOperand::createImm(CE->getValue()));
2735 }
2736
2737 void addImm7s4Operands(MCInst &Inst, unsigned N) const {
2738 assert(N == 1 && "Invalid number of operands!");
2739 // FIXME: We really want to scale the value here, but the VSTR/VLDR_VSYSR
2740 // instruction don't encode operands that way yet.
2741 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2742 Inst.addOperand(MCOperand::createImm(CE->getValue()));
2743 }
2744
2745 void addImm7Shift0Operands(MCInst &Inst, unsigned N) const {
2746 assert(N == 1 && "Invalid number of operands!");
2747 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2748 Inst.addOperand(MCOperand::createImm(CE->getValue()));
2749 }
2750
2751 void addImm7Shift1Operands(MCInst &Inst, unsigned N) const {
2752 assert(N == 1 && "Invalid number of operands!");
2753 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2754 Inst.addOperand(MCOperand::createImm(CE->getValue()));
2755 }
2756
2757 void addImm7Shift2Operands(MCInst &Inst, unsigned N) const {
2758 assert(N == 1 && "Invalid number of operands!");
2759 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2760 Inst.addOperand(MCOperand::createImm(CE->getValue()));
2761 }
2762
2763 void addImm7Operands(MCInst &Inst, unsigned N) const {
2764 assert(N == 1 && "Invalid number of operands!");
2765 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2766 Inst.addOperand(MCOperand::createImm(CE->getValue()));
2767 }
2768
2769 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
2770 assert(N == 1 && "Invalid number of operands!");
2771 // The immediate is scaled by four in the encoding and is stored
2772 // in the MCInst as such. Lop off the low two bits here.
2773 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2774 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4));
2775 }
2776
2777 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
2778 assert(N == 1 && "Invalid number of operands!");
2779 // The immediate is scaled by four in the encoding and is stored
2780 // in the MCInst as such. Lop off the low two bits here.
2781 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2782 Inst.addOperand(MCOperand::createImm(-(CE->getValue() / 4)));
2783 }
2784
2785 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
2786 assert(N == 1 && "Invalid number of operands!");
2787 // The immediate is scaled by four in the encoding and is stored
2788 // in the MCInst as such. Lop off the low two bits here.
2789 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2790 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4));
2791 }
2792
2793 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
2794 assert(N == 1 && "Invalid number of operands!");
2795 // The constant encodes as the immediate-1, and we store in the instruction
2796 // the bits as encoded, so subtract off one here.
2797 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2798 Inst.addOperand(MCOperand::createImm(CE->getValue() - 1));
2799 }
2800
2801 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
2802 assert(N == 1 && "Invalid number of operands!");
2803 // The constant encodes as the immediate-1, and we store in the instruction
2804 // the bits as encoded, so subtract off one here.
2805 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2806 Inst.addOperand(MCOperand::createImm(CE->getValue() - 1));
2807 }
2808
2809 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
2810 assert(N == 1 && "Invalid number of operands!");
2811 // The constant encodes as the immediate, except for 32, which encodes as
2812 // zero.
2813 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2814 unsigned Imm = CE->getValue();
2815 Inst.addOperand(MCOperand::createImm((Imm == 32 ? 0 : Imm)));
2816 }
2817
2818 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
2819 assert(N == 1 && "Invalid number of operands!");
2820 // An ASR value of 32 encodes as 0, so that's how we want to add it to
2821 // the instruction as well.
2822 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2823 int Val = CE->getValue();
2824 Inst.addOperand(MCOperand::createImm(Val == 32 ? 0 : Val));
2825 }
2826
2827 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
2828 assert(N == 1 && "Invalid number of operands!");
2829 // The operand is actually a t2_so_imm, but we have its bitwise
2830 // negation in the assembly source, so twiddle it here.
2831 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2832 Inst.addOperand(MCOperand::createImm(~(uint32_t)CE->getValue()));
2833 }
2834
2835 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
2836 assert(N == 1 && "Invalid number of operands!");
2837 // The operand is actually a t2_so_imm, but we have its
2838 // negation in the assembly source, so twiddle it here.
2839 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2840 Inst.addOperand(MCOperand::createImm(-(uint32_t)CE->getValue()));
2841 }
2842
2843 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
2844 assert(N == 1 && "Invalid number of operands!");
2845 // The operand is actually an imm0_4095, but we have its
2846 // negation in the assembly source, so twiddle it here.
2847 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2848 Inst.addOperand(MCOperand::createImm(-(uint32_t)CE->getValue()));
2849 }
2850
2851 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
2852 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
2853 Inst.addOperand(MCOperand::createImm(CE->getValue() >> 2));
2854 return;
2855 }
2856 const MCSymbolRefExpr *SR = cast<MCSymbolRefExpr>(Imm.Val);
2858 }
2859
2860 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
2861 assert(N == 1 && "Invalid number of operands!");
2862 if (isImm()) {
2863 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2864 if (CE) {
2865 Inst.addOperand(MCOperand::createImm(CE->getValue()));
2866 return;
2867 }
2868 const MCSymbolRefExpr *SR = cast<MCSymbolRefExpr>(Imm.Val);
2870 return;
2871 }
2872
2873 assert(isGPRMem() && "Unknown value type!");
2874 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
2875 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
2876 Inst.addOperand(MCOperand::createImm(CE->getValue()));
2877 else
2878 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
2879 }
2880
2881 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
2882 assert(N == 1 && "Invalid number of operands!");
2883 Inst.addOperand(MCOperand::createImm(unsigned(getMemBarrierOpt())));
2884 }
2885
2886 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
2887 assert(N == 1 && "Invalid number of operands!");
2888 Inst.addOperand(MCOperand::createImm(unsigned(getInstSyncBarrierOpt())));
2889 }
2890
2891 void addTraceSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
2892 assert(N == 1 && "Invalid number of operands!");
2893 Inst.addOperand(MCOperand::createImm(unsigned(getTraceSyncBarrierOpt())));
2894 }
2895
2896 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
2897 assert(N == 1 && "Invalid number of operands!");
2898 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
2899 }
2900
2901 void addMemNoOffsetT2Operands(MCInst &Inst, unsigned N) const {
2902 assert(N == 1 && "Invalid number of operands!");
2903 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
2904 }
2905
2906 void addMemNoOffsetT2NoSpOperands(MCInst &Inst, unsigned N) const {
2907 assert(N == 1 && "Invalid number of operands!");
2908 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
2909 }
2910
2911 void addMemNoOffsetTOperands(MCInst &Inst, unsigned N) const {
2912 assert(N == 1 && "Invalid number of operands!");
2913 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
2914 }
2915
2916 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
2917 assert(N == 1 && "Invalid number of operands!");
2918 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
2919 Inst.addOperand(MCOperand::createImm(CE->getValue()));
2920 else
2921 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
2922 }
2923
2924 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
2925 assert(N == 1 && "Invalid number of operands!");
2926 assert(isImm() && "Not an immediate!");
2927
2928 // If we have an immediate that's not a constant, treat it as a label
2929 // reference needing a fixup.
2930 if (!isa<MCConstantExpr>(getImm())) {
2932 return;
2933 }
2934
2935 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
2936 int Val = CE->getValue();
2938 }
2939
2940 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
2941 assert(N == 2 && "Invalid number of operands!");
2942 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
2943 Inst.addOperand(MCOperand::createImm(Memory.Alignment));
2944 }
2945
2946 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2947 addAlignedMemoryOperands(Inst, N);
2948 }
2949
2950 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2951 addAlignedMemoryOperands(Inst, N);
2952 }
2953
2954 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2955 addAlignedMemoryOperands(Inst, N);
2956 }
2957
2958 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2959 addAlignedMemoryOperands(Inst, N);
2960 }
2961
2962 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2963 addAlignedMemoryOperands(Inst, N);
2964 }
2965
2966 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2967 addAlignedMemoryOperands(Inst, N);
2968 }
2969
2970 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2971 addAlignedMemoryOperands(Inst, N);
2972 }
2973
2974 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2975 addAlignedMemoryOperands(Inst, N);
2976 }
2977
2978 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2979 addAlignedMemoryOperands(Inst, N);
2980 }
2981
2982 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2983 addAlignedMemoryOperands(Inst, N);
2984 }
2985
2986 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
2987 addAlignedMemoryOperands(Inst, N);
2988 }
2989
2990 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
2991 assert(N == 3 && "Invalid number of operands!");
2992 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
2993 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
2994 if (!Memory.OffsetRegNum) {
2995 if (!Memory.OffsetImm)
2997 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
2998 int32_t Val = CE->getValue();
3000 // Special case for #-0
3001 if (Val == std::numeric_limits<int32_t>::min())
3002 Val = 0;
3003 if (Val < 0)
3004 Val = -Val;
3005 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
3007 } else
3008 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
3009 } else {
3010 // For register offset, we encode the shift type and negation flag
3011 // here.
3012 int32_t Val =
3013 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
3014 Memory.ShiftImm, Memory.ShiftType);
3016 }
3017 }
3018
3019 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
3020 assert(N == 2 && "Invalid number of operands!");
3021 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
3022 assert(CE && "non-constant AM2OffsetImm operand!");
3023 int32_t Val = CE->getValue();
3025 // Special case for #-0
3026 if (Val == std::numeric_limits<int32_t>::min()) Val = 0;
3027 if (Val < 0) Val = -Val;
3028 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
3031 }
3032
3033 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
3034 assert(N == 3 && "Invalid number of operands!");
3035 // If we have an immediate that's not a constant, treat it as a label
3036 // reference needing a fixup. If it is a constant, it's something else
3037 // and we reject it.
3038 if (isImm()) {
3042 return;
3043 }
3044
3045 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3046 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
3047 if (!Memory.OffsetRegNum) {
3048 if (!Memory.OffsetImm)
3050 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
3051 int32_t Val = CE->getValue();
3053 // Special case for #-0
3054 if (Val == std::numeric_limits<int32_t>::min())
3055 Val = 0;
3056 if (Val < 0)
3057 Val = -Val;
3058 Val = ARM_AM::getAM3Opc(AddSub, Val);
3060 } else
3061 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
3062 } else {
3063 // For register offset, we encode the shift type and negation flag
3064 // here.
3065 int32_t Val =
3066 ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
3068 }
3069 }
3070
3071 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
3072 assert(N == 2 && "Invalid number of operands!");
3073 if (Kind == k_PostIndexRegister) {
3074 int32_t Val =
3075 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
3076 Inst.addOperand(MCOperand::createReg(PostIdxReg.RegNum));
3078 return;
3079 }
3080
3081 // Constant offset.
3082 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
3083 int32_t Val = CE->getValue();
3085 // Special case for #-0
3086 if (Val == std::numeric_limits<int32_t>::min()) Val = 0;
3087 if (Val < 0) Val = -Val;
3088 Val = ARM_AM::getAM3Opc(AddSub, Val);
3091 }
3092
3093 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
3094 assert(N == 2 && "Invalid number of operands!");
3095 // If we have an immediate that's not a constant, treat it as a label
3096 // reference needing a fixup. If it is a constant, it's something else
3097 // and we reject it.
3098 if (isImm()) {
3101 return;
3102 }
3103
3104 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3105 if (!Memory.OffsetImm)
3107 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
3108 // The lower two bits are always zero and as such are not encoded.
3109 int32_t Val = CE->getValue() / 4;
3111 // Special case for #-0
3112 if (Val == std::numeric_limits<int32_t>::min())
3113 Val = 0;
3114 if (Val < 0)
3115 Val = -Val;
3116 Val = ARM_AM::getAM5Opc(AddSub, Val);
3118 } else
3119 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
3120 }
3121
3122 void addAddrMode5FP16Operands(MCInst &Inst, unsigned N) const {
3123 assert(N == 2 && "Invalid number of operands!");
3124 // If we have an immediate that's not a constant, treat it as a label
3125 // reference needing a fixup. If it is a constant, it's something else
3126 // and we reject it.
3127 if (isImm()) {
3130 return;
3131 }
3132
3133 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3134 // The lower bit is always zero and as such is not encoded.
3135 if (!Memory.OffsetImm)
3137 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
3138 int32_t Val = CE->getValue() / 2;
3140 // Special case for #-0
3141 if (Val == std::numeric_limits<int32_t>::min())
3142 Val = 0;
3143 if (Val < 0)
3144 Val = -Val;
3145 Val = ARM_AM::getAM5FP16Opc(AddSub, Val);
3147 } else
3148 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
3149 }
3150
3151 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
3152 assert(N == 2 && "Invalid number of operands!");
3153 // If we have an immediate that's not a constant, treat it as a label
3154 // reference needing a fixup. If it is a constant, it's something else
3155 // and we reject it.
3156 if (isImm()) {
3159 return;
3160 }
3161
3162 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3163 addExpr(Inst, Memory.OffsetImm);
3164 }
3165
3166 void addMemImm7s4OffsetOperands(MCInst &Inst, unsigned N) const {
3167 assert(N == 2 && "Invalid number of operands!");
3168 // If we have an immediate that's not a constant, treat it as a label
3169 // reference needing a fixup. If it is a constant, it's something else
3170 // and we reject it.
3171 if (isImm()) {
3174 return;
3175 }
3176
3177 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3178 addExpr(Inst, Memory.OffsetImm);
3179 }
3180
3181 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
3182 assert(N == 2 && "Invalid number of operands!");
3183 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3184 if (!Memory.OffsetImm)
3186 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
3187 // The lower two bits are always zero and as such are not encoded.
3188 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4));
3189 else
3190 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
3191 }
3192
3193 void addMemImmOffsetOperands(MCInst &Inst, unsigned N) const {
3194 assert(N == 2 && "Invalid number of operands!");
3195 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3196 addExpr(Inst, Memory.OffsetImm);
3197 }
3198
3199 void addMemRegRQOffsetOperands(MCInst &Inst, unsigned N) const {
3200 assert(N == 2 && "Invalid number of operands!");
3201 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3202 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
3203 }
3204
3205 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
3206 assert(N == 2 && "Invalid number of operands!");
3207 // If this is an immediate, it's a label reference.
3208 if (isImm()) {
3209 addExpr(Inst, getImm());
3211 return;
3212 }
3213
3214 // Otherwise, it's a normal memory reg+offset.
3215 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3216 addExpr(Inst, Memory.OffsetImm);
3217 }
3218
3219 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
3220 assert(N == 2 && "Invalid number of operands!");
3221 // If this is an immediate, it's a label reference.
3222 if (isImm()) {
3223 addExpr(Inst, getImm());
3225 return;
3226 }
3227
3228 // Otherwise, it's a normal memory reg+offset.
3229 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3230 addExpr(Inst, Memory.OffsetImm);
3231 }
3232
3233 void addConstPoolAsmImmOperands(MCInst &Inst, unsigned N) const {
3234 assert(N == 1 && "Invalid number of operands!");
3235 // This is container for the immediate that we will create the constant
3236 // pool from
3237 addExpr(Inst, getConstantPoolImm());
3238 }
3239
3240 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
3241 assert(N == 2 && "Invalid number of operands!");
3242 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3243 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
3244 }
3245
3246 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
3247 assert(N == 2 && "Invalid number of operands!");
3248 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3249 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
3250 }
3251
3252 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
3253 assert(N == 3 && "Invalid number of operands!");
3254 unsigned Val =
3255 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
3256 Memory.ShiftImm, Memory.ShiftType);
3257 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3258 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
3260 }
3261
3262 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
3263 assert(N == 3 && "Invalid number of operands!");
3264 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3265 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
3266 Inst.addOperand(MCOperand::createImm(Memory.ShiftImm));
3267 }
3268
3269 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
3270 assert(N == 2 && "Invalid number of operands!");
3271 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3272 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
3273 }
3274
3275 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
3276 assert(N == 2 && "Invalid number of operands!");
3277 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3278 if (!Memory.OffsetImm)
3280 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
3281 // The lower two bits are always zero and as such are not encoded.
3282 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4));
3283 else
3284 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
3285 }
3286
3287 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
3288 assert(N == 2 && "Invalid number of operands!");
3289 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3290 if (!Memory.OffsetImm)
3292 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
3293 Inst.addOperand(MCOperand::createImm(CE->getValue() / 2));
3294 else
3295 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
3296 }
3297
3298 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
3299 assert(N == 2 && "Invalid number of operands!");
3300 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3301 addExpr(Inst, Memory.OffsetImm);
3302 }
3303
3304 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
3305 assert(N == 2 && "Invalid number of operands!");
3306 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
3307 if (!Memory.OffsetImm)
3309 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
3310 // The lower two bits are always zero and as such are not encoded.
3311 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4));
3312 else
3313 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
3314 }
3315
3316 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
3317 assert(N == 1 && "Invalid number of operands!");
3318 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
3319 assert(CE && "non-constant post-idx-imm8 operand!");
3320 int Imm = CE->getValue();
3321 bool isAdd = Imm >= 0;
3322 if (Imm == std::numeric_limits<int32_t>::min()) Imm = 0;
3323 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
3325 }
3326
3327 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
3328 assert(N == 1 && "Invalid number of operands!");
3329 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
3330 assert(CE && "non-constant post-idx-imm8s4 operand!");
3331 int Imm = CE->getValue();
3332 bool isAdd = Imm >= 0;
3333 if (Imm == std::numeric_limits<int32_t>::min()) Imm = 0;
3334 // Immediate is scaled by 4.
3335 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
3337 }
3338
3339 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
3340 assert(N == 2 && "Invalid number of operands!");
3341 Inst.addOperand(MCOperand::createReg(PostIdxReg.RegNum));
3342 Inst.addOperand(MCOperand::createImm(PostIdxReg.isAdd));
3343 }
3344
3345 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
3346 assert(N == 2 && "Invalid number of operands!");
3347 Inst.addOperand(MCOperand::createReg(PostIdxReg.RegNum));
3348 // The sign, shift type, and shift amount are encoded in a single operand
3349 // using the AM2 encoding helpers.
3350 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
3351 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
3352 PostIdxReg.ShiftTy);
3354 }
3355
3356 void addPowerTwoOperands(MCInst &Inst, unsigned N) const {
3357 assert(N == 1 && "Invalid number of operands!");
3358 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3359 Inst.addOperand(MCOperand::createImm(CE->getValue()));
3360 }
3361
3362 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
3363 assert(N == 1 && "Invalid number of operands!");
3364 Inst.addOperand(MCOperand::createImm(getMSRMask()));
3365 }
3366
3367 void addBankedRegOperands(MCInst &Inst, unsigned N) const {
3368 assert(N == 1 && "Invalid number of operands!");
3369 Inst.addOperand(MCOperand::createImm(getBankedReg()));
3370 }
3371
3372 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
3373 assert(N == 1 && "Invalid number of operands!");
3374 Inst.addOperand(MCOperand::createImm(unsigned(getProcIFlags())));
3375 }
3376
3377 void addVecListOperands(MCInst &Inst, unsigned N) const {
3378 assert(N == 1 && "Invalid number of operands!");
3379
3380 if (isAnyVectorList())
3381 Inst.addOperand(MCOperand::createReg(VectorList.RegNum));
3382 else if (isDReg() && !Parser->hasMVE()) {
3383 Inst.addOperand(MCOperand::createReg(Reg.RegNum));
3384 } else if (isQReg() && !Parser->hasMVE()) {
3385 MCRegister DPair = Parser->getDRegFromQReg(Reg.RegNum);
3386 DPair = Parser->getMRI()->getMatchingSuperReg(
3387 DPair, ARM::dsub_0, &getARMMCRegisterClass(ARM::DPairRegClassID));
3388 Inst.addOperand(MCOperand::createReg(DPair));
3389 } else {
3390 LLVM_DEBUG(dbgs() << "TYPE: " << Kind << "\n");
3392 "attempted to add a vector list register with wrong type!");
3393 }
3394 }
3395
3396 void addMVEVecListOperands(MCInst &Inst, unsigned N) const {
3397 assert(N == 1 && "Invalid number of operands!");
3398
3399 // When we come here, the VectorList field will identify a range
3400 // of q-registers by its base register and length, and it will
3401 // have already been error-checked to be the expected length of
3402 // range and contain only q-regs in the range q0-q7. So we can
3403 // count on the base register being in the range q0-q6 (for 2
3404 // regs) or q0-q4 (for 4)
3405 //
3406 // The MVE instructions taking a register range of this kind will
3407 // need an operand in the MQQPR or MQQQQPR class, representing the
3408 // entire range as a unit. So we must translate into that class,
3409 // by finding the index of the base register in the MQPR reg
3410 // class, and returning the super-register at the corresponding
3411 // index in the target class.
3412
3413 const MCRegisterClass *RC_in = &getARMMCRegisterClass(ARM::MQPRRegClassID);
3414 const MCRegisterClass *RC_out =
3415 (VectorList.Count == 2)
3416 ? &getARMMCRegisterClass(ARM::MQQPRRegClassID)
3417 : &getARMMCRegisterClass(ARM::MQQQQPRRegClassID);
3418
3419 unsigned I, E = RC_out->getNumRegs();
3420 for (I = 0; I < E; I++)
3421 if (RC_in->getRegister(I) == VectorList.RegNum)
3422 break;
3423 assert(I < E && "Invalid vector list start register!");
3424
3426 }
3427
3428 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
3429 assert(N == 2 && "Invalid number of operands!");
3430 Inst.addOperand(MCOperand::createReg(VectorList.RegNum));
3431 Inst.addOperand(MCOperand::createImm(VectorList.LaneIndex));
3432 }
3433
3434 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
3435 assert(N == 1 && "Invalid number of operands!");
3436 Inst.addOperand(MCOperand::createImm(getVectorIndex()));
3437 }
3438
3439 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
3440 assert(N == 1 && "Invalid number of operands!");
3441 Inst.addOperand(MCOperand::createImm(getVectorIndex()));
3442 }
3443
3444 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
3445 assert(N == 1 && "Invalid number of operands!");
3446 Inst.addOperand(MCOperand::createImm(getVectorIndex()));
3447 }
3448
3449 void addVectorIndex64Operands(MCInst &Inst, unsigned N) const {
3450 assert(N == 1 && "Invalid number of operands!");
3451 Inst.addOperand(MCOperand::createImm(getVectorIndex()));
3452 }
3453
3454 void addMVEVectorIndexOperands(MCInst &Inst, unsigned N) const {
3455 assert(N == 1 && "Invalid number of operands!");
3456 Inst.addOperand(MCOperand::createImm(getVectorIndex()));
3457 }
3458
3459 void addMVEPairVectorIndexOperands(MCInst &Inst, unsigned N) const {
3460 assert(N == 1 && "Invalid number of operands!");
3461 Inst.addOperand(MCOperand::createImm(getVectorIndex()));
3462 }
3463
3464 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
3465 assert(N == 1 && "Invalid number of operands!");
3466 // The immediate encodes the type of constant as well as the value.
3467 // Mask in that this is an i8 splat.
3468 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3469 Inst.addOperand(MCOperand::createImm(CE->getValue() | 0xe00));
3470 }
3471
3472 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
3473 assert(N == 1 && "Invalid number of operands!");
3474 // The immediate encodes the type of constant as well as the value.
3475 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3476 unsigned Value = CE->getValue();
3479 }
3480
3481 void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const {
3482 assert(N == 1 && "Invalid number of operands!");
3483 // The immediate encodes the type of constant as well as the value.
3484 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3485 unsigned Value = CE->getValue();
3488 }
3489
3490 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
3491 assert(N == 1 && "Invalid number of operands!");
3492 // The immediate encodes the type of constant as well as the value.
3493 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3494 unsigned Value = CE->getValue();
3497 }
3498
3499 void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const {
3500 assert(N == 1 && "Invalid number of operands!");
3501 // The immediate encodes the type of constant as well as the value.
3502 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3503 unsigned Value = CE->getValue();
3506 }
3507
3508 void addNEONi8ReplicateOperands(MCInst &Inst, bool Inv) const {
3509 // The immediate encodes the type of constant as well as the value.
3510 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3511 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
3512 Inst.getOpcode() == ARM::VMOVv16i8) &&
3513 "All instructions that wants to replicate non-zero byte "
3514 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
3515 unsigned Value = CE->getValue();
3516 if (Inv)
3517 Value = ~Value;
3518 unsigned B = Value & 0xff;
3519 B |= 0xe00; // cmode = 0b1110
3521 }
3522
3523 void addNEONinvi8ReplicateOperands(MCInst &Inst, unsigned N) const {
3524 assert(N == 1 && "Invalid number of operands!");
3525 addNEONi8ReplicateOperands(Inst, true);
3526 }
3527
3528 static unsigned encodeNeonVMOVImmediate(unsigned Value) {
3529 if (Value >= 256 && Value <= 0xffff)
3530 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
3531 else if (Value > 0xffff && Value <= 0xffffff)
3532 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
3533 else if (Value > 0xffffff)
3534 Value = (Value >> 24) | 0x600;
3535 return Value;
3536 }
3537
3538 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
3539 assert(N == 1 && "Invalid number of operands!");
3540 // The immediate encodes the type of constant as well as the value.
3541 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3542 unsigned Value = encodeNeonVMOVImmediate(CE->getValue());
3544 }
3545
3546 void addNEONvmovi8ReplicateOperands(MCInst &Inst, unsigned N) const {
3547 assert(N == 1 && "Invalid number of operands!");
3548 addNEONi8ReplicateOperands(Inst, false);
3549 }
3550
3551 void addNEONvmovi16ReplicateOperands(MCInst &Inst, unsigned N) const {
3552 assert(N == 1 && "Invalid number of operands!");
3553 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3554 assert((Inst.getOpcode() == ARM::VMOVv4i16 ||
3555 Inst.getOpcode() == ARM::VMOVv8i16 ||
3556 Inst.getOpcode() == ARM::VMVNv4i16 ||
3557 Inst.getOpcode() == ARM::VMVNv8i16) &&
3558 "All instructions that want to replicate non-zero half-word "
3559 "always must be replaced with V{MOV,MVN}v{4,8}i16.");
3560 uint64_t Value = CE->getValue();
3561 unsigned Elem = Value & 0xffff;
3562 if (Elem >= 256)
3563 Elem = (Elem >> 8) | 0x200;
3564 Inst.addOperand(MCOperand::createImm(Elem));
3565 }
3566
3567 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
3568 assert(N == 1 && "Invalid number of operands!");
3569 // The immediate encodes the type of constant as well as the value.
3570 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3571 unsigned Value = encodeNeonVMOVImmediate(~CE->getValue());
3573 }
3574
3575 void addNEONvmovi32ReplicateOperands(MCInst &Inst, unsigned N) const {
3576 assert(N == 1 && "Invalid number of operands!");
3577 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3578 assert((Inst.getOpcode() == ARM::VMOVv2i32 ||
3579 Inst.getOpcode() == ARM::VMOVv4i32 ||
3580 Inst.getOpcode() == ARM::VMVNv2i32 ||
3581 Inst.getOpcode() == ARM::VMVNv4i32) &&
3582 "All instructions that want to replicate non-zero word "
3583 "always must be replaced with V{MOV,MVN}v{2,4}i32.");
3584 uint64_t Value = CE->getValue();
3585 unsigned Elem = encodeNeonVMOVImmediate(Value & 0xffffffff);
3586 Inst.addOperand(MCOperand::createImm(Elem));
3587 }
3588
3589 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
3590 assert(N == 1 && "Invalid number of operands!");
3591 // The immediate encodes the type of constant as well as the value.
3592 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3593 uint64_t Value = CE->getValue();
3594 unsigned Imm = 0;
3595 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
3596 Imm |= (Value & 1) << i;
3597 }
3598 Inst.addOperand(MCOperand::createImm(Imm | 0x1e00));
3599 }
3600
3601 void addComplexRotationEvenOperands(MCInst &Inst, unsigned N) const {
3602 assert(N == 1 && "Invalid number of operands!");
3603 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3604 Inst.addOperand(MCOperand::createImm(CE->getValue() / 90));
3605 }
3606
3607 void addComplexRotationOddOperands(MCInst &Inst, unsigned N) const {
3608 assert(N == 1 && "Invalid number of operands!");
3609 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3610 Inst.addOperand(MCOperand::createImm((CE->getValue() - 90) / 180));
3611 }
3612
3613 void addMveSaturateOperands(MCInst &Inst, unsigned N) const {
3614 assert(N == 1 && "Invalid number of operands!");
3615 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
3616 unsigned Imm = CE->getValue();
3617 assert((Imm == 48 || Imm == 64) && "Invalid saturate operand");
3618 Inst.addOperand(MCOperand::createImm(Imm == 48 ? 1 : 0));
3619 }
3620
3621 void print(raw_ostream &OS, const MCAsmInfo &MAI) const override;
3622
3623 static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S,
3624 ARMAsmParser &Parser) {
3625 auto Op = std::make_unique<ARMOperand>(k_ITCondMask, Parser);
3626 Op->ITMask.Mask = Mask;
3627 Op->StartLoc = S;
3628 Op->EndLoc = S;
3629 return Op;
3630 }
3631
3632 static std::unique_ptr<ARMOperand>
3633 CreateCondCode(ARMCC::CondCodes CC, SMLoc S, ARMAsmParser &Parser) {
3634 auto Op = std::make_unique<ARMOperand>(k_CondCode, Parser);
3635 Op->CC.Val = CC;
3636 Op->StartLoc = S;
3637 Op->EndLoc = S;
3638 return Op;
3639 }
3640
3641 static std::unique_ptr<ARMOperand> CreateVPTPred(ARMVCC::VPTCodes CC, SMLoc S,
3642 ARMAsmParser &Parser) {
3643 auto Op = std::make_unique<ARMOperand>(k_VPTPred, Parser);
3644 Op->VCC.Val = CC;
3645 Op->StartLoc = S;
3646 Op->EndLoc = S;
3647 return Op;
3648 }
3649
3650 static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S,
3651 ARMAsmParser &Parser) {
3652 auto Op = std::make_unique<ARMOperand>(k_CoprocNum, Parser);
3653 Op->Cop.Val = CopVal;
3654 Op->StartLoc = S;
3655 Op->EndLoc = S;
3656 return Op;
3657 }
3658
3659 static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S,
3660 ARMAsmParser &Parser) {
3661 auto Op = std::make_unique<ARMOperand>(k_CoprocReg, Parser);
3662 Op->Cop.Val = CopVal;
3663 Op->StartLoc = S;
3664 Op->EndLoc = S;
3665 return Op;
3666 }
3667
3668 static std::unique_ptr<ARMOperand>
3669 CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E, ARMAsmParser &Parser) {
3670 auto Op = std::make_unique<ARMOperand>(k_CoprocOption, Parser);
3671 Op->Cop.Val = Val;
3672 Op->StartLoc = S;
3673 Op->EndLoc = E;
3674 return Op;
3675 }
3676
3677 static std::unique_ptr<ARMOperand> CreateCCOut(MCRegister Reg, SMLoc S,
3678 ARMAsmParser &Parser) {
3679 auto Op = std::make_unique<ARMOperand>(k_CCOut, Parser);
3680 Op->Reg.RegNum = Reg;
3681 Op->StartLoc = S;
3682 Op->EndLoc = S;
3683 return Op;
3684 }
3685
3686 static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S,
3687 ARMAsmParser &Parser) {
3688 auto Op = std::make_unique<ARMOperand>(k_Token, Parser);
3689 Op->Tok.Data = Str.data();
3690 Op->Tok.Length = Str.size();
3691 Op->StartLoc = S;
3692 Op->EndLoc = S;
3693 return Op;
3694 }
3695
3696 static std::unique_ptr<ARMOperand> CreateReg(MCRegister Reg, SMLoc S, SMLoc E,
3697 ARMAsmParser &Parser) {
3698 auto Op = std::make_unique<ARMOperand>(k_Register, Parser);
3699 Op->Reg.RegNum = Reg;
3700 Op->StartLoc = S;
3701 Op->EndLoc = E;
3702 return Op;
3703 }
3704
3705 static std::unique_ptr<ARMOperand>
3706 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, MCRegister SrcReg,
3707 MCRegister ShiftReg, unsigned ShiftImm, SMLoc S,
3708 SMLoc E, ARMAsmParser &Parser) {
3709 auto Op = std::make_unique<ARMOperand>(k_ShiftedRegister, Parser);
3710 Op->RegShiftedReg.ShiftTy = ShTy;
3711 Op->RegShiftedReg.SrcReg = SrcReg;
3712 Op->RegShiftedReg.ShiftReg = ShiftReg;
3713 Op->RegShiftedReg.ShiftImm = ShiftImm;
3714 Op->StartLoc = S;
3715 Op->EndLoc = E;
3716 return Op;
3717 }
3718
3719 static std::unique_ptr<ARMOperand>
3720 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, MCRegister SrcReg,
3721 unsigned ShiftImm, SMLoc S, SMLoc E,
3722 ARMAsmParser &Parser) {
3723 auto Op = std::make_unique<ARMOperand>(k_ShiftedImmediate, Parser);
3724 Op->RegShiftedImm.ShiftTy = ShTy;
3725 Op->RegShiftedImm.SrcReg = SrcReg;
3726 Op->RegShiftedImm.ShiftImm = ShiftImm;
3727 Op->StartLoc = S;
3728 Op->EndLoc = E;
3729 return Op;
3730 }
3731
3732 static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm,
3733 SMLoc S, SMLoc E,
3734 ARMAsmParser &Parser) {
3735 auto Op = std::make_unique<ARMOperand>(k_ShifterImmediate, Parser);
3736 Op->ShifterImm.isASR = isASR;
3737 Op->ShifterImm.Imm = Imm;
3738 Op->StartLoc = S;
3739 Op->EndLoc = E;
3740 return Op;
3741 }
3742
3743 static std::unique_ptr<ARMOperand>
3744 CreateRotImm(unsigned Imm, SMLoc S, SMLoc E, ARMAsmParser &Parser) {
3745 auto Op = std::make_unique<ARMOperand>(k_RotateImmediate, Parser);
3746 Op->RotImm.Imm = Imm;
3747 Op->StartLoc = S;
3748 Op->EndLoc = E;
3749 return Op;
3750 }
3751
3752 static std::unique_ptr<ARMOperand> CreateModImm(unsigned Bits, unsigned Rot,
3753 SMLoc S, SMLoc E,
3754 ARMAsmParser &Parser) {
3755 auto Op = std::make_unique<ARMOperand>(k_ModifiedImmediate, Parser);
3756 Op->ModImm.Bits = Bits;
3757 Op->ModImm.Rot = Rot;
3758 Op->StartLoc = S;
3759 Op->EndLoc = E;
3760 return Op;
3761 }
3762
3763 static std::unique_ptr<ARMOperand>
3764 CreateConstantPoolImm(const MCExpr *Val, SMLoc S, SMLoc E,
3765 ARMAsmParser &Parser) {
3766 auto Op = std::make_unique<ARMOperand>(k_ConstantPoolImmediate, Parser);
3767 Op->Imm.Val = Val;
3768 Op->StartLoc = S;
3769 Op->EndLoc = E;
3770 return Op;
3771 }
3772
3773 static std::unique_ptr<ARMOperand> CreateBitfield(unsigned LSB,
3774 unsigned Width, SMLoc S,
3775 SMLoc E,
3776 ARMAsmParser &Parser) {
3777 auto Op = std::make_unique<ARMOperand>(k_BitfieldDescriptor, Parser);
3778 Op->Bitfield.LSB = LSB;
3779 Op->Bitfield.Width = Width;
3780 Op->StartLoc = S;
3781 Op->EndLoc = E;
3782 return Op;
3783 }
3784
3785 static std::unique_ptr<ARMOperand>
3786 CreateRegList(SmallVectorImpl<std::pair<unsigned, MCRegister>> &Regs,
3787 SMLoc StartLoc, SMLoc EndLoc, ARMAsmParser &Parser) {
3788 assert(Regs.size() > 0 && "RegList contains no registers?");
3789 KindTy Kind = k_RegisterList;
3790
3791 if (getARMMCRegisterClass(ARM::DPRRegClassID)
3792 .contains(Regs.front().second)) {
3793 if (Regs.back().second == ARM::VPR)
3794 Kind = k_FPDRegisterListWithVPR;
3795 else
3796 Kind = k_DPRRegisterList;
3797 } else if (getARMMCRegisterClass(ARM::SPRRegClassID)
3798 .contains(Regs.front().second)) {
3799 if (Regs.back().second == ARM::VPR)
3800 Kind = k_FPSRegisterListWithVPR;
3801 else
3802 Kind = k_SPRRegisterList;
3803 } else if (Regs.front().second == ARM::VPR) {
3804 assert(Regs.size() == 1 &&
3805 "Register list starting with VPR expected to only contain VPR");
3806 Kind = k_FPSRegisterListWithVPR;
3807 }
3808
3809 if (Kind == k_RegisterList && Regs.back().second == ARM::APSR)
3810 Kind = k_RegisterListWithAPSR;
3811
3812 assert(llvm::is_sorted(Regs) && "Register list must be sorted by encoding");
3813
3814 auto Op = std::make_unique<ARMOperand>(Kind, Parser);
3815 for (const auto &P : Regs)
3816 Op->Registers.push_back(P.second);
3817
3818 Op->StartLoc = StartLoc;
3819 Op->EndLoc = EndLoc;
3820 return Op;
3821 }
3822
3823 static std::unique_ptr<ARMOperand>
3824 CreateVectorList(MCRegister Reg, unsigned Count, bool isDoubleSpaced, SMLoc S,
3825 SMLoc E, ARMAsmParser &Parser) {
3826 auto Op = std::make_unique<ARMOperand>(k_VectorList, Parser);
3827 Op->VectorList.RegNum = Reg;
3828 Op->VectorList.Count = Count;
3829 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
3830 Op->StartLoc = S;
3831 Op->EndLoc = E;
3832 return Op;
3833 }
3834
3835 static std::unique_ptr<ARMOperand>
3836 CreateVectorListAllLanes(MCRegister Reg, unsigned Count, bool isDoubleSpaced,
3837 SMLoc S, SMLoc E, ARMAsmParser &Parser) {
3838 auto Op = std::make_unique<ARMOperand>(k_VectorListAllLanes, Parser);
3839 Op->VectorList.RegNum = Reg;
3840 Op->VectorList.Count = Count;
3841 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
3842 Op->StartLoc = S;
3843 Op->EndLoc = E;
3844 return Op;
3845 }
3846
3847 static std::unique_ptr<ARMOperand>
3848 CreateVectorListIndexed(MCRegister Reg, unsigned Count, unsigned Index,
3849 bool isDoubleSpaced, SMLoc S, SMLoc E,
3850 ARMAsmParser &Parser) {
3851 auto Op = std::make_unique<ARMOperand>(k_VectorListIndexed, Parser);
3852 Op->VectorList.RegNum = Reg;
3853 Op->VectorList.Count = Count;
3854 Op->VectorList.LaneIndex = Index;
3855 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
3856 Op->StartLoc = S;
3857 Op->EndLoc = E;
3858 return Op;
3859 }
3860
3861 static std::unique_ptr<ARMOperand> CreateVectorIndex(unsigned Idx, SMLoc S,
3862 SMLoc E, MCContext &Ctx,
3863 ARMAsmParser &Parser) {
3864 auto Op = std::make_unique<ARMOperand>(k_VectorIndex, Parser);
3865 Op->VectorIndex.Val = Idx;
3866 Op->StartLoc = S;
3867 Op->EndLoc = E;
3868 return Op;
3869 }
3870
3871 static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S,
3872 SMLoc E, ARMAsmParser &Parser) {
3873 auto Op = std::make_unique<ARMOperand>(k_Immediate, Parser);
3874 Op->Imm.Val = Val;
3875 Op->StartLoc = S;
3876 Op->EndLoc = E;
3877 return Op;
3878 }
3879
3880 static std::unique_ptr<ARMOperand>
3881 CreateMem(MCRegister BaseReg, const MCExpr *OffsetImm, MCRegister OffsetReg,
3882 ARM_AM::ShiftOpc ShiftType, unsigned ShiftImm, unsigned Alignment,
3883 bool isNegative, SMLoc S, SMLoc E, ARMAsmParser &Parser,
3884 SMLoc AlignmentLoc = SMLoc()) {
3885 auto Op = std::make_unique<ARMOperand>(k_Memory, Parser);
3886 Op->Memory.BaseRegNum = BaseReg;
3887 Op->Memory.OffsetImm = OffsetImm;
3888 Op->Memory.OffsetRegNum = OffsetReg;
3889 Op->Memory.ShiftType = ShiftType;
3890 Op->Memory.ShiftImm = ShiftImm;
3891 Op->Memory.Alignment = Alignment;
3892 Op->Memory.isNegative = isNegative;
3893 Op->StartLoc = S;
3894 Op->EndLoc = E;
3895 Op->AlignmentLoc = AlignmentLoc;
3896 return Op;
3897 }
3898
3899 static std::unique_ptr<ARMOperand>
3900 CreatePostIdxReg(MCRegister Reg, bool isAdd, ARM_AM::ShiftOpc ShiftTy,
3901 unsigned ShiftImm, SMLoc S, SMLoc E, ARMAsmParser &Parser) {
3902 auto Op = std::make_unique<ARMOperand>(k_PostIndexRegister, Parser);
3903 Op->PostIdxReg.RegNum = Reg;
3904 Op->PostIdxReg.isAdd = isAdd;
3905 Op->PostIdxReg.ShiftTy = ShiftTy;
3906 Op->PostIdxReg.ShiftImm = ShiftImm;
3907 Op->StartLoc = S;
3908 Op->EndLoc = E;
3909 return Op;
3910 }
3911
3912 static std::unique_ptr<ARMOperand>
3913 CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S, ARMAsmParser &Parser) {
3914 auto Op = std::make_unique<ARMOperand>(k_MemBarrierOpt, Parser);
3915 Op->MBOpt.Val = Opt;
3916 Op->StartLoc = S;
3917 Op->EndLoc = S;
3918 return Op;
3919 }
3920
3921 static std::unique_ptr<ARMOperand>
3922 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S,
3923 ARMAsmParser &Parser) {
3924 auto Op = std::make_unique<ARMOperand>(k_InstSyncBarrierOpt, Parser);
3925 Op->ISBOpt.Val = Opt;
3926 Op->StartLoc = S;
3927 Op->EndLoc = S;
3928 return Op;
3929 }
3930
3931 static std::unique_ptr<ARMOperand>
3932 CreateTraceSyncBarrierOpt(ARM_TSB::TraceSyncBOpt Opt, SMLoc S,
3933 ARMAsmParser &Parser) {
3934 auto Op = std::make_unique<ARMOperand>(k_TraceSyncBarrierOpt, Parser);
3935 Op->TSBOpt.Val = Opt;
3936 Op->StartLoc = S;
3937 Op->EndLoc = S;
3938 return Op;
3939 }
3940
3941 static std::unique_ptr<ARMOperand>
3942 CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S, ARMAsmParser &Parser) {
3943 auto Op = std::make_unique<ARMOperand>(k_ProcIFlags, Parser);
3944 Op->IFlags.Val = IFlags;
3945 Op->StartLoc = S;
3946 Op->EndLoc = S;
3947 return Op;
3948 }
3949
3950 static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S,
3951 ARMAsmParser &Parser) {
3952 auto Op = std::make_unique<ARMOperand>(k_MSRMask, Parser);
3953 Op->MMask.Val = MMask;
3954 Op->StartLoc = S;
3955 Op->EndLoc = S;
3956 return Op;
3957 }
3958
3959 static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S,
3960 ARMAsmParser &Parser) {
3961 auto Op = std::make_unique<ARMOperand>(k_BankedReg, Parser);
3962 Op->BankedReg.Val = Reg;
3963 Op->StartLoc = S;
3964 Op->EndLoc = S;
3965 return Op;
3966 }
3967};
3968
3969} // end anonymous namespace.
3970
3971void ARMOperand::print(raw_ostream &OS, const MCAsmInfo &MAI) const {
3972 auto RegName = [](MCRegister Reg) {
3973 if (Reg)
3975 else
3976 return "noreg";
3977 };
3978
3979 switch (Kind) {
3980 case k_CondCode:
3981 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
3982 break;
3983 case k_VPTPred:
3984 OS << "<ARMVCC::" << ARMVPTPredToString(getVPTPred()) << ">";
3985 break;
3986 case k_CCOut:
3987 OS << "<ccout " << RegName(getReg()) << ">";
3988 break;
3989 case k_ITCondMask: {
3990 static const char *const MaskStr[] = {
3991 "(invalid)", "(tttt)", "(ttt)", "(ttte)",
3992 "(tt)", "(ttet)", "(tte)", "(ttee)",
3993 "(t)", "(tett)", "(tet)", "(tete)",
3994 "(te)", "(teet)", "(tee)", "(teee)",
3995 };
3996 assert((ITMask.Mask & 0xf) == ITMask.Mask);
3997 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
3998 break;
3999 }
4000 case k_CoprocNum:
4001 OS << "<coprocessor number: " << getCoproc() << ">";
4002 break;
4003 case k_CoprocReg:
4004 OS << "<coprocessor register: " << getCoproc() << ">";
4005 break;
4006 case k_CoprocOption:
4007 OS << "<coprocessor option: " << CoprocOption.Val << ">";
4008 break;
4009 case k_MSRMask:
4010 OS << "<mask: " << getMSRMask() << ">";
4011 break;
4012 case k_BankedReg:
4013 OS << "<banked reg: " << getBankedReg() << ">";
4014 break;
4015 case k_Immediate:
4016 MAI.printExpr(OS, *getImm());
4017 break;
4018 case k_MemBarrierOpt:
4019 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
4020 break;
4021 case k_InstSyncBarrierOpt:
4022 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
4023 break;
4024 case k_TraceSyncBarrierOpt:
4025 OS << "<ARM_TSB::" << TraceSyncBOptToString(getTraceSyncBarrierOpt()) << ">";
4026 break;
4027 case k_Memory:
4028 OS << "<memory";
4029 if (Memory.BaseRegNum)
4030 OS << " base:" << RegName(Memory.BaseRegNum);
4031 if (Memory.OffsetImm) {
4032 OS << " offset-imm:";
4033 MAI.printExpr(OS, *Memory.OffsetImm);
4034 }
4035 if (Memory.OffsetRegNum)
4036 OS << " offset-reg:" << (Memory.isNegative ? "-" : "")
4037 << RegName(Memory.OffsetRegNum);
4038 if (Memory.ShiftType != ARM_AM::no_shift) {
4039 OS << " shift-type:" << ARM_AM::getShiftOpcStr(Memory.ShiftType);
4040 OS << " shift-imm:" << Memory.ShiftImm;
4041 }
4042 if (Memory.Alignment)
4043 OS << " alignment:" << Memory.Alignment;
4044 OS << ">";
4045 break;
4046 case k_PostIndexRegister:
4047 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
4048 << RegName(PostIdxReg.RegNum);
4049 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
4050 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
4051 << PostIdxReg.ShiftImm;
4052 OS << ">";
4053 break;
4054 case k_ProcIFlags: {
4055 OS << "<ARM_PROC::";
4056 unsigned IFlags = getProcIFlags();
4057 for (int i=2; i >= 0; --i)
4058 if (IFlags & (1 << i))
4059 OS << ARM_PROC::IFlagsToString(1 << i);
4060 OS << ">";
4061 break;
4062 }
4063 case k_Register:
4064 OS << "<register " << RegName(getReg()) << ">";
4065 break;
4066 case k_ShifterImmediate:
4067 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
4068 << " #" << ShifterImm.Imm << ">";
4069 break;
4070 case k_ShiftedRegister:
4071 OS << "<so_reg_reg " << RegName(RegShiftedReg.SrcReg) << " "
4072 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy) << " "
4073 << RegName(RegShiftedReg.ShiftReg) << ">";
4074 break;
4075 case k_ShiftedImmediate:
4076 OS << "<so_reg_imm " << RegName(RegShiftedImm.SrcReg) << " "
4077 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy) << " #"
4078 << RegShiftedImm.ShiftImm << ">";
4079 break;
4080 case k_RotateImmediate:
4081 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
4082 break;
4083 case k_ModifiedImmediate:
4084 OS << "<mod_imm #" << ModImm.Bits << ", #"
4085 << ModImm.Rot << ")>";
4086 break;
4087 case k_ConstantPoolImmediate:
4088 OS << "<constant_pool_imm #";
4089 MAI.printExpr(OS, *getConstantPoolImm());
4090 break;
4091 case k_BitfieldDescriptor:
4092 OS << "<bitfield " << "lsb: " << Bitfield.LSB
4093 << ", width: " << Bitfield.Width << ">";
4094 break;
4095 case k_RegisterList:
4096 case k_RegisterListWithAPSR:
4097 case k_DPRRegisterList:
4098 case k_SPRRegisterList:
4099 case k_FPSRegisterListWithVPR:
4100 case k_FPDRegisterListWithVPR: {
4101 OS << "<register_list ";
4102
4103 const SmallVectorImpl<MCRegister> &RegList = getRegList();
4104 for (auto I = RegList.begin(), E = RegList.end(); I != E;) {
4105 OS << RegName(*I);
4106 if (++I < E) OS << ", ";
4107 }
4108
4109 OS << ">";
4110 break;
4111 }
4112 case k_VectorList:
4113 OS << "<vector_list " << VectorList.Count << " * "
4114 << RegName(VectorList.RegNum) << ">";
4115 break;
4116 case k_VectorListAllLanes:
4117 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
4118 << RegName(VectorList.RegNum) << ">";
4119 break;
4120 case k_VectorListIndexed:
4121 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
4122 << VectorList.Count << " * " << RegName(VectorList.RegNum) << ">";
4123 break;
4124 case k_Token:
4125 OS << "'" << getToken() << "'";
4126 break;
4127 case k_VectorIndex:
4128 OS << "<vectorindex " << getVectorIndex() << ">";
4129 break;
4130 }
4131}
4132
4133/// @name Auto-generated Match Functions
4134/// {
4135
4137
4138/// }
4139
4140static bool isDataTypeToken(StringRef Tok) {
4141 static const DenseSet<StringRef> DataTypes{
4142 ".8", ".16", ".32", ".64", ".i8", ".i16", ".i32", ".i64",
4143 ".u8", ".u16", ".u32", ".u64", ".s8", ".s16", ".s32", ".s64",
4144 ".p8", ".p16", ".f32", ".f64", ".f", ".d"};
4145 return DataTypes.contains(Tok);
4146}
4147
4149 unsigned MnemonicOpsEndInd = 1;
4150 // Special case for CPS which has a Mnemonic side token for possibly storing
4151 // ie/id variant
4152 if (Operands[0]->isToken() &&
4153 static_cast<ARMOperand &>(*Operands[0]).getToken() == "cps") {
4154 if (Operands.size() > 1 && Operands[1]->isImm() &&
4155 static_cast<ARMOperand &>(*Operands[1]).getImm()->getKind() ==
4158 static_cast<ARMOperand &>(*Operands[1]).getImm())
4159 ->getValue() == ARM_PROC::IE ||
4161 static_cast<ARMOperand &>(*Operands[1]).getImm())
4162 ->getValue() == ARM_PROC::ID))
4163 ++MnemonicOpsEndInd;
4164 }
4165
4166 // In some circumstances the condition code moves to the right
4167 bool RHSCondCode = false;
4168 while (MnemonicOpsEndInd < Operands.size()) {
4169 auto Op = static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd]);
4170 // Special case for it instructions which have a condition code on the RHS
4171 if (Op.isITMask()) {
4172 RHSCondCode = true;
4173 MnemonicOpsEndInd++;
4174 } else if (Op.isToken() &&
4175 (
4176 // There are several special cases not covered by
4177 // isDataTypeToken
4178 Op.getToken() == ".w" || Op.getToken() == ".bf16" ||
4179 Op.getToken() == ".p64" || Op.getToken() == ".f16" ||
4180 isDataTypeToken(Op.getToken()))) {
4181 // In the mnemonic operators the cond code must always precede the data
4182 // type. So we can now safely assume any subsequent cond code is on the
4183 // RHS. As is the case for VCMP and VPT.
4184 RHSCondCode = true;
4185 MnemonicOpsEndInd++;
4186 }
4187 // Skip all mnemonic operator types
4188 else if (Op.isCCOut() || (Op.isCondCode() && !RHSCondCode) ||
4189 Op.isVPTPred() || (Op.isToken() && Op.getToken() == ".w"))
4190 MnemonicOpsEndInd++;
4191 else
4192 break;
4193 }
4194 return MnemonicOpsEndInd;
4195}
4196
4197bool ARMAsmParser::parseRegister(MCRegister &Reg, SMLoc &StartLoc,
4198 SMLoc &EndLoc) {
4199 const AsmToken &Tok = getParser().getTok();
4200 StartLoc = Tok.getLoc();
4201 EndLoc = Tok.getEndLoc();
4202 Reg = tryParseRegister();
4203
4204 return !Reg;
4205}
4206
4207ParseStatus ARMAsmParser::tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
4208 SMLoc &EndLoc) {
4209 if (parseRegister(Reg, StartLoc, EndLoc))
4210 return ParseStatus::NoMatch;
4211 return ParseStatus::Success;
4212}
4213
4214/// Try to parse a register name. The token must be an Identifier when called,
4215/// and if it is a register name the token is eaten and the register is
4216/// returned. Otherwise return an invalid MCRegister.
4217MCRegister ARMAsmParser::tryParseRegister(bool AllowOutOfBoundReg) {
4218 MCAsmParser &Parser = getParser();
4219 const AsmToken &Tok = Parser.getTok();
4220 if (Tok.isNot(AsmToken::Identifier))
4221 return MCRegister();
4222
4223 std::string lowerCase = Tok.getString().lower();
4224 MCRegister Reg = MatchRegisterName(lowerCase);
4225 if (!Reg) {
4226 Reg = StringSwitch<MCRegister>(lowerCase)
4227 .Case("r13", ARM::SP)
4228 .Case("r14", ARM::LR)
4229 .Case("r15", ARM::PC)
4230 .Case("ip", ARM::R12)
4231 // Additional register name aliases for 'gas' compatibility.
4232 .Case("a1", ARM::R0)
4233 .Case("a2", ARM::R1)
4234 .Case("a3", ARM::R2)
4235 .Case("a4", ARM::R3)
4236 .Case("v1", ARM::R4)
4237 .Case("v2", ARM::R5)
4238 .Case("v3", ARM::R6)
4239 .Case("v4", ARM::R7)
4240 .Case("v5", ARM::R8)
4241 .Case("v6", ARM::R9)
4242 .Case("v7", ARM::R10)
4243 .Case("v8", ARM::R11)
4244 .Case("sb", ARM::R9)
4245 .Case("sl", ARM::R10)
4246 .Case("fp", ARM::R11)
4247 .Default(MCRegister());
4248 }
4249 if (!Reg) {
4250 // Check for aliases registered via .req. Canonicalize to lower case.
4251 // That's more consistent since register names are case insensitive, and
4252 // it's how the original entry was passed in from MC/MCParser/AsmParser.
4253 auto Entry = RegisterReqs.find(lowerCase);
4254 // If no match, return failure.
4255 if (Entry == RegisterReqs.end())
4256 return MCRegister();
4257 Parser.Lex(); // Eat identifier token.
4258 return Entry->getValue();
4259 }
4260
4261 // Some FPUs only have 16 D registers, so D16-D31 are invalid
4262 if (!AllowOutOfBoundReg && !hasD32() && Reg >= ARM::D16 && Reg <= ARM::D31)
4263 return MCRegister();
4264
4265 Parser.Lex(); // Eat identifier token.
4266
4267 return Reg;
4268}
4269
4270std::optional<ARM_AM::ShiftOpc> ARMAsmParser::tryParseShiftToken() {
4271 MCAsmParser &Parser = getParser();
4272 const AsmToken &Tok = Parser.getTok();
4273 if (Tok.isNot(AsmToken::Identifier))
4274 return std::nullopt;
4275
4276 std::string lowerCase = Tok.getString().lower();
4277 return StringSwitch<std::optional<ARM_AM::ShiftOpc>>(lowerCase)
4278 .Case("asl", ARM_AM::lsl)
4279 .Case("lsl", ARM_AM::lsl)
4280 .Case("lsr", ARM_AM::lsr)
4281 .Case("asr", ARM_AM::asr)
4282 .Case("ror", ARM_AM::ror)
4283 .Case("rrx", ARM_AM::rrx)
4284 .Default(std::nullopt);
4285}
4286
4287// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
4288// If a recoverable error occurs, return 1. If an irrecoverable error
4289// occurs, return -1. An irrecoverable error is one where tokens have been
4290// consumed in the process of trying to parse the shifter (i.e., when it is
4291// indeed a shifter operand, but malformed).
4292int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
4293 MCAsmParser &Parser = getParser();
4294 SMLoc S = Parser.getTok().getLoc();
4295
4296 auto ShiftTyOpt = tryParseShiftToken();
4297 if (ShiftTyOpt == std::nullopt)
4298 return 1;
4299 auto ShiftTy = ShiftTyOpt.value();
4300
4301 Parser.Lex(); // Eat the operator.
4302
4303 // The source register for the shift has already been added to the
4304 // operand list, so we need to pop it off and combine it into the shifted
4305 // register operand instead.
4306 std::unique_ptr<ARMOperand> PrevOp(
4307 (ARMOperand *)Operands.pop_back_val().release());
4308 if (!PrevOp->isReg())
4309 return Error(PrevOp->getStartLoc(), "shift must be of a register");
4310 MCRegister SrcReg = PrevOp->getReg();
4311
4312 SMLoc EndLoc;
4313 int64_t Imm = 0;
4314 MCRegister ShiftReg;
4315 if (ShiftTy == ARM_AM::rrx) {
4316 // RRX Doesn't have an explicit shift amount. The encoder expects
4317 // the shift register to be the same as the source register. Seems odd,
4318 // but OK.
4319 ShiftReg = SrcReg;
4320 } else {
4321 // Figure out if this is shifted by a constant or a register (for non-RRX).
4322 if (Parser.getTok().is(AsmToken::Hash) ||
4323 Parser.getTok().is(AsmToken::Dollar)) {
4324 Parser.Lex(); // Eat hash.
4325 SMLoc ImmLoc = Parser.getTok().getLoc();
4326 const MCExpr *ShiftExpr = nullptr;
4327 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
4328 Error(ImmLoc, "invalid immediate shift value");
4329 return -1;
4330 }
4331 // The expression must be evaluatable as an immediate.
4332 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
4333 if (!CE) {
4334 Error(ImmLoc, "invalid immediate shift value");
4335 return -1;
4336 }
4337 // Range check the immediate.
4338 // lsl, ror: 0 <= imm <= 31
4339 // lsr, asr: 0 <= imm <= 32
4340 Imm = CE->getValue();
4341 if (Imm < 0 ||
4342 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
4343 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
4344 Error(ImmLoc, "immediate shift value out of range");
4345 return -1;
4346 }
4347 // shift by zero is a nop. Always send it through as lsl.
4348 // ('as' compatibility)
4349 if (Imm == 0)
4350 ShiftTy = ARM_AM::lsl;
4351 } else if (Parser.getTok().is(AsmToken::Identifier)) {
4352 SMLoc L = Parser.getTok().getLoc();
4353 EndLoc = Parser.getTok().getEndLoc();
4354 ShiftReg = tryParseRegister();
4355 if (!ShiftReg) {
4356 Error(L, "expected immediate or register in shift operand");
4357 return -1;
4358 }
4359 } else {
4360 Error(Parser.getTok().getLoc(),
4361 "expected immediate or register in shift operand");
4362 return -1;
4363 }
4364 }
4365
4366 if (ShiftReg && ShiftTy != ARM_AM::rrx)
4367 Operands.push_back(ARMOperand::CreateShiftedRegister(
4368 ShiftTy, SrcReg, ShiftReg, Imm, S, EndLoc, *this));
4369 else
4370 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
4371 S, EndLoc, *this));
4372
4373 return 0;
4374}
4375
4376/// Try to parse a register name. The token must be an Identifier when called.
4377/// If it's a register, an AsmOperand is created. Another AsmOperand is created
4378/// if there is a "writeback". 'true' if it's not a register.
4379///
4380/// TODO this is likely to change to allow different register types and or to
4381/// parse for a specific register type.
4382bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
4383 MCAsmParser &Parser = getParser();
4384 SMLoc RegStartLoc = Parser.getTok().getLoc();
4385 SMLoc RegEndLoc = Parser.getTok().getEndLoc();
4386 MCRegister Reg = tryParseRegister();
4387 if (!Reg)
4388 return true;
4389
4390 Operands.push_back(ARMOperand::CreateReg(Reg, RegStartLoc, RegEndLoc, *this));
4391
4392 const AsmToken &ExclaimTok = Parser.getTok();
4393 if (ExclaimTok.is(AsmToken::Exclaim)) {
4394 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
4395 ExclaimTok.getLoc(), *this));
4396 Parser.Lex(); // Eat exclaim token
4397 return false;
4398 }
4399
4400 // Also check for an index operand. This is only legal for vector registers,
4401 // but that'll get caught OK in operand matching, so we don't need to
4402 // explicitly filter everything else out here.
4403 if (Parser.getTok().is(AsmToken::LBrac)) {
4404 SMLoc SIdx = Parser.getTok().getLoc();
4405 Parser.Lex(); // Eat left bracket token.
4406
4407 const MCExpr *ImmVal;
4408 if (getParser().parseExpression(ImmVal))
4409 return true;
4410 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
4411 if (!MCE)
4412 return TokError("immediate value expected for vector index");
4413
4414 if (Parser.getTok().isNot(AsmToken::RBrac))
4415 return Error(Parser.getTok().getLoc(), "']' expected");
4416
4417 SMLoc E = Parser.getTok().getEndLoc();
4418 Parser.Lex(); // Eat right bracket token.
4419
4420 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(), SIdx, E,
4421 getContext(), *this));
4422 }
4423
4424 return false;
4425}
4426
4427/// MatchCoprocessorOperandName - Try to parse an coprocessor related
4428/// instruction with a symbolic operand name.
4429/// We accept "crN" syntax for GAS compatibility.
4430/// <operand-name> ::= <prefix><number>
4431/// If CoprocOp is 'c', then:
4432/// <prefix> ::= c | cr
4433/// If CoprocOp is 'p', then :
4434/// <prefix> ::= p
4435/// <number> ::= integer in range [0, 15]
4436static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
4437 // Use the same layout as the tablegen'erated register name matcher. Ugly,
4438 // but efficient.
4439 if (Name.size() < 2 || Name[0] != CoprocOp)
4440 return -1;
4441 Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front();
4442
4443 switch (Name.size()) {
4444 default: return -1;
4445 case 1:
4446 switch (Name[0]) {
4447 default: return -1;
4448 case '0': return 0;
4449 case '1': return 1;
4450 case '2': return 2;
4451 case '3': return 3;
4452 case '4': return 4;
4453 case '5': return 5;
4454 case '6': return 6;
4455 case '7': return 7;
4456 case '8': return 8;
4457 case '9': return 9;
4458 }
4459 case 2:
4460 if (Name[0] != '1')
4461 return -1;
4462 switch (Name[1]) {
4463 default: return -1;
4464 // CP10 and CP11 are VFP/NEON and so vector instructions should be used.
4465 // However, old cores (v5/v6) did use them in that way.
4466 case '0': return 10;
4467 case '1': return 11;
4468 case '2': return 12;
4469 case '3': return 13;
4470 case '4': return 14;
4471 case '5': return 15;
4472 }
4473 }
4474}
4475
4476/// parseITCondCode - Try to parse a condition code for an IT instruction.
4477ParseStatus ARMAsmParser::parseITCondCode(OperandVector &Operands) {
4478 MCAsmParser &Parser = getParser();
4479 SMLoc S = Parser.getTok().getLoc();
4480 const AsmToken &Tok = Parser.getTok();
4481 if (!Tok.is(AsmToken::Identifier))
4482 return ParseStatus::NoMatch;
4483 unsigned CC = ARMCondCodeFromString(Tok.getString());
4484 if (CC == ~0U)
4485 return ParseStatus::NoMatch;
4486 Parser.Lex(); // Eat the token.
4487
4488 Operands.push_back(
4489 ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S, *this));
4490
4491 return ParseStatus::Success;
4492}
4493
4494/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
4495/// token must be an Identifier when called, and if it is a coprocessor
4496/// number, the token is eaten and the operand is added to the operand list.
4497ParseStatus ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) {
4498 MCAsmParser &Parser = getParser();
4499 SMLoc S = Parser.getTok().getLoc();
4500 const AsmToken &Tok = Parser.getTok();
4501 if (Tok.isNot(AsmToken::Identifier))
4502 return ParseStatus::NoMatch;
4503
4504 int Num = MatchCoprocessorOperandName(Tok.getString().lower(), 'p');
4505 if (Num == -1)
4506 return ParseStatus::NoMatch;
4507 if (!isValidCoprocessorNumber(Num, getSTI().getFeatureBits()))
4508 return ParseStatus::NoMatch;
4509
4510 Parser.Lex(); // Eat identifier token.
4511 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S, *this));
4512 return ParseStatus::Success;
4513}
4514
4515/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
4516/// token must be an Identifier when called, and if it is a coprocessor
4517/// number, the token is eaten and the operand is added to the operand list.
4518ParseStatus ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) {
4519 MCAsmParser &Parser = getParser();
4520 SMLoc S = Parser.getTok().getLoc();
4521 const AsmToken &Tok = Parser.getTok();
4522 if (Tok.isNot(AsmToken::Identifier))
4523 return ParseStatus::NoMatch;
4524
4525 int Reg = MatchCoprocessorOperandName(Tok.getString().lower(), 'c');
4526 if (Reg == -1)
4527 return ParseStatus::NoMatch;
4528
4529 Parser.Lex(); // Eat identifier token.
4530 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S, *this));
4531 return ParseStatus::Success;
4532}
4533
4534/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
4535/// coproc_option : '{' imm0_255 '}'
4536ParseStatus ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) {
4537 MCAsmParser &Parser = getParser();
4538 SMLoc S = Parser.getTok().getLoc();
4539
4540 // If this isn't a '{', this isn't a coprocessor immediate operand.
4541 if (Parser.getTok().isNot(AsmToken::LCurly))
4542 return ParseStatus::NoMatch;
4543 Parser.Lex(); // Eat the '{'
4544
4545 const MCExpr *Expr;
4546 SMLoc Loc = Parser.getTok().getLoc();
4547 if (getParser().parseExpression(Expr))
4548 return Error(Loc, "illegal expression");
4549 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4550 if (!CE || CE->getValue() < 0 || CE->getValue() > 255)
4551 return Error(Loc,
4552 "coprocessor option must be an immediate in range [0, 255]");
4553 int Val = CE->getValue();
4554
4555 // Check for and consume the closing '}'
4556 if (Parser.getTok().isNot(AsmToken::RCurly))
4557 return ParseStatus::Failure;
4558 SMLoc E = Parser.getTok().getEndLoc();
4559 Parser.Lex(); // Eat the '}'
4560
4561 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E, *this));
4562 return ParseStatus::Success;
4563}
4564
4565// For register list parsing, we need to map from raw GPR register numbering
4566// to the enumeration values. The enumeration values aren't sorted by
4567// register number due to our using "sp", "lr" and "pc" as canonical names.
4569 // If this is a GPR, we need to do it manually, otherwise we can rely
4570 // on the sort ordering of the enumeration since the other reg-classes
4571 // are sane.
4572 if (!getARMMCRegisterClass(ARM::GPRRegClassID).contains(Reg))
4573 return Reg + 1;
4574 switch (Reg.id()) {
4575 default: llvm_unreachable("Invalid GPR number!");
4576 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
4577 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
4578 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
4579 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
4580 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
4581 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
4582 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
4583 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
4584 }
4585}
4586
4587// Insert an <Encoding, Register> pair in an ordered vector. Return true on
4588// success, or false, if duplicate encoding found.
4589static bool
4590insertNoDuplicates(SmallVectorImpl<std::pair<unsigned, MCRegister>> &Regs,
4591 unsigned Enc, MCRegister Reg) {
4592 Regs.emplace_back(Enc, Reg);
4593 for (auto I = Regs.rbegin(), J = I + 1, E = Regs.rend(); J != E; ++I, ++J) {
4594 if (J->first == Enc) {
4595 Regs.erase(J.base());
4596 return false;
4597 }
4598 if (J->first < Enc)
4599 break;
4600 std::swap(*I, *J);
4601 }
4602 return true;
4603}
4604
4605/// Parse a register list.
4606bool ARMAsmParser::parseRegisterList(OperandVector &Operands, bool EnforceOrder,
4607 bool AllowRAAC, bool IsLazyLoadStore,
4608 bool IsVSCCLRM) {
4609 MCAsmParser &Parser = getParser();
4610 if (Parser.getTok().isNot(AsmToken::LCurly))
4611 return TokError("Token is not a Left Curly Brace");
4612 SMLoc S = Parser.getTok().getLoc();
4613 Parser.Lex(); // Eat '{' token.
4614 SMLoc RegLoc = Parser.getTok().getLoc();
4615
4616 // Check the first register in the list to see what register class
4617 // this is a list of.
4618 bool AllowOutOfBoundReg = IsLazyLoadStore || IsVSCCLRM;
4619 MCRegister Reg = tryParseRegister(AllowOutOfBoundReg);
4620 if (!Reg)
4621 return Error(RegLoc, "register expected");
4622 if (!AllowRAAC && Reg == ARM::RA_AUTH_CODE)
4623 return Error(RegLoc, "pseudo-register not allowed");
4624 // The reglist instructions have at most 32 registers, so reserve
4625 // space for that many.
4626 int EReg = 0;
4628
4629 // Single-precision VSCCLRM can have double-precision registers in the
4630 // register list. When VSCCLRMAdjustEncoding is true then we've switched from
4631 // single-precision to double-precision and we pretend that these registers
4632 // are encoded as S32 onwards, which we can do by adding 16 to the encoding
4633 // value.
4634 bool VSCCLRMAdjustEncoding = false;
4635
4636 // Allow Q regs and just interpret them as the two D sub-registers.
4637 if (getARMMCRegisterClass(ARM::QPRRegClassID).contains(Reg)) {
4638 Reg = getDRegFromQReg(Reg);
4639 EReg = MRI->getEncodingValue(Reg);
4640 Registers.emplace_back(EReg, Reg);
4641 Reg = Reg + 1;
4642 }
4643 const MCRegisterClass *RC;
4644 if (Reg == ARM::RA_AUTH_CODE ||
4645 getARMMCRegisterClass(ARM::GPRRegClassID).contains(Reg))
4646 RC = &getARMMCRegisterClass(ARM::GPRRegClassID);
4647 else if (getARMMCRegisterClass(ARM::DPRRegClassID).contains(Reg))
4648 RC = &getARMMCRegisterClass(ARM::DPRRegClassID);
4649 else if (getARMMCRegisterClass(ARM::SPRRegClassID).contains(Reg))
4650 RC = &getARMMCRegisterClass(ARM::SPRRegClassID);
4651 else if (getARMMCRegisterClass(ARM::GPRwithAPSRnospRegClassID).contains(Reg))
4652 RC = &getARMMCRegisterClass(ARM::GPRwithAPSRnospRegClassID);
4653 else if (Reg == ARM::VPR)
4654 RC = &getARMMCRegisterClass(ARM::FPWithVPRRegClassID);
4655 else
4656 return Error(RegLoc, "invalid register in register list");
4657
4658 // Store the register.
4659 EReg = MRI->getEncodingValue(Reg);
4660 Registers.emplace_back(EReg, Reg);
4661
4662 // This starts immediately after the first register token in the list,
4663 // so we can see either a comma or a minus (range separator) as a legal
4664 // next token.
4665 while (Parser.getTok().is(AsmToken::Comma) ||
4666 Parser.getTok().is(AsmToken::Minus)) {
4667 if (Parser.getTok().is(AsmToken::Minus)) {
4668 if (Reg == ARM::RA_AUTH_CODE)
4669 return Error(RegLoc, "pseudo-register not allowed");
4670 Parser.Lex(); // Eat the minus.
4671 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
4672 MCRegister EndReg = tryParseRegister(AllowOutOfBoundReg);
4673 if (!EndReg)
4674 return Error(AfterMinusLoc, "register expected");
4675 if (EndReg == ARM::RA_AUTH_CODE)
4676 return Error(AfterMinusLoc, "pseudo-register not allowed");
4677 // Allow Q regs and just interpret them as the two D sub-registers.
4678 if (getARMMCRegisterClass(ARM::QPRRegClassID).contains(EndReg))
4679 EndReg = getDRegFromQReg(EndReg) + 1;
4680 // If the register is the same as the start reg, there's nothing
4681 // more to do.
4682 if (Reg == EndReg)
4683 continue;
4684 // The register must be in the same register class as the first.
4685 if (!RC->contains(Reg))
4686 return Error(AfterMinusLoc, "invalid register in register list");
4687 // Ranges must go from low to high.
4688 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
4689 return Error(AfterMinusLoc, "bad range in register list");
4690
4691 // Add all the registers in the range to the register list.
4692 while (Reg != EndReg) {
4694 EReg = MRI->getEncodingValue(Reg);
4695 if (VSCCLRMAdjustEncoding)
4696 EReg += 16;
4697 if (!insertNoDuplicates(Registers, EReg, Reg)) {
4698 Warning(AfterMinusLoc, StringRef("duplicated register (") +
4700 ") in register list");
4701 }
4702 }
4703 continue;
4704 }
4705 Parser.Lex(); // Eat the comma.
4706 RegLoc = Parser.getTok().getLoc();
4707 MCRegister OldReg = Reg;
4708 int EOldReg = EReg;
4709 const AsmToken RegTok = Parser.getTok();
4710 Reg = tryParseRegister(AllowOutOfBoundReg);
4711 if (!Reg)
4712 return Error(RegLoc, "register expected");
4713 if (!AllowRAAC && Reg == ARM::RA_AUTH_CODE)
4714 return Error(RegLoc, "pseudo-register not allowed");
4715 // Allow Q regs and just interpret them as the two D sub-registers.
4716 bool isQReg = false;
4717 if (getARMMCRegisterClass(ARM::QPRRegClassID).contains(Reg)) {
4718 Reg = getDRegFromQReg(Reg);
4719 isQReg = true;
4720 }
4721 if (Reg != ARM::RA_AUTH_CODE && !RC->contains(Reg) &&
4722 RC->getID() == getARMMCRegisterClass(ARM::GPRRegClassID).getID() &&
4723 getARMMCRegisterClass(ARM::GPRwithAPSRnospRegClassID).contains(Reg)) {
4724 // switch the register classes, as GPRwithAPSRnospRegClassID is a partial
4725 // subset of GPRRegClassId except it contains APSR as well.
4726 RC = &getARMMCRegisterClass(ARM::GPRwithAPSRnospRegClassID);
4727 }
4728 if (Reg == ARM::VPR &&
4729 (RC == &getARMMCRegisterClass(ARM::SPRRegClassID) ||
4730 RC == &getARMMCRegisterClass(ARM::DPRRegClassID) ||
4731 RC == &getARMMCRegisterClass(ARM::FPWithVPRRegClassID))) {
4732 RC = &getARMMCRegisterClass(ARM::FPWithVPRRegClassID);
4733 EReg = MRI->getEncodingValue(Reg);
4734 if (!insertNoDuplicates(Registers, EReg, Reg)) {
4735 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
4736 ") in register list");
4737 }
4738 continue;
4739 }
4740 // VSCCLRM can switch from single-precision to double-precision only when
4741 // S31 is followed by D16.
4742 if (IsVSCCLRM && OldReg == ARM::S31 && Reg == ARM::D16) {
4743 VSCCLRMAdjustEncoding = true;
4744 RC = &getARMMCRegisterClass(ARM::FPWithVPRRegClassID);
4745 }
4746 // The register must be in the same register class as the first.
4747 if ((Reg == ARM::RA_AUTH_CODE &&
4748 RC != &getARMMCRegisterClass(ARM::GPRRegClassID)) ||
4749 (Reg != ARM::RA_AUTH_CODE && !RC->contains(Reg)))
4750 return Error(RegLoc, "invalid register in register list");
4751 // In most cases, the list must be monotonically increasing. An
4752 // exception is CLRM, which is order-independent anyway, so
4753 // there's no potential for confusion if you write clrm {r2,r1}
4754 // instead of clrm {r1,r2}.
4755 EReg = MRI->getEncodingValue(Reg);
4756 if (VSCCLRMAdjustEncoding)
4757 EReg += 16;
4758 if (EnforceOrder && EReg < EOldReg) {
4759 if (getARMMCRegisterClass(ARM::GPRRegClassID).contains(Reg))
4760 Warning(RegLoc, "register list not in ascending order");
4761 else if (!getARMMCRegisterClass(ARM::GPRwithAPSRnospRegClassID)
4762 .contains(Reg))
4763 return Error(RegLoc, "register list not in ascending order");
4764 }
4765 // VFP register lists must also be contiguous.
4766 if (RC != &getARMMCRegisterClass(ARM::GPRRegClassID) &&
4767 RC != &getARMMCRegisterClass(ARM::GPRwithAPSRnospRegClassID) &&
4768 EReg != EOldReg + 1)
4769 return Error(RegLoc, "non-contiguous register range");
4770
4771 if (!insertNoDuplicates(Registers, EReg, Reg)) {
4772 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
4773 ") in register list");
4774 }
4775 if (isQReg) {
4776 Reg = Reg + 1;
4777 EReg = MRI->getEncodingValue(Reg);
4778 Registers.emplace_back(EReg, Reg);
4779 }
4780 }
4781
4782 if (Parser.getTok().isNot(AsmToken::RCurly))
4783 return Error(Parser.getTok().getLoc(), "'}' expected");
4784 SMLoc E = Parser.getTok().getEndLoc();
4785 Parser.Lex(); // Eat '}' token.
4786
4787 // Push the register list operand.
4788 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E, *this));
4789
4790 // The ARM system instruction variants for LDM/STM have a '^' token here.
4791 if (Parser.getTok().is(AsmToken::Caret)) {
4792 Operands.push_back(
4793 ARMOperand::CreateToken("^", Parser.getTok().getLoc(), *this));
4794 Parser.Lex(); // Eat '^' token.
4795 }
4796
4797 return false;
4798}
4799
4800// Helper function to parse the lane index for vector lists.
4801ParseStatus ARMAsmParser::parseVectorLane(VectorLaneTy &LaneKind,
4802 unsigned &Index, SMLoc &EndLoc) {
4803 MCAsmParser &Parser = getParser();
4804 Index = 0; // Always return a defined index value.
4805 if (Parser.getTok().is(AsmToken::LBrac)) {
4806 Parser.Lex(); // Eat the '['.
4807 if (Parser.getTok().is(AsmToken::RBrac)) {
4808 // "Dn[]" is the 'all lanes' syntax.
4809 LaneKind = AllLanes;
4810 EndLoc = Parser.getTok().getEndLoc();
4811 Parser.Lex(); // Eat the ']'.
4812 return ParseStatus::Success;
4813 }
4814
4815 // There's an optional '#' token here. Normally there wouldn't be, but
4816 // inline assemble puts one in, and it's friendly to accept that.
4817 if (Parser.getTok().is(AsmToken::Hash))
4818 Parser.Lex(); // Eat '#' or '$'.
4819
4820 const MCExpr *LaneIndex;
4821 SMLoc Loc = Parser.getTok().getLoc();
4822 if (getParser().parseExpression(LaneIndex))
4823 return Error(Loc, "illegal expression");
4824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
4825 if (!CE)
4826 return Error(Loc, "lane index must be empty or an integer");
4827 if (Parser.getTok().isNot(AsmToken::RBrac))
4828 return Error(Parser.getTok().getLoc(), "']' expected");
4829 EndLoc = Parser.getTok().getEndLoc();
4830 Parser.Lex(); // Eat the ']'.
4831 int64_t Val = CE->getValue();
4832
4833 // FIXME: Make this range check context sensitive for .8, .16, .32.
4834 if (Val < 0 || Val > 7)
4835 return Error(Parser.getTok().getLoc(), "lane index out of range");
4836 Index = Val;
4837 LaneKind = IndexedLane;
4838 return ParseStatus::Success;
4839 }
4840 LaneKind = NoLanes;
4841 return ParseStatus::Success;
4842}
4843
4844// parse a vector register list
4845ParseStatus ARMAsmParser::parseVectorList(OperandVector &Operands) {
4846 MCAsmParser &Parser = getParser();
4847 VectorLaneTy LaneKind;
4848 unsigned LaneIndex;
4849 SMLoc S = Parser.getTok().getLoc();
4850 // As an extension (to match gas), support a plain D register or Q register
4851 // (without encosing curly braces) as a single or double entry list,
4852 // respectively.
4853 // If there is no lane supplied, just parse as a register and
4854 // use the custom matcher to convert to list if necessary
4855 if (!hasMVE() && Parser.getTok().is(AsmToken::Identifier)) {
4856 SMLoc E = Parser.getTok().getEndLoc();
4857 MCRegister Reg = tryParseRegister();
4858 if (!Reg)
4859 return ParseStatus::NoMatch;
4860 if (getARMMCRegisterClass(ARM::DPRRegClassID).contains(Reg)) {
4861 ParseStatus Res = parseVectorLane(LaneKind, LaneIndex, E);
4862 if (!Res.isSuccess())
4863 return Res;
4864 switch (LaneKind) {
4865 case NoLanes:
4866 Operands.push_back(ARMOperand::CreateReg(Reg, S, E, *this));
4867 break;
4868 case AllLanes:
4869 Operands.push_back(
4870 ARMOperand::CreateVectorListAllLanes(Reg, 1, false, S, E, *this));
4871 break;
4872 case IndexedLane:
4873 Operands.push_back(ARMOperand::CreateVectorListIndexed(
4874 Reg, 1, LaneIndex, false, S, E, *this));
4875 break;
4876 }
4877 return ParseStatus::Success;
4878 }
4879 if (getARMMCRegisterClass(ARM::QPRRegClassID).contains(Reg)) {
4880 Reg = getDRegFromQReg(Reg);
4881 ParseStatus Res = parseVectorLane(LaneKind, LaneIndex, E);
4882 if (!Res.isSuccess())
4883 return Res;
4884 switch (LaneKind) {
4885 case NoLanes:
4886 Operands.push_back(ARMOperand::CreateReg(Reg, S, E, *this));
4887 break;
4888 case AllLanes:
4889 Reg = MRI->getMatchingSuperReg(
4890 Reg, ARM::dsub_0, &getARMMCRegisterClass(ARM::DPairRegClassID));
4891 Operands.push_back(
4892 ARMOperand::CreateVectorListAllLanes(Reg, 2, false, S, E, *this));
4893 break;
4894 case IndexedLane:
4895 Operands.push_back(ARMOperand::CreateVectorListIndexed(
4896 Reg, 2, LaneIndex, false, S, E, *this));
4897 break;
4898 }
4899 return ParseStatus::Success;
4900 }
4901 Operands.push_back(ARMOperand::CreateReg(Reg, S, E, *this));
4902 return ParseStatus::Success;
4903 }
4904
4905 if (Parser.getTok().isNot(AsmToken::LCurly))
4906 return ParseStatus::NoMatch;
4907
4908 Parser.Lex(); // Eat '{' token.
4909 SMLoc RegLoc = Parser.getTok().getLoc();
4910
4911 MCRegister Reg = tryParseRegister();
4912 if (!Reg)
4913 return Error(RegLoc, "register expected");
4914 unsigned Count = 1;
4915 int Spacing = 0;
4916 MCRegister FirstReg = Reg;
4917
4918 if (hasMVE() && !getARMMCRegisterClass(ARM::MQPRRegClassID).contains(Reg))
4919 return Error(Parser.getTok().getLoc(),
4920 "vector register in range Q0-Q7 expected");
4921 // The list is of D registers, but we also allow Q regs and just interpret
4922 // them as the two D sub-registers.
4923 else if (!hasMVE() &&
4924 getARMMCRegisterClass(ARM::QPRRegClassID).contains(Reg)) {
4925 FirstReg = Reg = getDRegFromQReg(Reg);
4926 Spacing = 1; // double-spacing requires explicit D registers, otherwise
4927 // it's ambiguous with four-register single spaced.
4928 Reg = Reg + 1;
4929 ++Count;
4930 }
4931
4932 SMLoc E;
4933 if (!parseVectorLane(LaneKind, LaneIndex, E).isSuccess())
4934 return ParseStatus::Failure;
4935
4936 while (Parser.getTok().is(AsmToken::Comma) ||
4937 Parser.getTok().is(AsmToken::Minus)) {
4938 if (Parser.getTok().is(AsmToken::Minus)) {
4939 if (!Spacing)
4940 Spacing = 1; // Register range implies a single spaced list.
4941 else if (Spacing == 2)
4942 return Error(Parser.getTok().getLoc(),
4943 "sequential registers in double spaced list");
4944 Parser.Lex(); // Eat the minus.
4945 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
4946 MCRegister EndReg = tryParseRegister();
4947 if (!EndReg)
4948 return Error(AfterMinusLoc, "register expected");
4949 // Allow Q regs and just interpret them as the two D sub-registers.
4950 if (!hasMVE() &&
4951 getARMMCRegisterClass(ARM::QPRRegClassID).contains(EndReg))
4952 EndReg = getDRegFromQReg(EndReg) + 1;
4953 // If the register is the same as the start reg, there's nothing
4954 // more to do.
4955 if (Reg == EndReg)
4956 continue;
4957 // The register must be in the same register class as the first.
4958 if ((hasMVE() &&
4959 !getARMMCRegisterClass(ARM::MQPRRegClassID).contains(EndReg)) ||
4960 (!hasMVE() &&
4961 !getARMMCRegisterClass(ARM::DPRRegClassID).contains(EndReg)))
4962 return Error(AfterMinusLoc, "invalid register in register list");
4963 // Ranges must go from low to high.
4964 if (Reg > EndReg)
4965 return Error(AfterMinusLoc, "bad range in register list");
4966 // Parse the lane specifier if present.
4967 VectorLaneTy NextLaneKind;
4968 unsigned NextLaneIndex;
4969 if (!parseVectorLane(NextLaneKind, NextLaneIndex, E).isSuccess())
4970 return ParseStatus::Failure;
4971 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex)
4972 return Error(AfterMinusLoc, "mismatched lane index in register list");
4973
4974 // Add all the registers in the range to the register list.
4975 Count += EndReg - Reg;
4976 Reg = EndReg;
4977 continue;
4978 }
4979 Parser.Lex(); // Eat the comma.
4980 RegLoc = Parser.getTok().getLoc();
4981 MCRegister OldReg = Reg;
4982 Reg = tryParseRegister();
4983 if (!Reg)
4984 return Error(RegLoc, "register expected");
4985
4986 if (hasMVE()) {
4987 if (!getARMMCRegisterClass(ARM::MQPRRegClassID).contains(Reg))
4988 return Error(RegLoc, "vector register in range Q0-Q7 expected");
4989 Spacing = 1;
4990 }
4991 // vector register lists must be contiguous.
4992 // It's OK to use the enumeration values directly here rather, as the
4993 // VFP register classes have the enum sorted properly.
4994 //
4995 // The list is of D registers, but we also allow Q regs and just interpret
4996 // them as the two D sub-registers.
4997 else if (getARMMCRegisterClass(ARM::QPRRegClassID).contains(Reg)) {
4998 if (!Spacing)
4999 Spacing = 1; // Register range implies a single spaced list.
5000 else if (Spacing == 2)
5001 return Error(
5002 RegLoc,
5003 "invalid register in double-spaced list (must be 'D' register')");
5004 Reg = getDRegFromQReg(Reg);
5005 if (Reg != OldReg + 1)
5006 return Error(RegLoc, "non-contiguous register range");
5007 Reg = Reg + 1;
5008 Count += 2;
5009 // Parse the lane specifier if present.
5010 VectorLaneTy NextLaneKind;
5011 unsigned NextLaneIndex;
5012 SMLoc LaneLoc = Parser.getTok().getLoc();
5013 if (!parseVectorLane(NextLaneKind, NextLaneIndex, E).isSuccess())
5014 return ParseStatus::Failure;
5015 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex)
5016 return Error(LaneLoc, "mismatched lane index in register list");
5017 continue;
5018 }
5019 // Normal D register.
5020 // Figure out the register spacing (single or double) of the list if
5021 // we don't know it already.
5022 if (!Spacing)
5023 Spacing = 1 + (Reg == OldReg + 2);
5024
5025 // Just check that it's contiguous and keep going.
5026 if (Reg != OldReg + Spacing)
5027 return Error(RegLoc, "non-contiguous register range");
5028 ++Count;
5029 // Parse the lane specifier if present.
5030 VectorLaneTy NextLaneKind;
5031 unsigned NextLaneIndex;
5032 SMLoc EndLoc = Parser.getTok().getLoc();
5033 if (!parseVectorLane(NextLaneKind, NextLaneIndex, E).isSuccess())
5034 return ParseStatus::Failure;
5035 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex)
5036 return Error(EndLoc, "mismatched lane index in register list");
5037 }
5038
5039 if (Parser.getTok().isNot(AsmToken::RCurly))
5040 return Error(Parser.getTok().getLoc(), "'}' expected");
5041 E = Parser.getTok().getEndLoc();
5042 Parser.Lex(); // Eat '}' token.
5043
5044 switch (LaneKind) {
5045 case NoLanes:
5046 case AllLanes: {
5047 // Two-register operands have been converted to the
5048 // composite register classes.
5049 if (Count == 2 && !hasMVE()) {
5050 const MCRegisterClass *RC =
5051 (Spacing == 1) ? &getARMMCRegisterClass(ARM::DPairRegClassID)
5052 : &getARMMCRegisterClass(ARM::DPairSpcRegClassID);
5053 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
5054 }
5055 auto Create = (LaneKind == NoLanes ? ARMOperand::CreateVectorList :
5056 ARMOperand::CreateVectorListAllLanes);
5057 Operands.push_back(Create(FirstReg, Count, (Spacing == 2), S, E, *this));
5058 break;
5059 }
5060 case IndexedLane:
5061 Operands.push_back(ARMOperand::CreateVectorListIndexed(
5062 FirstReg, Count, LaneIndex, (Spacing == 2), S, E, *this));
5063 break;
5064 }
5065 return ParseStatus::Success;
5066}
5067
5068/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
5069ParseStatus ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) {
5070 MCAsmParser &Parser = getParser();
5071 SMLoc S = Parser.getTok().getLoc();
5072 const AsmToken &Tok = Parser.getTok();
5073 unsigned Opt;
5074
5075 if (Tok.is(AsmToken::Identifier)) {
5076 StringRef OptStr = Tok.getString();
5077
5078 Opt = StringSwitch<unsigned>(OptStr.lower())
5079 .Case("sy", ARM_MB::SY)
5080 .Case("st", ARM_MB::ST)
5081 .Case("ld", ARM_MB::LD)
5082 .Case("sh", ARM_MB::ISH)
5083 .Case("ish", ARM_MB::ISH)
5084 .Case("shst", ARM_MB::ISHST)
5085 .Case("ishst", ARM_MB::ISHST)
5086 .Case("ishld", ARM_MB::ISHLD)
5087 .Case("nsh", ARM_MB::NSH)
5088 .Case("un", ARM_MB::NSH)
5089 .Case("nshst", ARM_MB::NSHST)
5090 .Case("nshld", ARM_MB::NSHLD)
5091 .Case("unst", ARM_MB::NSHST)
5092 .Case("osh", ARM_MB::OSH)
5093 .Case("oshst", ARM_MB::OSHST)
5094 .Case("oshld", ARM_MB::OSHLD)
5095 .Default(~0U);
5096
5097 // ishld, oshld, nshld and ld are only available from ARMv8.
5098 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
5099 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
5100 Opt = ~0U;
5101
5102 if (Opt == ~0U)
5103 return ParseStatus::NoMatch;
5104
5105 Parser.Lex(); // Eat identifier token.
5106 } else if (Tok.is(AsmToken::Hash) ||
5107 Tok.is(AsmToken::Dollar) ||
5108 Tok.is(AsmToken::Integer)) {
5109 if (Parser.getTok().isNot(AsmToken::Integer))
5110 Parser.Lex(); // Eat '#' or '$'.
5111 SMLoc Loc = Parser.getTok().getLoc();
5112
5113 const MCExpr *MemBarrierID;
5114 if (getParser().parseExpression(MemBarrierID))
5115 return Error(Loc, "illegal expression");
5116
5117 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
5118 if (!CE)
5119 return Error(Loc, "constant expression expected");
5120
5121 int Val = CE->getValue();
5122 if (Val & ~0xf)
5123 return Error(Loc, "immediate value out of range");
5124
5125 Opt = ARM_MB::RESERVED_0 + Val;
5126 } else
5127 return Error(Parser.getTok().getLoc(),
5128 "expected an immediate or barrier type");
5129
5130 Operands.push_back(
5131 ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S, *this));
5132 return ParseStatus::Success;
5133}
5134
5135ParseStatus
5136ARMAsmParser::parseTraceSyncBarrierOptOperand(OperandVector &Operands) {
5137 MCAsmParser &Parser = getParser();
5138 SMLoc S = Parser.getTok().getLoc();
5139 const AsmToken &Tok = Parser.getTok();
5140
5141 if (Tok.isNot(AsmToken::Identifier))
5142 return ParseStatus::NoMatch;
5143
5144 if (!Tok.getString().equals_insensitive("csync"))
5145 return ParseStatus::NoMatch;
5146
5147 Parser.Lex(); // Eat identifier token.
5148
5149 Operands.push_back(
5150 ARMOperand::CreateTraceSyncBarrierOpt(ARM_TSB::CSYNC, S, *this));
5151 return ParseStatus::Success;
5152}
5153
5154/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
5155ParseStatus
5156ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) {
5157 MCAsmParser &Parser = getParser();
5158 SMLoc S = Parser.getTok().getLoc();
5159 const AsmToken &Tok = Parser.getTok();
5160 unsigned Opt;
5161
5162 if (Tok.is(AsmToken::Identifier)) {
5163 StringRef OptStr = Tok.getString();
5164
5165 if (OptStr.equals_insensitive("sy"))
5166 Opt = ARM_ISB::SY;
5167 else
5168 return ParseStatus::NoMatch;
5169
5170 Parser.Lex(); // Eat identifier token.
5171 } else if (Tok.is(AsmToken::Hash) ||
5172 Tok.is(AsmToken::Dollar) ||
5173 Tok.is(AsmToken::Integer)) {
5174 if (Parser.getTok().isNot(AsmToken::Integer))
5175 Parser.Lex(); // Eat '#' or '$'.
5176 SMLoc Loc = Parser.getTok().getLoc();
5177
5178 const MCExpr *ISBarrierID;
5179 if (getParser().parseExpression(ISBarrierID))
5180 return Error(Loc, "illegal expression");
5181
5182 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
5183 if (!CE)
5184 return Error(Loc, "constant expression expected");
5185
5186 int Val = CE->getValue();
5187 if (Val & ~0xf)
5188 return Error(Loc, "immediate value out of range");
5189
5190 Opt = ARM_ISB::RESERVED_0 + Val;
5191 } else
5192 return Error(Parser.getTok().getLoc(),
5193 "expected an immediate or barrier type");
5194
5195 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
5196 (ARM_ISB::InstSyncBOpt)Opt, S, *this));
5197 return ParseStatus::Success;
5198}
5199
5200/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
5201ParseStatus ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) {
5202 MCAsmParser &Parser = getParser();
5203 SMLoc S = Parser.getTok().getLoc();
5204 const AsmToken &Tok = Parser.getTok();
5205 if (!Tok.is(AsmToken::Identifier))
5206 return ParseStatus::NoMatch;
5207 StringRef IFlagsStr = Tok.getString();
5208
5209 // An iflags string of "none" is interpreted to mean that none of the AIF
5210 // bits are set. Not a terribly useful instruction, but a valid encoding.
5211 unsigned IFlags = 0;
5212 if (IFlagsStr != "none") {
5213 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
5214 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1).lower())
5215 .Case("a", ARM_PROC::A)
5216 .Case("i", ARM_PROC::I)
5217 .Case("f", ARM_PROC::F)
5218 .Default(~0U);
5219
5220 // If some specific iflag is already set, it means that some letter is
5221 // present more than once, this is not acceptable.
5222 if (Flag == ~0U || (IFlags & Flag))
5223 return ParseStatus::NoMatch;
5224
5225 IFlags |= Flag;
5226 }
5227 }
5228
5229 Parser.Lex(); // Eat identifier token.
5230 Operands.push_back(
5231 ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S, *this));
5232 return ParseStatus::Success;
5233}
5234
5235/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
5236ParseStatus ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) {
5237 // Don't parse two MSR registers in a row
5238 if (static_cast<ARMOperand &>(*Operands.back()).isMSRMask() ||
5239 static_cast<ARMOperand &>(*Operands.back()).isBankedReg())
5240 return ParseStatus::NoMatch;
5241 MCAsmParser &Parser = getParser();
5242 SMLoc S = Parser.getTok().getLoc();
5243 const AsmToken &Tok = Parser.getTok();
5244
5245 if (Tok.is(AsmToken::Integer)) {
5246 int64_t Val = Tok.getIntVal();
5247 if (Val > 255 || Val < 0) {
5248 return ParseStatus::NoMatch;
5249 }
5250 unsigned SYSmvalue = Val & 0xFF;
5251 Parser.Lex();
5252 Operands.push_back(ARMOperand::CreateMSRMask(SYSmvalue, S, *this));
5253 return ParseStatus::Success;
5254 }
5255
5256 if (!Tok.is(AsmToken::Identifier))
5257 return ParseStatus::NoMatch;
5258 StringRef Mask = Tok.getString();
5259
5260 if (isMClass()) {
5261 auto TheReg = ARMSysReg::lookupMClassSysRegByName(Mask.lower());
5262 if (!TheReg || !TheReg->hasRequiredFeatures(getSTI().getFeatureBits()))
5263 return ParseStatus::NoMatch;
5264
5265 unsigned SYSmvalue = TheReg->Encoding & 0xFFF;
5266
5267 Parser.Lex(); // Eat identifier token.
5268 Operands.push_back(ARMOperand::CreateMSRMask(SYSmvalue, S, *this));
5269 return ParseStatus::Success;
5270 }
5271
5272 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
5273 size_t Start = 0, Next = Mask.find('_');
5274 StringRef Flags = "";
5275 std::string SpecReg = Mask.slice(Start, Next).lower();
5276 if (Next != StringRef::npos)
5277 Flags = Mask.substr(Next + 1);
5278
5279 // FlagsVal contains the complete mask:
5280 // 3-0: Mask
5281 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
5282 unsigned FlagsVal = 0;
5283
5284 if (SpecReg == "apsr") {
5285 FlagsVal = StringSwitch<unsigned>(Flags)
5286 .Case("nzcvq", 0x8) // same as CPSR_f
5287 .Case("g", 0x4) // same as CPSR_s
5288 .Case("nzcvqg", 0xc) // same as CPSR_fs
5289 .Default(~0U);
5290
5291 if (FlagsVal == ~0U) {
5292 if (!Flags.empty())
5293 return ParseStatus::NoMatch;
5294 else
5295 FlagsVal = 8; // No flag
5296 }
5297 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
5298 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
5299 if (Flags == "all" || Flags == "")
5300 Flags = "fc";
5301 for (int i = 0, e = Flags.size(); i != e; ++i) {
5302 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
5303 .Case("c", 1)
5304 .Case("x", 2)
5305 .Case("s", 4)
5306 .Case("f", 8)
5307 .Default(~0U);
5308
5309 // If some specific flag is already set, it means that some letter is
5310 // present more than once, this is not acceptable.
5311 if (Flag == ~0U || (FlagsVal & Flag))
5312 return ParseStatus::NoMatch;
5313 FlagsVal |= Flag;
5314 }
5315 } else // No match for special register.
5316 return ParseStatus::NoMatch;
5317
5318 // Special register without flags is NOT equivalent to "fc" flags.
5319 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
5320 // two lines would enable gas compatibility at the expense of breaking
5321 // round-tripping.
5322 //
5323 // if (!FlagsVal)
5324 // FlagsVal = 0x9;
5325
5326 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
5327 if (SpecReg == "spsr")
5328 FlagsVal |= 16;
5329
5330 Parser.Lex(); // Eat identifier token.
5331 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S, *this));
5332 return ParseStatus::Success;
5333}
5334
5335/// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for
5336/// use in the MRS/MSR instructions added to support virtualization.
5337ParseStatus ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) {
5338 // Don't parse two Banked registers in a row
5339 if (static_cast<ARMOperand &>(*Operands.back()).isBankedReg() ||
5340 static_cast<ARMOperand &>(*Operands.back()).isMSRMask())
5341 return ParseStatus::NoMatch;
5342 MCAsmParser &Parser = getParser();
5343 SMLoc S = Parser.getTok().getLoc();
5344 const AsmToken &Tok = Parser.getTok();
5345 if (!Tok.is(AsmToken::Identifier))
5346 return ParseStatus::NoMatch;
5347 StringRef RegName = Tok.getString();
5348
5349 auto TheReg = ARMBankedReg::lookupBankedRegByName(RegName.lower());
5350 if (!TheReg)
5351 return ParseStatus::NoMatch;
5352 unsigned Encoding = TheReg->Encoding;
5353
5354 Parser.Lex(); // Eat identifier token.
5355 Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S, *this));
5356 return ParseStatus::Success;
5357}
5358
5359// FIXME: Unify the different methods for handling shift operators
5360// and use TableGen matching mechanisms to do the validation rather than
5361// separate parsing paths.
5362ParseStatus ARMAsmParser::parsePKHImm(OperandVector &Operands,
5363 ARM_AM::ShiftOpc Op, int Low, int High) {
5364 MCAsmParser &Parser = getParser();
5365 auto ShiftCodeOpt = tryParseShiftToken();
5366
5367 if (!ShiftCodeOpt.has_value())
5368 return ParseStatus::NoMatch;
5369 auto ShiftCode = ShiftCodeOpt.value();
5370
5371 // The wrong shift code has been provided. Can error here as has matched the
5372 // correct operand in this case.
5373 if (ShiftCode != Op)
5374 return Error(Parser.getTok().getLoc(),
5375 ARM_AM::getShiftOpcStr(Op) + " operand expected.");
5376
5377 Parser.Lex(); // Eat shift type token.
5378
5379 // There must be a '#' and a shift amount.
5380 if (Parser.getTok().isNot(AsmToken::Hash) &&
5381 Parser.getTok().isNot(AsmToken::Dollar))
5382 return ParseStatus::NoMatch;
5383 Parser.Lex(); // Eat hash token.
5384
5385 const MCExpr *ShiftAmount;
5386 SMLoc Loc = Parser.getTok().getLoc();
5387 SMLoc EndLoc;
5388 if (getParser().parseExpression(ShiftAmount, EndLoc))
5389 return Error(Loc, "illegal expression");
5390 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
5391 if (!CE)
5392 return Error(Loc, "constant expression expected");
5393 int Val = CE->getValue();
5394 if (Val < Low || Val > High)
5395 return Error(Loc, "immediate value out of range");
5396
5397 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc, *this));
5398
5399 return ParseStatus::Success;
5400}
5401
5402ParseStatus ARMAsmParser::parseSetEndImm(OperandVector &Operands) {
5403 MCAsmParser &Parser = getParser();
5404 const AsmToken &Tok = Parser.getTok();
5405 SMLoc S = Tok.getLoc();
5406 if (Tok.isNot(AsmToken::Identifier))
5407 return Error(S, "'be' or 'le' operand expected");
5408 int Val = StringSwitch<int>(Tok.getString().lower())
5409 .Case("be", 1)
5410 .Case("le", 0)
5411 .Default(-1);
5412 Parser.Lex(); // Eat the token.
5413
5414 if (Val == -1)
5415 return Error(S, "'be' or 'le' operand expected");
5416 Operands.push_back(ARMOperand::CreateImm(
5417 MCConstantExpr::create(Val, getContext()), S, Tok.getEndLoc(), *this));
5418 return ParseStatus::Success;
5419}
5420
5421/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
5422/// instructions. Legal values are:
5423/// lsl #n 'n' in [0,31]
5424/// asr #n 'n' in [1,32]
5425/// n == 32 encoded as n == 0.
5426ParseStatus ARMAsmParser::parseShifterImm(OperandVector &Operands) {
5427 MCAsmParser &Parser = getParser();
5428 const AsmToken &Tok = Parser.getTok();
5429 SMLoc S = Tok.getLoc();
5430 if (Tok.isNot(AsmToken::Identifier))
5431 return ParseStatus::NoMatch;
5432 StringRef ShiftName = Tok.getString();
5433 bool isASR;
5434 if (ShiftName == "lsl" || ShiftName == "LSL")
5435 isASR = false;
5436 else if (ShiftName == "asr" || ShiftName == "ASR")
5437 isASR = true;
5438 else
5439 return ParseStatus::NoMatch;
5440 Parser.Lex(); // Eat the operator.
5441
5442 // A '#' and a shift amount.
5443 if (Parser.getTok().isNot(AsmToken::Hash) &&
5444 Parser.getTok().isNot(AsmToken::Dollar))
5445 return Error(Parser.getTok().getLoc(), "'#' expected");
5446 Parser.Lex(); // Eat hash token.
5447 SMLoc ExLoc = Parser.getTok().getLoc();
5448
5449 const MCExpr *ShiftAmount;
5450 SMLoc EndLoc;
5451 if (getParser().parseExpression(ShiftAmount, EndLoc))
5452 return Error(ExLoc, "malformed shift expression");
5453 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
5454 if (!CE)
5455 return Error(ExLoc, "shift amount must be an immediate");
5456
5457 int64_t Val = CE->getValue();
5458 if (isASR) {
5459 // Shift amount must be in [1,32]
5460 if (Val < 1 || Val > 32)
5461 return Error(ExLoc, "'asr' shift amount must be in range [1,32]");
5462 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
5463 if (isThumb() && Val == 32)
5464 return Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
5465 if (Val == 32) Val = 0;
5466 } else {
5467 // Shift amount must be in [1,32]
5468 if (Val < 0 || Val > 31)
5469 return Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
5470 }
5471
5472 Operands.push_back(
5473 ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc, *this));
5474
5475 return ParseStatus::Success;
5476}
5477
5478/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
5479/// of instructions. Legal values are:
5480/// ror #n 'n' in {0, 8, 16, 24}
5481ParseStatus ARMAsmParser::parseRotImm(OperandVector &Operands) {
5482 MCAsmParser &Parser = getParser();
5483 const AsmToken &Tok = Parser.getTok();
5484 SMLoc S = Tok.getLoc();
5485 if (Tok.isNot(AsmToken::Identifier))
5486 return ParseStatus::NoMatch;
5487 StringRef ShiftName = Tok.getString();
5488 if (ShiftName != "ror" && ShiftName != "ROR")
5489 return ParseStatus::NoMatch;
5490 Parser.Lex(); // Eat the operator.
5491
5492 // A '#' and a rotate amount.
5493 if (Parser.getTok().isNot(AsmToken::Hash) &&
5494 Parser.getTok().isNot(AsmToken::Dollar))
5495 return Error(Parser.getTok().getLoc(), "'#' expected");
5496 Parser.Lex(); // Eat hash token.
5497 SMLoc ExLoc = Parser.getTok().getLoc();
5498
5499 const MCExpr *ShiftAmount;
5500 SMLoc EndLoc;
5501 if (getParser().parseExpression(ShiftAmount, EndLoc))
5502 return Error(ExLoc, "malformed rotate expression");
5503 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
5504 if (!CE)
5505 return Error(ExLoc, "rotate amount must be an immediate");
5506
5507 int64_t Val = CE->getValue();
5508 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
5509 // normally, zero is represented in asm by omitting the rotate operand
5510 // entirely.
5511 if (Val != 8 && Val != 16 && Val != 24 && Val != 0)
5512 return Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
5513
5514 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc, *this));
5515
5516 return ParseStatus::Success;
5517}
5518
5519ParseStatus ARMAsmParser::parseModImm(OperandVector &Operands) {
5520 MCAsmParser &Parser = getParser();
5521 AsmLexer &Lexer = getLexer();
5522 int64_t Imm1, Imm2;
5523
5524 SMLoc S = Parser.getTok().getLoc();
5525
5526 // 1) A mod_imm operand can appear in the place of a register name:
5527 // add r0, #mod_imm
5528 // add r0, r0, #mod_imm
5529 // to correctly handle the latter, we bail out as soon as we see an
5530 // identifier.
5531 //
5532 // 2) Similarly, we do not want to parse into complex operands:
5533 // mov r0, #mod_imm
5534 // mov r0, :lower16:(_foo)
5535 if (Parser.getTok().is(AsmToken::Identifier) ||
5536 Parser.getTok().is(AsmToken::Colon))
5537 return ParseStatus::NoMatch;
5538
5539 // Hash (dollar) is optional as per the ARMARM
5540 if (Parser.getTok().is(AsmToken::Hash) ||
5541 Parser.getTok().is(AsmToken::Dollar)) {
5542 // Avoid parsing into complex operands (#:)
5543 if (Lexer.peekTok().is(AsmToken::Colon))
5544 return ParseStatus::NoMatch;
5545
5546 // Eat the hash (dollar)
5547 Parser.Lex();
5548 }
5549
5550 SMLoc Sx1, Ex1;
5551 Sx1 = Parser.getTok().getLoc();
5552 const MCExpr *Imm1Exp;
5553 if (getParser().parseExpression(Imm1Exp, Ex1))
5554 return Error(Sx1, "malformed expression");
5555
5556 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm1Exp);
5557
5558 if (CE) {
5559 // Immediate must fit within 32-bits
5560 Imm1 = CE->getValue();
5561 int Enc = ARM_AM::getSOImmVal(Imm1);
5562 if (Enc != -1 && Parser.getTok().is(AsmToken::EndOfStatement)) {
5563 // We have a match!
5564 Operands.push_back(ARMOperand::CreateModImm(
5565 (Enc & 0xFF), (Enc & 0xF00) >> 7, Sx1, Ex1, *this));
5566 return ParseStatus::Success;
5567 }
5568
5569 // We have parsed an immediate which is not for us, fallback to a plain
5570 // immediate. This can happen for instruction aliases. For an example,
5571 // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform
5572 // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite
5573 // instruction with a mod_imm operand. The alias is defined such that the
5574 // parser method is shared, that's why we have to do this here.
5575 if (Parser.getTok().is(AsmToken::EndOfStatement)) {
5576 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1, *this));
5577 return ParseStatus::Success;
5578 }
5579 } else {
5580 // Operands like #(l1 - l2) can only be evaluated at a later stage (via an
5581 // MCFixup). Fallback to a plain immediate.
5582 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1, *this));
5583 return ParseStatus::Success;
5584 }
5585
5586 // From this point onward, we expect the input to be a (#bits, #rot) pair
5587 if (Parser.getTok().isNot(AsmToken::Comma))
5588 return Error(Sx1,
5589 "expected modified immediate operand: #[0, 255], #even[0-30]");
5590
5591 if (Imm1 & ~0xFF)
5592 return Error(Sx1, "immediate operand must a number in the range [0, 255]");
5593
5594 // Eat the comma
5595 Parser.Lex();
5596
5597 // Repeat for #rot
5598 SMLoc Sx2, Ex2;
5599 Sx2 = Parser.getTok().getLoc();
5600
5601 // Eat the optional hash (dollar)
5602 if (Parser.getTok().is(AsmToken::Hash) ||
5603 Parser.getTok().is(AsmToken::Dollar))
5604 Parser.Lex();
5605
5606 const MCExpr *Imm2Exp;
5607 if (getParser().parseExpression(Imm2Exp, Ex2))
5608 return Error(Sx2, "malformed expression");
5609
5610 CE = dyn_cast<MCConstantExpr>(Imm2Exp);
5611
5612 if (CE) {
5613 Imm2 = CE->getValue();
5614 if (!(Imm2 & ~0x1E)) {
5615 // We have a match!
5616 Operands.push_back(ARMOperand::CreateModImm(Imm1, Imm2, S, Ex2, *this));
5617 return ParseStatus::Success;
5618 }
5619 return Error(Sx2,
5620 "immediate operand must an even number in the range [0, 30]");
5621 } else {
5622 return Error(Sx2, "constant expression expected");
5623 }
5624}
5625
5626ParseStatus ARMAsmParser::parseBitfield(OperandVector &Operands) {
5627 MCAsmParser &Parser = getParser();
5628 SMLoc S = Parser.getTok().getLoc();
5629 // The bitfield descriptor is really two operands, the LSB and the width.
5630 if (Parser.getTok().isNot(AsmToken::Hash) &&
5631 Parser.getTok().isNot(AsmToken::Dollar))
5632 return ParseStatus::NoMatch;
5633 Parser.Lex(); // Eat hash token.
5634
5635 const MCExpr *LSBExpr;
5636 SMLoc E = Parser.getTok().getLoc();
5637 if (getParser().parseExpression(LSBExpr))
5638 return Error(E, "malformed immediate expression");
5639 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
5640 if (!CE)
5641 return Error(E, "'lsb' operand must be an immediate");
5642
5643 int64_t LSB = CE->getValue();
5644 // The LSB must be in the range [0,31]
5645 if (LSB < 0 || LSB > 31)
5646 return Error(E, "'lsb' operand must be in the range [0,31]");
5647 E = Parser.getTok().getLoc();
5648
5649 // Expect another immediate operand.
5650 if (Parser.getTok().isNot(AsmToken::Comma))
5651 return Error(Parser.getTok().getLoc(), "too few operands");
5652 Parser.Lex(); // Eat hash token.
5653 if (Parser.getTok().isNot(AsmToken::Hash) &&
5654 Parser.getTok().isNot(AsmToken::Dollar))
5655 return Error(Parser.getTok().getLoc(), "'#' expected");
5656 Parser.Lex(); // Eat hash token.
5657
5658 const MCExpr *WidthExpr;
5659 SMLoc EndLoc;
5660 if (getParser().parseExpression(WidthExpr, EndLoc))
5661 return Error(E, "malformed immediate expression");
5662 CE = dyn_cast<MCConstantExpr>(WidthExpr);
5663 if (!CE)
5664 return Error(E, "'width' operand must be an immediate");
5665
5666 int64_t Width = CE->getValue();
5667 // The LSB must be in the range [1,32-lsb]
5668 if (Width < 1 || Width > 32 - LSB)
5669 return Error(E, "'width' operand must be in the range [1,32-lsb]");
5670
5671 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc, *this));
5672
5673 return ParseStatus::Success;
5674}
5675
5676ParseStatus ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
5677 // Check for a post-index addressing register operand. Specifically:
5678 // postidx_reg := '+' register {, shift}
5679 // | '-' register {, shift}
5680 // | register {, shift}
5681
5682 // This method must return ParseStatus::NoMatch without consuming any tokens
5683 // in the case where there is no match, as other alternatives take other
5684 // parse methods.
5685 MCAsmParser &Parser = getParser();
5686 AsmToken Tok = Parser.getTok();
5687 SMLoc S = Tok.getLoc();
5688 bool haveEaten = false;
5689 bool isAdd = true;
5690 if (Tok.is(AsmToken::Plus)) {
5691 Parser.Lex(); // Eat the '+' token.
5692 haveEaten = true;
5693 } else if (Tok.is(AsmToken::Minus)) {
5694 Parser.Lex(); // Eat the '-' token.
5695 isAdd = false;
5696 haveEaten = true;
5697 }
5698
5699 SMLoc E = Parser.getTok().getEndLoc();
5700 MCRegister Reg = tryParseRegister();
5701 if (!Reg) {
5702 if (!haveEaten)
5703 return ParseStatus::NoMatch;
5704 return Error(Parser.getTok().getLoc(), "register expected");
5705 }
5706
5708 unsigned ShiftImm = 0;
5709 if (Parser.getTok().is(AsmToken::Comma)) {
5710 Parser.Lex(); // Eat the ','.
5711 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
5712 return ParseStatus::Failure;
5713
5714 // FIXME: Only approximates end...may include intervening whitespace.
5715 E = Parser.getTok().getLoc();
5716 }
5717
5718 Operands.push_back(
5719 ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy, ShiftImm, S, E, *this));
5720
5721 return ParseStatus::Success;
5722}
5723
5724ParseStatus ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
5725 // Check for a post-index addressing register operand. Specifically:
5726 // am3offset := '+' register
5727 // | '-' register
5728 // | register
5729 // | # imm
5730 // | # + imm
5731 // | # - imm
5732
5733 // This method must return ParseStatus::NoMatch without consuming any tokens
5734 // in the case where there is no match, as other alternatives take other
5735 // parse methods.
5736 MCAsmParser &Parser = getParser();
5737 AsmToken Tok = Parser.getTok();
5738 SMLoc S = Tok.getLoc();
5739
5740 // Do immediates first, as we always parse those if we have a '#'.
5741 if (Parser.getTok().is(AsmToken::Hash) ||
5742 Parser.getTok().is(AsmToken::Dollar)) {
5743 Parser.Lex(); // Eat '#' or '$'.
5744 // Explicitly look for a '-', as we need to encode negative zero
5745 // differently.
5746 bool isNegative = Parser.getTok().is(AsmToken::Minus);
5747 const MCExpr *Offset;
5748 SMLoc E;
5749 if (getParser().parseExpression(Offset, E))
5750 return ParseStatus::Failure;
5751 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
5752 if (!CE)
5753 return Error(S, "constant expression expected");
5754 // Negative zero is encoded as the flag value
5755 // std::numeric_limits<int32_t>::min().
5756 int32_t Val = CE->getValue();
5757 if (isNegative && Val == 0)
5758 Val = std::numeric_limits<int32_t>::min();
5759
5760 Operands.push_back(ARMOperand::CreateImm(
5761 MCConstantExpr::create(Val, getContext()), S, E, *this));
5762
5763 return ParseStatus::Success;
5764 }
5765
5766 bool haveEaten = false;
5767 bool isAdd = true;
5768 if (Tok.is(AsmToken::Plus)) {
5769 Parser.Lex(); // Eat the '+' token.
5770 haveEaten = true;
5771 } else if (Tok.is(AsmToken::Minus)) {
5772 Parser.Lex(); // Eat the '-' token.
5773 isAdd = false;
5774 haveEaten = true;
5775 }
5776
5777 Tok = Parser.getTok();
5778 MCRegister Reg = tryParseRegister();
5779 if (!Reg) {
5780 if (!haveEaten)
5781 return ParseStatus::NoMatch;
5782 return Error(Tok.getLoc(), "register expected");
5783 }
5784
5785 Operands.push_back(ARMOperand::CreatePostIdxReg(
5786 Reg, isAdd, ARM_AM::no_shift, 0, S, Tok.getEndLoc(), *this));
5787
5788 return ParseStatus::Success;
5789}
5790
5791// Finds the index of the first CondCode operator, if there is none returns 0
5793 unsigned MnemonicOpsEndInd) {
5794 for (unsigned I = 1; I < MnemonicOpsEndInd; ++I) {
5795 auto Op = static_cast<ARMOperand &>(*Operands[I]);
5796 if (Op.isCondCode())
5797 return I;
5798 }
5799 return 0;
5800}
5801
5803 unsigned MnemonicOpsEndInd) {
5804 for (unsigned I = 1; I < MnemonicOpsEndInd; ++I) {
5805 auto Op = static_cast<ARMOperand &>(*Operands[I]);
5806 if (Op.isCCOut())
5807 return I;
5808 }
5809 return 0;
5810}
5811
5812/// Convert parsed operands to MCInst. Needed here because this instruction
5813/// only has two register operands, but multiplication is commutative so
5814/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
5815void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
5816 const OperandVector &Operands) {
5817 unsigned MnemonicOpsEndInd = getMnemonicOpsEndInd(Operands);
5818 unsigned CondI = findCondCodeInd(Operands, MnemonicOpsEndInd);
5819 unsigned CondOutI = findCCOutInd(Operands, MnemonicOpsEndInd);
5820
5821 // 2 operand form
5822 unsigned RegRd = MnemonicOpsEndInd;
5823 unsigned RegRn = MnemonicOpsEndInd + 1;
5824 unsigned RegRm = MnemonicOpsEndInd;
5825
5826 if (Operands.size() == MnemonicOpsEndInd + 3) {
5827 // If we have a three-operand form, make sure to set Rn to be the operand
5828 // that isn't the same as Rd.
5829 if (((ARMOperand &)*Operands[RegRd]).getReg() ==
5830 ((ARMOperand &)*Operands[MnemonicOpsEndInd + 1]).getReg()) {
5831 RegRn = MnemonicOpsEndInd + 2;
5832 RegRm = MnemonicOpsEndInd + 1;
5833 } else {
5834 RegRn = MnemonicOpsEndInd + 1;
5835 RegRm = MnemonicOpsEndInd + 2;
5836 }
5837 }
5838
5839 // Rd
5840 ((ARMOperand &)*Operands[RegRd]).addRegOperands(Inst, 1);
5841 // CCOut
5842 if (CondOutI != 0) {
5843 ((ARMOperand &)*Operands[CondOutI]).addCCOutOperands(Inst, 1);
5844 } else {
5845 ARMOperand Op =
5846 *ARMOperand::CreateCCOut(0, Operands[0]->getEndLoc(), *this);
5847 Op.addCCOutOperands(Inst, 1);
5848 }
5849 // Rn
5850 ((ARMOperand &)*Operands[RegRn]).addRegOperands(Inst, 1);
5851 // Rm
5852 ((ARMOperand &)*Operands[RegRm]).addRegOperands(Inst, 1);
5853
5854 // Cond code
5855 if (CondI != 0) {
5856 ((ARMOperand &)*Operands[CondI]).addCondCodeOperands(Inst, 2);
5857 } else {
5858 ARMOperand Op = *ARMOperand::CreateCondCode(
5859 llvm::ARMCC::AL, Operands[0]->getEndLoc(), *this);
5860 Op.addCondCodeOperands(Inst, 2);
5861 }
5862}
5863
5864void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
5865 const OperandVector &Operands) {
5866 unsigned MnemonicOpsEndInd = getMnemonicOpsEndInd(Operands);
5867 unsigned CondI = findCondCodeInd(Operands, MnemonicOpsEndInd);
5868 unsigned Cond =
5869 (CondI == 0 ? ARMCC::AL
5870 : static_cast<ARMOperand &>(*Operands[CondI]).getCondCode());
5871
5872 // first decide whether or not the branch should be conditional
5873 // by looking at it's location relative to an IT block
5874 if(inITBlock()) {
5875 // inside an IT block we cannot have any conditional branches. any
5876 // such instructions needs to be converted to unconditional form
5877 switch(Inst.getOpcode()) {
5878 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
5879 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
5880 }
5881 } else {
5882 switch(Inst.getOpcode()) {
5883 case ARM::tB:
5884 case ARM::tBcc:
5885 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
5886 break;
5887 case ARM::t2B:
5888 case ARM::t2Bcc:
5889 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
5890 break;
5891 }
5892 }
5893
5894 // now decide on encoding size based on branch target range
5895 switch(Inst.getOpcode()) {
5896 // classify tB as either t2B or t1B based on range of immediate operand
5897 case ARM::tB: {
5898 ARMOperand &op = static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd]);
5899 if (!op.isSignedOffset<11, 1>() && isThumb() && hasV8MBaseline())
5900 Inst.setOpcode(ARM::t2B);
5901 break;
5902 }
5903 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
5904 case ARM::tBcc: {
5905 ARMOperand &op = static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd]);
5906 if (!op.isSignedOffset<8, 1>() && isThumb() && hasV8MBaseline())
5907 Inst.setOpcode(ARM::t2Bcc);
5908 break;
5909 }
5910 }
5911 ((ARMOperand &)*Operands[MnemonicOpsEndInd]).addImmOperands(Inst, 1);
5912 if (CondI != 0) {
5913 ((ARMOperand &)*Operands[CondI]).addCondCodeOperands(Inst, 2);
5914 } else {
5915 ARMOperand Op = *ARMOperand::CreateCondCode(
5916 llvm::ARMCC::AL, Operands[0]->getEndLoc(), *this);
5917 Op.addCondCodeOperands(Inst, 2);
5918 }
5919}
5920
5921void ARMAsmParser::cvtMVEVMOVQtoDReg(
5922 MCInst &Inst, const OperandVector &Operands) {
5923
5924 unsigned MnemonicOpsEndInd = getMnemonicOpsEndInd(Operands);
5925 unsigned CondI = findCondCodeInd(Operands, MnemonicOpsEndInd);
5926
5927 // mnemonic, condition code, Rt, Rt2, Qd, idx, Qd again, idx2
5928 assert(Operands.size() == MnemonicOpsEndInd + 6);
5929
5930 ((ARMOperand &)*Operands[MnemonicOpsEndInd]).addRegOperands(Inst, 1); // Rt
5931 ((ARMOperand &)*Operands[MnemonicOpsEndInd + 1])
5932 .addRegOperands(Inst, 1); // Rt2
5933 ((ARMOperand &)*Operands[MnemonicOpsEndInd + 2])
5934 .addRegOperands(Inst, 1); // Qd
5935 ((ARMOperand &)*Operands[MnemonicOpsEndInd + 3])
5936 .addMVEPairVectorIndexOperands(Inst, 1); // idx
5937 // skip second copy of Qd in Operands[6]
5938 ((ARMOperand &)*Operands[MnemonicOpsEndInd + 5])
5939 .addMVEPairVectorIndexOperands(Inst, 1); // idx2
5940 if (CondI != 0) {
5941 ((ARMOperand &)*Operands[CondI])
5942 .addCondCodeOperands(Inst, 2); // condition code
5943 } else {
5944 ARMOperand Op =
5945 *ARMOperand::CreateCondCode(ARMCC::AL, Operands[0]->getEndLoc(), *this);
5946 Op.addCondCodeOperands(Inst, 2);
5947 }
5948}
5949
5950/// Parse an ARM memory expression, return false if successful else return true
5951/// or an error. The first token must be a '[' when called.
5952bool ARMAsmParser::parseMemory(OperandVector &Operands) {
5953 MCAsmParser &Parser = getParser();
5954 SMLoc S, E;
5955 if (Parser.getTok().isNot(AsmToken::LBrac))
5956 return TokError("Token is not a Left Bracket");
5957 S = Parser.getTok().getLoc();
5958 Parser.Lex(); // Eat left bracket token.
5959
5960 const AsmToken &BaseRegTok = Parser.getTok();
5961 MCRegister BaseReg = tryParseRegister();
5962 if (!BaseReg)
5963 return Error(BaseRegTok.getLoc(), "register expected");
5964
5965 // The next token must either be a comma, a colon or a closing bracket.
5966 const AsmToken &Tok = Parser.getTok();
5967 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
5968 !Tok.is(AsmToken::RBrac))
5969 return Error(Tok.getLoc(), "malformed memory operand");
5970
5971 if (Tok.is(AsmToken::RBrac)) {
5972 E = Tok.getEndLoc();
5973 Parser.Lex(); // Eat right bracket token.
5974
5975 Operands.push_back(ARMOperand::CreateMem(
5976 BaseReg, nullptr, 0, ARM_AM::no_shift, 0, 0, false, S, E, *this));
5977
5978 // If there's a pre-indexing writeback marker, '!', just add it as a token
5979 // operand. It's rather odd, but syntactically valid.
5980 if (Parser.getTok().is(AsmToken::Exclaim)) {
5981 Operands.push_back(
5982 ARMOperand::CreateToken("!", Parser.getTok().getLoc(), *this));
5983 Parser.Lex(); // Eat the '!'.
5984 }
5985
5986 return false;
5987 }
5988
5989 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
5990 "Lost colon or comma in memory operand?!");
5991 if (Tok.is(AsmToken::Comma)) {
5992 Parser.Lex(); // Eat the comma.
5993 }
5994
5995 // If we have a ':', it's an alignment specifier.
5996 if (Parser.getTok().is(AsmToken::Colon)) {
5997 Parser.Lex(); // Eat the ':'.
5998 E = Parser.getTok().getLoc();
5999 SMLoc AlignmentLoc = Tok.getLoc();
6000
6001 const MCExpr *Expr;
6002 if (getParser().parseExpression(Expr))
6003 return true;
6004
6005 // The expression has to be a constant. Memory references with relocations
6006 // don't come through here, as they use the <label> forms of the relevant
6007 // instructions.
6008 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
6009 if (!CE)
6010 return Error (E, "constant expression expected");
6011
6012 unsigned Align = 0;
6013 switch (CE->getValue()) {
6014 default:
6015 return Error(E,
6016 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
6017 case 16: Align = 2; break;
6018 case 32: Align = 4; break;
6019 case 64: Align = 8; break;
6020 case 128: Align = 16; break;
6021 case 256: Align = 32; break;
6022 }
6023
6024 // Now we should have the closing ']'
6025 if (Parser.getTok().isNot(AsmToken::RBrac))
6026 return Error(Parser.getTok().getLoc(), "']' expected");
6027 E = Parser.getTok().getEndLoc();
6028 Parser.Lex(); // Eat right bracket token.
6029
6030 // Don't worry about range checking the value here. That's handled by
6031 // the is*() predicates.
6032 Operands.push_back(ARMOperand::CreateMem(BaseReg, nullptr, 0,
6033 ARM_AM::no_shift, 0, Align, false,
6034 S, E, *this, AlignmentLoc));
6035
6036 // If there's a pre-indexing writeback marker, '!', just add it as a token
6037 // operand.
6038 if (Parser.getTok().is(AsmToken::Exclaim)) {
6039 Operands.push_back(
6040 ARMOperand::CreateToken("!", Parser.getTok().getLoc(), *this));
6041 Parser.Lex(); // Eat the '!'.
6042 }
6043
6044 return false;
6045 }
6046
6047 // If we have a '#' or '$', it's an immediate offset, else assume it's a
6048 // register offset. Be friendly and also accept a plain integer or expression
6049 // (without a leading hash) for gas compatibility.
6050 if (Parser.getTok().is(AsmToken::Hash) ||
6051 Parser.getTok().is(AsmToken::Dollar) ||
6052 Parser.getTok().is(AsmToken::LParen) ||
6053 Parser.getTok().is(AsmToken::Integer)) {
6054 if (Parser.getTok().is(AsmToken::Hash) ||
6055 Parser.getTok().is(AsmToken::Dollar))
6056 Parser.Lex(); // Eat '#' or '$'
6057 E = Parser.getTok().getLoc();
6058
6059 bool isNegative = getParser().getTok().is(AsmToken::Minus);
6060 const MCExpr *Offset, *AdjustedOffset;
6061 if (getParser().parseExpression(Offset))
6062 return true;
6063
6064 if (const auto *CE = dyn_cast<MCConstantExpr>(Offset)) {
6065 // If the constant was #-0, represent it as
6066 // std::numeric_limits<int32_t>::min().
6067 int32_t Val = CE->getValue();
6068 if (isNegative && Val == 0)
6069 CE = MCConstantExpr::create(std::numeric_limits<int32_t>::min(),
6070 getContext());
6071 // Don't worry about range checking the value here. That's handled by
6072 // the is*() predicates.
6073 AdjustedOffset = CE;
6074 } else
6075 AdjustedOffset = Offset;
6076 Operands.push_back(ARMOperand::CreateMem(BaseReg, AdjustedOffset, 0,
6077 ARM_AM::no_shift, 0, 0, false, S,
6078 E, *this));
6079
6080 // Now we should have the closing ']'
6081 if (Parser.getTok().isNot(AsmToken::RBrac))
6082 return Error(Parser.getTok().getLoc(), "']' expected");
6083 E = Parser.getTok().getEndLoc();
6084 Parser.Lex(); // Eat right bracket token.
6085
6086 // If there's a pre-indexing writeback marker, '!', just add it as a token
6087 // operand.
6088 if (Parser.getTok().is(AsmToken::Exclaim)) {
6089 Operands.push_back(
6090 ARMOperand::CreateToken("!", Parser.getTok().getLoc(), *this));
6091 Parser.Lex(); // Eat the '!'.
6092 }
6093
6094 return false;
6095 }
6096
6097 // The register offset is optionally preceded by a '+' or '-'
6098 bool isNegative = false;
6099 if (Parser.getTok().is(AsmToken::Minus)) {
6100 isNegative = true;
6101 Parser.Lex(); // Eat the '-'.
6102 } else if (Parser.getTok().is(AsmToken::Plus)) {
6103 // Nothing to do.
6104 Parser.Lex(); // Eat the '+'.
6105 }
6106
6107 E = Parser.getTok().getLoc();
6108 MCRegister OffsetReg = tryParseRegister();
6109 if (!OffsetReg)
6110 return Error(E, "register expected");
6111
6112 // If there's a shift operator, handle it.
6114 unsigned ShiftImm = 0;
6115 if (Parser.getTok().is(AsmToken::Comma)) {
6116 Parser.Lex(); // Eat the ','.
6117 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
6118 return true;
6119 }
6120
6121 // Now we should have the closing ']'
6122 if (Parser.getTok().isNot(AsmToken::RBrac))
6123 return Error(Parser.getTok().getLoc(), "']' expected");
6124 E = Parser.getTok().getEndLoc();
6125 Parser.Lex(); // Eat right bracket token.
6126
6127 Operands.push_back(ARMOperand::CreateMem(BaseReg, nullptr, OffsetReg,
6128 ShiftType, ShiftImm, 0, isNegative,
6129 S, E, *this));
6130
6131 // If there's a pre-indexing writeback marker, '!', just add it as a token
6132 // operand.
6133 if (Parser.getTok().is(AsmToken::Exclaim)) {
6134 Operands.push_back(
6135 ARMOperand::CreateToken("!", Parser.getTok().getLoc(), *this));
6136 Parser.Lex(); // Eat the '!'.
6137 }
6138
6139 return false;
6140}
6141
6142/// parseMemRegOffsetShift - one of these two:
6143/// ( lsl | lsr | asr | ror ) , # shift_amount
6144/// rrx
6145/// return true if it parses a shift otherwise it returns false.
6146bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
6147 unsigned &Amount) {
6148 MCAsmParser &Parser = getParser();
6149 SMLoc Loc = Parser.getTok().getLoc();
6150 const AsmToken &Tok = Parser.getTok();
6151 if (Tok.isNot(AsmToken::Identifier))
6152 return Error(Loc, "illegal shift operator");
6153 StringRef ShiftName = Tok.getString();
6154 if (ShiftName == "lsl" || ShiftName == "LSL" ||
6155 ShiftName == "asl" || ShiftName == "ASL")
6156 St = ARM_AM::lsl;
6157 else if (ShiftName == "lsr" || ShiftName == "LSR")
6158 St = ARM_AM::lsr;
6159 else if (ShiftName == "asr" || ShiftName == "ASR")
6160 St = ARM_AM::asr;
6161 else if (ShiftName == "ror" || ShiftName == "ROR")
6162 St = ARM_AM::ror;
6163 else if (ShiftName == "rrx" || ShiftName == "RRX")
6164 St = ARM_AM::rrx;
6165 else if (ShiftName == "uxtw" || ShiftName == "UXTW")
6166 St = ARM_AM::uxtw;
6167 else
6168 return Error(Loc, "illegal shift operator");
6169 Parser.Lex(); // Eat shift type token.
6170
6171 // rrx stands alone.
6172 Amount = 0;
6173 if (St != ARM_AM::rrx) {
6174 Loc = Parser.getTok().getLoc();
6175 // A '#' and a shift amount.
6176 const AsmToken &HashTok = Parser.getTok();
6177 if (HashTok.isNot(AsmToken::Hash) &&
6178 HashTok.isNot(AsmToken::Dollar))
6179 return Error(HashTok.getLoc(), "'#' expected");
6180 Parser.Lex(); // Eat hash token.
6181
6182 const MCExpr *Expr;
6183 if (getParser().parseExpression(Expr))
6184 return true;
6185 // Range check the immediate.
6186 // lsl, ror: 0 <= imm <= 31
6187 // lsr, asr: 0 <= imm <= 32
6188 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
6189 if (!CE)
6190 return Error(Loc, "shift amount must be an immediate");
6191 int64_t Imm = CE->getValue();
6192 if (Imm < 0 ||
6193 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
6194 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
6195 return Error(Loc, "immediate shift value out of range");
6196 // If <ShiftTy> #0, turn it into a no_shift.
6197 if (Imm == 0)
6198 St = ARM_AM::lsl;
6199 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
6200 if (Imm == 32)
6201 Imm = 0;
6202 Amount = Imm;
6203 }
6204
6205 return false;
6206}
6207
6208/// parseFPImm - A floating point immediate expression operand.
6209ParseStatus ARMAsmParser::parseFPImm(OperandVector &Operands) {
6210 LLVM_DEBUG(dbgs() << "PARSE FPImm, Ops: " << Operands.size());
6211
6212 MCAsmParser &Parser = getParser();
6213 // Anything that can accept a floating point constant as an operand
6214 // needs to go through here, as the regular parseExpression is
6215 // integer only.
6216 //
6217 // This routine still creates a generic Immediate operand, containing
6218 // a bitcast of the 64-bit floating point value. The various operands
6219 // that accept floats can check whether the value is valid for them
6220 // via the standard is*() predicates.
6221
6222 SMLoc S = Parser.getTok().getLoc();
6223
6224 if (Parser.getTok().isNot(AsmToken::Hash) &&
6225 Parser.getTok().isNot(AsmToken::Dollar))
6226 return ParseStatus::NoMatch;
6227
6228 // Disambiguate the VMOV forms that can accept an FP immediate.
6229 // vmov.f32 <sreg>, #imm
6230 // vmov.f64 <dreg>, #imm
6231 // vmov.f32 <dreg>, #imm @ vector f32x2
6232 // vmov.f32 <qreg>, #imm @ vector f32x4
6233 //
6234 // There are also the NEON VMOV instructions which expect an
6235 // integer constant. Make sure we don't try to parse an FPImm
6236 // for these:
6237 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
6238
6239 bool isVmovf = false;
6240 unsigned MnemonicOpsEndInd = getMnemonicOpsEndInd(Operands);
6241 for (unsigned I = 1; I < MnemonicOpsEndInd; ++I) {
6242 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[I]);
6243 if (TyOp.isToken() &&
6244 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64" ||
6245 TyOp.getToken() == ".f16")) {
6246 isVmovf = true;
6247 break;
6248 }
6249 }
6250
6251 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
6252 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
6253 Mnemonic.getToken() == "fconsts");
6254 if (!(isVmovf || isFconst))
6255 return ParseStatus::NoMatch;
6256
6257 Parser.Lex(); // Eat '#' or '$'.
6258
6259 // Handle negation, as that still comes through as a separate token.
6260 bool isNegative = false;
6261 if (Parser.getTok().is(AsmToken::Minus)) {
6262 isNegative = true;
6263 Parser.Lex();
6264 }
6265 const AsmToken &Tok = Parser.getTok();
6266 SMLoc Loc = Tok.getLoc();
6267 if (Tok.is(AsmToken::Real) && isVmovf) {
6268 APFloat RealVal(APFloat::IEEEsingle(), Tok.getString());
6269 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
6270 // If we had a '-' in front, toggle the sign bit.
6271 IntVal ^= (uint64_t)isNegative << 31;
6272 Parser.Lex(); // Eat the token.
6273 Operands.push_back(
6274 ARMOperand::CreateImm(MCConstantExpr::create(IntVal, getContext()), S,
6275 Parser.getTok().getLoc(), *this));
6276 return ParseStatus::Success;
6277 }
6278 // Also handle plain integers. Instructions which allow floating point
6279 // immediates also allow a raw encoded 8-bit value.
6280 if (Tok.is(AsmToken::Integer) && isFconst) {
6281 int64_t Val = Tok.getIntVal();
6282 Parser.Lex(); // Eat the token.
6283 if (Val > 255 || Val < 0)
6284 return Error(Loc, "encoded floating point value out of range");
6285 float RealVal = ARM_AM::getFPImmFloat(Val);
6286 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
6287
6288 Operands.push_back(
6289 ARMOperand::CreateImm(MCConstantExpr::create(Val, getContext()), S,
6290 Parser.getTok().getLoc(), *this));
6291 return ParseStatus::Success;
6292 }
6293
6294 return Error(Loc, "invalid floating point immediate");
6295}
6296
6297/// Parse a arm instruction operand. For now this parses the operand regardless
6298/// of the mnemonic.
6299bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
6300 MCAsmParser &Parser = getParser();
6301 SMLoc S, E;
6302
6303 // Check if the current operand has a custom associated parser, if so, try to
6304 // custom parse the operand, or fallback to the general approach.
6305 ParseStatus ResTy = MatchOperandParserImpl(Operands, Mnemonic);
6306 if (ResTy.isSuccess())
6307 return false;
6308 // If there wasn't a custom match, try the generic matcher below. Otherwise,
6309 // there was a match, but an error occurred, in which case, just return that
6310 // the operand parsing failed.
6311 if (ResTy.isFailure())
6312 return true;
6313
6314 switch (getLexer().getKind()) {
6315 default:
6316 Error(Parser.getTok().getLoc(), "unexpected token in operand");
6317 return true;
6318 case AsmToken::Identifier: {
6319 // If we've seen a branch mnemonic, the next operand must be a label. This
6320 // is true even if the label is a register name. So "br r1" means branch to
6321 // label "r1".
6322 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
6323 if (!ExpectLabel) {
6324 if (!tryParseRegisterWithWriteBack(Operands))
6325 return false;
6326 int Res = tryParseShiftRegister(Operands);
6327 if (Res == 0) // success
6328 return false;
6329 else if (Res == -1) // irrecoverable error
6330 return true;
6331 // If this is VMRS, check for the apsr_nzcv operand.
6332 if (Mnemonic == "vmrs" &&
6333 Parser.getTok().getString().equals_insensitive("apsr_nzcv")) {
6334 S = Parser.getTok().getLoc();
6335 Parser.Lex();
6336 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S, *this));
6337 return false;
6338 }
6339 }
6340
6341 // Fall though for the Identifier case that is not a register or a
6342 // special name.
6343 [[fallthrough]];
6344 }
6345 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
6346 case AsmToken::Integer: // things like 1f and 2b as a branch targets
6347 case AsmToken::String: // quoted label names.
6348 case AsmToken::Dot: { // . as a branch target
6349 // This was not a register so parse other operands that start with an
6350 // identifier (like labels) as expressions and create them as immediates.
6351 const MCExpr *IdVal;
6352 S = Parser.getTok().getLoc();
6353 if (getParser().parseExpression(IdVal))
6354 return true;
6355 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
6356 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E, *this));
6357 return false;
6358 }
6359 case AsmToken::LBrac:
6360 return parseMemory(Operands);
6361 case AsmToken::LCurly: {
6362 bool IsLazyLoadStore = Mnemonic == "vlldm" || Mnemonic == "vlstm";
6363 bool IsVSCCLRM = Mnemonic == "vscclrm";
6364 return parseRegisterList(Operands, !Mnemonic.starts_with("clr"), false,
6365 IsLazyLoadStore, IsVSCCLRM);
6366 }
6367 case AsmToken::Dollar:
6368 case AsmToken::Hash: {
6369 // #42 -> immediate
6370 // $ 42 -> immediate
6371 // $foo -> symbol name
6372 // $42 -> symbol name
6373 S = Parser.getTok().getLoc();
6374
6375 // Favor the interpretation of $-prefixed operands as symbol names.
6376 // Cases where immediates are explicitly expected are handled by their
6377 // specific ParseMethod implementations.
6378 auto AdjacentToken = getLexer().peekTok(/*ShouldSkipSpace=*/false);
6379 bool ExpectIdentifier = Parser.getTok().is(AsmToken::Dollar) &&
6380 (AdjacentToken.is(AsmToken::Identifier) ||
6381 AdjacentToken.is(AsmToken::Integer));
6382 if (!ExpectIdentifier) {
6383 // Token is not part of identifier. Drop leading $ or # before parsing
6384 // expression.
6385 Parser.Lex();
6386 }
6387
6388 if (Parser.getTok().isNot(AsmToken::Colon)) {
6389 bool IsNegative = Parser.getTok().is(AsmToken::Minus);
6390 const MCExpr *ImmVal;
6391 if (getParser().parseExpression(ImmVal))
6392 return true;
6393 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
6394 if (CE) {
6395 int32_t Val = CE->getValue();
6396 if (IsNegative && Val == 0)
6397 ImmVal = MCConstantExpr::create(std::numeric_limits<int32_t>::min(),
6398 getContext());
6399 }
6400 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
6401 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E, *this));
6402
6403 // There can be a trailing '!' on operands that we want as a separate
6404 // '!' Token operand. Handle that here. For example, the compatibility
6405 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
6406 if (Parser.getTok().is(AsmToken::Exclaim)) {
6407 Operands.push_back(ARMOperand::CreateToken(
6408 Parser.getTok().getString(), Parser.getTok().getLoc(), *this));
6409 Parser.Lex(); // Eat exclaim token
6410 }
6411 return false;
6412 }
6413 // w/ a ':' after the '#', it's just like a plain ':'.
6414 [[fallthrough]];
6415 }
6416 case AsmToken::Colon: {
6417 S = Parser.getTok().getLoc();
6418 // ":lower16:", ":upper16:", ":lower0_7:", ":lower8_15:", ":upper0_7:" and
6419 // ":upper8_15:", expression prefixes
6420 // FIXME: Check it's an expression prefix,
6421 // e.g. (FOO - :lower16:BAR) isn't legal.
6422 ARM::Specifier Spec;
6423 if (parsePrefix(Spec))
6424 return true;
6425
6426 const MCExpr *SubExprVal;
6427 if (getParser().parseExpression(SubExprVal))
6428 return true;
6429
6430 const auto *ExprVal =
6431 MCSpecifierExpr::create(SubExprVal, Spec, getContext(), S);
6432 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
6433 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E, *this));
6434 return false;
6435 }
6436 case AsmToken::Equal: {
6437 S = Parser.getTok().getLoc();
6438 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
6439 return Error(S, "unexpected token in operand");
6440 Parser.Lex(); // Eat '='
6441 const MCExpr *SubExprVal;
6442 if (getParser().parseExpression(SubExprVal))
6443 return true;
6444 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
6445
6446 // execute-only: we assume that assembly programmers know what they are
6447 // doing and allow literal pool creation here
6448 Operands.push_back(
6449 ARMOperand::CreateConstantPoolImm(SubExprVal, S, E, *this));
6450 return false;
6451 }
6452 }
6453}
6454
6455bool ARMAsmParser::parseImmExpr(int64_t &Out) {
6456 const MCExpr *Expr = nullptr;
6457 SMLoc L = getParser().getTok().getLoc();
6458 if (check(getParser().parseExpression(Expr), L, "expected expression"))
6459 return true;
6460 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
6461 if (check(!Value, L, "expected constant expression"))
6462 return true;
6463 Out = Value->getValue();
6464 return false;
6465}
6466
6467// parsePrefix - Parse ARM 16-bit relocations expression prefixes, i.e.
6468// :lower16: and :upper16: and Thumb 8-bit relocation expression prefixes, i.e.
6469// :upper8_15:, :upper0_7:, :lower8_15: and :lower0_7:
6470bool ARMAsmParser::parsePrefix(ARM::Specifier &Spec) {
6471 MCAsmParser &Parser = getParser();
6472 Spec = ARM::S_None;
6473
6474 // consume an optional '#' (GNU compatibility)
6475 if (getLexer().is(AsmToken::Hash))
6476 Parser.Lex();
6477
6478 assert(getLexer().is(AsmToken::Colon) && "expected a :");
6479 Parser.Lex(); // Eat ':'
6480
6481 if (getLexer().isNot(AsmToken::Identifier)) {
6482 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
6483 return true;
6484 }
6485
6486 enum {
6487 COFF = (1 << MCContext::IsCOFF),
6488 ELF = (1 << MCContext::IsELF),
6489 MACHO = (1 << MCContext::IsMachO),
6490 WASM = (1 << MCContext::IsWasm),
6491 };
6492 static const struct PrefixEntry {
6493 const char *Spelling;
6494 ARM::Specifier Spec;
6495 uint8_t SupportedFormats;
6496 } PrefixEntries[] = {
6497 {"upper16", ARM::S_HI16, COFF | ELF | MACHO},
6498 {"lower16", ARM::S_LO16, COFF | ELF | MACHO},
6499 {"upper8_15", ARM::S_HI_8_15, ELF},
6500 {"upper0_7", ARM::S_HI_0_7, ELF},
6501 {"lower8_15", ARM::S_LO_8_15, ELF},
6502 {"lower0_7", ARM::S_LO_0_7, ELF},
6503 };
6504
6505 StringRef IDVal = Parser.getTok().getIdentifier();
6506
6507 const auto &Prefix =
6508 llvm::find_if(PrefixEntries, [&IDVal](const PrefixEntry &PE) {
6509 return PE.Spelling == IDVal;
6510 });
6511 if (Prefix == std::end(PrefixEntries)) {
6512 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
6513 return true;
6514 }
6515
6516 uint8_t CurrentFormat;
6517 switch (getContext().getObjectFileType()) {
6518 case MCContext::IsMachO:
6519 CurrentFormat = MACHO;
6520 break;
6521 case MCContext::IsELF:
6522 CurrentFormat = ELF;
6523 break;
6524 case MCContext::IsCOFF:
6525 CurrentFormat = COFF;
6526 break;
6527 case MCContext::IsWasm:
6528 CurrentFormat = WASM;
6529 break;
6530 case MCContext::IsGOFF:
6531 case MCContext::IsSPIRV:
6532 case MCContext::IsXCOFF:
6534 llvm_unreachable("unexpected object format");
6535 break;
6536 }
6537
6538 if (~Prefix->SupportedFormats & CurrentFormat) {
6539 Error(Parser.getTok().getLoc(),
6540 "cannot represent relocation in the current file format");
6541 return true;
6542 }
6543
6544 Spec = Prefix->Spec;
6545 Parser.Lex();
6546
6547 if (getLexer().isNot(AsmToken::Colon)) {
6548 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
6549 return true;
6550 }
6551 Parser.Lex(); // Eat the last ':'
6552
6553 // consume an optional trailing '#' (GNU compatibility) bla
6554 parseOptionalToken(AsmToken::Hash);
6555
6556 return false;
6557}
6558
6559/// Given a mnemonic, split out possible predication code and carry
6560/// setting letters to form a canonical mnemonic and flags.
6561//
6562// FIXME: Would be nice to autogen this.
6563// FIXME: This is a bit of a maze of special cases.
6564StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic, StringRef ExtraToken,
6565 ARMCC::CondCodes &PredicationCode,
6566 ARMVCC::VPTCodes &VPTPredicationCode,
6567 bool &CarrySetting,
6568 unsigned &ProcessorIMod,
6569 StringRef &ITMask) {
6570 PredicationCode = ARMCC::AL;
6571 VPTPredicationCode = ARMVCC::None;
6572 CarrySetting = false;
6573 ProcessorIMod = 0;
6574
6575 // Ignore some mnemonics we know aren't predicated forms.
6576 //
6577 // FIXME: Would be nice to autogen this.
6578 if ((Mnemonic == "movs" && isThumb()) || Mnemonic == "teq" ||
6579 Mnemonic == "vceq" || Mnemonic == "svc" || Mnemonic == "mls" ||
6580 Mnemonic == "smmls" || Mnemonic == "vcls" || Mnemonic == "vmls" ||
6581 Mnemonic == "vnmls" || Mnemonic == "vacge" || Mnemonic == "vcge" ||
6582 Mnemonic == "vclt" || Mnemonic == "vacgt" || Mnemonic == "vaclt" ||
6583 Mnemonic == "vacle" || Mnemonic == "hlt" || Mnemonic == "vcgt" ||
6584 Mnemonic == "vcle" || Mnemonic == "smlal" || Mnemonic == "umaal" ||
6585 Mnemonic == "umlal" || Mnemonic == "vabal" || Mnemonic == "vmlal" ||
6586 Mnemonic == "vpadal" || Mnemonic == "vqdmlal" || Mnemonic == "fmuls" ||
6587 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
6588 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
6589 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
6590 Mnemonic == "vrintm" || Mnemonic == "hvc" ||
6591 Mnemonic.starts_with("vsel") || Mnemonic == "vins" ||
6592 Mnemonic == "vmovx" || Mnemonic == "bxns" || Mnemonic == "blxns" ||
6593 Mnemonic == "vdot" || Mnemonic == "vmmla" || Mnemonic == "vudot" ||
6594 Mnemonic == "vsdot" || Mnemonic == "vcmla" || Mnemonic == "vcadd" ||
6595 Mnemonic == "vfmal" || Mnemonic == "vfmsl" || Mnemonic == "wls" ||
6596 Mnemonic == "le" || Mnemonic == "dls" || Mnemonic == "csel" ||
6597 Mnemonic == "csinc" || Mnemonic == "csinv" || Mnemonic == "csneg" ||
6598 Mnemonic == "cinc" || Mnemonic == "cinv" || Mnemonic == "cneg" ||
6599 Mnemonic == "cset" || Mnemonic == "csetm" || Mnemonic == "aut" ||
6600 Mnemonic == "pac" || Mnemonic == "pacbti" || Mnemonic == "bti")
6601 return Mnemonic;
6602
6603 // First, split out any predication code. Ignore mnemonics we know aren't
6604 // predicated but do have a carry-set and so weren't caught above.
6605 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
6606 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
6607 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
6608 Mnemonic != "sbcs" && Mnemonic != "rscs" &&
6609 !(hasMVE() &&
6610 (Mnemonic == "vmine" || Mnemonic == "vshle" || Mnemonic == "vshlt" ||
6611 Mnemonic == "vshllt" || Mnemonic == "vrshle" || Mnemonic == "vrshlt" ||
6612 Mnemonic == "vmvne" || Mnemonic == "vorne" || Mnemonic == "vnege" ||
6613 Mnemonic == "vnegt" || Mnemonic == "vmule" || Mnemonic == "vmult" ||
6614 Mnemonic == "vrintne" || Mnemonic == "vcmult" ||
6615 Mnemonic == "vcmule" || Mnemonic == "vpsele" || Mnemonic == "vpselt" ||
6616 Mnemonic.starts_with("vq")))) {
6617 unsigned CC = ARMCondCodeFromString(Mnemonic.substr(Mnemonic.size()-2));
6618 if (CC != ~0U) {
6619 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
6620 PredicationCode = static_cast<ARMCC::CondCodes>(CC);
6621 }
6622 }
6623
6624 // Next, determine if we have a carry setting bit. We explicitly ignore all
6625 // the instructions we know end in 's'.
6626 if (Mnemonic.ends_with("s") &&
6627 !(Mnemonic == "cps" || Mnemonic == "mls" || Mnemonic == "mrs" ||
6628 Mnemonic == "smmls" || Mnemonic == "vabs" || Mnemonic == "vcls" ||
6629 Mnemonic == "vmls" || Mnemonic == "vmrs" || Mnemonic == "vnmls" ||
6630 Mnemonic == "vqabs" || Mnemonic == "vrecps" || Mnemonic == "vrsqrts" ||
6631 Mnemonic == "srs" || Mnemonic == "flds" || Mnemonic == "fmrs" ||
6632 Mnemonic == "fsqrts" || Mnemonic == "fsubs" || Mnemonic == "fsts" ||
6633 Mnemonic == "fcpys" || Mnemonic == "fdivs" || Mnemonic == "fmuls" ||
6634 Mnemonic == "fcmps" || Mnemonic == "fcmpzs" || Mnemonic == "vfms" ||
6635 Mnemonic == "vfnms" || Mnemonic == "fconsts" || Mnemonic == "bxns" ||
6636 Mnemonic == "blxns" || Mnemonic == "vfmas" || Mnemonic == "vmlas" ||
6637 (Mnemonic == "movs" && isThumb()))) {
6638 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
6639 CarrySetting = true;
6640 }
6641
6642 // The "cps" instruction can have a interrupt mode operand which is glued into
6643 // the mnemonic. Check if this is the case, split it and parse the imod op
6644 if (Mnemonic.starts_with("cps")) {
6645 // Split out any imod code.
6646 unsigned IMod =
6647 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
6648 .Case("ie", ARM_PROC::IE)
6649 .Case("id", ARM_PROC::ID)
6650 .Default(~0U);
6651 if (IMod != ~0U) {
6652 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
6653 ProcessorIMod = IMod;
6654 }
6655 }
6656
6657 if (isMnemonicVPTPredicable(Mnemonic, ExtraToken) && Mnemonic != "vmovlt" &&
6658 Mnemonic != "vshllt" && Mnemonic != "vrshrnt" && Mnemonic != "vshrnt" &&
6659 Mnemonic != "vqrshrunt" && Mnemonic != "vqshrunt" &&
6660 Mnemonic != "vqrshrnt" && Mnemonic != "vqshrnt" && Mnemonic != "vmullt" &&
6661 Mnemonic != "vqmovnt" && Mnemonic != "vqmovunt" && Mnemonic != "vmovnt" &&
6662 Mnemonic != "vqdmullt" && Mnemonic != "vpnot" && Mnemonic != "vcvtt" &&
6663 Mnemonic != "vcvt") {
6664 unsigned VCC =
6665 ARMVectorCondCodeFromString(Mnemonic.substr(Mnemonic.size() - 1));
6666 if (VCC != ~0U) {
6667 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-1);
6668 VPTPredicationCode = static_cast<ARMVCC::VPTCodes>(VCC);
6669 }
6670 return Mnemonic;
6671 }
6672
6673 // The "it" instruction has the condition mask on the end of the mnemonic.
6674 if (Mnemonic.starts_with("it")) {
6675 ITMask = Mnemonic.substr(2);
6676 Mnemonic = Mnemonic.slice(0, 2);
6677 }
6678
6679 if (Mnemonic.starts_with("vpst")) {
6680 ITMask = Mnemonic.substr(4);
6681 Mnemonic = Mnemonic.slice(0, 4);
6682 } else if (Mnemonic.starts_with("vpt")) {
6683 ITMask = Mnemonic.substr(3);
6684 Mnemonic = Mnemonic.slice(0, 3);
6685 }
6686
6687 return Mnemonic;
6688}
6689
6690/// Given a canonical mnemonic, determine if the instruction ever allows
6691/// inclusion of carry set or predication code operands.
6692//
6693// FIXME: It would be nice to autogen this.
6694void ARMAsmParser::getMnemonicAcceptInfo(StringRef Mnemonic,
6695 StringRef ExtraToken,
6696 StringRef FullInst,
6697 bool &CanAcceptCarrySet,
6698 bool &CanAcceptPredicationCode,
6699 bool &CanAcceptVPTPredicationCode) {
6700 CanAcceptVPTPredicationCode = isMnemonicVPTPredicable(Mnemonic, ExtraToken);
6701
6702 CanAcceptCarrySet =
6703 Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
6704 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
6705 Mnemonic == "add" || Mnemonic == "adc" || Mnemonic == "mul" ||
6706 Mnemonic == "bic" || Mnemonic == "asr" || Mnemonic == "orr" ||
6707 Mnemonic == "mvn" || Mnemonic == "rsb" || Mnemonic == "rsc" ||
6708 Mnemonic == "orn" || Mnemonic == "sbc" || Mnemonic == "eor" ||
6709 Mnemonic == "neg" || Mnemonic == "vfm" || Mnemonic == "vfnm" ||
6710 (!isThumb() &&
6711 (Mnemonic == "smull" || Mnemonic == "mov" || Mnemonic == "mla" ||
6712 Mnemonic == "smlal" || Mnemonic == "umlal" || Mnemonic == "umull"));
6713
6714 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
6715 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
6716 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
6717 Mnemonic.starts_with("crc32") || Mnemonic.starts_with("cps") ||
6718 Mnemonic.starts_with("vsel") || Mnemonic == "vmaxnm" ||
6719 Mnemonic == "vminnm" || Mnemonic == "vcvta" || Mnemonic == "vcvtn" ||
6720 Mnemonic == "vcvtp" || Mnemonic == "vcvtm" || Mnemonic == "vrinta" ||
6721 Mnemonic == "vrintn" || Mnemonic == "vrintp" || Mnemonic == "vrintm" ||
6722 Mnemonic.starts_with("aes") || Mnemonic == "hvc" ||
6723 Mnemonic == "setpan" || Mnemonic.starts_with("sha1") ||
6724 Mnemonic.starts_with("sha256") ||
6725 (FullInst.starts_with("vmull") && FullInst.ends_with(".p64")) ||
6726 Mnemonic == "vmovx" || Mnemonic == "vins" || Mnemonic == "vudot" ||
6727 Mnemonic == "vsdot" || Mnemonic == "vcmla" || Mnemonic == "vcadd" ||
6728 Mnemonic == "vfmal" || Mnemonic == "vfmsl" || Mnemonic == "vfmat" ||
6729 Mnemonic == "vfmab" || Mnemonic == "vdot" || Mnemonic == "vmmla" ||
6730 Mnemonic == "sb" || Mnemonic == "ssbb" || Mnemonic == "pssbb" ||
6731 Mnemonic == "vsmmla" || Mnemonic == "vummla" || Mnemonic == "vusmmla" ||
6732 Mnemonic == "vusdot" || Mnemonic == "vsudot" || Mnemonic == "bfcsel" ||
6733 Mnemonic == "wls" || Mnemonic == "dls" || Mnemonic == "le" ||
6734 Mnemonic == "csel" || Mnemonic == "csinc" || Mnemonic == "csinv" ||
6735 Mnemonic == "csneg" || Mnemonic == "cinc" || Mnemonic == "cinv" ||
6736 Mnemonic == "cneg" || Mnemonic == "cset" || Mnemonic == "csetm" ||
6737 (hasCDE() && MS.isCDEInstr(Mnemonic) &&
6738 !MS.isITPredicableCDEInstr(Mnemonic)) ||
6739 Mnemonic.starts_with("vpt") || Mnemonic.starts_with("vpst") ||
6740 Mnemonic == "pac" || Mnemonic == "pacbti" || Mnemonic == "aut" ||
6741 Mnemonic == "bti" ||
6742 (hasMVE() &&
6743 (Mnemonic.starts_with("vst2") || Mnemonic.starts_with("vld2") ||
6744 Mnemonic.starts_with("vst4") || Mnemonic.starts_with("vld4") ||
6745 Mnemonic.starts_with("wlstp") || Mnemonic.starts_with("dlstp") ||
6746 Mnemonic.starts_with("letp")))) {
6747 // These mnemonics are never predicable
6748 CanAcceptPredicationCode = false;
6749 } else if (!isThumb()) {
6750 // Some instructions are only predicable in Thumb mode
6751 CanAcceptPredicationCode =
6752 Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
6753 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
6754 Mnemonic != "dmb" && Mnemonic != "dfb" && Mnemonic != "dsb" &&
6755 Mnemonic != "isb" && Mnemonic != "pld" && Mnemonic != "pli" &&
6756 Mnemonic != "pldw" && Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
6757 Mnemonic != "stc2" && Mnemonic != "stc2l" && Mnemonic != "tsb" &&
6758 !Mnemonic.starts_with("rfe") && !Mnemonic.starts_with("srs");
6759 } else if (isThumbOne()) {
6760 if (hasV6MOps())
6761 CanAcceptPredicationCode = Mnemonic != "movs";
6762 else
6763 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
6764 } else
6765 CanAcceptPredicationCode = true;
6766}
6767
6768bool operandsContainWide(OperandVector &Operands, unsigned MnemonicOpsEndInd) {
6769 for (unsigned I = 0; I < MnemonicOpsEndInd; ++I) {
6770 auto &Op = static_cast<ARMOperand &>(*Operands[I]);
6771 if (Op.isToken() && Op.getToken() == ".w")
6772 return true;
6773 }
6774 return false;
6775}
6776
6777// Some Thumb instructions have two operand forms that are not
6778// available as three operand, convert to two operand form if possible.
6779//
6780// FIXME: We would really like to be able to tablegen'erate this.
6781void ARMAsmParser::tryConvertingToTwoOperandForm(
6782 StringRef Mnemonic, ARMCC::CondCodes PredicationCode, bool CarrySetting,
6783 OperandVector &Operands, unsigned MnemonicOpsEndInd) {
6784
6785 if (operandsContainWide(Operands, MnemonicOpsEndInd))
6786 return;
6787 if (Operands.size() != MnemonicOpsEndInd + 3)
6788 return;
6789
6790 const auto &Op3 = static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd]);
6791 auto &Op4 = static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1]);
6792 if (!Op3.isReg() || !Op4.isReg())
6793 return;
6794
6795 auto Op3Reg = Op3.getReg();
6796 auto Op4Reg = Op4.getReg();
6797
6798 // For most Thumb2 cases we just generate the 3 operand form and reduce
6799 // it in processInstruction(), but the 3 operand form of ADD (t2ADDrr)
6800 // won't accept SP or PC so we do the transformation here taking care
6801 // with immediate range in the 'add sp, sp #imm' case.
6802 auto &Op5 = static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 2]);
6803 if (isThumbTwo()) {
6804 if (Mnemonic != "add")
6805 return;
6806 bool TryTransform = Op3Reg == ARM::PC || Op4Reg == ARM::PC ||
6807 (Op5.isReg() && Op5.getReg() == ARM::PC);
6808 if (!TryTransform) {
6809 TryTransform = (Op3Reg == ARM::SP || Op4Reg == ARM::SP ||
6810 (Op5.isReg() && Op5.getReg() == ARM::SP)) &&
6811 !(Op3Reg == ARM::SP && Op4Reg == ARM::SP &&
6812 Op5.isImm() && !Op5.isImm0_508s4());
6813 }
6814 if (!TryTransform)
6815 return;
6816 } else if (!isThumbOne())
6817 return;
6818
6819 if (!(Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" ||
6820 Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
6821 Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" ||
6822 Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic"))
6823 return;
6824
6825 // If first 2 operands of a 3 operand instruction are the same
6826 // then transform to 2 operand version of the same instruction
6827 // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1'
6828 bool Transform = Op3Reg == Op4Reg;
6829
6830 // For communtative operations, we might be able to transform if we swap
6831 // Op4 and Op5. The 'ADD Rdm, SP, Rdm' form is already handled specially
6832 // as tADDrsp.
6833 const ARMOperand *LastOp = &Op5;
6834 bool Swap = false;
6835 if (!Transform && Op5.isReg() && Op3Reg == Op5.getReg() &&
6836 ((Mnemonic == "add" && Op4Reg != ARM::SP) ||
6837 Mnemonic == "and" || Mnemonic == "eor" ||
6838 Mnemonic == "adc" || Mnemonic == "orr")) {
6839 Swap = true;
6840 LastOp = &Op4;
6841 Transform = true;
6842 }
6843
6844 // If both registers are the same then remove one of them from
6845 // the operand list, with certain exceptions.
6846 if (Transform) {
6847 // Don't transform 'adds Rd, Rd, Rm' or 'sub{s} Rd, Rd, Rm' because the
6848 // 2 operand forms don't exist.
6849 if (((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub") &&
6850 LastOp->isReg())
6851 Transform = false;
6852
6853 // Don't transform 'add/sub{s} Rd, Rd, #imm' if the immediate fits into
6854 // 3-bits because the ARMARM says not to.
6855 if ((Mnemonic == "add" || Mnemonic == "sub") && LastOp->isImm0_7())
6856 Transform = false;
6857 }
6858
6859 if (Transform) {
6860 if (Swap)
6861 std::swap(Op4, Op5);
6862 Operands.erase(Operands.begin() + MnemonicOpsEndInd);
6863 }
6864}
6865
6866static bool isARMMCExpr(MCParsedAsmOperand &MCOp);
6867// this function returns true if the operand is one of the following
6868// relocations: :upper8_15:, :upper0_7:, :lower8_15: or :lower0_7:
6870 assert(isARMMCExpr(MCOp));
6871 ARMOperand &Op = static_cast<ARMOperand &>(MCOp);
6872 auto *ARM16Expr = dyn_cast<MCSpecifierExpr>(Op.getImm());
6873 if (ARM16Expr && (ARM16Expr->getSpecifier() == ARM::S_HI_8_15 ||
6874 ARM16Expr->getSpecifier() == ARM::S_HI_0_7 ||
6875 ARM16Expr->getSpecifier() == ARM::S_LO_8_15 ||
6876 ARM16Expr->getSpecifier() == ARM::S_LO_0_7))
6877 return true;
6878 return false;
6879}
6880
6881bool ARMAsmParser::shouldOmitVectorPredicateOperand(
6882 StringRef Mnemonic, OperandVector &Operands, unsigned MnemonicOpsEndInd) {
6883 if (!hasMVE() || Operands.size() <= MnemonicOpsEndInd)
6884 return true;
6885
6886 if (Mnemonic.starts_with("vld2") || Mnemonic.starts_with("vld4") ||
6887 Mnemonic.starts_with("vst2") || Mnemonic.starts_with("vst4"))
6888 return true;
6889
6890 if (Mnemonic.starts_with("vctp") || Mnemonic.starts_with("vpnot"))
6891 return false;
6892
6893 if (Mnemonic.starts_with("vmov") &&
6894 !(Mnemonic.starts_with("vmovl") || Mnemonic.starts_with("vmovn") ||
6895 Mnemonic.starts_with("vmovx"))) {
6896 for (auto &Operand : Operands) {
6897 if (static_cast<ARMOperand &>(*Operand).isVectorIndex() ||
6898 ((*Operand).isReg() && (getARMMCRegisterClass(ARM::SPRRegClassID)
6899 .contains((*Operand).getReg()) ||
6900 getARMMCRegisterClass(ARM::DPRRegClassID)
6901 .contains((*Operand).getReg())))) {
6902 return true;
6903 }
6904 }
6905 return false;
6906 } else {
6907 for (auto &Operand : Operands) {
6908 // We check the larger class QPR instead of just the legal class
6909 // MQPR, to more accurately report errors when using Q registers
6910 // outside of the allowed range.
6911 if (static_cast<ARMOperand &>(*Operand).isVectorIndex() ||
6912 static_cast<ARMOperand &>(*Operand).isQReg())
6913 return false;
6914 }
6915 return true;
6916 }
6917}
6918
6919// FIXME: This bit should probably be handled via an explicit match class
6920// in the .td files that matches the suffix instead of having it be
6921// a literal string token the way it is now.
6923 return Mnemonic.starts_with("vldm") || Mnemonic.starts_with("vstm");
6924}
6925
6926static void applyMnemonicAliases(StringRef &Mnemonic,
6927 const FeatureBitset &Features,
6928 unsigned VariantID);
6929
6930// The GNU assembler has aliases of ldrd, strd, ldrexd, strexd, ldaexd, and
6931// stlexd with the second register omitted. We don't have a way to do that in
6932// tablegen, so fix it up here.
6933//
6934// We have to be careful to not emit an invalid Rt2 here, because the rest of
6935// the assembly parser could then generate confusing diagnostics referring to
6936// it. If we do find anything that prevents us from doing the transformation we
6937// bail out, and let the assembly parser report an error on the instruction as
6938// it is written.
6939void ARMAsmParser::fixupGNULDRDAlias(StringRef Mnemonic,
6941 unsigned MnemonicOpsEndInd) {
6942 if (Mnemonic != "ldrd" && Mnemonic != "strd" && Mnemonic != "ldrexd" &&
6943 Mnemonic != "strexd" && Mnemonic != "ldaexd" && Mnemonic != "stlexd")
6944 return;
6945
6946 unsigned IdX = Mnemonic == "strexd" || Mnemonic == "stlexd"
6947 ? MnemonicOpsEndInd + 1
6948 : MnemonicOpsEndInd;
6949
6950 if (Operands.size() < IdX + 2)
6951 return;
6952
6953 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[IdX]);
6954 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[IdX + 1]);
6955
6956 if (!Op2.isReg())
6957 return;
6958 if (!Op3.isGPRMem())
6959 return;
6960
6961 const MCRegisterClass &GPR = MRI->getRegClass(ARM::GPRRegClassID);
6962 if (!GPR.contains(Op2.getReg()))
6963 return;
6964
6965 unsigned RtEncoding = MRI->getEncodingValue(Op2.getReg());
6966 if (!isThumb() && (RtEncoding & 1)) {
6967 // In ARM mode, the registers must be from an aligned pair, this
6968 // restriction does not apply in Thumb mode.
6969 return;
6970 }
6971 if (Op2.getReg() == ARM::PC)
6972 return;
6973 MCRegister PairedReg = GPR.getRegister(RtEncoding + 1);
6974 if (!PairedReg || PairedReg == ARM::PC ||
6975 (PairedReg == ARM::SP && !hasV8Ops()))
6976 return;
6977
6978 Operands.insert(Operands.begin() + IdX + 1,
6979 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(),
6980 Op2.getEndLoc(), *this));
6981}
6982
6983// Dual-register instruction have the following syntax:
6984// <mnemonic> <predicate>? <coproc>, <Rdest>, <Rdest+1>, <Rsrc>, ..., #imm
6985// This function tries to remove <Rdest+1> and replace <Rdest> with a pair
6986// operand. If the conversion fails an error is diagnosed, and the function
6987// returns true.
6988bool ARMAsmParser::CDEConvertDualRegOperand(StringRef Mnemonic,
6990 unsigned MnemonicOpsEndInd) {
6991 assert(MS.isCDEDualRegInstr(Mnemonic));
6992
6993 if (Operands.size() < 3 + MnemonicOpsEndInd)
6994 return false;
6995
6996 StringRef Op2Diag(
6997 "operand must be an even-numbered register in the range [r0, r10]");
6998
6999 const MCParsedAsmOperand &Op2 = *Operands[MnemonicOpsEndInd + 1];
7000 if (!Op2.isReg())
7001 return Error(Op2.getStartLoc(), Op2Diag);
7002
7003 MCRegister RNext;
7004 MCRegister RPair;
7005 switch (Op2.getReg().id()) {
7006 default:
7007 return Error(Op2.getStartLoc(), Op2Diag);
7008 case ARM::R0:
7009 RNext = ARM::R1;
7010 RPair = ARM::R0_R1;
7011 break;
7012 case ARM::R2:
7013 RNext = ARM::R3;
7014 RPair = ARM::R2_R3;
7015 break;
7016 case ARM::R4:
7017 RNext = ARM::R5;
7018 RPair = ARM::R4_R5;
7019 break;
7020 case ARM::R6:
7021 RNext = ARM::R7;
7022 RPair = ARM::R6_R7;
7023 break;
7024 case ARM::R8:
7025 RNext = ARM::R9;
7026 RPair = ARM::R8_R9;
7027 break;
7028 case ARM::R10:
7029 RNext = ARM::R11;
7030 RPair = ARM::R10_R11;
7031 break;
7032 }
7033
7034 const MCParsedAsmOperand &Op3 = *Operands[MnemonicOpsEndInd + 2];
7035 if (!Op3.isReg() || Op3.getReg() != RNext)
7036 return Error(Op3.getStartLoc(), "operand must be a consecutive register");
7037
7038 Operands.erase(Operands.begin() + MnemonicOpsEndInd + 2);
7039 Operands[MnemonicOpsEndInd + 1] =
7040 ARMOperand::CreateReg(RPair, Op2.getStartLoc(), Op2.getEndLoc(), *this);
7041 return false;
7042}
7043
7044void removeCondCode(OperandVector &Operands, unsigned &MnemonicOpsEndInd) {
7045 for (unsigned I = 0; I < MnemonicOpsEndInd; ++I)
7046 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode()) {
7047 Operands.erase(Operands.begin() + I);
7048 --MnemonicOpsEndInd;
7049 break;
7050 }
7051}
7052
7053void removeCCOut(OperandVector &Operands, unsigned &MnemonicOpsEndInd) {
7054 for (unsigned I = 0; I < MnemonicOpsEndInd; ++I)
7055 if (static_cast<ARMOperand &>(*Operands[I]).isCCOut()) {
7056 Operands.erase(Operands.begin() + I);
7057 --MnemonicOpsEndInd;
7058 break;
7059 }
7060}
7061
7062void removeVPTCondCode(OperandVector &Operands, unsigned &MnemonicOpsEndInd) {
7063 for (unsigned I = 0; I < MnemonicOpsEndInd; ++I)
7064 if (static_cast<ARMOperand &>(*Operands[I]).isVPTPred()) {
7065 Operands.erase(Operands.begin() + I);
7066 --MnemonicOpsEndInd;
7067 break;
7068 }
7069}
7070
7071/// Parse an arm instruction mnemonic followed by its operands.
7072bool ARMAsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
7073 SMLoc NameLoc, OperandVector &Operands) {
7074 MCAsmParser &Parser = getParser();
7075
7076 // Apply mnemonic aliases before doing anything else, as the destination
7077 // mnemonic may include suffices and we want to handle them normally.
7078 // The generic tblgen'erated code does this later, at the start of
7079 // MatchInstructionImpl(), but that's too late for aliases that include
7080 // any sort of suffix.
7081 const FeatureBitset &AvailableFeatures = getAvailableFeatures();
7082 unsigned AssemblerDialect = getParser().getAssemblerDialect();
7083 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
7084
7085 // First check for the ARM-specific .req directive.
7086 if (Parser.getTok().is(AsmToken::Identifier) &&
7087 Parser.getTok().getIdentifier().lower() == ".req") {
7088 parseDirectiveReq(Name, NameLoc);
7089 // We always return 'error' for this, as we're done with this
7090 // statement and don't need to match the 'instruction."
7091 return true;
7092 }
7093
7094 // Create the leading tokens for the mnemonic, split by '.' characters.
7095 size_t Start = 0, Next = Name.find('.');
7096 StringRef Mnemonic = Name.slice(Start, Next);
7097 StringRef ExtraToken = Name.slice(Next, Name.find(' ', Next + 1));
7098
7099 // Split out the predication code and carry setting flag from the mnemonic.
7100 ARMCC::CondCodes PredicationCode;
7101 ARMVCC::VPTCodes VPTPredicationCode;
7102 unsigned ProcessorIMod;
7103 bool CarrySetting;
7104 StringRef ITMask;
7105 Mnemonic = splitMnemonic(Mnemonic, ExtraToken, PredicationCode, VPTPredicationCode,
7106 CarrySetting, ProcessorIMod, ITMask);
7107
7108 // In Thumb1, only the branch (B) instruction can be predicated.
7109 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
7110 return Error(NameLoc, "conditional execution not supported in Thumb1");
7111 }
7112
7113 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc, *this));
7114
7115 // Handle the mask for IT and VPT instructions. In ARMOperand and
7116 // MCOperand, this is stored in a format independent of the
7117 // condition code: the lowest set bit indicates the end of the
7118 // encoding, and above that, a 1 bit indicates 'else', and an 0
7119 // indicates 'then'. E.g.
7120 // IT -> 1000
7121 // ITx -> x100 (ITT -> 0100, ITE -> 1100)
7122 // ITxy -> xy10 (e.g. ITET -> 1010)
7123 // ITxyz -> xyz1 (e.g. ITEET -> 1101)
7124 // Note: See the ARM::PredBlockMask enum in
7125 // /lib/Target/ARM/Utils/ARMBaseInfo.h
7126 if (Mnemonic == "it" || Mnemonic.starts_with("vpt") ||
7127 Mnemonic.starts_with("vpst")) {
7128 SMLoc Loc = Mnemonic == "it" ? SMLoc::getFromPointer(NameLoc.getPointer() + 2) :
7129 Mnemonic == "vpt" ? SMLoc::getFromPointer(NameLoc.getPointer() + 3) :
7130 SMLoc::getFromPointer(NameLoc.getPointer() + 4);
7131 if (ITMask.size() > 3) {
7132 if (Mnemonic == "it")
7133 return Error(Loc, "too many conditions on IT instruction");
7134 return Error(Loc, "too many conditions on VPT instruction");
7135 }
7136 unsigned Mask = 8;
7137 for (char Pos : llvm::reverse(ITMask)) {
7138 if (Pos != 't' && Pos != 'e') {
7139 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
7140 }
7141 Mask >>= 1;
7142 if (Pos == 'e')
7143 Mask |= 8;
7144 }
7145 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc, *this));
7146 }
7147
7148 // FIXME: This is all a pretty gross hack. We should automatically handle
7149 // optional operands like this via tblgen.
7150
7151 // Next, add the CCOut and ConditionCode operands, if needed.
7152 //
7153 // For mnemonics which can ever incorporate a carry setting bit or predication
7154 // code, our matching model involves us always generating CCOut and
7155 // ConditionCode operands to match the mnemonic "as written" and then we let
7156 // the matcher deal with finding the right instruction or generating an
7157 // appropriate error.
7158 bool CanAcceptCarrySet, CanAcceptPredicationCode, CanAcceptVPTPredicationCode;
7159 getMnemonicAcceptInfo(Mnemonic, ExtraToken, Name, CanAcceptCarrySet,
7160 CanAcceptPredicationCode, CanAcceptVPTPredicationCode);
7161
7162 // If we had a carry-set on an instruction that can't do that, issue an
7163 // error.
7164 if (!CanAcceptCarrySet && CarrySetting) {
7165 return Error(NameLoc, "instruction '" + Mnemonic +
7166 "' can not set flags, but 's' suffix specified");
7167 }
7168 // If we had a predication code on an instruction that can't do that, issue an
7169 // error.
7170 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
7171 return Error(NameLoc, "instruction '" + Mnemonic +
7172 "' is not predicable, but condition code specified");
7173 }
7174
7175 // If we had a VPT predication code on an instruction that can't do that, issue an
7176 // error.
7177 if (!CanAcceptVPTPredicationCode && VPTPredicationCode != ARMVCC::None) {
7178 return Error(NameLoc, "instruction '" + Mnemonic +
7179 "' is not VPT predicable, but VPT code T/E is specified");
7180 }
7181
7182 // Add the carry setting operand, if necessary.
7183 if (CanAcceptCarrySet && CarrySetting) {
7184 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
7185 Operands.push_back(ARMOperand::CreateCCOut(
7186 CarrySetting ? ARM::CPSR : ARM::NoRegister, Loc, *this));
7187 }
7188
7189 // Add the predication code operand, if necessary.
7190 if (CanAcceptPredicationCode && PredicationCode != llvm::ARMCC::AL) {
7191 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
7192 CarrySetting);
7193 Operands.push_back(ARMOperand::CreateCondCode(
7194 ARMCC::CondCodes(PredicationCode), Loc, *this));
7195 }
7196
7197 // Add the VPT predication code operand, if necessary.
7198 // Dont add in certain cases of VCVT as this needs to be disambiguated
7199 // after operand parsing.
7200 if (CanAcceptVPTPredicationCode && VPTPredicationCode != llvm::ARMVCC::None &&
7201 !(Mnemonic.starts_with("vcvt") && Mnemonic != "vcvta" &&
7202 Mnemonic != "vcvtn" && Mnemonic != "vcvtp" && Mnemonic != "vcvtm")) {
7203 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
7204 CarrySetting);
7205 Operands.push_back(ARMOperand::CreateVPTPred(
7206 ARMVCC::VPTCodes(VPTPredicationCode), Loc, *this));
7207 }
7208
7209 // Add the processor imod operand, if necessary.
7210 if (ProcessorIMod) {
7211 Operands.push_back(ARMOperand::CreateImm(
7212 MCConstantExpr::create(ProcessorIMod, getContext()), NameLoc, NameLoc,
7213 *this));
7214 } else if (Mnemonic == "cps" && isMClass()) {
7215 return Error(NameLoc, "instruction 'cps' requires effect for M-class");
7216 }
7217
7218 // Add the remaining tokens in the mnemonic.
7219 while (Next != StringRef::npos) {
7220 Start = Next;
7221 Next = Name.find('.', Start + 1);
7222 ExtraToken = Name.slice(Start, Next);
7223
7224 // Some NEON instructions have an optional datatype suffix that is
7225 // completely ignored. Check for that.
7226 if (isDataTypeToken(ExtraToken) &&
7227 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
7228 continue;
7229
7230 // For for ARM mode generate an error if the .n qualifier is used.
7231 if (ExtraToken == ".n" && !isThumb()) {
7232 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
7233 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
7234 "arm mode");
7235 }
7236
7237 // The .n qualifier is always discarded as that is what the tables
7238 // and matcher expect. In ARM mode the .w qualifier has no effect,
7239 // so discard it to avoid errors that can be caused by the matcher.
7240 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
7241 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
7242 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc, *this));
7243 }
7244 }
7245
7246 // This marks the end of the LHS Mnemonic operators.
7247 // This is used for indexing into the non-mnemonic operators as some of the
7248 // mnemonic operators are optional and therefore indexes can differ.
7249 unsigned MnemonicOpsEndInd = Operands.size();
7250
7251 // Read the remaining operands.
7252 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7253 // Read the first operand.
7254 if (parseOperand(Operands, Mnemonic)) {
7255 return true;
7256 }
7257
7258 while (parseOptionalToken(AsmToken::Comma)) {
7259 // Parse and remember the operand.
7260 if (parseOperand(Operands, Mnemonic)) {
7261 return true;
7262 }
7263 }
7264 }
7265
7266 if (parseToken(AsmToken::EndOfStatement, "unexpected token in argument list"))
7267 return true;
7268
7269 tryConvertingToTwoOperandForm(Mnemonic, PredicationCode, CarrySetting,
7270 Operands, MnemonicOpsEndInd);
7271
7272 if (hasCDE() && MS.isCDEInstr(Mnemonic)) {
7273 // Dual-register instructions use even-odd register pairs as their
7274 // destination operand, in assembly such pair is spelled as two
7275 // consecutive registers, without any special syntax. ConvertDualRegOperand
7276 // tries to convert such operand into register pair, e.g. r2, r3 -> r2_r3.
7277 // It returns true, if an error message has been emitted. If the function
7278 // returns false, the function either succeeded or an error (e.g. missing
7279 // operand) will be diagnosed elsewhere.
7280 if (MS.isCDEDualRegInstr(Mnemonic)) {
7281 bool GotError =
7282 CDEConvertDualRegOperand(Mnemonic, Operands, MnemonicOpsEndInd);
7283 if (GotError)
7284 return GotError;
7285 }
7286 }
7287
7288 if (hasMVE()) {
7289 if (!shouldOmitVectorPredicateOperand(Mnemonic, Operands,
7290 MnemonicOpsEndInd) &&
7291 Mnemonic == "vmov" && PredicationCode == ARMCC::LT) {
7292 // Very nasty hack to deal with the vector predicated variant of vmovlt
7293 // the scalar predicated vmov with condition 'lt'. We can not tell them
7294 // apart until we have parsed their operands.
7295 Operands.erase(Operands.begin() + 1);
7296 Operands.erase(Operands.begin());
7297 SMLoc MLoc = SMLoc::getFromPointer(NameLoc.getPointer());
7298 SMLoc PLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
7299 Mnemonic.size() - 1 + CarrySetting);
7300 Operands.insert(Operands.begin(),
7301 ARMOperand::CreateVPTPred(ARMVCC::None, PLoc, *this));
7302 Operands.insert(Operands.begin(), ARMOperand::CreateToken(
7303 StringRef("vmovlt"), MLoc, *this));
7304 } else if (Mnemonic == "vcvt" && PredicationCode == ARMCC::NE &&
7305 !shouldOmitVectorPredicateOperand(Mnemonic, Operands,
7306 MnemonicOpsEndInd)) {
7307 // Another nasty hack to deal with the ambiguity between vcvt with scalar
7308 // predication 'ne' and vcvtn with vector predication 'e'. As above we
7309 // can only distinguish between the two after we have parsed their
7310 // operands.
7311 Operands.erase(Operands.begin() + 1);
7312 Operands.erase(Operands.begin());
7313 SMLoc MLoc = SMLoc::getFromPointer(NameLoc.getPointer());
7314 SMLoc PLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
7315 Mnemonic.size() - 1 + CarrySetting);
7316 Operands.insert(Operands.begin(),
7317 ARMOperand::CreateVPTPred(ARMVCC::Else, PLoc, *this));
7318 Operands.insert(Operands.begin(),
7319 ARMOperand::CreateToken(StringRef("vcvtn"), MLoc, *this));
7320 } else if (Mnemonic == "vmul" && PredicationCode == ARMCC::LT &&
7321 !shouldOmitVectorPredicateOperand(Mnemonic, Operands,
7322 MnemonicOpsEndInd)) {
7323 // Another hack, this time to distinguish between scalar predicated vmul
7324 // with 'lt' predication code and the vector instruction vmullt with
7325 // vector predication code "none"
7326 removeCondCode(Operands, MnemonicOpsEndInd);
7327 Operands.erase(Operands.begin());
7328 SMLoc MLoc = SMLoc::getFromPointer(NameLoc.getPointer());
7329 Operands.insert(Operands.begin(), ARMOperand::CreateToken(
7330 StringRef("vmullt"), MLoc, *this));
7331 } else if (Mnemonic.starts_with("vcvt") && !Mnemonic.starts_with("vcvta") &&
7332 !Mnemonic.starts_with("vcvtn") &&
7333 !Mnemonic.starts_with("vcvtp") &&
7334 !Mnemonic.starts_with("vcvtm")) {
7335 if (!shouldOmitVectorPredicateOperand(Mnemonic, Operands,
7336 MnemonicOpsEndInd)) {
7337 // We could not split the vector predicate off vcvt because it might
7338 // have been the scalar vcvtt instruction. Now we know its a vector
7339 // instruction, we still need to check whether its the vector
7340 // predicated vcvt with 'Then' predication or the vector vcvtt. We can
7341 // distinguish the two based on the suffixes, if it is any of
7342 // ".f16.f32", ".f32.f16", ".f16.f64" or ".f64.f16" then it is the vcvtt.
7343 if (Mnemonic.starts_with("vcvtt") && MnemonicOpsEndInd > 2) {
7344 auto Sz1 =
7345 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd - 2]);
7346 auto Sz2 =
7347 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd - 1]);
7348 if (!(Sz1.isToken() && Sz1.getToken().starts_with(".f") &&
7349 Sz2.isToken() && Sz2.getToken().starts_with(".f"))) {
7350 Operands.erase(Operands.begin());
7351 SMLoc MLoc = SMLoc::getFromPointer(NameLoc.getPointer());
7352 VPTPredicationCode = ARMVCC::Then;
7353
7354 Mnemonic = Mnemonic.substr(0, 4);
7355 Operands.insert(Operands.begin(),
7356 ARMOperand::CreateToken(Mnemonic, MLoc, *this));
7357 }
7358 }
7359 SMLoc PLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
7360 Mnemonic.size() + CarrySetting);
7361 // Add VPTPred
7362 Operands.insert(Operands.begin() + 1,
7363 ARMOperand::CreateVPTPred(
7364 ARMVCC::VPTCodes(VPTPredicationCode), PLoc, *this));
7365 ++MnemonicOpsEndInd;
7366 }
7367 } else if (CanAcceptVPTPredicationCode) {
7368 // For all other instructions, make sure only one of the two
7369 // predication operands is left behind, depending on whether we should
7370 // use the vector predication.
7371 if (shouldOmitVectorPredicateOperand(Mnemonic, Operands,
7372 MnemonicOpsEndInd)) {
7373 removeVPTCondCode(Operands, MnemonicOpsEndInd);
7374 }
7375 }
7376 }
7377
7378 if (VPTPredicationCode != ARMVCC::None) {
7379 bool usedVPTPredicationCode = false;
7380 for (unsigned I = 1; I < Operands.size(); ++I)
7381 if (static_cast<ARMOperand &>(*Operands[I]).isVPTPred())
7382 usedVPTPredicationCode = true;
7383 if (!usedVPTPredicationCode) {
7384 // If we have a VPT predication code and we haven't just turned it
7385 // into an operand, then it was a mistake for splitMnemonic to
7386 // separate it from the rest of the mnemonic in the first place,
7387 // and this may lead to wrong disassembly (e.g. scalar floating
7388 // point VCMPE is actually a different instruction from VCMP, so
7389 // we mustn't treat them the same). In that situation, glue it
7390 // back on.
7391 Mnemonic = Name.slice(0, Mnemonic.size() + 1);
7392 Operands.erase(Operands.begin());
7393 Operands.insert(Operands.begin(),
7394 ARMOperand::CreateToken(Mnemonic, NameLoc, *this));
7395 }
7396 }
7397
7398 // ARM mode 'blx' need special handling, as the register operand version
7399 // is predicable, but the label operand version is not. So, we can't rely
7400 // on the Mnemonic based checking to correctly figure out when to put
7401 // a k_CondCode operand in the list. If we're trying to match the label
7402 // version, remove the k_CondCode operand here.
7403 if (!isThumb() && Mnemonic == "blx" &&
7404 Operands.size() == MnemonicOpsEndInd + 1 &&
7405 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd]).isImm())
7406 removeCondCode(Operands, MnemonicOpsEndInd);
7407
7408 // GNU Assembler extension (compatibility).
7409 fixupGNULDRDAlias(Mnemonic, Operands, MnemonicOpsEndInd);
7410
7411 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
7412 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
7413 // a single GPRPair reg operand is used in the .td file to replace the two
7414 // GPRs. However, when parsing from asm, the two GRPs cannot be
7415 // automatically
7416 // expressed as a GPRPair, so we have to manually merge them.
7417 // FIXME: We would really like to be able to tablegen'erate this.
7418 bool IsLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
7419 if (!isThumb() && Operands.size() > MnemonicOpsEndInd + 1 + (!IsLoad) &&
7420 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
7421 Mnemonic == "stlexd")) {
7422 unsigned Idx = IsLoad ? MnemonicOpsEndInd : MnemonicOpsEndInd + 1;
7423 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
7424 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
7425
7426 const MCRegisterClass &MRC = MRI->getRegClass(ARM::GPRRegClassID);
7427 // Adjust only if Op1 is a GPR.
7428 if (Op1.isReg() && MRC.contains(Op1.getReg())) {
7429 MCRegister Reg1 = Op1.getReg();
7430 unsigned Rt = MRI->getEncodingValue(Reg1);
7431 MCRegister Reg2 = Op2.getReg();
7432 unsigned Rt2 = MRI->getEncodingValue(Reg2);
7433 // Rt2 must be Rt + 1.
7434 if (Rt + 1 != Rt2)
7435 return Error(Op2.getStartLoc(),
7436 IsLoad ? "destination operands must be sequential"
7437 : "source operands must be sequential");
7438
7439 // Rt must be even
7440 if (Rt & 1)
7441 return Error(
7442 Op1.getStartLoc(),
7443 IsLoad ? "destination operands must start start at an even register"
7444 : "source operands must start start at an even register");
7445
7446 MCRegister NewReg = MRI->getMatchingSuperReg(
7447 Reg1, ARM::gsub_0, &(MRI->getRegClass(ARM::GPRPairRegClassID)));
7448 Operands[Idx] = ARMOperand::CreateReg(NewReg, Op1.getStartLoc(),
7449 Op2.getEndLoc(), *this);
7450 Operands.erase(Operands.begin() + Idx + 1);
7451 }
7452 }
7453
7454 // FIXME: As said above, this is all a pretty gross hack. This instruction
7455 // does not fit with other "subs" and tblgen.
7456 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
7457 // so the Mnemonic is "subs" and delete the CCOut operand so it will match
7458 // the table entry.
7459 if (isThumbTwo() && Mnemonic == "sub" && CarrySetting &&
7460 Operands.size() == MnemonicOpsEndInd + 3 &&
7461 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd]).isReg() &&
7462 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd]).getReg() ==
7463 ARM::PC &&
7464 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1]).isReg() &&
7465 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1]).getReg() ==
7466 ARM::LR &&
7467 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 2]).isImm()) {
7468 Operands.front() = ARMOperand::CreateToken("subs", NameLoc, *this);
7469 removeCCOut(Operands, MnemonicOpsEndInd);
7470 }
7471 return false;
7472}
7473
7474// Validate context-sensitive operand constraints.
7475
7476// return 'true' if register list contains non-low GPR registers,
7477// 'false' otherwise. If Reg is in the register list or is HiReg, set
7478// 'containsReg' to true.
7479static bool checkLowRegisterList(const MCInst &Inst, unsigned OpNo,
7480 MCRegister Reg, MCRegister HiReg,
7481 bool &containsReg) {
7482 containsReg = false;
7483 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
7484 MCRegister OpReg = Inst.getOperand(i).getReg();
7485 if (OpReg == Reg)
7486 containsReg = true;
7487 // Anything other than a low register isn't legal here.
7488 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
7489 return true;
7490 }
7491 return false;
7492}
7493
7494// Check if the specified regisgter is in the register list of the inst,
7495// starting at the indicated operand number.
7496static bool listContainsReg(const MCInst &Inst, unsigned OpNo, MCRegister Reg) {
7497 for (unsigned i = OpNo, e = Inst.getNumOperands(); i < e; ++i) {
7498 MCRegister OpReg = Inst.getOperand(i).getReg();
7499 if (OpReg == Reg)
7500 return true;
7501 }
7502 return false;
7503}
7504
7505// Return true if instruction has the interesting property of being
7506// allowed in IT blocks, but not being predicable.
7507static bool instIsBreakpoint(const MCInst &Inst) {
7508 return Inst.getOpcode() == ARM::tBKPT ||
7509 Inst.getOpcode() == ARM::BKPT ||
7510 Inst.getOpcode() == ARM::tHLT ||
7511 Inst.getOpcode() == ARM::HLT;
7512}
7513
7515 unsigned MnemonicOpsEndInd) {
7516 for (unsigned I = MnemonicOpsEndInd; I < Operands.size(); ++I) {
7517 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[I]);
7518 if (Op.isRegList()) {
7519 return I;
7520 }
7521 }
7522 return 0;
7523}
7524
7525bool ARMAsmParser::validatetLDMRegList(const MCInst &Inst,
7526 const OperandVector &Operands,
7527 unsigned MnemonicOpsEndInd,
7528 unsigned ListIndex, bool IsARPop) {
7529 bool ListContainsSP = listContainsReg(Inst, ListIndex, ARM::SP);
7530 bool ListContainsLR = listContainsReg(Inst, ListIndex, ARM::LR);
7531 bool ListContainsPC = listContainsReg(Inst, ListIndex, ARM::PC);
7532
7533 if (!IsARPop && ListContainsSP)
7534 return Error(
7535 Operands[getRegListInd(Operands, MnemonicOpsEndInd)]->getStartLoc(),
7536 "SP may not be in the register list");
7537 if (ListContainsPC && ListContainsLR)
7538 return Error(
7539 Operands[getRegListInd(Operands, MnemonicOpsEndInd)]->getStartLoc(),
7540 "PC and LR may not be in the register list simultaneously");
7541 return false;
7542}
7543
7544bool ARMAsmParser::validatetSTMRegList(const MCInst &Inst,
7545 const OperandVector &Operands,
7546 unsigned MnemonicOpsEndInd,
7547 unsigned ListIndex) {
7548 bool ListContainsSP = listContainsReg(Inst, ListIndex, ARM::SP);
7549 bool ListContainsPC = listContainsReg(Inst, ListIndex, ARM::PC);
7550
7551 if (ListContainsSP && ListContainsPC)
7552 return Error(
7553 Operands[getRegListInd(Operands, MnemonicOpsEndInd)]->getStartLoc(),
7554 "SP and PC may not be in the register list");
7555 if (ListContainsSP)
7556 return Error(
7557 Operands[getRegListInd(Operands, MnemonicOpsEndInd)]->getStartLoc(),
7558 "SP may not be in the register list");
7559 if (ListContainsPC)
7560 return Error(
7561 Operands[getRegListInd(Operands, MnemonicOpsEndInd)]->getStartLoc(),
7562 "PC may not be in the register list");
7563 return false;
7564}
7565
7566bool ARMAsmParser::validateLDRDSTRD(MCInst &Inst, const OperandVector &Operands,
7567 bool Load, bool ARMMode, bool Writeback,
7568 unsigned MnemonicOpsEndInd) {
7569 unsigned RtIndex = Load || !Writeback ? 0 : 1;
7570 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(RtIndex).getReg());
7571 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(RtIndex + 1).getReg());
7572
7573 if (ARMMode) {
7574 // Rt can't be R14.
7575 if (Rt == 14)
7576 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7577 "Rt can't be R14");
7578
7579 // Rt must be even-numbered.
7580 if ((Rt & 1) == 1)
7581 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7582 "Rt must be even-numbered");
7583
7584 // Rt2 must be Rt + 1.
7585 if (Rt2 != Rt + 1) {
7586 if (Load)
7587 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7588 "destination operands must be sequential");
7589 else
7590 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7591 "source operands must be sequential");
7592 }
7593
7594 // FIXME: Diagnose m == 15
7595 // FIXME: Diagnose ldrd with m == t || m == t2.
7596 }
7597
7598 if (!ARMMode && Load) {
7599 if (Rt2 == Rt)
7600 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7601 "destination operands can't be identical");
7602 }
7603
7604 if (Writeback) {
7605 unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
7606
7607 if (Rn == Rt || Rn == Rt2) {
7608 if (Load)
7609 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7610 "base register needs to be different from destination "
7611 "registers");
7612 else
7613 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
7614 "source register and base register can't be identical");
7615 }
7616
7617 // FIXME: Diagnose ldrd/strd with writeback and n == 15.
7618 // (Except the immediate form of ldrd?)
7619 }
7620
7621 return false;
7622}
7623
7625 for (unsigned i = 0; i < MCID.NumOperands; ++i) {
7626 if (ARM::isVpred(MCID.operands()[i].OperandType))
7627 return i;
7628 }
7629 return -1;
7630}
7631
7633 return findFirstVectorPredOperandIdx(MCID) != -1;
7634}
7635
7637 ARMOperand &Op = static_cast<ARMOperand &>(MCOp);
7638 if (!Op.isImm())
7639 return false;
7640 return !isa<MCConstantExpr>(Op.getImm());
7641}
7642
7643// FIXME: We would really like to be able to tablegen'erate this.
7644bool ARMAsmParser::validateInstruction(MCInst &Inst,
7645 const OperandVector &Operands,
7646 unsigned MnemonicOpsEndInd) {
7647 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
7648 SMLoc Loc = Operands[0]->getStartLoc();
7649
7650 // Check the IT block state first.
7651 // NOTE: BKPT and HLT instructions have the interesting property of being
7652 // allowed in IT blocks, but not being predicable. They just always execute.
7653 if (inITBlock() && !instIsBreakpoint(Inst)) {
7654 // The instruction must be predicable.
7655 if (!MCID.isPredicable())
7656 return Error(Loc, "instructions in IT block must be predicable");
7659 if (Cond != currentITCond()) {
7660 // Find the condition code Operand to get its SMLoc information.
7661 SMLoc CondLoc = Operands[0]->getEndLoc();
7662 for (unsigned I = 1; I < Operands.size(); ++I)
7663 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
7664 CondLoc = Operands[I]->getStartLoc();
7665 return Error(CondLoc, "incorrect condition in IT block; got '" +
7666 StringRef(ARMCondCodeToString(Cond)) +
7667 "', but expected '" +
7668 ARMCondCodeToString(currentITCond()) + "'");
7669 }
7670 // Check for non-'al' condition codes outside of the IT block.
7671 } else if (isThumbTwo() && MCID.isPredicable() &&
7672 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
7673 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
7674 Inst.getOpcode() != ARM::t2Bcc &&
7675 Inst.getOpcode() != ARM::t2BFic) {
7676 return Error(Loc, "predicated instructions must be in IT block");
7677 } else if (!isThumb() && !useImplicitITARM() && MCID.isPredicable() &&
7678 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
7679 ARMCC::AL) {
7680 return Warning(Loc, "predicated instructions should be in IT block");
7681 } else if (!MCID.isPredicable()) {
7682 // Check the instruction doesn't have a predicate operand anyway
7683 // that it's not allowed to use. Sometimes this happens in order
7684 // to keep instructions the same shape even though one cannot
7685 // legally be predicated, e.g. vmul.f16 vs vmul.f32.
7686 for (unsigned i = 0, e = MCID.getNumOperands(); i != e; ++i) {
7687 if (MCID.operands()[i].isPredicate()) {
7688 if (Inst.getOperand(i).getImm() != ARMCC::AL)
7689 return Error(Loc, "instruction is not predicable");
7690 break;
7691 }
7692 }
7693 }
7694
7695 // PC-setting instructions in an IT block, but not the last instruction of
7696 // the block, are UNPREDICTABLE.
7697 if (inExplicitITBlock() && !lastInITBlock() && isITBlockTerminator(Inst)) {
7698 return Error(Loc, "instruction must be outside of IT block or the last instruction in an IT block");
7699 }
7700
7701 if (inVPTBlock() && !instIsBreakpoint(Inst)) {
7702 unsigned Bit = extractITMaskBit(VPTState.Mask, VPTState.CurPosition);
7703 if (!isVectorPredicable(MCID))
7704 return Error(Loc, "instruction in VPT block must be predicable");
7705 unsigned Pred = Inst.getOperand(findFirstVectorPredOperandIdx(MCID)).getImm();
7706 unsigned VPTPred = Bit ? ARMVCC::Else : ARMVCC::Then;
7707 if (Pred != VPTPred) {
7708 SMLoc PredLoc;
7709 for (unsigned I = 1; I < Operands.size(); ++I)
7710 if (static_cast<ARMOperand &>(*Operands[I]).isVPTPred())
7711 PredLoc = Operands[I]->getStartLoc();
7712 return Error(PredLoc, "incorrect predication in VPT block; got '" +
7714 "', but expected '" +
7715 ARMVPTPredToString(ARMVCC::VPTCodes(VPTPred)) + "'");
7716 }
7717 }
7718 else if (isVectorPredicable(MCID) &&
7721 return Error(Loc, "VPT predicated instructions must be in VPT block");
7722
7723 const unsigned Opcode = Inst.getOpcode();
7724 switch (Opcode) {
7725 case ARM::VLLDM:
7726 case ARM::VLLDM_T2:
7727 case ARM::VLSTM:
7728 case ARM::VLSTM_T2: {
7729 // Since in some cases both T1 and T2 are valid, tablegen can not always
7730 // pick the correct instruction.
7731 if (Operands.size() ==
7732 MnemonicOpsEndInd + 2) { // a register list has been provided
7733 ARMOperand &Op = static_cast<ARMOperand &>(
7734 *Operands[MnemonicOpsEndInd + 1]); // the register list, a dpr_reglist
7735 assert(Op.isDPRRegList());
7736 auto &RegList = Op.getRegList();
7737 // T2 requires v8.1-M.Main (cannot be handled by tablegen)
7738 if (RegList.size() == 32 && !hasV8_1MMainline()) {
7739 return Error(Op.getEndLoc(), "T2 version requires v8.1-M.Main");
7740 }
7741 // When target has 32 D registers, T1 is undefined.
7742 if (hasD32() && RegList.size() != 32) {
7743 return Error(Op.getEndLoc(), "operand must be exactly {d0-d31}");
7744 }
7745 // When target has 16 D registers, both T1 and T2 are valid.
7746 if (!hasD32() && (RegList.size() != 16 && RegList.size() != 32)) {
7747 return Error(Op.getEndLoc(),
7748 "operand must be exactly {d0-d15} (T1) or {d0-d31} (T2)");
7749 }
7750 }
7751 return false;
7752 }
7753 case ARM::t2IT: {
7754 // Encoding is unpredictable if it ever results in a notional 'NV'
7755 // predicate. Since we don't parse 'NV' directly this means an 'AL'
7756 // predicate with an "else" mask bit.
7757 unsigned Cond = Inst.getOperand(0).getImm();
7758 unsigned Mask = Inst.getOperand(1).getImm();
7759
7760 // Conditions only allowing a 't' are those with no set bit except
7761 // the lowest-order one that indicates the end of the sequence. In
7762 // other words, powers of 2.
7763 if (Cond == ARMCC::AL && llvm::popcount(Mask) != 1)
7764 return Error(Loc, "unpredictable IT predicate sequence");
7765 break;
7766 }
7767 case ARM::LDRD:
7768 if (validateLDRDSTRD(Inst, Operands, /*Load*/ true, /*ARMMode*/ true,
7769 /*Writeback*/ false, MnemonicOpsEndInd))
7770 return true;
7771 break;
7772 case ARM::LDRD_PRE:
7773 case ARM::LDRD_POST:
7774 if (validateLDRDSTRD(Inst, Operands, /*Load*/ true, /*ARMMode*/ true,
7775 /*Writeback*/ true, MnemonicOpsEndInd))
7776 return true;
7777 break;
7778 case ARM::t2LDRDi8:
7779 if (validateLDRDSTRD(Inst, Operands, /*Load*/ true, /*ARMMode*/ false,
7780 /*Writeback*/ false, MnemonicOpsEndInd))
7781 return true;
7782 break;
7783 case ARM::t2LDRD_PRE:
7784 case ARM::t2LDRD_POST:
7785 if (validateLDRDSTRD(Inst, Operands, /*Load*/ true, /*ARMMode*/ false,
7786 /*Writeback*/ true, MnemonicOpsEndInd))
7787 return true;
7788 break;
7789 case ARM::t2BXJ: {
7790 const MCRegister RmReg = Inst.getOperand(0).getReg();
7791 // Rm = SP is no longer unpredictable in v8-A
7792 if (RmReg == ARM::SP && !hasV8Ops())
7793 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7794 "r13 (SP) is an unpredictable operand to BXJ");
7795 return false;
7796 }
7797 case ARM::STRD:
7798 if (validateLDRDSTRD(Inst, Operands, /*Load*/ false, /*ARMMode*/ true,
7799 /*Writeback*/ false, MnemonicOpsEndInd))
7800 return true;
7801 break;
7802 case ARM::STRD_PRE:
7803 case ARM::STRD_POST:
7804 if (validateLDRDSTRD(Inst, Operands, /*Load*/ false, /*ARMMode*/ true,
7805 /*Writeback*/ true, MnemonicOpsEndInd))
7806 return true;
7807 break;
7808 case ARM::t2STRD_PRE:
7809 case ARM::t2STRD_POST:
7810 if (validateLDRDSTRD(Inst, Operands, /*Load*/ false, /*ARMMode*/ false,
7811 /*Writeback*/ true, MnemonicOpsEndInd))
7812 return true;
7813 break;
7814 case ARM::t2STRi12:
7815 case ARM::t2STRi8:
7816 case ARM::t2STRs:
7817 // Rt == PC is UNPREDICTABLE.
7818 if (Inst.getOperand(0).getReg() == ARM::PC)
7819 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7820 "operand must be a register in range [r0, r14]");
7821 break;
7822 case ARM::STR_PRE_IMM:
7823 case ARM::STR_PRE_REG:
7824 case ARM::t2STR_PRE:
7825 case ARM::STR_POST_IMM:
7826 case ARM::STR_POST_REG:
7827 case ARM::t2STR_POST:
7828 case ARM::STRH_PRE:
7829 case ARM::t2STRH_PRE:
7830 case ARM::STRH_POST:
7831 case ARM::t2STRH_POST:
7832 case ARM::STRB_PRE_IMM:
7833 case ARM::STRB_PRE_REG:
7834 case ARM::t2STRB_PRE:
7835 case ARM::STRB_POST_IMM:
7836 case ARM::STRB_POST_REG:
7837 case ARM::t2STRB_POST: {
7838 // Rt must be different from Rn.
7839 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
7840 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
7841
7842 if (Rt == Rn)
7843 return Error(Operands[MnemonicOpsEndInd + 1]->getStartLoc(),
7844 "source register and base register can't be identical");
7845 return false;
7846 }
7847 case ARM::t2LDR_PRE_imm:
7848 case ARM::t2LDR_POST_imm:
7849 case ARM::t2STR_PRE_imm:
7850 case ARM::t2STR_POST_imm: {
7851 // Rt must be different from Rn.
7852 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
7853 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(1).getReg());
7854
7855 if (Rt == Rn)
7856 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7857 "destination register and base register can't be identical");
7858 if (Inst.getOpcode() == ARM::t2LDR_POST_imm ||
7859 Inst.getOpcode() == ARM::t2STR_POST_imm) {
7860 int Imm = Inst.getOperand(2).getImm();
7861 if (Imm > 255 || Imm < -255)
7862 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
7863 "operand must be in range [-255, 255]");
7864 }
7865 if (Inst.getOpcode() == ARM::t2STR_PRE_imm ||
7866 Inst.getOpcode() == ARM::t2STR_POST_imm) {
7867 if (Inst.getOperand(0).getReg() == ARM::PC) {
7868 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7869 "operand must be a register in range [r0, r14]");
7870 }
7871 }
7872 return false;
7873 }
7874
7875 case ARM::t2LDRB_OFFSET_imm:
7876 case ARM::t2LDRB_PRE_imm:
7877 case ARM::t2LDRB_POST_imm:
7878 case ARM::t2STRB_OFFSET_imm:
7879 case ARM::t2STRB_PRE_imm:
7880 case ARM::t2STRB_POST_imm: {
7881 if (Inst.getOpcode() == ARM::t2LDRB_POST_imm ||
7882 Inst.getOpcode() == ARM::t2STRB_POST_imm ||
7883 Inst.getOpcode() == ARM::t2LDRB_PRE_imm ||
7884 Inst.getOpcode() == ARM::t2STRB_PRE_imm) {
7885 int Imm = Inst.getOperand(2).getImm();
7886 if (Imm > 255 || Imm < -255)
7887 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
7888 "operand must be in range [-255, 255]");
7889 } else if (Inst.getOpcode() == ARM::t2LDRB_OFFSET_imm ||
7890 Inst.getOpcode() == ARM::t2STRB_OFFSET_imm) {
7891 int Imm = Inst.getOperand(2).getImm();
7892 if (Imm > 0 || Imm < -255)
7893 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
7894 "operand must be in range [0, 255] with a negative sign");
7895 }
7896 if (Inst.getOperand(0).getReg() == ARM::PC) {
7897 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7898 "if operand is PC, should call the LDRB (literal)");
7899 }
7900 return false;
7901 }
7902
7903 case ARM::t2LDRH_OFFSET_imm:
7904 case ARM::t2LDRH_PRE_imm:
7905 case ARM::t2LDRH_POST_imm:
7906 case ARM::t2STRH_OFFSET_imm:
7907 case ARM::t2STRH_PRE_imm:
7908 case ARM::t2STRH_POST_imm: {
7909 if (Inst.getOpcode() == ARM::t2LDRH_POST_imm ||
7910 Inst.getOpcode() == ARM::t2STRH_POST_imm ||
7911 Inst.getOpcode() == ARM::t2LDRH_PRE_imm ||
7912 Inst.getOpcode() == ARM::t2STRH_PRE_imm) {
7913 int Imm = Inst.getOperand(2).getImm();
7914 if (Imm > 255 || Imm < -255)
7915 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
7916 "operand must be in range [-255, 255]");
7917 } else if (Inst.getOpcode() == ARM::t2LDRH_OFFSET_imm ||
7918 Inst.getOpcode() == ARM::t2STRH_OFFSET_imm) {
7919 int Imm = Inst.getOperand(2).getImm();
7920 if (Imm > 0 || Imm < -255)
7921 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
7922 "operand must be in range [0, 255] with a negative sign");
7923 }
7924 if (Inst.getOperand(0).getReg() == ARM::PC) {
7925 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7926 "if operand is PC, should call the LDRH (literal)");
7927 }
7928 return false;
7929 }
7930
7931 case ARM::t2LDRSB_OFFSET_imm:
7932 case ARM::t2LDRSB_PRE_imm:
7933 case ARM::t2LDRSB_POST_imm: {
7934 if (Inst.getOpcode() == ARM::t2LDRSB_POST_imm ||
7935 Inst.getOpcode() == ARM::t2LDRSB_PRE_imm) {
7936 int Imm = Inst.getOperand(2).getImm();
7937 if (Imm > 255 || Imm < -255)
7938 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
7939 "operand must be in range [-255, 255]");
7940 } else if (Inst.getOpcode() == ARM::t2LDRSB_OFFSET_imm) {
7941 int Imm = Inst.getOperand(2).getImm();
7942 if (Imm > 0 || Imm < -255)
7943 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
7944 "operand must be in range [0, 255] with a negative sign");
7945 }
7946 if (Inst.getOperand(0).getReg() == ARM::PC) {
7947 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
7948 "if operand is PC, should call the LDRH (literal)");
7949 }
7950 return false;
7951 }
7952
7953 case ARM::t2LDRSH_OFFSET_imm:
7954 case ARM::t2LDRSH_PRE_imm:
7955 case ARM::t2LDRSH_POST_imm: {
7956 if (Inst.getOpcode() == ARM::t2LDRSH_POST_imm ||
7957 Inst.getOpcode() == ARM::t2LDRSH_PRE_imm) {
7958 int Imm = Inst.getOperand(2).getImm();
7959 if (Imm > 255 || Imm < -255)
7960 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
7961 "operand must be in range [-255, 255]");
7962 } else if (Inst.getOpcode() == ARM::t2LDRSH_OFFSET_imm) {
7963 int Imm = Inst.getOperand(2).getImm();
7964 if (Imm > 0 || Imm < -255)
7965 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
7966 "operand must be in range [0, 255] with a negative sign");
7967 }
7968 if (Inst.getOperand(0).getReg() == ARM::PC) {
7969 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
7970 "if operand is PC, should call the LDRH (literal)");
7971 }
7972 return false;
7973 }
7974
7975 case ARM::LDR_PRE_IMM:
7976 case ARM::LDR_PRE_REG:
7977 case ARM::t2LDR_PRE:
7978 case ARM::LDR_POST_IMM:
7979 case ARM::LDR_POST_REG:
7980 case ARM::t2LDR_POST:
7981 case ARM::LDRH_PRE:
7982 case ARM::t2LDRH_PRE:
7983 case ARM::LDRH_POST:
7984 case ARM::t2LDRH_POST:
7985 case ARM::LDRSH_PRE:
7986 case ARM::t2LDRSH_PRE:
7987 case ARM::LDRSH_POST:
7988 case ARM::t2LDRSH_POST:
7989 case ARM::LDRB_PRE_IMM:
7990 case ARM::LDRB_PRE_REG:
7991 case ARM::t2LDRB_PRE:
7992 case ARM::LDRB_POST_IMM:
7993 case ARM::LDRB_POST_REG:
7994 case ARM::t2LDRB_POST:
7995 case ARM::LDRSB_PRE:
7996 case ARM::t2LDRSB_PRE:
7997 case ARM::LDRSB_POST:
7998 case ARM::t2LDRSB_POST: {
7999 // Rt must be different from Rn.
8000 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
8001 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
8002
8003 if (Rt == Rn)
8004 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8005 "destination register and base register can't be identical");
8006 return false;
8007 }
8008
8009 case ARM::MVE_VLDRBU8_rq:
8010 case ARM::MVE_VLDRBU16_rq:
8011 case ARM::MVE_VLDRBS16_rq:
8012 case ARM::MVE_VLDRBU32_rq:
8013 case ARM::MVE_VLDRBS32_rq:
8014 case ARM::MVE_VLDRHU16_rq:
8015 case ARM::MVE_VLDRHU16_rq_u:
8016 case ARM::MVE_VLDRHU32_rq:
8017 case ARM::MVE_VLDRHU32_rq_u:
8018 case ARM::MVE_VLDRHS32_rq:
8019 case ARM::MVE_VLDRHS32_rq_u:
8020 case ARM::MVE_VLDRWU32_rq:
8021 case ARM::MVE_VLDRWU32_rq_u:
8022 case ARM::MVE_VLDRDU64_rq:
8023 case ARM::MVE_VLDRDU64_rq_u:
8024 case ARM::MVE_VLDRWU32_qi:
8025 case ARM::MVE_VLDRWU32_qi_pre:
8026 case ARM::MVE_VLDRDU64_qi:
8027 case ARM::MVE_VLDRDU64_qi_pre: {
8028 // Qd must be different from Qm.
8029 unsigned QdIdx = 0, QmIdx = 2;
8030 bool QmIsPointer = false;
8031 switch (Opcode) {
8032 case ARM::MVE_VLDRWU32_qi:
8033 case ARM::MVE_VLDRDU64_qi:
8034 QmIdx = 1;
8035 QmIsPointer = true;
8036 break;
8037 case ARM::MVE_VLDRWU32_qi_pre:
8038 case ARM::MVE_VLDRDU64_qi_pre:
8039 QdIdx = 1;
8040 QmIsPointer = true;
8041 break;
8042 }
8043
8044 const unsigned Qd = MRI->getEncodingValue(Inst.getOperand(QdIdx).getReg());
8045 const unsigned Qm = MRI->getEncodingValue(Inst.getOperand(QmIdx).getReg());
8046
8047 if (Qd == Qm) {
8048 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8049 Twine("destination vector register and vector ") +
8050 (QmIsPointer ? "pointer" : "offset") +
8051 " register can't be identical");
8052 }
8053 return false;
8054 }
8055
8056 case ARM::SBFX:
8057 case ARM::t2SBFX:
8058 case ARM::UBFX:
8059 case ARM::t2UBFX: {
8060 // Width must be in range [1, 32-lsb].
8061 unsigned LSB = Inst.getOperand(2).getImm();
8062 unsigned Widthm1 = Inst.getOperand(3).getImm();
8063 if (Widthm1 >= 32 - LSB)
8064 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
8065 "bitfield width must be in range [1,32-lsb]");
8066 return false;
8067 }
8068 // Notionally handles ARM::tLDMIA_UPD too.
8069 case ARM::tLDMIA: {
8070 // If we're parsing Thumb2, the .w variant is available and handles
8071 // most cases that are normally illegal for a Thumb1 LDM instruction.
8072 // We'll make the transformation in processInstruction() if necessary.
8073 //
8074 // Thumb LDM instructions are writeback iff the base register is not
8075 // in the register list.
8076 MCRegister Rn = Inst.getOperand(0).getReg();
8077 bool HasWritebackToken =
8078 (static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1])
8079 .isToken() &&
8080 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1])
8081 .getToken() == "!");
8082
8083 bool ListContainsBase;
8084 if (checkLowRegisterList(Inst, 3, Rn, MCRegister(), ListContainsBase) &&
8085 !isThumbTwo())
8086 return Error(
8087 Operands[getRegListInd(Operands, MnemonicOpsEndInd)]->getStartLoc(),
8088 "registers must be in range r0-r7");
8089 // If we should have writeback, then there should be a '!' token.
8090 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
8091 return Error(
8092 Operands[getRegListInd(Operands, MnemonicOpsEndInd)]->getStartLoc(),
8093 "writeback operator '!' expected");
8094 // If we should not have writeback, there must not be a '!'. This is
8095 // true even for the 32-bit wide encodings.
8096 if (ListContainsBase && HasWritebackToken)
8097 return Error(Operands[MnemonicOpsEndInd + 1]->getStartLoc(),
8098 "writeback operator '!' not allowed when base register "
8099 "in register list");
8100
8101 if (validatetLDMRegList(Inst, Operands, MnemonicOpsEndInd, 3))
8102 return true;
8103 break;
8104 }
8105 case ARM::LDMIA_UPD:
8106 case ARM::LDMDB_UPD:
8107 case ARM::LDMIB_UPD:
8108 case ARM::LDMDA_UPD:
8109 // ARM variants loading and updating the same register are only officially
8110 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
8111 if (!hasV7Ops())
8112 break;
8113 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
8114 return Error(Operands.back()->getStartLoc(),
8115 "writeback register not allowed in register list");
8116 break;
8117 case ARM::t2LDMIA:
8118 case ARM::t2LDMDB:
8119 if (validatetLDMRegList(Inst, Operands, MnemonicOpsEndInd, 3))
8120 return true;
8121 break;
8122 case ARM::t2STMIA:
8123 case ARM::t2STMDB:
8124 if (validatetSTMRegList(Inst, Operands, MnemonicOpsEndInd, 3))
8125 return true;
8126 break;
8127 case ARM::t2LDMIA_UPD:
8128 case ARM::t2LDMDB_UPD:
8129 case ARM::t2STMIA_UPD:
8130 case ARM::t2STMDB_UPD:
8131 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
8132 return Error(Operands.back()->getStartLoc(),
8133 "writeback register not allowed in register list");
8134
8135 if (Opcode == ARM::t2LDMIA_UPD || Opcode == ARM::t2LDMDB_UPD) {
8136 if (validatetLDMRegList(Inst, Operands, MnemonicOpsEndInd, 3))
8137 return true;
8138 } else {
8139 if (validatetSTMRegList(Inst, Operands, MnemonicOpsEndInd, 3))
8140 return true;
8141 }
8142 break;
8143
8144 case ARM::sysLDMIA_UPD:
8145 case ARM::sysLDMDA_UPD:
8146 case ARM::sysLDMDB_UPD:
8147 case ARM::sysLDMIB_UPD:
8148 if (!listContainsReg(Inst, 3, ARM::PC))
8149 return Error(Operands[MnemonicOpsEndInd + 1]->getStartLoc(),
8150 "writeback register only allowed on system LDM "
8151 "if PC in register-list");
8152 break;
8153 case ARM::sysSTMIA_UPD:
8154 case ARM::sysSTMDA_UPD:
8155 case ARM::sysSTMDB_UPD:
8156 case ARM::sysSTMIB_UPD:
8157 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8158 "system STM cannot have writeback register");
8159 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
8160 // so only issue a diagnostic for thumb1. The instructions will be
8161 // switched to the t2 encodings in processInstruction() if necessary.
8162 case ARM::tPOP: {
8163 bool ListContainsBase;
8164 if (checkLowRegisterList(Inst, 2, MCRegister(), ARM::PC,
8165 ListContainsBase) &&
8166 !isThumbTwo())
8167 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8168 "registers must be in range r0-r7 or pc");
8169 if (validatetLDMRegList(Inst, Operands, MnemonicOpsEndInd, 2, !isMClass()))
8170 return true;
8171 break;
8172 }
8173 case ARM::tPUSH: {
8174 bool ListContainsBase;
8175 if (checkLowRegisterList(Inst, 2, MCRegister(), ARM::LR,
8176 ListContainsBase) &&
8177 !isThumbTwo())
8178 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8179 "registers must be in range r0-r7 or lr");
8180 if (validatetSTMRegList(Inst, Operands, MnemonicOpsEndInd, 2))
8181 return true;
8182 break;
8183 }
8184 case ARM::tSTMIA_UPD: {
8185 bool ListContainsBase, InvalidLowList;
8186 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
8187 0, ListContainsBase);
8188 if (InvalidLowList && !isThumbTwo())
8189 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
8190 "registers must be in range r0-r7");
8191
8192 // This would be converted to a 32-bit stm, but that's not valid if the
8193 // writeback register is in the list.
8194 if (InvalidLowList && ListContainsBase)
8195 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8196 "writeback operator '!' not allowed when base register "
8197 "in register list");
8198
8199 if (validatetSTMRegList(Inst, Operands, MnemonicOpsEndInd, 4))
8200 return true;
8201 break;
8202 }
8203 case ARM::tADDrSP:
8204 // If the non-SP source operand and the destination operand are not the
8205 // same, we need thumb2 (for the wide encoding), or we have an error.
8206 if (!isThumbTwo() &&
8207 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
8208 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
8209 "source register must be the same as destination");
8210 }
8211 break;
8212
8213 case ARM::t2ADDrr:
8214 case ARM::t2ADDrs:
8215 case ARM::t2SUBrr:
8216 case ARM::t2SUBrs:
8217 if (Inst.getOperand(0).getReg() == ARM::SP &&
8218 Inst.getOperand(1).getReg() != ARM::SP)
8219 return Error(Operands[MnemonicOpsEndInd + 1]->getStartLoc(),
8220 "source register must be sp if destination is sp");
8221 break;
8222
8223 // Final range checking for Thumb unconditional branch instructions.
8224 case ARM::tB:
8225 if (!(static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd]))
8226 .isSignedOffset<11, 1>())
8227 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8228 "branch target out of range");
8229 break;
8230 case ARM::t2B: {
8231 int op = (Operands[MnemonicOpsEndInd]->isImm()) ? MnemonicOpsEndInd
8232 : MnemonicOpsEndInd + 1;
8233 ARMOperand &Operand = static_cast<ARMOperand &>(*Operands[op]);
8234 // Delay the checks of symbolic expressions until they are resolved.
8235 if (!isa<MCBinaryExpr>(Operand.getImm()) &&
8236 !Operand.isSignedOffset<24, 1>())
8237 return Error(Operands[op]->getStartLoc(), "branch target out of range");
8238 break;
8239 }
8240 // Final range checking for Thumb conditional branch instructions.
8241 case ARM::tBcc:
8242 if (!static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd])
8243 .isSignedOffset<8, 1>())
8244 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8245 "branch target out of range");
8246 break;
8247 case ARM::t2Bcc: {
8248 int Op = (Operands[MnemonicOpsEndInd]->isImm()) ? MnemonicOpsEndInd
8249 : MnemonicOpsEndInd + 1;
8250 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
8251 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
8252 break;
8253 }
8254 case ARM::tCBZ:
8255 case ARM::tCBNZ: {
8256 if (!static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1])
8257 .isUnsignedOffset<6, 1>())
8258 return Error(Operands[MnemonicOpsEndInd + 1]->getStartLoc(),
8259 "branch target out of range");
8260 break;
8261 }
8262 case ARM::MOVi16:
8263 case ARM::MOVTi16:
8264 case ARM::t2MOVi16:
8265 case ARM::t2MOVTi16:
8266 {
8267 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
8268 // especially when we turn it into a movw and the expression <symbol> does
8269 // not have a :lower16: or :upper16 as part of the expression. We don't
8270 // want the behavior of silently truncating, which can be unexpected and
8271 // lead to bugs that are difficult to find since this is an easy mistake
8272 // to make.
8273 int i = (Operands[MnemonicOpsEndInd]->isImm()) ? MnemonicOpsEndInd
8274 : MnemonicOpsEndInd + 1;
8275 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
8276 const MCExpr *E = Op.getImm();
8278 break;
8279 auto *ARM16Expr = dyn_cast<MCSpecifierExpr>(E);
8280 if (!ARM16Expr || (ARM16Expr->getSpecifier() != ARM::S_HI16 &&
8281 ARM16Expr->getSpecifier() != ARM::S_LO16))
8282 return Error(
8283 Op.getStartLoc(),
8284 "immediate expression for mov requires :lower16: or :upper16");
8285 break;
8286 }
8287 case ARM::tADDi8: {
8288 int i = (Operands[MnemonicOpsEndInd + 1]->isImm()) ? MnemonicOpsEndInd + 1
8289 : MnemonicOpsEndInd + 2;
8290 MCParsedAsmOperand &Op = *Operands[i];
8292 return Error(Op.getStartLoc(),
8293 "Immediate expression for Thumb adds requires :lower0_7:,"
8294 " :lower8_15:, :upper0_7: or :upper8_15:");
8295 break;
8296 }
8297 case ARM::tMOVi8: {
8298 MCParsedAsmOperand &Op = *Operands[MnemonicOpsEndInd + 1];
8300 return Error(Op.getStartLoc(),
8301 "Immediate expression for Thumb movs requires :lower0_7:,"
8302 " :lower8_15:, :upper0_7: or :upper8_15:");
8303 break;
8304 }
8305 case ARM::HINT:
8306 case ARM::t2HINT: {
8307 unsigned Imm8 = Inst.getOperand(0).getImm();
8308 unsigned Pred = Inst.getOperand(1).getImm();
8309 // ESB is not predicable (pred must be AL). Without the RAS extension, this
8310 // behaves as any other unallocated hint.
8311 if (Imm8 == 0x10 && Pred != ARMCC::AL && hasRAS())
8312 return Error(Operands[1]->getStartLoc(), "instruction 'esb' is not "
8313 "predicable, but condition "
8314 "code specified");
8315 if (Imm8 == 0x14 && Pred != ARMCC::AL)
8316 return Error(Operands[1]->getStartLoc(), "instruction 'csdb' is not "
8317 "predicable, but condition "
8318 "code specified");
8319 break;
8320 }
8321 case ARM::t2BFi:
8322 case ARM::t2BFr:
8323 case ARM::t2BFLi:
8324 case ARM::t2BFLr: {
8325 if (!static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd])
8326 .isUnsignedOffset<4, 1>() ||
8327 (Inst.getOperand(0).isImm() && Inst.getOperand(0).getImm() == 0)) {
8328 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8329 "branch location out of range or not a multiple of 2");
8330 }
8331
8332 if (Opcode == ARM::t2BFi) {
8333 if (!static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1])
8334 .isSignedOffset<16, 1>())
8335 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8336 "branch target out of range or not a multiple of 2");
8337 } else if (Opcode == ARM::t2BFLi) {
8338 if (!static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1])
8339 .isSignedOffset<18, 1>())
8340 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8341 "branch target out of range or not a multiple of 2");
8342 }
8343 break;
8344 }
8345 case ARM::t2BFic: {
8346 if (!static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd])
8347 .isUnsignedOffset<4, 1>() ||
8348 (Inst.getOperand(0).isImm() && Inst.getOperand(0).getImm() == 0))
8349 return Error(Operands[1]->getStartLoc(),
8350 "branch location out of range or not a multiple of 2");
8351
8352 if (!static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1])
8353 .isSignedOffset<16, 1>())
8354 return Error(Operands[MnemonicOpsEndInd + 1]->getStartLoc(),
8355 "branch target out of range or not a multiple of 2");
8356
8357 assert(Inst.getOperand(0).isImm() == Inst.getOperand(2).isImm() &&
8358 "branch location and else branch target should either both be "
8359 "immediates or both labels");
8360
8361 if (Inst.getOperand(0).isImm() && Inst.getOperand(2).isImm()) {
8362 int Diff = Inst.getOperand(2).getImm() - Inst.getOperand(0).getImm();
8363 if (Diff != 4 && Diff != 2)
8364 return Error(
8365 Operands[3]->getStartLoc(),
8366 "else branch target must be 2 or 4 greater than the branch location");
8367 }
8368 break;
8369 }
8370 case ARM::t2CLRM: {
8371 for (unsigned i = 2; i < Inst.getNumOperands(); i++) {
8372 if (Inst.getOperand(i).isReg() &&
8373 !getARMMCRegisterClass(ARM::GPRwithAPSRnospRegClassID)
8374 .contains(Inst.getOperand(i).getReg())) {
8375 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8376 "invalid register in register list. Valid registers are "
8377 "r0-r12, lr/r14 and APSR.");
8378 }
8379 }
8380 break;
8381 }
8382 case ARM::DSB:
8383 case ARM::t2DSB: {
8384
8385 if (Inst.getNumOperands() < 2)
8386 break;
8387
8388 unsigned Option = Inst.getOperand(0).getImm();
8389 unsigned Pred = Inst.getOperand(1).getImm();
8390
8391 // SSBB and PSSBB (DSB #0|#4) are not predicable (pred must be AL).
8392 if (Option == 0 && Pred != ARMCC::AL)
8393 return Error(Operands[1]->getStartLoc(),
8394 "instruction 'ssbb' is not predicable, but condition code "
8395 "specified");
8396 if (Option == 4 && Pred != ARMCC::AL)
8397 return Error(Operands[1]->getStartLoc(),
8398 "instruction 'pssbb' is not predicable, but condition code "
8399 "specified");
8400 break;
8401 }
8402 case ARM::VMOVRRS: {
8403 // Source registers must be sequential.
8404 const unsigned Sm = MRI->getEncodingValue(Inst.getOperand(2).getReg());
8405 const unsigned Sm1 = MRI->getEncodingValue(Inst.getOperand(3).getReg());
8406 if (Sm1 != Sm + 1)
8407 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
8408 "source operands must be sequential");
8409 break;
8410 }
8411 case ARM::VMOVSRR: {
8412 // Destination registers must be sequential.
8413 const unsigned Sm = MRI->getEncodingValue(Inst.getOperand(0).getReg());
8414 const unsigned Sm1 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
8415 if (Sm1 != Sm + 1)
8416 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8417 "destination operands must be sequential");
8418 break;
8419 }
8420 case ARM::VLDMDIA:
8421 case ARM::VSTMDIA: {
8422 ARMOperand &Op =
8423 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1]);
8424 auto &RegList = Op.getRegList();
8425 if (RegList.size() < 1 || RegList.size() > 16)
8426 return Error(Operands[MnemonicOpsEndInd + 1]->getStartLoc(),
8427 "list of registers must be at least 1 and at most 16");
8428 break;
8429 }
8430 case ARM::MVE_VQDMULLs32bh:
8431 case ARM::MVE_VQDMULLs32th:
8432 case ARM::MVE_VCMULf32:
8433 case ARM::MVE_VMULLBs32:
8434 case ARM::MVE_VMULLTs32:
8435 case ARM::MVE_VMULLBu32:
8436 case ARM::MVE_VMULLTu32: {
8437 if (Operands[MnemonicOpsEndInd]->getReg() ==
8438 Operands[MnemonicOpsEndInd + 1]->getReg()) {
8439 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8440 "Qd register and Qn register can't be identical");
8441 }
8442 if (Operands[MnemonicOpsEndInd]->getReg() ==
8443 Operands[MnemonicOpsEndInd + 2]->getReg()) {
8444 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8445 "Qd register and Qm register can't be identical");
8446 }
8447 break;
8448 }
8449 case ARM::MVE_VREV64_8:
8450 case ARM::MVE_VREV64_16:
8451 case ARM::MVE_VREV64_32:
8452 case ARM::MVE_VQDMULL_qr_s32bh:
8453 case ARM::MVE_VQDMULL_qr_s32th: {
8454 if (Operands[MnemonicOpsEndInd]->getReg() ==
8455 Operands[MnemonicOpsEndInd + 1]->getReg()) {
8456 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8457 "Qd register and Qn register can't be identical");
8458 }
8459 break;
8460 }
8461 case ARM::MVE_VCADDi32:
8462 case ARM::MVE_VCADDf32:
8463 case ARM::MVE_VHCADDs32: {
8464 if (Operands[MnemonicOpsEndInd]->getReg() ==
8465 Operands[MnemonicOpsEndInd + 2]->getReg()) {
8466 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8467 "Qd register and Qm register can't be identical");
8468 }
8469 break;
8470 }
8471 case ARM::MVE_VMOV_rr_q: {
8472 if (Operands[MnemonicOpsEndInd + 2]->getReg() !=
8473 Operands[MnemonicOpsEndInd + 4]->getReg())
8474 return Error(Operands[MnemonicOpsEndInd + 2]->getStartLoc(),
8475 "Q-registers must be the same");
8476 if (static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 3])
8477 .getVectorIndex() !=
8478 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 5])
8479 .getVectorIndex() +
8480 2)
8481 return Error(Operands[MnemonicOpsEndInd + 3]->getStartLoc(),
8482 "Q-register indexes must be 2 and 0 or 3 and 1");
8483 break;
8484 }
8485 case ARM::MVE_VMOV_q_rr: {
8486 if (Operands[MnemonicOpsEndInd]->getReg() !=
8487 Operands[MnemonicOpsEndInd + 2]->getReg())
8488 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8489 "Q-registers must be the same");
8490 if (static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1])
8491 .getVectorIndex() !=
8492 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 3])
8493 .getVectorIndex() +
8494 2)
8495 return Error(Operands[MnemonicOpsEndInd + 1]->getStartLoc(),
8496 "Q-register indexes must be 2 and 0 or 3 and 1");
8497 break;
8498 }
8499 case ARM::MVE_SQRSHR:
8500 case ARM::MVE_UQRSHL: {
8501 if (Operands[MnemonicOpsEndInd]->getReg() ==
8502 Operands[MnemonicOpsEndInd + 1]->getReg()) {
8503 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8504 "Rda register and Rm register can't be identical");
8505 }
8506 break;
8507 }
8508 case ARM::UMAAL:
8509 case ARM::UMLAL:
8510 case ARM::UMULL:
8511 case ARM::t2UMAAL:
8512 case ARM::t2UMLAL:
8513 case ARM::t2UMULL:
8514 case ARM::SMLAL:
8515 case ARM::SMLALBB:
8516 case ARM::SMLALBT:
8517 case ARM::SMLALD:
8518 case ARM::SMLALDX:
8519 case ARM::SMLALTB:
8520 case ARM::SMLALTT:
8521 case ARM::SMLSLD:
8522 case ARM::SMLSLDX:
8523 case ARM::SMULL:
8524 case ARM::t2SMLAL:
8525 case ARM::t2SMLALBB:
8526 case ARM::t2SMLALBT:
8527 case ARM::t2SMLALD:
8528 case ARM::t2SMLALDX:
8529 case ARM::t2SMLALTB:
8530 case ARM::t2SMLALTT:
8531 case ARM::t2SMLSLD:
8532 case ARM::t2SMLSLDX:
8533 case ARM::t2SMULL: {
8534 MCRegister RdHi = Inst.getOperand(0).getReg();
8535 MCRegister RdLo = Inst.getOperand(1).getReg();
8536 if(RdHi == RdLo) {
8537 return Error(Loc,
8538 "unpredictable instruction, RdHi and RdLo must be different");
8539 }
8540 break;
8541 }
8542
8543 case ARM::CDE_CX1:
8544 case ARM::CDE_CX1A:
8545 case ARM::CDE_CX1D:
8546 case ARM::CDE_CX1DA:
8547 case ARM::CDE_CX2:
8548 case ARM::CDE_CX2A:
8549 case ARM::CDE_CX2D:
8550 case ARM::CDE_CX2DA:
8551 case ARM::CDE_CX3:
8552 case ARM::CDE_CX3A:
8553 case ARM::CDE_CX3D:
8554 case ARM::CDE_CX3DA:
8555 case ARM::CDE_VCX1_vec:
8556 case ARM::CDE_VCX1_fpsp:
8557 case ARM::CDE_VCX1_fpdp:
8558 case ARM::CDE_VCX1A_vec:
8559 case ARM::CDE_VCX1A_fpsp:
8560 case ARM::CDE_VCX1A_fpdp:
8561 case ARM::CDE_VCX2_vec:
8562 case ARM::CDE_VCX2_fpsp:
8563 case ARM::CDE_VCX2_fpdp:
8564 case ARM::CDE_VCX2A_vec:
8565 case ARM::CDE_VCX2A_fpsp:
8566 case ARM::CDE_VCX2A_fpdp:
8567 case ARM::CDE_VCX3_vec:
8568 case ARM::CDE_VCX3_fpsp:
8569 case ARM::CDE_VCX3_fpdp:
8570 case ARM::CDE_VCX3A_vec:
8571 case ARM::CDE_VCX3A_fpsp:
8572 case ARM::CDE_VCX3A_fpdp: {
8573 assert(Inst.getOperand(1).isImm() &&
8574 "CDE operand 1 must be a coprocessor ID");
8575 int64_t Coproc = Inst.getOperand(1).getImm();
8576 if (Coproc < 8 && !ARM::isCDECoproc(Coproc, *STI))
8577 return Error(Operands[1]->getStartLoc(),
8578 "coprocessor must be configured as CDE");
8579 else if (Coproc >= 8)
8580 return Error(Operands[1]->getStartLoc(),
8581 "coprocessor must be in the range [p0, p7]");
8582 break;
8583 }
8584
8585 case ARM::t2CDP:
8586 case ARM::t2CDP2:
8587 case ARM::t2LDC2L_OFFSET:
8588 case ARM::t2LDC2L_OPTION:
8589 case ARM::t2LDC2L_POST:
8590 case ARM::t2LDC2L_PRE:
8591 case ARM::t2LDC2_OFFSET:
8592 case ARM::t2LDC2_OPTION:
8593 case ARM::t2LDC2_POST:
8594 case ARM::t2LDC2_PRE:
8595 case ARM::t2LDCL_OFFSET:
8596 case ARM::t2LDCL_OPTION:
8597 case ARM::t2LDCL_POST:
8598 case ARM::t2LDCL_PRE:
8599 case ARM::t2LDC_OFFSET:
8600 case ARM::t2LDC_OPTION:
8601 case ARM::t2LDC_POST:
8602 case ARM::t2LDC_PRE:
8603 case ARM::t2MCR:
8604 case ARM::t2MCR2:
8605 case ARM::t2MCRR:
8606 case ARM::t2MCRR2:
8607 case ARM::t2MRC:
8608 case ARM::t2MRC2:
8609 case ARM::t2MRRC:
8610 case ARM::t2MRRC2:
8611 case ARM::t2STC2L_OFFSET:
8612 case ARM::t2STC2L_OPTION:
8613 case ARM::t2STC2L_POST:
8614 case ARM::t2STC2L_PRE:
8615 case ARM::t2STC2_OFFSET:
8616 case ARM::t2STC2_OPTION:
8617 case ARM::t2STC2_POST:
8618 case ARM::t2STC2_PRE:
8619 case ARM::t2STCL_OFFSET:
8620 case ARM::t2STCL_OPTION:
8621 case ARM::t2STCL_POST:
8622 case ARM::t2STCL_PRE:
8623 case ARM::t2STC_OFFSET:
8624 case ARM::t2STC_OPTION:
8625 case ARM::t2STC_POST:
8626 case ARM::t2STC_PRE: {
8627 unsigned Opcode = Inst.getOpcode();
8628 // Inst.getOperand indexes operands in the (oops ...) and (iops ...) dags,
8629 // CopInd is the index of the coprocessor operand.
8630 size_t CopInd = 0;
8631 if (Opcode == ARM::t2MRRC || Opcode == ARM::t2MRRC2)
8632 CopInd = 2;
8633 else if (Opcode == ARM::t2MRC || Opcode == ARM::t2MRC2)
8634 CopInd = 1;
8635 assert(Inst.getOperand(CopInd).isImm() &&
8636 "Operand must be a coprocessor ID");
8637 int64_t Coproc = Inst.getOperand(CopInd).getImm();
8638 // Operands[2] is the coprocessor operand at syntactic level
8639 if (ARM::isCDECoproc(Coproc, *STI))
8640 return Error(Operands[2]->getStartLoc(),
8641 "coprocessor must be configured as GCP");
8642 break;
8643 }
8644
8645 case ARM::VTOSHH:
8646 case ARM::VTOUHH:
8647 case ARM::VTOSLH:
8648 case ARM::VTOULH:
8649 case ARM::VTOSHS:
8650 case ARM::VTOUHS:
8651 case ARM::VTOSLS:
8652 case ARM::VTOULS:
8653 case ARM::VTOSHD:
8654 case ARM::VTOUHD:
8655 case ARM::VTOSLD:
8656 case ARM::VTOULD:
8657 case ARM::VSHTOH:
8658 case ARM::VUHTOH:
8659 case ARM::VSLTOH:
8660 case ARM::VULTOH:
8661 case ARM::VSHTOS:
8662 case ARM::VUHTOS:
8663 case ARM::VSLTOS:
8664 case ARM::VULTOS:
8665 case ARM::VSHTOD:
8666 case ARM::VUHTOD:
8667 case ARM::VSLTOD:
8668 case ARM::VULTOD: {
8669 if (Operands[MnemonicOpsEndInd]->getReg() !=
8670 Operands[MnemonicOpsEndInd + 1]->getReg())
8671 return Error(Operands[MnemonicOpsEndInd]->getStartLoc(),
8672 "source and destination registers must be the same");
8673 break;
8674 }
8675 }
8676
8677 return false;
8678}
8679
8680static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
8681 switch(Opc) {
8682 default: llvm_unreachable("unexpected opcode!");
8683 // VST1LN
8684 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
8685 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
8686 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
8687 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
8688 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
8689 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
8690 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
8691 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
8692 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
8693
8694 // VST2LN
8695 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
8696 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
8697 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
8698 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
8699 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
8700
8701 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
8702 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
8703 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
8704 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
8705 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
8706
8707 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
8708 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
8709 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
8710 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
8711 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
8712
8713 // VST3LN
8714 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
8715 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
8716 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
8717 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
8718 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
8719 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
8720 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
8721 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
8722 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
8723 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
8724 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
8725 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
8726 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
8727 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
8728 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
8729
8730 // VST3
8731 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
8732 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
8733 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
8734 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
8735 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
8736 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
8737 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
8738 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
8739 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
8740 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
8741 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
8742 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
8743 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
8744 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
8745 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
8746 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
8747 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
8748 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
8749
8750 // VST4LN
8751 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
8752 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
8753 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
8754 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
8755 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
8756 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
8757 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
8758 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
8759 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
8760 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
8761 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
8762 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
8763 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
8764 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
8765 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
8766
8767 // VST4
8768 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
8769 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
8770 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
8771 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
8772 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
8773 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
8774 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
8775 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
8776 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
8777 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
8778 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
8779 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
8780 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
8781 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
8782 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
8783 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
8784 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
8785 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
8786 }
8787}
8788
8789static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
8790 switch(Opc) {
8791 default: llvm_unreachable("unexpected opcode!");
8792 // VLD1LN
8793 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
8794 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
8795 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
8796 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
8797 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
8798 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
8799 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
8800 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
8801 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
8802
8803 // VLD2LN
8804 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
8805 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
8806 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
8807 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
8808 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
8809 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
8810 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
8811 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
8812 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
8813 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
8814 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
8815 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
8816 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
8817 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
8818 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
8819
8820 // VLD3DUP
8821 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
8822 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
8823 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
8824 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
8825 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
8826 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
8827 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
8828 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
8829 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
8830 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
8831 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
8832 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
8833 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
8834 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
8835 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
8836 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
8837 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
8838 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
8839
8840 // VLD3LN
8841 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
8842 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
8843 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
8844 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
8845 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
8846 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
8847 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
8848 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
8849 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
8850 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
8851 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
8852 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
8853 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
8854 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
8855 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
8856
8857 // VLD3
8858 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
8859 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
8860 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
8861 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
8862 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
8863 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
8864 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
8865 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
8866 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
8867 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
8868 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
8869 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
8870 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
8871 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
8872 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
8873 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
8874 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
8875 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
8876
8877 // VLD4LN
8878 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
8879 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
8880 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
8881 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
8882 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
8883 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
8884 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
8885 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
8886 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
8887 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
8888 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
8889 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
8890 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
8891 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
8892 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
8893
8894 // VLD4DUP
8895 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
8896 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
8897 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
8898 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
8899 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
8900 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
8901 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
8902 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
8903 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
8904 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
8905 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
8906 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
8907 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
8908 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
8909 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
8910 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
8911 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
8912 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
8913
8914 // VLD4
8915 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
8916 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
8917 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
8918 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
8919 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
8920 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
8921 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
8922 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
8923 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
8924 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
8925 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
8926 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
8927 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
8928 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
8929 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
8930 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
8931 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
8932 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
8933 }
8934}
8935
8936bool ARMAsmParser::processInstruction(MCInst &Inst,
8937 const OperandVector &Operands,
8938 unsigned MnemonicOpsEndInd,
8939 MCStreamer &Out) {
8940 // Check if we have the wide qualifier, because if it's present we
8941 // must avoid selecting a 16-bit thumb instruction.
8942 bool HasWideQualifier = false;
8943 for (auto &Op : Operands) {
8944 ARMOperand &ARMOp = static_cast<ARMOperand&>(*Op);
8945 if (ARMOp.isToken() && ARMOp.getToken() == ".w") {
8946 HasWideQualifier = true;
8947 break;
8948 }
8949 }
8950
8951 switch (Inst.getOpcode()) {
8952 case ARM::VLLDM:
8953 case ARM::VLSTM: {
8954 // In some cases both T1 and T2 are valid, causing tablegen pick T1 instead
8955 // of T2
8956 if (Operands.size() ==
8957 MnemonicOpsEndInd + 2) { // a register list has been provided
8958 ARMOperand &Op = static_cast<ARMOperand &>(
8959 *Operands[MnemonicOpsEndInd + 1]); // the register list, a dpr_reglist
8960 assert(Op.isDPRRegList());
8961 auto &RegList = Op.getRegList();
8962 // When the register list is {d0-d31} the instruction has to be the T2
8963 // variant
8964 if (RegList.size() == 32) {
8965 const unsigned Opcode =
8966 (Inst.getOpcode() == ARM::VLLDM) ? ARM::VLLDM_T2 : ARM::VLSTM_T2;
8967 MCInst TmpInst;
8968 TmpInst.setOpcode(Opcode);
8969 TmpInst.addOperand(Inst.getOperand(0));
8970 TmpInst.addOperand(Inst.getOperand(1));
8971 TmpInst.addOperand(Inst.getOperand(2));
8972 TmpInst.addOperand(Inst.getOperand(3));
8973 Inst = TmpInst;
8974 return true;
8975 }
8976 }
8977 return false;
8978 }
8979 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
8980 case ARM::LDRT_POST:
8981 case ARM::LDRBT_POST: {
8982 const unsigned Opcode =
8983 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
8984 : ARM::LDRBT_POST_IMM;
8985 MCInst TmpInst;
8986 TmpInst.setOpcode(Opcode);
8987 TmpInst.addOperand(Inst.getOperand(0));
8988 TmpInst.addOperand(Inst.getOperand(1));
8989 TmpInst.addOperand(Inst.getOperand(1));
8990 TmpInst.addOperand(MCOperand::createReg(0));
8991 TmpInst.addOperand(MCOperand::createImm(0));
8992 TmpInst.addOperand(Inst.getOperand(2));
8993 TmpInst.addOperand(Inst.getOperand(3));
8994 Inst = TmpInst;
8995 return true;
8996 }
8997 // Alias for 'ldr{sb,h,sh}t Rt, [Rn] {, #imm}' for omitted immediate.
8998 case ARM::LDRSBTii:
8999 case ARM::LDRHTii:
9000 case ARM::LDRSHTii: {
9001 MCInst TmpInst;
9002
9003 if (Inst.getOpcode() == ARM::LDRSBTii)
9004 TmpInst.setOpcode(ARM::LDRSBTi);
9005 else if (Inst.getOpcode() == ARM::LDRHTii)
9006 TmpInst.setOpcode(ARM::LDRHTi);
9007 else if (Inst.getOpcode() == ARM::LDRSHTii)
9008 TmpInst.setOpcode(ARM::LDRSHTi);
9009 TmpInst.addOperand(Inst.getOperand(0));
9010 TmpInst.addOperand(Inst.getOperand(1));
9011 TmpInst.addOperand(Inst.getOperand(1));
9012 TmpInst.addOperand(MCOperand::createImm(256));
9013 TmpInst.addOperand(Inst.getOperand(2));
9014 Inst = TmpInst;
9015 return true;
9016 }
9017 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
9018 case ARM::STRT_POST:
9019 case ARM::STRBT_POST: {
9020 const unsigned Opcode =
9021 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
9022 : ARM::STRBT_POST_IMM;
9023 MCInst TmpInst;
9024 TmpInst.setOpcode(Opcode);
9025 TmpInst.addOperand(Inst.getOperand(1));
9026 TmpInst.addOperand(Inst.getOperand(0));
9027 TmpInst.addOperand(Inst.getOperand(1));
9028 TmpInst.addOperand(MCOperand::createReg(0));
9029 TmpInst.addOperand(MCOperand::createImm(0));
9030 TmpInst.addOperand(Inst.getOperand(2));
9031 TmpInst.addOperand(Inst.getOperand(3));
9032 Inst = TmpInst;
9033 return true;
9034 }
9035 // Alias for alternate form of 'ADR Rd, #imm' instruction.
9036 case ARM::ADDri: {
9037 if (Inst.getOperand(1).getReg() != ARM::PC || Inst.getOperand(5).getReg() ||
9038 !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm()))
9039 return false;
9040 MCInst TmpInst;
9041 TmpInst.setOpcode(ARM::ADR);
9042 TmpInst.addOperand(Inst.getOperand(0));
9043 if (Inst.getOperand(2).isImm()) {
9044 // Immediate (mod_imm) will be in its encoded form, we must unencode it
9045 // before passing it to the ADR instruction.
9046 unsigned Enc = Inst.getOperand(2).getImm();
9048 llvm::rotr<uint32_t>(Enc & 0xFF, (Enc & 0xF00) >> 7)));
9049 } else {
9050 // Turn PC-relative expression into absolute expression.
9051 // Reading PC provides the start of the current instruction + 8 and
9052 // the transform to adr is biased by that.
9053 MCSymbol *Dot = getContext().createTempSymbol();
9054 Out.emitLabel(Dot);
9055 const MCExpr *OpExpr = Inst.getOperand(2).getExpr();
9056 const MCExpr *InstPC = MCSymbolRefExpr::create(Dot,
9057 getContext());
9058 const MCExpr *Const8 = MCConstantExpr::create(8, getContext());
9059 const MCExpr *ReadPC = MCBinaryExpr::createAdd(InstPC, Const8,
9060 getContext());
9061 const MCExpr *FixupAddr = MCBinaryExpr::createAdd(ReadPC, OpExpr,
9062 getContext());
9063 TmpInst.addOperand(MCOperand::createExpr(FixupAddr));
9064 }
9065 TmpInst.addOperand(Inst.getOperand(3));
9066 TmpInst.addOperand(Inst.getOperand(4));
9067 Inst = TmpInst;
9068 return true;
9069 }
9070 // Aliases for imm syntax of LDR instructions.
9071 case ARM::t2LDR_PRE_imm:
9072 case ARM::t2LDR_POST_imm: {
9073 MCInst TmpInst;
9074 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2LDR_PRE_imm ? ARM::t2LDR_PRE
9075 : ARM::t2LDR_POST);
9076 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9077 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb
9078 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9079 TmpInst.addOperand(Inst.getOperand(2)); // imm
9080 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9081 TmpInst.addOperand(Inst.getOperand(4));
9082 Inst = TmpInst;
9083 return true;
9084 }
9085 // Aliases for imm syntax of STR instructions.
9086 case ARM::t2STR_PRE_imm:
9087 case ARM::t2STR_POST_imm: {
9088 MCInst TmpInst;
9089 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2STR_PRE_imm ? ARM::t2STR_PRE
9090 : ARM::t2STR_POST);
9091 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb
9092 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9093 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9094 TmpInst.addOperand(Inst.getOperand(2)); // imm
9095 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9096 TmpInst.addOperand(Inst.getOperand(4));
9097 Inst = TmpInst;
9098 return true;
9099 }
9100 // Aliases for imm syntax of LDRB instructions.
9101 case ARM::t2LDRB_OFFSET_imm: {
9102 MCInst TmpInst;
9103 TmpInst.setOpcode(ARM::t2LDRBi8);
9104 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9105 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9106 TmpInst.addOperand(Inst.getOperand(2)); // imm
9107 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9108 Inst = TmpInst;
9109 return true;
9110 }
9111 case ARM::t2LDRB_PRE_imm:
9112 case ARM::t2LDRB_POST_imm: {
9113 MCInst TmpInst;
9114 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2LDRB_PRE_imm
9115 ? ARM::t2LDRB_PRE
9116 : ARM::t2LDRB_POST);
9117 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9118 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb
9119 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9120 TmpInst.addOperand(Inst.getOperand(2)); // imm
9121 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9122 TmpInst.addOperand(Inst.getOperand(4));
9123 Inst = TmpInst;
9124 return true;
9125 }
9126 // Aliases for imm syntax of STRB instructions.
9127 case ARM::t2STRB_OFFSET_imm: {
9128 MCInst TmpInst;
9129 TmpInst.setOpcode(ARM::t2STRBi8);
9130 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9131 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9132 TmpInst.addOperand(Inst.getOperand(2)); // imm
9133 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9134 Inst = TmpInst;
9135 return true;
9136 }
9137 case ARM::t2STRB_PRE_imm:
9138 case ARM::t2STRB_POST_imm: {
9139 MCInst TmpInst;
9140 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2STRB_PRE_imm
9141 ? ARM::t2STRB_PRE
9142 : ARM::t2STRB_POST);
9143 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb
9144 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9145 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9146 TmpInst.addOperand(Inst.getOperand(2)); // imm
9147 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9148 TmpInst.addOperand(Inst.getOperand(4));
9149 Inst = TmpInst;
9150 return true;
9151 }
9152 // Aliases for imm syntax of LDRH instructions.
9153 case ARM::t2LDRH_OFFSET_imm: {
9154 MCInst TmpInst;
9155 TmpInst.setOpcode(ARM::t2LDRHi8);
9156 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9157 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9158 TmpInst.addOperand(Inst.getOperand(2)); // imm
9159 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9160 Inst = TmpInst;
9161 return true;
9162 }
9163 case ARM::t2LDRH_PRE_imm:
9164 case ARM::t2LDRH_POST_imm: {
9165 MCInst TmpInst;
9166 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2LDRH_PRE_imm
9167 ? ARM::t2LDRH_PRE
9168 : ARM::t2LDRH_POST);
9169 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9170 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb
9171 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9172 TmpInst.addOperand(Inst.getOperand(2)); // imm
9173 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9174 TmpInst.addOperand(Inst.getOperand(4));
9175 Inst = TmpInst;
9176 return true;
9177 }
9178 // Aliases for imm syntax of STRH instructions.
9179 case ARM::t2STRH_OFFSET_imm: {
9180 MCInst TmpInst;
9181 TmpInst.setOpcode(ARM::t2STRHi8);
9182 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9183 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9184 TmpInst.addOperand(Inst.getOperand(2)); // imm
9185 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9186 Inst = TmpInst;
9187 return true;
9188 }
9189 case ARM::t2STRH_PRE_imm:
9190 case ARM::t2STRH_POST_imm: {
9191 MCInst TmpInst;
9192 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2STRH_PRE_imm
9193 ? ARM::t2STRH_PRE
9194 : ARM::t2STRH_POST);
9195 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb
9196 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9197 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9198 TmpInst.addOperand(Inst.getOperand(2)); // imm
9199 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9200 TmpInst.addOperand(Inst.getOperand(4));
9201 Inst = TmpInst;
9202 return true;
9203 }
9204 // Aliases for imm syntax of LDRSB instructions.
9205 case ARM::t2LDRSB_OFFSET_imm: {
9206 MCInst TmpInst;
9207 TmpInst.setOpcode(ARM::t2LDRSBi8);
9208 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9209 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9210 TmpInst.addOperand(Inst.getOperand(2)); // imm
9211 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9212 Inst = TmpInst;
9213 return true;
9214 }
9215 case ARM::t2LDRSB_PRE_imm:
9216 case ARM::t2LDRSB_POST_imm: {
9217 MCInst TmpInst;
9218 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2LDRSB_PRE_imm
9219 ? ARM::t2LDRSB_PRE
9220 : ARM::t2LDRSB_POST);
9221 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9222 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb
9223 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9224 TmpInst.addOperand(Inst.getOperand(2)); // imm
9225 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9226 TmpInst.addOperand(Inst.getOperand(4));
9227 Inst = TmpInst;
9228 return true;
9229 }
9230 // Aliases for imm syntax of LDRSH instructions.
9231 case ARM::t2LDRSH_OFFSET_imm: {
9232 MCInst TmpInst;
9233 TmpInst.setOpcode(ARM::t2LDRSHi8);
9234 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9235 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9236 TmpInst.addOperand(Inst.getOperand(2)); // imm
9237 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9238 Inst = TmpInst;
9239 return true;
9240 }
9241 case ARM::t2LDRSH_PRE_imm:
9242 case ARM::t2LDRSH_POST_imm: {
9243 MCInst TmpInst;
9244 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2LDRSH_PRE_imm
9245 ? ARM::t2LDRSH_PRE
9246 : ARM::t2LDRSH_POST);
9247 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9248 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb
9249 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9250 TmpInst.addOperand(Inst.getOperand(2)); // imm
9251 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9252 TmpInst.addOperand(Inst.getOperand(4));
9253 Inst = TmpInst;
9254 return true;
9255 }
9256 // Aliases for alternate PC+imm syntax of LDR instructions.
9257 case ARM::t2LDRpcrel:
9258 // Select the narrow version if the immediate will fit.
9259 if (Inst.getOperand(1).getImm() > 0 &&
9260 Inst.getOperand(1).getImm() <= 0xff &&
9261 !HasWideQualifier)
9262 Inst.setOpcode(ARM::tLDRpci);
9263 else
9264 Inst.setOpcode(ARM::t2LDRpci);
9265 return true;
9266 case ARM::t2LDRBpcrel:
9267 Inst.setOpcode(ARM::t2LDRBpci);
9268 return true;
9269 case ARM::t2LDRHpcrel:
9270 Inst.setOpcode(ARM::t2LDRHpci);
9271 return true;
9272 case ARM::t2LDRSBpcrel:
9273 Inst.setOpcode(ARM::t2LDRSBpci);
9274 return true;
9275 case ARM::t2LDRSHpcrel:
9276 Inst.setOpcode(ARM::t2LDRSHpci);
9277 return true;
9278 case ARM::LDRConstPool:
9279 case ARM::tLDRConstPool:
9280 case ARM::t2LDRConstPool: {
9281 // Pseudo instruction ldr rt, =immediate is converted to a
9282 // MOV rt, immediate if immediate is known and representable
9283 // otherwise we create a constant pool entry that we load from.
9284 MCInst TmpInst;
9285 if (Inst.getOpcode() == ARM::LDRConstPool)
9286 TmpInst.setOpcode(ARM::LDRi12);
9287 else if (Inst.getOpcode() == ARM::tLDRConstPool)
9288 TmpInst.setOpcode(ARM::tLDRpci);
9289 else if (Inst.getOpcode() == ARM::t2LDRConstPool)
9290 TmpInst.setOpcode(ARM::t2LDRpci);
9291 const ARMOperand &PoolOperand =
9292 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1]);
9293 const MCExpr *SubExprVal = PoolOperand.getConstantPoolImm();
9294 // If SubExprVal is a constant we may be able to use a MOV
9295 if (isa<MCConstantExpr>(SubExprVal) &&
9296 Inst.getOperand(0).getReg() != ARM::PC &&
9297 Inst.getOperand(0).getReg() != ARM::SP) {
9298 int64_t Value = (cast<MCConstantExpr>(SubExprVal))->getValue();
9299 bool UseMov = true;
9300 bool MovHasS = true;
9301 if (Inst.getOpcode() == ARM::LDRConstPool) {
9302 // ARM Constant
9303 if (ARM_AM::getSOImmVal(Value) != -1) {
9305 TmpInst.setOpcode(ARM::MOVi);
9306 }
9307 else if (ARM_AM::getSOImmVal(~Value) != -1) {
9309 TmpInst.setOpcode(ARM::MVNi);
9310 }
9311 else if (hasV6T2Ops() &&
9312 Value >=0 && Value < 65536) {
9313 TmpInst.setOpcode(ARM::MOVi16);
9314 MovHasS = false;
9315 }
9316 else
9317 UseMov = false;
9318 }
9319 else {
9320 // Thumb/Thumb2 Constant
9321 if (hasThumb2() &&
9323 TmpInst.setOpcode(ARM::t2MOVi);
9324 else if (hasThumb2() &&
9325 ARM_AM::getT2SOImmVal(~Value) != -1) {
9326 TmpInst.setOpcode(ARM::t2MVNi);
9327 Value = ~Value;
9328 }
9329 else if (hasV8MBaseline() &&
9330 Value >=0 && Value < 65536) {
9331 TmpInst.setOpcode(ARM::t2MOVi16);
9332 MovHasS = false;
9333 }
9334 else
9335 UseMov = false;
9336 }
9337 if (UseMov) {
9338 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9339 TmpInst.addOperand(MCOperand::createImm(Value)); // Immediate
9340 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
9341 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9342 if (MovHasS)
9343 TmpInst.addOperand(MCOperand::createReg(0)); // S
9344 Inst = TmpInst;
9345 return true;
9346 }
9347 }
9348 // No opportunity to use MOV/MVN create constant pool
9349 const MCExpr *CPLoc =
9350 getTargetStreamer().addConstantPoolEntry(SubExprVal,
9351 PoolOperand.getStartLoc());
9352 TmpInst.addOperand(Inst.getOperand(0)); // Rt
9353 TmpInst.addOperand(MCOperand::createExpr(CPLoc)); // offset to constpool
9354 if (TmpInst.getOpcode() == ARM::LDRi12)
9355 TmpInst.addOperand(MCOperand::createImm(0)); // unused offset
9356 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
9357 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
9358 Inst = TmpInst;
9359 return true;
9360 }
9361 // Handle NEON VST complex aliases.
9362 case ARM::VST1LNdWB_register_Asm_8:
9363 case ARM::VST1LNdWB_register_Asm_16:
9364 case ARM::VST1LNdWB_register_Asm_32: {
9365 MCInst TmpInst;
9366 // Shuffle the operands around so the lane index operand is in the
9367 // right place.
9368 unsigned Spacing;
9369 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
9370 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9371 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9372 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9373 TmpInst.addOperand(Inst.getOperand(4)); // Rm
9374 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9375 TmpInst.addOperand(Inst.getOperand(1)); // lane
9376 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
9377 TmpInst.addOperand(Inst.getOperand(6));
9378 Inst = TmpInst;
9379 return true;
9380 }
9381
9382 case ARM::VST2LNdWB_register_Asm_8:
9383 case ARM::VST2LNdWB_register_Asm_16:
9384 case ARM::VST2LNdWB_register_Asm_32:
9385 case ARM::VST2LNqWB_register_Asm_16:
9386 case ARM::VST2LNqWB_register_Asm_32: {
9387 MCInst TmpInst;
9388 // Shuffle the operands around so the lane index operand is in the
9389 // right place.
9390 unsigned Spacing;
9391 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
9392 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9393 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9394 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9395 TmpInst.addOperand(Inst.getOperand(4)); // Rm
9396 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9398 Spacing));
9399 TmpInst.addOperand(Inst.getOperand(1)); // lane
9400 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
9401 TmpInst.addOperand(Inst.getOperand(6));
9402 Inst = TmpInst;
9403 return true;
9404 }
9405
9406 case ARM::VST3LNdWB_register_Asm_8:
9407 case ARM::VST3LNdWB_register_Asm_16:
9408 case ARM::VST3LNdWB_register_Asm_32:
9409 case ARM::VST3LNqWB_register_Asm_16:
9410 case ARM::VST3LNqWB_register_Asm_32: {
9411 MCInst TmpInst;
9412 // Shuffle the operands around so the lane index operand is in the
9413 // right place.
9414 unsigned Spacing;
9415 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
9416 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9417 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9418 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9419 TmpInst.addOperand(Inst.getOperand(4)); // Rm
9420 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9422 Spacing));
9424 Spacing * 2));
9425 TmpInst.addOperand(Inst.getOperand(1)); // lane
9426 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
9427 TmpInst.addOperand(Inst.getOperand(6));
9428 Inst = TmpInst;
9429 return true;
9430 }
9431
9432 case ARM::VST4LNdWB_register_Asm_8:
9433 case ARM::VST4LNdWB_register_Asm_16:
9434 case ARM::VST4LNdWB_register_Asm_32:
9435 case ARM::VST4LNqWB_register_Asm_16:
9436 case ARM::VST4LNqWB_register_Asm_32: {
9437 MCInst TmpInst;
9438 // Shuffle the operands around so the lane index operand is in the
9439 // right place.
9440 unsigned Spacing;
9441 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
9442 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9443 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9444 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9445 TmpInst.addOperand(Inst.getOperand(4)); // Rm
9446 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9448 Spacing));
9450 Spacing * 2));
9452 Spacing * 3));
9453 TmpInst.addOperand(Inst.getOperand(1)); // lane
9454 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
9455 TmpInst.addOperand(Inst.getOperand(6));
9456 Inst = TmpInst;
9457 return true;
9458 }
9459
9460 case ARM::VST1LNdWB_fixed_Asm_8:
9461 case ARM::VST1LNdWB_fixed_Asm_16:
9462 case ARM::VST1LNdWB_fixed_Asm_32: {
9463 MCInst TmpInst;
9464 // Shuffle the operands around so the lane index operand is in the
9465 // right place.
9466 unsigned Spacing;
9467 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
9468 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9469 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9470 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9471 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
9472 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9473 TmpInst.addOperand(Inst.getOperand(1)); // lane
9474 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9475 TmpInst.addOperand(Inst.getOperand(5));
9476 Inst = TmpInst;
9477 return true;
9478 }
9479
9480 case ARM::VST2LNdWB_fixed_Asm_8:
9481 case ARM::VST2LNdWB_fixed_Asm_16:
9482 case ARM::VST2LNdWB_fixed_Asm_32:
9483 case ARM::VST2LNqWB_fixed_Asm_16:
9484 case ARM::VST2LNqWB_fixed_Asm_32: {
9485 MCInst TmpInst;
9486 // Shuffle the operands around so the lane index operand is in the
9487 // right place.
9488 unsigned Spacing;
9489 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
9490 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9491 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9492 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9493 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
9494 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9496 Spacing));
9497 TmpInst.addOperand(Inst.getOperand(1)); // lane
9498 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9499 TmpInst.addOperand(Inst.getOperand(5));
9500 Inst = TmpInst;
9501 return true;
9502 }
9503
9504 case ARM::VST3LNdWB_fixed_Asm_8:
9505 case ARM::VST3LNdWB_fixed_Asm_16:
9506 case ARM::VST3LNdWB_fixed_Asm_32:
9507 case ARM::VST3LNqWB_fixed_Asm_16:
9508 case ARM::VST3LNqWB_fixed_Asm_32: {
9509 MCInst TmpInst;
9510 // Shuffle the operands around so the lane index operand is in the
9511 // right place.
9512 unsigned Spacing;
9513 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
9514 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9515 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9516 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9517 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
9518 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9520 Spacing));
9522 Spacing * 2));
9523 TmpInst.addOperand(Inst.getOperand(1)); // lane
9524 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9525 TmpInst.addOperand(Inst.getOperand(5));
9526 Inst = TmpInst;
9527 return true;
9528 }
9529
9530 case ARM::VST4LNdWB_fixed_Asm_8:
9531 case ARM::VST4LNdWB_fixed_Asm_16:
9532 case ARM::VST4LNdWB_fixed_Asm_32:
9533 case ARM::VST4LNqWB_fixed_Asm_16:
9534 case ARM::VST4LNqWB_fixed_Asm_32: {
9535 MCInst TmpInst;
9536 // Shuffle the operands around so the lane index operand is in the
9537 // right place.
9538 unsigned Spacing;
9539 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
9540 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9541 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9542 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9543 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
9544 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9546 Spacing));
9548 Spacing * 2));
9550 Spacing * 3));
9551 TmpInst.addOperand(Inst.getOperand(1)); // lane
9552 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9553 TmpInst.addOperand(Inst.getOperand(5));
9554 Inst = TmpInst;
9555 return true;
9556 }
9557
9558 case ARM::VST1LNdAsm_8:
9559 case ARM::VST1LNdAsm_16:
9560 case ARM::VST1LNdAsm_32: {
9561 MCInst TmpInst;
9562 // Shuffle the operands around so the lane index operand is in the
9563 // right place.
9564 unsigned Spacing;
9565 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
9566 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9567 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9568 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9569 TmpInst.addOperand(Inst.getOperand(1)); // lane
9570 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9571 TmpInst.addOperand(Inst.getOperand(5));
9572 Inst = TmpInst;
9573 return true;
9574 }
9575
9576 case ARM::VST2LNdAsm_8:
9577 case ARM::VST2LNdAsm_16:
9578 case ARM::VST2LNdAsm_32:
9579 case ARM::VST2LNqAsm_16:
9580 case ARM::VST2LNqAsm_32: {
9581 MCInst TmpInst;
9582 // Shuffle the operands around so the lane index operand is in the
9583 // right place.
9584 unsigned Spacing;
9585 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
9586 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9587 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9588 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9590 Spacing));
9591 TmpInst.addOperand(Inst.getOperand(1)); // lane
9592 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9593 TmpInst.addOperand(Inst.getOperand(5));
9594 Inst = TmpInst;
9595 return true;
9596 }
9597
9598 case ARM::VST3LNdAsm_8:
9599 case ARM::VST3LNdAsm_16:
9600 case ARM::VST3LNdAsm_32:
9601 case ARM::VST3LNqAsm_16:
9602 case ARM::VST3LNqAsm_32: {
9603 MCInst TmpInst;
9604 // Shuffle the operands around so the lane index operand is in the
9605 // right place.
9606 unsigned Spacing;
9607 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
9608 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9609 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9610 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9612 Spacing));
9614 Spacing * 2));
9615 TmpInst.addOperand(Inst.getOperand(1)); // lane
9616 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9617 TmpInst.addOperand(Inst.getOperand(5));
9618 Inst = TmpInst;
9619 return true;
9620 }
9621
9622 case ARM::VST4LNdAsm_8:
9623 case ARM::VST4LNdAsm_16:
9624 case ARM::VST4LNdAsm_32:
9625 case ARM::VST4LNqAsm_16:
9626 case ARM::VST4LNqAsm_32: {
9627 MCInst TmpInst;
9628 // Shuffle the operands around so the lane index operand is in the
9629 // right place.
9630 unsigned Spacing;
9631 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
9632 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9633 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9634 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9636 Spacing));
9638 Spacing * 2));
9640 Spacing * 3));
9641 TmpInst.addOperand(Inst.getOperand(1)); // lane
9642 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9643 TmpInst.addOperand(Inst.getOperand(5));
9644 Inst = TmpInst;
9645 return true;
9646 }
9647
9648 // Handle NEON VLD complex aliases.
9649 case ARM::VLD1LNdWB_register_Asm_8:
9650 case ARM::VLD1LNdWB_register_Asm_16:
9651 case ARM::VLD1LNdWB_register_Asm_32: {
9652 MCInst TmpInst;
9653 // Shuffle the operands around so the lane index operand is in the
9654 // right place.
9655 unsigned Spacing;
9656 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9657 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9658 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9659 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9660 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9661 TmpInst.addOperand(Inst.getOperand(4)); // Rm
9662 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
9663 TmpInst.addOperand(Inst.getOperand(1)); // lane
9664 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
9665 TmpInst.addOperand(Inst.getOperand(6));
9666 Inst = TmpInst;
9667 return true;
9668 }
9669
9670 case ARM::VLD2LNdWB_register_Asm_8:
9671 case ARM::VLD2LNdWB_register_Asm_16:
9672 case ARM::VLD2LNdWB_register_Asm_32:
9673 case ARM::VLD2LNqWB_register_Asm_16:
9674 case ARM::VLD2LNqWB_register_Asm_32: {
9675 MCInst TmpInst;
9676 // Shuffle the operands around so the lane index operand is in the
9677 // right place.
9678 unsigned Spacing;
9679 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9680 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9682 Spacing));
9683 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9684 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9685 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9686 TmpInst.addOperand(Inst.getOperand(4)); // Rm
9687 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
9689 Spacing));
9690 TmpInst.addOperand(Inst.getOperand(1)); // lane
9691 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
9692 TmpInst.addOperand(Inst.getOperand(6));
9693 Inst = TmpInst;
9694 return true;
9695 }
9696
9697 case ARM::VLD3LNdWB_register_Asm_8:
9698 case ARM::VLD3LNdWB_register_Asm_16:
9699 case ARM::VLD3LNdWB_register_Asm_32:
9700 case ARM::VLD3LNqWB_register_Asm_16:
9701 case ARM::VLD3LNqWB_register_Asm_32: {
9702 MCInst TmpInst;
9703 // Shuffle the operands around so the lane index operand is in the
9704 // right place.
9705 unsigned Spacing;
9706 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9707 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9709 Spacing));
9711 Spacing * 2));
9712 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9713 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9714 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9715 TmpInst.addOperand(Inst.getOperand(4)); // Rm
9716 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
9718 Spacing));
9720 Spacing * 2));
9721 TmpInst.addOperand(Inst.getOperand(1)); // lane
9722 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
9723 TmpInst.addOperand(Inst.getOperand(6));
9724 Inst = TmpInst;
9725 return true;
9726 }
9727
9728 case ARM::VLD4LNdWB_register_Asm_8:
9729 case ARM::VLD4LNdWB_register_Asm_16:
9730 case ARM::VLD4LNdWB_register_Asm_32:
9731 case ARM::VLD4LNqWB_register_Asm_16:
9732 case ARM::VLD4LNqWB_register_Asm_32: {
9733 MCInst TmpInst;
9734 // Shuffle the operands around so the lane index operand is in the
9735 // right place.
9736 unsigned Spacing;
9737 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9738 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9740 Spacing));
9742 Spacing * 2));
9744 Spacing * 3));
9745 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9746 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9747 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9748 TmpInst.addOperand(Inst.getOperand(4)); // Rm
9749 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
9751 Spacing));
9753 Spacing * 2));
9755 Spacing * 3));
9756 TmpInst.addOperand(Inst.getOperand(1)); // lane
9757 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
9758 TmpInst.addOperand(Inst.getOperand(6));
9759 Inst = TmpInst;
9760 return true;
9761 }
9762
9763 case ARM::VLD1LNdWB_fixed_Asm_8:
9764 case ARM::VLD1LNdWB_fixed_Asm_16:
9765 case ARM::VLD1LNdWB_fixed_Asm_32: {
9766 MCInst TmpInst;
9767 // Shuffle the operands around so the lane index operand is in the
9768 // right place.
9769 unsigned Spacing;
9770 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9771 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9772 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9773 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9774 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9775 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
9776 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
9777 TmpInst.addOperand(Inst.getOperand(1)); // lane
9778 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9779 TmpInst.addOperand(Inst.getOperand(5));
9780 Inst = TmpInst;
9781 return true;
9782 }
9783
9784 case ARM::VLD2LNdWB_fixed_Asm_8:
9785 case ARM::VLD2LNdWB_fixed_Asm_16:
9786 case ARM::VLD2LNdWB_fixed_Asm_32:
9787 case ARM::VLD2LNqWB_fixed_Asm_16:
9788 case ARM::VLD2LNqWB_fixed_Asm_32: {
9789 MCInst TmpInst;
9790 // Shuffle the operands around so the lane index operand is in the
9791 // right place.
9792 unsigned Spacing;
9793 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9794 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9796 Spacing));
9797 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9798 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9799 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9800 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
9801 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
9803 Spacing));
9804 TmpInst.addOperand(Inst.getOperand(1)); // lane
9805 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9806 TmpInst.addOperand(Inst.getOperand(5));
9807 Inst = TmpInst;
9808 return true;
9809 }
9810
9811 case ARM::VLD3LNdWB_fixed_Asm_8:
9812 case ARM::VLD3LNdWB_fixed_Asm_16:
9813 case ARM::VLD3LNdWB_fixed_Asm_32:
9814 case ARM::VLD3LNqWB_fixed_Asm_16:
9815 case ARM::VLD3LNqWB_fixed_Asm_32: {
9816 MCInst TmpInst;
9817 // Shuffle the operands around so the lane index operand is in the
9818 // right place.
9819 unsigned Spacing;
9820 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9821 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9823 Spacing));
9825 Spacing * 2));
9826 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9827 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9828 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9829 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
9830 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
9832 Spacing));
9834 Spacing * 2));
9835 TmpInst.addOperand(Inst.getOperand(1)); // lane
9836 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9837 TmpInst.addOperand(Inst.getOperand(5));
9838 Inst = TmpInst;
9839 return true;
9840 }
9841
9842 case ARM::VLD4LNdWB_fixed_Asm_8:
9843 case ARM::VLD4LNdWB_fixed_Asm_16:
9844 case ARM::VLD4LNdWB_fixed_Asm_32:
9845 case ARM::VLD4LNqWB_fixed_Asm_16:
9846 case ARM::VLD4LNqWB_fixed_Asm_32: {
9847 MCInst TmpInst;
9848 // Shuffle the operands around so the lane index operand is in the
9849 // right place.
9850 unsigned Spacing;
9851 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9852 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9854 Spacing));
9856 Spacing * 2));
9858 Spacing * 3));
9859 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
9860 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9861 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9862 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
9863 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
9865 Spacing));
9867 Spacing * 2));
9869 Spacing * 3));
9870 TmpInst.addOperand(Inst.getOperand(1)); // lane
9871 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9872 TmpInst.addOperand(Inst.getOperand(5));
9873 Inst = TmpInst;
9874 return true;
9875 }
9876
9877 case ARM::VLD1LNdAsm_8:
9878 case ARM::VLD1LNdAsm_16:
9879 case ARM::VLD1LNdAsm_32: {
9880 MCInst TmpInst;
9881 // Shuffle the operands around so the lane index operand is in the
9882 // right place.
9883 unsigned Spacing;
9884 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9885 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9886 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9887 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9888 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
9889 TmpInst.addOperand(Inst.getOperand(1)); // lane
9890 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9891 TmpInst.addOperand(Inst.getOperand(5));
9892 Inst = TmpInst;
9893 return true;
9894 }
9895
9896 case ARM::VLD2LNdAsm_8:
9897 case ARM::VLD2LNdAsm_16:
9898 case ARM::VLD2LNdAsm_32:
9899 case ARM::VLD2LNqAsm_16:
9900 case ARM::VLD2LNqAsm_32: {
9901 MCInst TmpInst;
9902 // Shuffle the operands around so the lane index operand is in the
9903 // right place.
9904 unsigned Spacing;
9905 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9906 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9908 Spacing));
9909 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9910 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9911 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
9913 Spacing));
9914 TmpInst.addOperand(Inst.getOperand(1)); // lane
9915 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9916 TmpInst.addOperand(Inst.getOperand(5));
9917 Inst = TmpInst;
9918 return true;
9919 }
9920
9921 case ARM::VLD3LNdAsm_8:
9922 case ARM::VLD3LNdAsm_16:
9923 case ARM::VLD3LNdAsm_32:
9924 case ARM::VLD3LNqAsm_16:
9925 case ARM::VLD3LNqAsm_32: {
9926 MCInst TmpInst;
9927 // Shuffle the operands around so the lane index operand is in the
9928 // right place.
9929 unsigned Spacing;
9930 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9931 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9933 Spacing));
9935 Spacing * 2));
9936 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9937 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9938 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
9940 Spacing));
9942 Spacing * 2));
9943 TmpInst.addOperand(Inst.getOperand(1)); // lane
9944 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9945 TmpInst.addOperand(Inst.getOperand(5));
9946 Inst = TmpInst;
9947 return true;
9948 }
9949
9950 case ARM::VLD4LNdAsm_8:
9951 case ARM::VLD4LNdAsm_16:
9952 case ARM::VLD4LNdAsm_32:
9953 case ARM::VLD4LNqAsm_16:
9954 case ARM::VLD4LNqAsm_32: {
9955 MCInst TmpInst;
9956 // Shuffle the operands around so the lane index operand is in the
9957 // right place.
9958 unsigned Spacing;
9959 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9960 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9962 Spacing));
9964 Spacing * 2));
9966 Spacing * 3));
9967 TmpInst.addOperand(Inst.getOperand(2)); // Rn
9968 TmpInst.addOperand(Inst.getOperand(3)); // alignment
9969 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
9971 Spacing));
9973 Spacing * 2));
9975 Spacing * 3));
9976 TmpInst.addOperand(Inst.getOperand(1)); // lane
9977 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
9978 TmpInst.addOperand(Inst.getOperand(5));
9979 Inst = TmpInst;
9980 return true;
9981 }
9982
9983 // VLD3DUP single 3-element structure to all lanes instructions.
9984 case ARM::VLD3DUPdAsm_8:
9985 case ARM::VLD3DUPdAsm_16:
9986 case ARM::VLD3DUPdAsm_32:
9987 case ARM::VLD3DUPqAsm_8:
9988 case ARM::VLD3DUPqAsm_16:
9989 case ARM::VLD3DUPqAsm_32: {
9990 MCInst TmpInst;
9991 unsigned Spacing;
9992 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
9993 TmpInst.addOperand(Inst.getOperand(0)); // Vd
9995 Spacing));
9997 Spacing * 2));
9998 TmpInst.addOperand(Inst.getOperand(1)); // Rn
9999 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10000 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10001 TmpInst.addOperand(Inst.getOperand(4));
10002 Inst = TmpInst;
10003 return true;
10004 }
10005
10006 case ARM::VLD3DUPdWB_fixed_Asm_8:
10007 case ARM::VLD3DUPdWB_fixed_Asm_16:
10008 case ARM::VLD3DUPdWB_fixed_Asm_32:
10009 case ARM::VLD3DUPqWB_fixed_Asm_8:
10010 case ARM::VLD3DUPqWB_fixed_Asm_16:
10011 case ARM::VLD3DUPqWB_fixed_Asm_32: {
10012 MCInst TmpInst;
10013 unsigned Spacing;
10014 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
10015 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10017 Spacing));
10019 Spacing * 2));
10020 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10021 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
10022 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10023 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
10024 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10025 TmpInst.addOperand(Inst.getOperand(4));
10026 Inst = TmpInst;
10027 return true;
10028 }
10029
10030 case ARM::VLD3DUPdWB_register_Asm_8:
10031 case ARM::VLD3DUPdWB_register_Asm_16:
10032 case ARM::VLD3DUPdWB_register_Asm_32:
10033 case ARM::VLD3DUPqWB_register_Asm_8:
10034 case ARM::VLD3DUPqWB_register_Asm_16:
10035 case ARM::VLD3DUPqWB_register_Asm_32: {
10036 MCInst TmpInst;
10037 unsigned Spacing;
10038 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
10039 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10041 Spacing));
10043 Spacing * 2));
10044 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10045 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
10046 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10047 TmpInst.addOperand(Inst.getOperand(3)); // Rm
10048 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
10049 TmpInst.addOperand(Inst.getOperand(5));
10050 Inst = TmpInst;
10051 return true;
10052 }
10053
10054 // VLD3 multiple 3-element structure instructions.
10055 case ARM::VLD3dAsm_8:
10056 case ARM::VLD3dAsm_16:
10057 case ARM::VLD3dAsm_32:
10058 case ARM::VLD3qAsm_8:
10059 case ARM::VLD3qAsm_16:
10060 case ARM::VLD3qAsm_32: {
10061 MCInst TmpInst;
10062 unsigned Spacing;
10063 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
10064 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10066 Spacing));
10068 Spacing * 2));
10069 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10070 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10071 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10072 TmpInst.addOperand(Inst.getOperand(4));
10073 Inst = TmpInst;
10074 return true;
10075 }
10076
10077 case ARM::VLD3dWB_fixed_Asm_8:
10078 case ARM::VLD3dWB_fixed_Asm_16:
10079 case ARM::VLD3dWB_fixed_Asm_32:
10080 case ARM::VLD3qWB_fixed_Asm_8:
10081 case ARM::VLD3qWB_fixed_Asm_16:
10082 case ARM::VLD3qWB_fixed_Asm_32: {
10083 MCInst TmpInst;
10084 unsigned Spacing;
10085 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
10086 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10088 Spacing));
10090 Spacing * 2));
10091 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10092 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
10093 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10094 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
10095 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10096 TmpInst.addOperand(Inst.getOperand(4));
10097 Inst = TmpInst;
10098 return true;
10099 }
10100
10101 case ARM::VLD3dWB_register_Asm_8:
10102 case ARM::VLD3dWB_register_Asm_16:
10103 case ARM::VLD3dWB_register_Asm_32:
10104 case ARM::VLD3qWB_register_Asm_8:
10105 case ARM::VLD3qWB_register_Asm_16:
10106 case ARM::VLD3qWB_register_Asm_32: {
10107 MCInst TmpInst;
10108 unsigned Spacing;
10109 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
10110 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10112 Spacing));
10114 Spacing * 2));
10115 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10116 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
10117 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10118 TmpInst.addOperand(Inst.getOperand(3)); // Rm
10119 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
10120 TmpInst.addOperand(Inst.getOperand(5));
10121 Inst = TmpInst;
10122 return true;
10123 }
10124
10125 // VLD4DUP single 3-element structure to all lanes instructions.
10126 case ARM::VLD4DUPdAsm_8:
10127 case ARM::VLD4DUPdAsm_16:
10128 case ARM::VLD4DUPdAsm_32:
10129 case ARM::VLD4DUPqAsm_8:
10130 case ARM::VLD4DUPqAsm_16:
10131 case ARM::VLD4DUPqAsm_32: {
10132 MCInst TmpInst;
10133 unsigned Spacing;
10134 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
10135 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10137 Spacing));
10139 Spacing * 2));
10141 Spacing * 3));
10142 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10143 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10144 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10145 TmpInst.addOperand(Inst.getOperand(4));
10146 Inst = TmpInst;
10147 return true;
10148 }
10149
10150 case ARM::VLD4DUPdWB_fixed_Asm_8:
10151 case ARM::VLD4DUPdWB_fixed_Asm_16:
10152 case ARM::VLD4DUPdWB_fixed_Asm_32:
10153 case ARM::VLD4DUPqWB_fixed_Asm_8:
10154 case ARM::VLD4DUPqWB_fixed_Asm_16:
10155 case ARM::VLD4DUPqWB_fixed_Asm_32: {
10156 MCInst TmpInst;
10157 unsigned Spacing;
10158 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
10159 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10161 Spacing));
10163 Spacing * 2));
10165 Spacing * 3));
10166 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10167 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
10168 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10169 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
10170 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10171 TmpInst.addOperand(Inst.getOperand(4));
10172 Inst = TmpInst;
10173 return true;
10174 }
10175
10176 case ARM::VLD4DUPdWB_register_Asm_8:
10177 case ARM::VLD4DUPdWB_register_Asm_16:
10178 case ARM::VLD4DUPdWB_register_Asm_32:
10179 case ARM::VLD4DUPqWB_register_Asm_8:
10180 case ARM::VLD4DUPqWB_register_Asm_16:
10181 case ARM::VLD4DUPqWB_register_Asm_32: {
10182 MCInst TmpInst;
10183 unsigned Spacing;
10184 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
10185 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10187 Spacing));
10189 Spacing * 2));
10191 Spacing * 3));
10192 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10193 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
10194 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10195 TmpInst.addOperand(Inst.getOperand(3)); // Rm
10196 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
10197 TmpInst.addOperand(Inst.getOperand(5));
10198 Inst = TmpInst;
10199 return true;
10200 }
10201
10202 // VLD4 multiple 4-element structure instructions.
10203 case ARM::VLD4dAsm_8:
10204 case ARM::VLD4dAsm_16:
10205 case ARM::VLD4dAsm_32:
10206 case ARM::VLD4qAsm_8:
10207 case ARM::VLD4qAsm_16:
10208 case ARM::VLD4qAsm_32: {
10209 MCInst TmpInst;
10210 unsigned Spacing;
10211 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
10212 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10214 Spacing));
10216 Spacing * 2));
10218 Spacing * 3));
10219 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10220 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10221 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10222 TmpInst.addOperand(Inst.getOperand(4));
10223 Inst = TmpInst;
10224 return true;
10225 }
10226
10227 case ARM::VLD4dWB_fixed_Asm_8:
10228 case ARM::VLD4dWB_fixed_Asm_16:
10229 case ARM::VLD4dWB_fixed_Asm_32:
10230 case ARM::VLD4qWB_fixed_Asm_8:
10231 case ARM::VLD4qWB_fixed_Asm_16:
10232 case ARM::VLD4qWB_fixed_Asm_32: {
10233 MCInst TmpInst;
10234 unsigned Spacing;
10235 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
10236 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10238 Spacing));
10240 Spacing * 2));
10242 Spacing * 3));
10243 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10244 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
10245 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10246 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
10247 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10248 TmpInst.addOperand(Inst.getOperand(4));
10249 Inst = TmpInst;
10250 return true;
10251 }
10252
10253 case ARM::VLD4dWB_register_Asm_8:
10254 case ARM::VLD4dWB_register_Asm_16:
10255 case ARM::VLD4dWB_register_Asm_32:
10256 case ARM::VLD4qWB_register_Asm_8:
10257 case ARM::VLD4qWB_register_Asm_16:
10258 case ARM::VLD4qWB_register_Asm_32: {
10259 MCInst TmpInst;
10260 unsigned Spacing;
10261 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
10262 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10264 Spacing));
10266 Spacing * 2));
10268 Spacing * 3));
10269 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10270 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
10271 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10272 TmpInst.addOperand(Inst.getOperand(3)); // Rm
10273 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
10274 TmpInst.addOperand(Inst.getOperand(5));
10275 Inst = TmpInst;
10276 return true;
10277 }
10278
10279 // VST3 multiple 3-element structure instructions.
10280 case ARM::VST3dAsm_8:
10281 case ARM::VST3dAsm_16:
10282 case ARM::VST3dAsm_32:
10283 case ARM::VST3qAsm_8:
10284 case ARM::VST3qAsm_16:
10285 case ARM::VST3qAsm_32: {
10286 MCInst TmpInst;
10287 unsigned Spacing;
10288 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
10289 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10290 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10291 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10293 Spacing));
10295 Spacing * 2));
10296 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10297 TmpInst.addOperand(Inst.getOperand(4));
10298 Inst = TmpInst;
10299 return true;
10300 }
10301
10302 case ARM::VST3dWB_fixed_Asm_8:
10303 case ARM::VST3dWB_fixed_Asm_16:
10304 case ARM::VST3dWB_fixed_Asm_32:
10305 case ARM::VST3qWB_fixed_Asm_8:
10306 case ARM::VST3qWB_fixed_Asm_16:
10307 case ARM::VST3qWB_fixed_Asm_32: {
10308 MCInst TmpInst;
10309 unsigned Spacing;
10310 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
10311 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10312 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
10313 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10314 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
10315 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10317 Spacing));
10319 Spacing * 2));
10320 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10321 TmpInst.addOperand(Inst.getOperand(4));
10322 Inst = TmpInst;
10323 return true;
10324 }
10325
10326 case ARM::VST3dWB_register_Asm_8:
10327 case ARM::VST3dWB_register_Asm_16:
10328 case ARM::VST3dWB_register_Asm_32:
10329 case ARM::VST3qWB_register_Asm_8:
10330 case ARM::VST3qWB_register_Asm_16:
10331 case ARM::VST3qWB_register_Asm_32: {
10332 MCInst TmpInst;
10333 unsigned Spacing;
10334 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
10335 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10336 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
10337 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10338 TmpInst.addOperand(Inst.getOperand(3)); // Rm
10339 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10341 Spacing));
10343 Spacing * 2));
10344 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
10345 TmpInst.addOperand(Inst.getOperand(5));
10346 Inst = TmpInst;
10347 return true;
10348 }
10349
10350 // VST4 multiple 3-element structure instructions.
10351 case ARM::VST4dAsm_8:
10352 case ARM::VST4dAsm_16:
10353 case ARM::VST4dAsm_32:
10354 case ARM::VST4qAsm_8:
10355 case ARM::VST4qAsm_16:
10356 case ARM::VST4qAsm_32: {
10357 MCInst TmpInst;
10358 unsigned Spacing;
10359 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
10360 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10361 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10362 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10364 Spacing));
10366 Spacing * 2));
10368 Spacing * 3));
10369 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10370 TmpInst.addOperand(Inst.getOperand(4));
10371 Inst = TmpInst;
10372 return true;
10373 }
10374
10375 case ARM::VST4dWB_fixed_Asm_8:
10376 case ARM::VST4dWB_fixed_Asm_16:
10377 case ARM::VST4dWB_fixed_Asm_32:
10378 case ARM::VST4qWB_fixed_Asm_8:
10379 case ARM::VST4qWB_fixed_Asm_16:
10380 case ARM::VST4qWB_fixed_Asm_32: {
10381 MCInst TmpInst;
10382 unsigned Spacing;
10383 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
10384 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10385 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
10386 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10387 TmpInst.addOperand(MCOperand::createReg(0)); // Rm
10388 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10390 Spacing));
10392 Spacing * 2));
10394 Spacing * 3));
10395 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10396 TmpInst.addOperand(Inst.getOperand(4));
10397 Inst = TmpInst;
10398 return true;
10399 }
10400
10401 case ARM::VST4dWB_register_Asm_8:
10402 case ARM::VST4dWB_register_Asm_16:
10403 case ARM::VST4dWB_register_Asm_32:
10404 case ARM::VST4qWB_register_Asm_8:
10405 case ARM::VST4qWB_register_Asm_16:
10406 case ARM::VST4qWB_register_Asm_32: {
10407 MCInst TmpInst;
10408 unsigned Spacing;
10409 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
10410 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10411 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
10412 TmpInst.addOperand(Inst.getOperand(2)); // alignment
10413 TmpInst.addOperand(Inst.getOperand(3)); // Rm
10414 TmpInst.addOperand(Inst.getOperand(0)); // Vd
10416 Spacing));
10418 Spacing * 2));
10420 Spacing * 3));
10421 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
10422 TmpInst.addOperand(Inst.getOperand(5));
10423 Inst = TmpInst;
10424 return true;
10425 }
10426
10427 // Handle encoding choice for the shift-immediate instructions.
10428 case ARM::t2LSLri:
10429 case ARM::t2LSRri:
10430 case ARM::t2ASRri:
10431 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
10432 isARMLowRegister(Inst.getOperand(1).getReg()) &&
10433 Inst.getOperand(5).getReg() ==
10434 (inITBlock() ? ARM::NoRegister : ARM::CPSR) &&
10435 !HasWideQualifier) {
10436 unsigned NewOpc;
10437 switch (Inst.getOpcode()) {
10438 default: llvm_unreachable("unexpected opcode");
10439 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
10440 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
10441 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
10442 }
10443 // The Thumb1 operands aren't in the same order. Awesome, eh?
10444 MCInst TmpInst;
10445 TmpInst.setOpcode(NewOpc);
10446 TmpInst.addOperand(Inst.getOperand(0));
10447 TmpInst.addOperand(Inst.getOperand(5));
10448 TmpInst.addOperand(Inst.getOperand(1));
10449 TmpInst.addOperand(Inst.getOperand(2));
10450 TmpInst.addOperand(Inst.getOperand(3));
10451 TmpInst.addOperand(Inst.getOperand(4));
10452 Inst = TmpInst;
10453 return true;
10454 }
10455 return false;
10456
10457 // Handle the Thumb2 mode MOV complex aliases.
10458 case ARM::t2MOVsr:
10459 case ARM::t2MOVSsr: {
10460 // Which instruction to expand to depends on the CCOut operand and
10461 // whether we're in an IT block if the register operands are low
10462 // registers.
10463 bool isNarrow = false;
10464 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
10465 isARMLowRegister(Inst.getOperand(1).getReg()) &&
10466 isARMLowRegister(Inst.getOperand(2).getReg()) &&
10467 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
10468 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr) &&
10469 !HasWideQualifier)
10470 isNarrow = true;
10471 MCInst TmpInst;
10472 unsigned newOpc;
10473 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
10474 default: llvm_unreachable("unexpected opcode!");
10475 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
10476 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
10477 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
10478 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
10479 }
10480 TmpInst.setOpcode(newOpc);
10481 TmpInst.addOperand(Inst.getOperand(0)); // Rd
10482 if (isNarrow)
10484 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : ARM::NoRegister));
10485 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10486 TmpInst.addOperand(Inst.getOperand(2)); // Rm
10487 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
10488 TmpInst.addOperand(Inst.getOperand(5));
10489 if (!isNarrow)
10491 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : ARM::NoRegister));
10492 Inst = TmpInst;
10493 return true;
10494 }
10495 case ARM::t2MOVsi:
10496 case ARM::t2MOVSsi: {
10497 // Which instruction to expand to depends on the CCOut operand and
10498 // whether we're in an IT block if the register operands are low
10499 // registers.
10500 bool isNarrow = false;
10501 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
10502 isARMLowRegister(Inst.getOperand(1).getReg()) &&
10503 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi) &&
10504 !HasWideQualifier)
10505 isNarrow = true;
10506 MCInst TmpInst;
10507 unsigned newOpc;
10508 unsigned Shift = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
10509 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
10510 bool isMov = false;
10511 // MOV rd, rm, LSL #0 is actually a MOV instruction
10512 if (Shift == ARM_AM::lsl && Amount == 0) {
10513 isMov = true;
10514 // The 16-bit encoding of MOV rd, rm, LSL #N is explicitly encoding T2 of
10515 // MOV (register) in the ARMv8-A and ARMv8-M manuals, and immediate 0 is
10516 // unpredictable in an IT block so the 32-bit encoding T3 has to be used
10517 // instead.
10518 if (inITBlock()) {
10519 isNarrow = false;
10520 }
10521 newOpc = isNarrow ? ARM::tMOVSr : ARM::t2MOVr;
10522 } else {
10523 switch(Shift) {
10524 default: llvm_unreachable("unexpected opcode!");
10525 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
10526 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
10527 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
10528 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
10529 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
10530 }
10531 }
10532 if (Amount == 32) Amount = 0;
10533 TmpInst.setOpcode(newOpc);
10534 TmpInst.addOperand(Inst.getOperand(0)); // Rd
10535 if (isNarrow && !isMov)
10537 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : ARM::NoRegister));
10538 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10539 if (newOpc != ARM::t2RRX && !isMov)
10540 TmpInst.addOperand(MCOperand::createImm(Amount));
10541 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10542 TmpInst.addOperand(Inst.getOperand(4));
10543 if (!isNarrow)
10545 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : ARM::NoRegister));
10546 Inst = TmpInst;
10547 return true;
10548 }
10549 // Handle the ARM mode MOV complex aliases.
10550 case ARM::ASRr:
10551 case ARM::LSRr:
10552 case ARM::LSLr:
10553 case ARM::RORr: {
10554 ARM_AM::ShiftOpc ShiftTy;
10555 switch(Inst.getOpcode()) {
10556 default: llvm_unreachable("unexpected opcode!");
10557 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
10558 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
10559 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
10560 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
10561 }
10562 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
10563 MCInst TmpInst;
10564 TmpInst.setOpcode(ARM::MOVsr);
10565 TmpInst.addOperand(Inst.getOperand(0)); // Rd
10566 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10567 TmpInst.addOperand(Inst.getOperand(2)); // Rm
10568 TmpInst.addOperand(MCOperand::createImm(Shifter)); // Shift value and ty
10569 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10570 TmpInst.addOperand(Inst.getOperand(4));
10571 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
10572 Inst = TmpInst;
10573 return true;
10574 }
10575 case ARM::ASRi:
10576 case ARM::LSRi:
10577 case ARM::LSLi:
10578 case ARM::RORi: {
10579 ARM_AM::ShiftOpc ShiftTy;
10580 switch(Inst.getOpcode()) {
10581 default: llvm_unreachable("unexpected opcode!");
10582 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
10583 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
10584 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
10585 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
10586 }
10587 // A shift by zero is a plain MOVr, not a MOVsi.
10588 unsigned Amt = Inst.getOperand(2).getImm();
10589 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
10590 // A shift by 32 should be encoded as 0 when permitted
10591 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
10592 Amt = 0;
10593 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
10594 MCInst TmpInst;
10595 TmpInst.setOpcode(Opc);
10596 TmpInst.addOperand(Inst.getOperand(0)); // Rd
10597 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10598 if (Opc == ARM::MOVsi)
10599 TmpInst.addOperand(MCOperand::createImm(Shifter)); // Shift value and ty
10600 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
10601 TmpInst.addOperand(Inst.getOperand(4));
10602 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
10603 Inst = TmpInst;
10604 return true;
10605 }
10606 case ARM::RRXi: {
10607 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
10608 MCInst TmpInst;
10609 TmpInst.setOpcode(ARM::MOVsi);
10610 TmpInst.addOperand(Inst.getOperand(0)); // Rd
10611 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10612 TmpInst.addOperand(MCOperand::createImm(Shifter)); // Shift value and ty
10613 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
10614 TmpInst.addOperand(Inst.getOperand(3));
10615 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
10616 Inst = TmpInst;
10617 return true;
10618 }
10619 case ARM::t2LDMIA_UPD: {
10620 // If this is a load of a single register, then we should use
10621 // a post-indexed LDR instruction instead, per the ARM ARM.
10622 if (Inst.getNumOperands() != 5)
10623 return false;
10624 MCInst TmpInst;
10625 TmpInst.setOpcode(ARM::t2LDR_POST);
10626 TmpInst.addOperand(Inst.getOperand(4)); // Rt
10627 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
10628 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10629 TmpInst.addOperand(MCOperand::createImm(4));
10630 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
10631 TmpInst.addOperand(Inst.getOperand(3));
10632 Inst = TmpInst;
10633 return true;
10634 }
10635 case ARM::t2STMDB_UPD: {
10636 // If this is a store of a single register, then we should use
10637 // a pre-indexed STR instruction instead, per the ARM ARM.
10638 if (Inst.getNumOperands() != 5)
10639 return false;
10640 MCInst TmpInst;
10641 TmpInst.setOpcode(ARM::t2STR_PRE);
10642 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
10643 TmpInst.addOperand(Inst.getOperand(4)); // Rt
10644 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10645 TmpInst.addOperand(MCOperand::createImm(-4));
10646 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
10647 TmpInst.addOperand(Inst.getOperand(3));
10648 Inst = TmpInst;
10649 return true;
10650 }
10651 case ARM::LDMIA_UPD:
10652 // If this is a load of a single register via a 'pop', then we should use
10653 // a post-indexed LDR instruction instead, per the ARM ARM.
10654 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
10655 Inst.getNumOperands() == 5) {
10656 MCInst TmpInst;
10657 TmpInst.setOpcode(ARM::LDR_POST_IMM);
10658 TmpInst.addOperand(Inst.getOperand(4)); // Rt
10659 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
10660 TmpInst.addOperand(Inst.getOperand(1)); // Rn
10661 TmpInst.addOperand(MCOperand::createReg(0)); // am2offset
10662 TmpInst.addOperand(MCOperand::createImm(4));
10663 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
10664 TmpInst.addOperand(Inst.getOperand(3));
10665 Inst = TmpInst;
10666 return true;
10667 }
10668 break;
10669 case ARM::STMDB_UPD:
10670 // If this is a store of a single register via a 'push', then we should use
10671 // a pre-indexed STR instruction instead, per the ARM ARM.
10672 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
10673 Inst.getNumOperands() == 5) {
10674 MCInst TmpInst;
10675 TmpInst.setOpcode(ARM::STR_PRE_IMM);
10676 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
10677 TmpInst.addOperand(Inst.getOperand(4)); // Rt
10678 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
10679 TmpInst.addOperand(MCOperand::createImm(-4));
10680 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
10681 TmpInst.addOperand(Inst.getOperand(3));
10682 Inst = TmpInst;
10683 }
10684 break;
10685 case ARM::t2ADDri12:
10686 case ARM::t2SUBri12:
10687 case ARM::t2ADDspImm12:
10688 case ARM::t2SUBspImm12: {
10689 // If the immediate fits for encoding T3 and the generic
10690 // mnemonic was used, encoding T3 is preferred.
10691 const StringRef Token = static_cast<ARMOperand &>(*Operands[0]).getToken();
10692 if ((Token != "add" && Token != "sub") ||
10693 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
10694 break;
10695 switch (Inst.getOpcode()) {
10696 case ARM::t2ADDri12:
10697 Inst.setOpcode(ARM::t2ADDri);
10698 break;
10699 case ARM::t2SUBri12:
10700 Inst.setOpcode(ARM::t2SUBri);
10701 break;
10702 case ARM::t2ADDspImm12:
10703 Inst.setOpcode(ARM::t2ADDspImm);
10704 break;
10705 case ARM::t2SUBspImm12:
10706 Inst.setOpcode(ARM::t2SUBspImm);
10707 break;
10708 }
10709
10710 Inst.addOperand(MCOperand::createReg(0)); // cc_out
10711 return true;
10712 }
10713 case ARM::tADDi8:
10714 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
10715 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
10716 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
10717 // to encoding T1 if <Rd> is omitted."
10718 if (Inst.getOperand(3).isImm() &&
10719 (unsigned)Inst.getOperand(3).getImm() < 8 &&
10720 Operands.size() == MnemonicOpsEndInd + 3) {
10721 Inst.setOpcode(ARM::tADDi3);
10722 return true;
10723 }
10724 break;
10725 case ARM::tSUBi8:
10726 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
10727 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
10728 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
10729 // to encoding T1 if <Rd> is omitted."
10730 if ((unsigned)Inst.getOperand(3).getImm() < 8 &&
10731 Operands.size() == MnemonicOpsEndInd + 3) {
10732 Inst.setOpcode(ARM::tSUBi3);
10733 return true;
10734 }
10735 break;
10736 case ARM::t2ADDri:
10737 case ARM::t2SUBri: {
10738 // If the destination and first source operand are the same, and
10739 // the flags are compatible with the current IT status, use encoding T2
10740 // instead of T3. For compatibility with the system 'as'. Make sure the
10741 // wide encoding wasn't explicit.
10742 if (HasWideQualifier)
10743 break; // source code has asked for the 32-bit instruction
10744 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg())
10745 break; // tADDi8 can't take different input and output registers
10746 if (!isARMLowRegister(Inst.getOperand(0).getReg()))
10747 break; // high register that tADDi8 can't access
10748 if (Inst.getOperand(5).getReg() !=
10749 (inITBlock() ? ARM::NoRegister : ARM::CPSR))
10750 break; // flag-modification would require overriding the IT state
10751 if (Inst.getOperand(2).isImm()) {
10752 if ((unsigned)Inst.getOperand(2).getImm() > 255)
10753 break; // large immediate that tADDi8 can't contain
10754 } else {
10755 int i = (Operands[MnemonicOpsEndInd + 1]->isImm())
10756 ? MnemonicOpsEndInd + 1
10757 : MnemonicOpsEndInd + 2;
10758 MCParsedAsmOperand &Op = *Operands[i];
10760 break; // a type of non-immediate that tADDi8 can't represent
10761 }
10762 MCInst TmpInst;
10763 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
10764 ARM::tADDi8 : ARM::tSUBi8);
10765 TmpInst.addOperand(Inst.getOperand(0));
10766 TmpInst.addOperand(Inst.getOperand(5));
10767 TmpInst.addOperand(Inst.getOperand(0));
10768 TmpInst.addOperand(Inst.getOperand(2));
10769 TmpInst.addOperand(Inst.getOperand(3));
10770 TmpInst.addOperand(Inst.getOperand(4));
10771 Inst = TmpInst;
10772 return true;
10773 }
10774 case ARM::t2ADDspImm:
10775 case ARM::t2SUBspImm: {
10776 // Prefer T1 encoding if possible
10777 if (Inst.getOperand(5).getReg() || HasWideQualifier)
10778 break;
10779 unsigned V = Inst.getOperand(2).getImm();
10780 if (V & 3 || V > ((1 << 7) - 1) << 2)
10781 break;
10782 MCInst TmpInst;
10783 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDspImm ? ARM::tADDspi
10784 : ARM::tSUBspi);
10785 TmpInst.addOperand(MCOperand::createReg(ARM::SP)); // destination reg
10786 TmpInst.addOperand(MCOperand::createReg(ARM::SP)); // source reg
10787 TmpInst.addOperand(MCOperand::createImm(V / 4)); // immediate
10788 TmpInst.addOperand(Inst.getOperand(3)); // pred
10789 TmpInst.addOperand(Inst.getOperand(4));
10790 Inst = TmpInst;
10791 return true;
10792 }
10793 case ARM::t2ADDrr: {
10794 // If the destination and first source operand are the same, and
10795 // there's no setting of the flags, use encoding T2 instead of T3.
10796 // Note that this is only for ADD, not SUB. This mirrors the system
10797 // 'as' behaviour. Also take advantage of ADD being commutative.
10798 // Make sure the wide encoding wasn't explicit.
10799 bool Swap = false;
10800 auto DestReg = Inst.getOperand(0).getReg();
10801 bool Transform = DestReg == Inst.getOperand(1).getReg();
10802 if (!Transform && DestReg == Inst.getOperand(2).getReg()) {
10803 Transform = true;
10804 Swap = true;
10805 }
10806 if (!Transform || Inst.getOperand(5).getReg() || HasWideQualifier)
10807 break;
10808 MCInst TmpInst;
10809 TmpInst.setOpcode(ARM::tADDhirr);
10810 TmpInst.addOperand(Inst.getOperand(0));
10811 TmpInst.addOperand(Inst.getOperand(0));
10812 TmpInst.addOperand(Inst.getOperand(Swap ? 1 : 2));
10813 TmpInst.addOperand(Inst.getOperand(3));
10814 TmpInst.addOperand(Inst.getOperand(4));
10815 Inst = TmpInst;
10816 return true;
10817 }
10818 case ARM::tADDrSP:
10819 // If the non-SP source operand and the destination operand are not the
10820 // same, we need to use the 32-bit encoding if it's available.
10821 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
10822 Inst.setOpcode(ARM::t2ADDrr);
10823 Inst.addOperand(MCOperand::createReg(0)); // cc_out
10824 return true;
10825 }
10826 break;
10827 case ARM::tB:
10828 // A Thumb conditional branch outside of an IT block is a tBcc.
10829 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
10830 Inst.setOpcode(ARM::tBcc);
10831 return true;
10832 }
10833 break;
10834 case ARM::t2B:
10835 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
10836 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
10837 Inst.setOpcode(ARM::t2Bcc);
10838 return true;
10839 }
10840 break;
10841 case ARM::t2Bcc:
10842 // If the conditional is AL or we're in an IT block, we really want t2B.
10843 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
10844 Inst.setOpcode(ARM::t2B);
10845 return true;
10846 }
10847 break;
10848 case ARM::tBcc:
10849 // If the conditional is AL, we really want tB.
10850 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
10851 Inst.setOpcode(ARM::tB);
10852 return true;
10853 }
10854 break;
10855 case ARM::tLDMIA: {
10856 // If the register list contains any high registers, or if the writeback
10857 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
10858 // instead if we're in Thumb2. Otherwise, this should have generated
10859 // an error in validateInstruction().
10860 MCRegister Rn = Inst.getOperand(0).getReg();
10861 bool hasWritebackToken =
10862 (static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1])
10863 .isToken() &&
10864 static_cast<ARMOperand &>(*Operands[MnemonicOpsEndInd + 1])
10865 .getToken() == "!");
10866 bool listContainsBase;
10867 if (checkLowRegisterList(Inst, 3, Rn, MCRegister(), listContainsBase) ||
10868 (!listContainsBase && !hasWritebackToken) ||
10869 (listContainsBase && hasWritebackToken)) {
10870 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
10871 assert(isThumbTwo());
10872 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
10873 // If we're switching to the updating version, we need to insert
10874 // the writeback tied operand.
10875 if (hasWritebackToken)
10876 Inst.insert(Inst.begin(),
10878 return true;
10879 }
10880 break;
10881 }
10882 case ARM::tSTMIA_UPD: {
10883 // If the register list contains any high registers, we need to use
10884 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
10885 // should have generated an error in validateInstruction().
10886 MCRegister Rn = Inst.getOperand(0).getReg();
10887 bool listContainsBase;
10888 if (checkLowRegisterList(Inst, 4, Rn, MCRegister(), listContainsBase)) {
10889 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
10890 assert(isThumbTwo());
10891 Inst.setOpcode(ARM::t2STMIA_UPD);
10892 return true;
10893 }
10894 break;
10895 }
10896 case ARM::tPOP: {
10897 bool listContainsBase;
10898 // If the register list contains any high registers, we need to use
10899 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
10900 // should have generated an error in validateInstruction().
10901 if (!checkLowRegisterList(Inst, 2, MCRegister(), ARM::PC, listContainsBase))
10902 return false;
10903 assert(isThumbTwo());
10904 Inst.setOpcode(ARM::t2LDMIA_UPD);
10905 // Add the base register and writeback operands.
10906 Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP));
10907 Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP));
10908 return true;
10909 }
10910 case ARM::tPUSH: {
10911 bool listContainsBase;
10912 if (!checkLowRegisterList(Inst, 2, MCRegister(), ARM::LR, listContainsBase))
10913 return false;
10914 assert(isThumbTwo());
10915 Inst.setOpcode(ARM::t2STMDB_UPD);
10916 // Add the base register and writeback operands.
10917 Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP));
10918 Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP));
10919 return true;
10920 }
10921 case ARM::t2MOVi:
10922 // If we can use the 16-bit encoding and the user didn't explicitly
10923 // request the 32-bit variant, transform it here.
10924 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
10925 (Inst.getOperand(1).isImm() &&
10926 (unsigned)Inst.getOperand(1).getImm() <= 255) &&
10927 Inst.getOperand(4).getReg() ==
10928 (inITBlock() ? ARM::NoRegister : ARM::CPSR) &&
10929 !HasWideQualifier) {
10930 // The operands aren't in the same order for tMOVi8...
10931 MCInst TmpInst;
10932 TmpInst.setOpcode(ARM::tMOVi8);
10933 TmpInst.addOperand(Inst.getOperand(0));
10934 TmpInst.addOperand(Inst.getOperand(4));
10935 TmpInst.addOperand(Inst.getOperand(1));
10936 TmpInst.addOperand(Inst.getOperand(2));
10937 TmpInst.addOperand(Inst.getOperand(3));
10938 Inst = TmpInst;
10939 return true;
10940 }
10941 break;
10942
10943 case ARM::t2MOVr:
10944 // If we can use the 16-bit encoding and the user didn't explicitly
10945 // request the 32-bit variant, transform it here.
10946 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
10947 isARMLowRegister(Inst.getOperand(1).getReg()) &&
10948 Inst.getOperand(2).getImm() == ARMCC::AL &&
10949 Inst.getOperand(4).getReg() == ARM::CPSR &&
10950 !HasWideQualifier) {
10951 // The operands aren't the same for tMOV[S]r... (no cc_out)
10952 MCInst TmpInst;
10953 unsigned Op = Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr;
10954 TmpInst.setOpcode(Op);
10955 TmpInst.addOperand(Inst.getOperand(0));
10956 TmpInst.addOperand(Inst.getOperand(1));
10957 if (Op == ARM::tMOVr) {
10958 TmpInst.addOperand(Inst.getOperand(2));
10959 TmpInst.addOperand(Inst.getOperand(3));
10960 }
10961 Inst = TmpInst;
10962 return true;
10963 }
10964 break;
10965
10966 case ARM::t2SXTH:
10967 case ARM::t2SXTB:
10968 case ARM::t2UXTH:
10969 case ARM::t2UXTB:
10970 // If we can use the 16-bit encoding and the user didn't explicitly
10971 // request the 32-bit variant, transform it here.
10972 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
10973 isARMLowRegister(Inst.getOperand(1).getReg()) &&
10974 Inst.getOperand(2).getImm() == 0 &&
10975 !HasWideQualifier) {
10976 unsigned NewOpc;
10977 switch (Inst.getOpcode()) {
10978 default: llvm_unreachable("Illegal opcode!");
10979 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
10980 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
10981 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
10982 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
10983 }
10984 // The operands aren't the same for thumb1 (no rotate operand).
10985 MCInst TmpInst;
10986 TmpInst.setOpcode(NewOpc);
10987 TmpInst.addOperand(Inst.getOperand(0));
10988 TmpInst.addOperand(Inst.getOperand(1));
10989 TmpInst.addOperand(Inst.getOperand(3));
10990 TmpInst.addOperand(Inst.getOperand(4));
10991 Inst = TmpInst;
10992 return true;
10993 }
10994 break;
10995
10996 case ARM::MOVsi: {
10998 // rrx shifts and asr/lsr of #32 is encoded as 0
10999 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
11000 return false;
11001 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
11002 // Shifting by zero is accepted as a vanilla 'MOVr'
11003 MCInst TmpInst;
11004 TmpInst.setOpcode(ARM::MOVr);
11005 TmpInst.addOperand(Inst.getOperand(0));
11006 TmpInst.addOperand(Inst.getOperand(1));
11007 TmpInst.addOperand(Inst.getOperand(3));
11008 TmpInst.addOperand(Inst.getOperand(4));
11009 TmpInst.addOperand(Inst.getOperand(5));
11010 Inst = TmpInst;
11011 return true;
11012 }
11013 return false;
11014 }
11015 case ARM::ANDrsi:
11016 case ARM::ORRrsi:
11017 case ARM::EORrsi:
11018 case ARM::BICrsi:
11019 case ARM::SUBrsi:
11020 case ARM::ADDrsi: {
11021 unsigned newOpc;
11023 if (SOpc == ARM_AM::rrx) return false;
11024 switch (Inst.getOpcode()) {
11025 default: llvm_unreachable("unexpected opcode!");
11026 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
11027 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
11028 case ARM::EORrsi: newOpc = ARM::EORrr; break;
11029 case ARM::BICrsi: newOpc = ARM::BICrr; break;
11030 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
11031 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
11032 }
11033 // If the shift is by zero, use the non-shifted instruction definition.
11034 // The exception is for right shifts, where 0 == 32
11035 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
11036 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
11037 MCInst TmpInst;
11038 TmpInst.setOpcode(newOpc);
11039 TmpInst.addOperand(Inst.getOperand(0));
11040 TmpInst.addOperand(Inst.getOperand(1));
11041 TmpInst.addOperand(Inst.getOperand(2));
11042 TmpInst.addOperand(Inst.getOperand(4));
11043 TmpInst.addOperand(Inst.getOperand(5));
11044 TmpInst.addOperand(Inst.getOperand(6));
11045 Inst = TmpInst;
11046 return true;
11047 }
11048 return false;
11049 }
11050 case ARM::ITasm:
11051 case ARM::t2IT: {
11052 // Set up the IT block state according to the IT instruction we just
11053 // matched.
11054 assert(!inITBlock() && "nested IT blocks?!");
11055 startExplicitITBlock(ARMCC::CondCodes(Inst.getOperand(0).getImm()),
11056 Inst.getOperand(1).getImm());
11057 break;
11058 }
11059 case ARM::t2LSLrr:
11060 case ARM::t2LSRrr:
11061 case ARM::t2ASRrr:
11062 case ARM::t2SBCrr:
11063 case ARM::t2RORrr:
11064 case ARM::t2BICrr:
11065 // Assemblers should use the narrow encodings of these instructions when permissible.
11066 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
11067 isARMLowRegister(Inst.getOperand(2).getReg())) &&
11068 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
11069 Inst.getOperand(5).getReg() ==
11070 (inITBlock() ? ARM::NoRegister : ARM::CPSR) &&
11071 !HasWideQualifier) {
11072 unsigned NewOpc;
11073 switch (Inst.getOpcode()) {
11074 default: llvm_unreachable("unexpected opcode");
11075 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
11076 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
11077 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
11078 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
11079 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
11080 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
11081 }
11082 MCInst TmpInst;
11083 TmpInst.setOpcode(NewOpc);
11084 TmpInst.addOperand(Inst.getOperand(0));
11085 TmpInst.addOperand(Inst.getOperand(5));
11086 TmpInst.addOperand(Inst.getOperand(1));
11087 TmpInst.addOperand(Inst.getOperand(2));
11088 TmpInst.addOperand(Inst.getOperand(3));
11089 TmpInst.addOperand(Inst.getOperand(4));
11090 Inst = TmpInst;
11091 return true;
11092 }
11093 return false;
11094
11095 case ARM::t2ANDrr:
11096 case ARM::t2EORrr:
11097 case ARM::t2ADCrr:
11098 case ARM::t2ORRrr:
11099 // Assemblers should use the narrow encodings of these instructions when permissible.
11100 // These instructions are special in that they are commutable, so shorter encodings
11101 // are available more often.
11102 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
11103 isARMLowRegister(Inst.getOperand(2).getReg())) &&
11104 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
11105 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
11106 Inst.getOperand(5).getReg() ==
11107 (inITBlock() ? ARM::NoRegister : ARM::CPSR) &&
11108 !HasWideQualifier) {
11109 unsigned NewOpc;
11110 switch (Inst.getOpcode()) {
11111 default: llvm_unreachable("unexpected opcode");
11112 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
11113 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
11114 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
11115 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
11116 }
11117 MCInst TmpInst;
11118 TmpInst.setOpcode(NewOpc);
11119 TmpInst.addOperand(Inst.getOperand(0));
11120 TmpInst.addOperand(Inst.getOperand(5));
11121 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
11122 TmpInst.addOperand(Inst.getOperand(1));
11123 TmpInst.addOperand(Inst.getOperand(2));
11124 } else {
11125 TmpInst.addOperand(Inst.getOperand(2));
11126 TmpInst.addOperand(Inst.getOperand(1));
11127 }
11128 TmpInst.addOperand(Inst.getOperand(3));
11129 TmpInst.addOperand(Inst.getOperand(4));
11130 Inst = TmpInst;
11131 return true;
11132 }
11133 return false;
11134 case ARM::MVE_VPST:
11135 case ARM::MVE_VPTv16i8:
11136 case ARM::MVE_VPTv8i16:
11137 case ARM::MVE_VPTv4i32:
11138 case ARM::MVE_VPTv16u8:
11139 case ARM::MVE_VPTv8u16:
11140 case ARM::MVE_VPTv4u32:
11141 case ARM::MVE_VPTv16s8:
11142 case ARM::MVE_VPTv8s16:
11143 case ARM::MVE_VPTv4s32:
11144 case ARM::MVE_VPTv4f32:
11145 case ARM::MVE_VPTv8f16:
11146 case ARM::MVE_VPTv16i8r:
11147 case ARM::MVE_VPTv8i16r:
11148 case ARM::MVE_VPTv4i32r:
11149 case ARM::MVE_VPTv16u8r:
11150 case ARM::MVE_VPTv8u16r:
11151 case ARM::MVE_VPTv4u32r:
11152 case ARM::MVE_VPTv16s8r:
11153 case ARM::MVE_VPTv8s16r:
11154 case ARM::MVE_VPTv4s32r:
11155 case ARM::MVE_VPTv4f32r:
11156 case ARM::MVE_VPTv8f16r: {
11157 assert(!inVPTBlock() && "Nested VPT blocks are not allowed");
11158 MCOperand &MO = Inst.getOperand(0);
11159 VPTState.Mask = MO.getImm();
11160 VPTState.CurPosition = 0;
11161 break;
11162 }
11163 }
11164 return false;
11165}
11166
11167unsigned
11168ARMAsmParser::checkEarlyTargetMatchPredicate(MCInst &Inst,
11169 const OperandVector &Operands) {
11170 unsigned Opc = Inst.getOpcode();
11171 switch (Opc) {
11172 // Prevent the mov r8 r8 encoding for nop being selected when the v6/thumb 2
11173 // encoding is available.
11174 case ARM::tMOVr: {
11175 if (Operands[0]->isToken() &&
11176 static_cast<ARMOperand &>(*Operands[0]).getToken() == "nop" &&
11177 ((isThumb() && !isThumbOne()) || hasV6MOps())) {
11178 return Match_MnemonicFail;
11179 }
11180 }
11181 [[fallthrough]];
11182 default:
11183 return Match_Success;
11184 }
11185}
11186
11187unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
11188 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
11189 // suffix depending on whether they're in an IT block or not.
11190 unsigned Opc = Inst.getOpcode();
11191 const MCInstrDesc &MCID = MII.get(Opc);
11193 assert(MCID.hasOptionalDef() &&
11194 "optionally flag setting instruction missing optional def operand");
11195 assert(MCID.NumOperands == Inst.getNumOperands() &&
11196 "operand count mismatch!");
11197 bool IsCPSR = false;
11198 // Check if the instruction has CPSR set.
11199 for (unsigned OpNo = 0; OpNo < MCID.NumOperands; ++OpNo) {
11200 if (MCID.operands()[OpNo].isOptionalDef() &&
11201 Inst.getOperand(OpNo).isReg() &&
11202 Inst.getOperand(OpNo).getReg() == ARM::CPSR)
11203 IsCPSR = true;
11204 }
11205
11206 // If we're parsing Thumb1, reject it completely.
11207 if (isThumbOne() && !IsCPSR)
11208 return Match_RequiresFlagSetting;
11209 // If we're parsing Thumb2, which form is legal depends on whether we're
11210 // in an IT block.
11211 if (isThumbTwo() && !IsCPSR && !inITBlock())
11212 return Match_RequiresITBlock;
11213 if (isThumbTwo() && IsCPSR && inITBlock())
11214 return Match_RequiresNotITBlock;
11215 // LSL with zero immediate is not allowed in an IT block
11216 if (Opc == ARM::tLSLri && Inst.getOperand(3).getImm() == 0 && inITBlock())
11217 return Match_RequiresNotITBlock;
11218 } else if (isThumbOne()) {
11219 // Some high-register supporting Thumb1 encodings only allow both registers
11220 // to be from r0-r7 when in Thumb2.
11221 if (Opc == ARM::tADDhirr && !hasV6MOps() &&
11222 isARMLowRegister(Inst.getOperand(1).getReg()) &&
11224 return Match_RequiresThumb2;
11225 // Others only require ARMv6 or later.
11226 else if (Opc == ARM::tMOVr && !hasV6Ops() &&
11227 isARMLowRegister(Inst.getOperand(0).getReg()) &&
11229 return Match_RequiresV6;
11230 }
11231
11232 // Before ARMv8 the rules for when SP is allowed in t2MOVr are more complex
11233 // than the loop below can handle, so it uses the GPRnopc register class and
11234 // we do SP handling here.
11235 if (Opc == ARM::t2MOVr && !hasV8Ops())
11236 {
11237 // SP as both source and destination is not allowed
11238 if (Inst.getOperand(0).getReg() == ARM::SP &&
11239 Inst.getOperand(1).getReg() == ARM::SP)
11240 return Match_RequiresV8;
11241 // When flags-setting SP as either source or destination is not allowed
11242 if (Inst.getOperand(4).getReg() == ARM::CPSR &&
11243 (Inst.getOperand(0).getReg() == ARM::SP ||
11244 Inst.getOperand(1).getReg() == ARM::SP))
11245 return Match_RequiresV8;
11246 }
11247
11248 switch (Inst.getOpcode()) {
11249 case ARM::VMRS:
11250 case ARM::VMSR:
11251 case ARM::VMRS_FPCXTS:
11252 case ARM::VMRS_FPCXTNS:
11253 case ARM::VMSR_FPCXTS:
11254 case ARM::VMSR_FPCXTNS:
11255 case ARM::VMRS_FPSCR_NZCVQC:
11256 case ARM::VMSR_FPSCR_NZCVQC:
11257 case ARM::FMSTAT:
11258 case ARM::VMRS_VPR:
11259 case ARM::VMRS_P0:
11260 case ARM::VMSR_VPR:
11261 case ARM::VMSR_P0:
11262 // Use of SP for VMRS/VMSR is only allowed in ARM mode with the exception of
11263 // ARMv8-A.
11264 if (Inst.getOperand(0).isReg() && Inst.getOperand(0).getReg() == ARM::SP &&
11265 (isThumb() && !hasV8Ops()))
11266 return Match_InvalidOperand;
11267 break;
11268 case ARM::t2TBB:
11269 case ARM::t2TBH:
11270 // Rn = sp is only allowed with ARMv8-A
11271 if (!hasV8Ops() && (Inst.getOperand(0).getReg() == ARM::SP))
11272 return Match_RequiresV8;
11273 break;
11274 case ARM::tMUL:
11275 // The second source operand must be the same register as the destination
11276 // operand.
11277 // FIXME: Ideally this would be handled by ARMGenAsmMatcher and
11278 // emitAsmTiedOperandConstraints.
11279 if (Inst.getOperand(0).getReg() != Inst.getOperand(3).getReg())
11280 return Match_InvalidTiedOperand;
11281 break;
11282 default:
11283 break;
11284 }
11285
11286 for (unsigned I = 0; I < MCID.NumOperands; ++I)
11287 if (MCID.operands()[I].RegClass == ARM::rGPRRegClassID) {
11288 // rGPRRegClass excludes PC, and also excluded SP before ARMv8
11289 const auto &Op = Inst.getOperand(I);
11290 if (!Op.isReg()) {
11291 // This can happen in awkward cases with tied operands, e.g. a
11292 // writeback load/store with a complex addressing mode in
11293 // which there's an output operand corresponding to the
11294 // updated written-back base register: the Tablegen-generated
11295 // AsmMatcher will have written a placeholder operand to that
11296 // slot in the form of an immediate 0, because it can't
11297 // generate the register part of the complex addressing-mode
11298 // operand ahead of time.
11299 continue;
11300 }
11301
11302 MCRegister Reg = Op.getReg();
11303 if ((Reg == ARM::SP) && !hasV8Ops())
11304 return Match_RequiresV8;
11305 else if (Reg == ARM::PC)
11306 return Match_InvalidOperand;
11307 }
11308
11309 return Match_Success;
11310}
11311
11312namespace llvm {
11313
11314template <> inline bool IsCPSRDead<MCInst>(const MCInst *Instr) {
11315 return true; // In an assembly source, no need to second-guess
11316}
11317
11318} // end namespace llvm
11319
11320// Returns true if Inst is unpredictable if it is in and IT block, but is not
11321// the last instruction in the block.
11322bool ARMAsmParser::isITBlockTerminator(MCInst &Inst) const {
11323 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
11324
11325 // All branch & call instructions terminate IT blocks with the exception of
11326 // SVC.
11327 if (MCID.isTerminator() || (MCID.isCall() && Inst.getOpcode() != ARM::tSVC) ||
11328 MCID.isReturn() || MCID.isBranch() || MCID.isIndirectBranch())
11329 return true;
11330
11331 // Any arithmetic instruction which writes to the PC also terminates the IT
11332 // block.
11333 if (MCID.hasDefOfPhysReg(Inst, ARM::PC, *MRI))
11334 return true;
11335
11336 return false;
11337}
11338
11339unsigned ARMAsmParser::MatchInstruction(OperandVector &Operands, MCInst &Inst,
11340 SmallVectorImpl<NearMissInfo> &NearMisses,
11341 bool MatchingInlineAsm,
11342 bool &EmitInITBlock,
11343 MCStreamer &Out) {
11344 // If we can't use an implicit IT block here, just match as normal.
11345 if (inExplicitITBlock() || !isThumbTwo() || !useImplicitITThumb())
11346 return MatchInstructionImpl(Operands, Inst, &NearMisses, MatchingInlineAsm);
11347
11348 // Try to match the instruction in an extension of the current IT block (if
11349 // there is one).
11350 if (inImplicitITBlock()) {
11351 extendImplicitITBlock(ITState.Cond);
11352 if (MatchInstructionImpl(Operands, Inst, nullptr, MatchingInlineAsm) ==
11353 Match_Success) {
11354 // The match succeeded, but we still have to check that the instruction is
11355 // valid in this implicit IT block.
11356 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
11357 if (MCID.isPredicable()) {
11358 ARMCC::CondCodes InstCond =
11360 .getImm();
11361 ARMCC::CondCodes ITCond = currentITCond();
11362 if (InstCond == ITCond) {
11363 EmitInITBlock = true;
11364 return Match_Success;
11365 } else if (InstCond == ARMCC::getOppositeCondition(ITCond)) {
11366 invertCurrentITCondition();
11367 EmitInITBlock = true;
11368 return Match_Success;
11369 }
11370 }
11371 }
11372 rewindImplicitITPosition();
11373 }
11374
11375 // Finish the current IT block, and try to match outside any IT block.
11376 flushPendingInstructions(Out);
11377 unsigned PlainMatchResult =
11378 MatchInstructionImpl(Operands, Inst, &NearMisses, MatchingInlineAsm);
11379 if (PlainMatchResult == Match_Success) {
11380 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
11381 if (MCID.isPredicable()) {
11382 ARMCC::CondCodes InstCond =
11384 .getImm();
11385 // Some forms of the branch instruction have their own condition code
11386 // fields, so can be conditionally executed without an IT block.
11387 if (Inst.getOpcode() == ARM::tBcc || Inst.getOpcode() == ARM::t2Bcc) {
11388 EmitInITBlock = false;
11389 return Match_Success;
11390 }
11391 if (InstCond == ARMCC::AL) {
11392 EmitInITBlock = false;
11393 return Match_Success;
11394 }
11395 } else {
11396 EmitInITBlock = false;
11397 return Match_Success;
11398 }
11399 }
11400
11401 // Try to match in a new IT block. The matcher doesn't check the actual
11402 // condition, so we create an IT block with a dummy condition, and fix it up
11403 // once we know the actual condition.
11404 startImplicitITBlock();
11405 if (MatchInstructionImpl(Operands, Inst, nullptr, MatchingInlineAsm) ==
11406 Match_Success) {
11407 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
11408 if (MCID.isPredicable()) {
11409 ITState.Cond =
11411 .getImm();
11412 EmitInITBlock = true;
11413 return Match_Success;
11414 }
11415 }
11416 discardImplicitITBlock();
11417
11418 // If none of these succeed, return the error we got when trying to match
11419 // outside any IT blocks.
11420 EmitInITBlock = false;
11421 return PlainMatchResult;
11422}
11423
11424static std::string ARMMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS,
11425 unsigned VariantID = 0);
11426
11427static const char *getSubtargetFeatureName(uint64_t Val);
11428bool ARMAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
11431 bool MatchingInlineAsm) {
11432 MCInst Inst;
11433 unsigned MatchResult;
11434 bool PendConditionalInstruction = false;
11435
11437 MatchResult = MatchInstruction(Operands, Inst, NearMisses, MatchingInlineAsm,
11438 PendConditionalInstruction, Out);
11439
11440 // Find the number of operators that are part of the Mnumonic (LHS).
11441 unsigned MnemonicOpsEndInd = getMnemonicOpsEndInd(Operands);
11442
11443 switch (MatchResult) {
11444 case Match_Success:
11445 LLVM_DEBUG(dbgs() << "Parsed as: ";
11446 Inst.dump_pretty(dbgs(), MII.getName(Inst.getOpcode()));
11447 dbgs() << "\n");
11448
11449 // Context sensitive operand constraints aren't handled by the matcher,
11450 // so check them here.
11451 if (validateInstruction(Inst, Operands, MnemonicOpsEndInd)) {
11452 // Still progress the IT block, otherwise one wrong condition causes
11453 // nasty cascading errors.
11454 forwardITPosition();
11455 forwardVPTPosition();
11456 return true;
11457 }
11458
11459 {
11460 // Some instructions need post-processing to, for example, tweak which
11461 // encoding is selected. Loop on it while changes happen so the
11462 // individual transformations can chain off each other. E.g.,
11463 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
11464 while (processInstruction(Inst, Operands, MnemonicOpsEndInd, Out))
11465 LLVM_DEBUG(dbgs() << "Changed to: ";
11466 Inst.dump_pretty(dbgs(), MII.getName(Inst.getOpcode()));
11467 dbgs() << "\n");
11468 }
11469
11470 // Only move forward at the very end so that everything in validate
11471 // and process gets a consistent answer about whether we're in an IT
11472 // block.
11473 forwardITPosition();
11474 forwardVPTPosition();
11475
11476 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
11477 // doesn't actually encode.
11478 if (Inst.getOpcode() == ARM::ITasm)
11479 return false;
11480
11481 Inst.setLoc(IDLoc);
11482 if (PendConditionalInstruction) {
11483 PendingConditionalInsts.push_back(Inst);
11484 if (isITBlockFull() || isITBlockTerminator(Inst))
11485 flushPendingInstructions(Out);
11486 } else {
11487 Out.emitInstruction(Inst, getSTI());
11488 }
11489 return false;
11490 case Match_NearMisses:
11491 ReportNearMisses(NearMisses, IDLoc, Operands);
11492 return true;
11493 case Match_MnemonicFail: {
11494 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
11495 std::string Suggestion = ARMMnemonicSpellCheck(
11496 ((ARMOperand &)*Operands[0]).getToken(), FBS);
11497 return Error(IDLoc, "invalid instruction" + Suggestion,
11498 ((ARMOperand &)*Operands[0]).getLocRange());
11499 }
11500 }
11501
11502 llvm_unreachable("Implement any new match types added!");
11503}
11504
11505/// ParseDirective parses the arm specific directives
11506bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
11507 const MCContext::Environment Format = getContext().getObjectFileType();
11508 bool IsMachO = Format == MCContext::IsMachO;
11509 bool IsCOFF = Format == MCContext::IsCOFF;
11510
11511 std::string IDVal = DirectiveID.getIdentifier().lower();
11512 if (IDVal == ".word")
11513 parseLiteralValues(4, DirectiveID.getLoc());
11514 else if (IDVal == ".short" || IDVal == ".hword")
11515 parseLiteralValues(2, DirectiveID.getLoc());
11516 else if (IDVal == ".thumb")
11517 parseDirectiveThumb(DirectiveID.getLoc());
11518 else if (IDVal == ".arm")
11519 parseDirectiveARM(DirectiveID.getLoc());
11520 else if (IDVal == ".thumb_func")
11521 parseDirectiveThumbFunc(DirectiveID.getLoc());
11522 else if (IDVal == ".code")
11523 parseDirectiveCode(DirectiveID.getLoc());
11524 else if (IDVal == ".syntax")
11525 parseDirectiveSyntax(DirectiveID.getLoc());
11526 else if (IDVal == ".unreq")
11527 parseDirectiveUnreq(DirectiveID.getLoc());
11528 else if (IDVal == ".fnend")
11529 parseDirectiveFnEnd(DirectiveID.getLoc());
11530 else if (IDVal == ".cantunwind")
11531 parseDirectiveCantUnwind(DirectiveID.getLoc());
11532 else if (IDVal == ".personality")
11533 parseDirectivePersonality(DirectiveID.getLoc());
11534 else if (IDVal == ".handlerdata")
11535 parseDirectiveHandlerData(DirectiveID.getLoc());
11536 else if (IDVal == ".setfp")
11537 parseDirectiveSetFP(DirectiveID.getLoc());
11538 else if (IDVal == ".pad")
11539 parseDirectivePad(DirectiveID.getLoc());
11540 else if (IDVal == ".save")
11541 parseDirectiveRegSave(DirectiveID.getLoc(), false);
11542 else if (IDVal == ".vsave")
11543 parseDirectiveRegSave(DirectiveID.getLoc(), true);
11544 else if (IDVal == ".ltorg" || IDVal == ".pool")
11545 parseDirectiveLtorg(DirectiveID.getLoc());
11546 else if (IDVal == ".even")
11547 parseDirectiveEven(DirectiveID.getLoc());
11548 else if (IDVal == ".personalityindex")
11549 parseDirectivePersonalityIndex(DirectiveID.getLoc());
11550 else if (IDVal == ".unwind_raw")
11551 parseDirectiveUnwindRaw(DirectiveID.getLoc());
11552 else if (IDVal == ".movsp")
11553 parseDirectiveMovSP(DirectiveID.getLoc());
11554 else if (IDVal == ".arch_extension")
11555 parseDirectiveArchExtension(DirectiveID.getLoc());
11556 else if (IDVal == ".align")
11557 return parseDirectiveAlign(DirectiveID.getLoc()); // Use Generic on failure.
11558 else if (IDVal == ".thumb_set")
11559 parseDirectiveThumbSet(DirectiveID.getLoc());
11560 else if (IDVal == ".inst")
11561 parseDirectiveInst(DirectiveID.getLoc());
11562 else if (IDVal == ".inst.n")
11563 parseDirectiveInst(DirectiveID.getLoc(), 'n');
11564 else if (IDVal == ".inst.w")
11565 parseDirectiveInst(DirectiveID.getLoc(), 'w');
11566 else if (!IsMachO && !IsCOFF) {
11567 if (IDVal == ".arch")
11568 parseDirectiveArch(DirectiveID.getLoc());
11569 else if (IDVal == ".cpu")
11570 parseDirectiveCPU(DirectiveID.getLoc());
11571 else if (IDVal == ".eabi_attribute")
11572 parseDirectiveEabiAttr(DirectiveID.getLoc());
11573 else if (IDVal == ".fpu")
11574 parseDirectiveFPU(DirectiveID.getLoc());
11575 else if (IDVal == ".fnstart")
11576 parseDirectiveFnStart(DirectiveID.getLoc());
11577 else if (IDVal == ".object_arch")
11578 parseDirectiveObjectArch(DirectiveID.getLoc());
11579 else if (IDVal == ".tlsdescseq")
11580 parseDirectiveTLSDescSeq(DirectiveID.getLoc());
11581 else
11582 return true;
11583 } else if (IsCOFF) {
11584 if (IDVal == ".seh_stackalloc")
11585 parseDirectiveSEHAllocStack(DirectiveID.getLoc(), /*Wide=*/false);
11586 else if (IDVal == ".seh_stackalloc_w")
11587 parseDirectiveSEHAllocStack(DirectiveID.getLoc(), /*Wide=*/true);
11588 else if (IDVal == ".seh_save_regs")
11589 parseDirectiveSEHSaveRegs(DirectiveID.getLoc(), /*Wide=*/false);
11590 else if (IDVal == ".seh_save_regs_w")
11591 parseDirectiveSEHSaveRegs(DirectiveID.getLoc(), /*Wide=*/true);
11592 else if (IDVal == ".seh_save_sp")
11593 parseDirectiveSEHSaveSP(DirectiveID.getLoc());
11594 else if (IDVal == ".seh_save_fregs")
11595 parseDirectiveSEHSaveFRegs(DirectiveID.getLoc());
11596 else if (IDVal == ".seh_save_lr")
11597 parseDirectiveSEHSaveLR(DirectiveID.getLoc());
11598 else if (IDVal == ".seh_endprologue")
11599 parseDirectiveSEHPrologEnd(DirectiveID.getLoc(), /*Fragment=*/false);
11600 else if (IDVal == ".seh_endprologue_fragment")
11601 parseDirectiveSEHPrologEnd(DirectiveID.getLoc(), /*Fragment=*/true);
11602 else if (IDVal == ".seh_nop")
11603 parseDirectiveSEHNop(DirectiveID.getLoc(), /*Wide=*/false);
11604 else if (IDVal == ".seh_nop_w")
11605 parseDirectiveSEHNop(DirectiveID.getLoc(), /*Wide=*/true);
11606 else if (IDVal == ".seh_startepilogue")
11607 parseDirectiveSEHEpilogStart(DirectiveID.getLoc(), /*Condition=*/false);
11608 else if (IDVal == ".seh_startepilogue_cond")
11609 parseDirectiveSEHEpilogStart(DirectiveID.getLoc(), /*Condition=*/true);
11610 else if (IDVal == ".seh_endepilogue")
11611 parseDirectiveSEHEpilogEnd(DirectiveID.getLoc());
11612 else if (IDVal == ".seh_custom")
11613 parseDirectiveSEHCustom(DirectiveID.getLoc());
11614 else
11615 return true;
11616 } else
11617 return true;
11618 return false;
11619}
11620
11621/// parseLiteralValues
11622/// ::= .hword expression [, expression]*
11623/// ::= .short expression [, expression]*
11624/// ::= .word expression [, expression]*
11625bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
11626 auto parseOne = [&]() -> bool {
11627 const MCExpr *Value;
11628 if (getParser().parseExpression(Value))
11629 return true;
11630 getParser().getStreamer().emitValue(Value, Size, L);
11631 return false;
11632 };
11633 return (parseMany(parseOne));
11634}
11635
11636/// parseDirectiveThumb
11637/// ::= .thumb
11638bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
11639 if (parseEOL() || check(!hasThumb(), L, "target does not support Thumb mode"))
11640 return true;
11641
11642 if (!isThumb())
11643 SwitchMode();
11644
11645 getTargetStreamer().emitCode16();
11646 getParser().getStreamer().emitCodeAlignment(Align(2), getSTI(), 0);
11647 return false;
11648}
11649
11650/// parseDirectiveARM
11651/// ::= .arm
11652bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
11653 if (parseEOL() || check(!hasARM(), L, "target does not support ARM mode"))
11654 return true;
11655
11656 if (isThumb())
11657 SwitchMode();
11658 getTargetStreamer().emitCode32();
11659 getParser().getStreamer().emitCodeAlignment(Align(4), getSTI(), 0);
11660 return false;
11661}
11662
11663void ARMAsmParser::doBeforeLabelEmit(MCSymbol *Symbol, SMLoc IDLoc) {
11664 // We need to flush the current implicit IT block on a label, because it is
11665 // not legal to branch into an IT block.
11666 flushPendingInstructions(getStreamer());
11667}
11668
11669void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
11670 if (NextSymbolIsThumb) {
11671 getTargetStreamer().emitThumbFunc(Symbol);
11672 NextSymbolIsThumb = false;
11673 }
11674}
11675
11676/// parseDirectiveThumbFunc
11677/// ::= .thumbfunc symbol_name
11678bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
11679 MCAsmParser &Parser = getParser();
11680 const auto Format = getContext().getObjectFileType();
11681 bool IsMachO = Format == MCContext::IsMachO;
11682
11683 // Darwin asm has (optionally) function name after .thumb_func direction
11684 // ELF doesn't
11685
11686 if (IsMachO) {
11687 if (Parser.getTok().is(AsmToken::Identifier) ||
11688 Parser.getTok().is(AsmToken::String)) {
11689 MCSymbol *Func = getParser().getContext().getOrCreateSymbol(
11690 Parser.getTok().getIdentifier());
11691 getTargetStreamer().emitThumbFunc(Func);
11692 Parser.Lex();
11693 if (parseEOL())
11694 return true;
11695 return false;
11696 }
11697 }
11698
11699 if (parseEOL())
11700 return true;
11701
11702 // .thumb_func implies .thumb
11703 if (!isThumb())
11704 SwitchMode();
11705
11706 getTargetStreamer().emitCode16();
11707
11708 NextSymbolIsThumb = true;
11709 return false;
11710}
11711
11712/// parseDirectiveSyntax
11713/// ::= .syntax unified | divided
11714bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
11715 MCAsmParser &Parser = getParser();
11716 const AsmToken &Tok = Parser.getTok();
11717 if (Tok.isNot(AsmToken::Identifier)) {
11718 Error(L, "unexpected token in .syntax directive");
11719 return false;
11720 }
11721
11722 StringRef Mode = Tok.getString();
11723 Parser.Lex();
11724 if (check(Mode == "divided" || Mode == "DIVIDED", L,
11725 "'.syntax divided' arm assembly not supported") ||
11726 check(Mode != "unified" && Mode != "UNIFIED", L,
11727 "unrecognized syntax mode in .syntax directive") ||
11728 parseEOL())
11729 return true;
11730
11731 // TODO tell the MC streamer the mode
11732 // getParser().getStreamer().Emit???();
11733 return false;
11734}
11735
11736/// parseDirectiveCode
11737/// ::= .code 16 | 32
11738bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
11739 MCAsmParser &Parser = getParser();
11740 const AsmToken &Tok = Parser.getTok();
11741 if (Tok.isNot(AsmToken::Integer))
11742 return Error(L, "unexpected token in .code directive");
11743 int64_t Val = Parser.getTok().getIntVal();
11744 if (Val != 16 && Val != 32) {
11745 Error(L, "invalid operand to .code directive");
11746 return false;
11747 }
11748 Parser.Lex();
11749
11750 if (parseEOL())
11751 return true;
11752
11753 if (Val == 16) {
11754 if (!hasThumb())
11755 return Error(L, "target does not support Thumb mode");
11756
11757 if (!isThumb())
11758 SwitchMode();
11759 getTargetStreamer().emitCode16();
11760 } else {
11761 if (!hasARM())
11762 return Error(L, "target does not support ARM mode");
11763
11764 if (isThumb())
11765 SwitchMode();
11766 getTargetStreamer().emitCode32();
11767 }
11768
11769 return false;
11770}
11771
11772/// parseDirectiveReq
11773/// ::= name .req registername
11774bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
11775 MCAsmParser &Parser = getParser();
11776 Parser.Lex(); // Eat the '.req' token.
11777 MCRegister Reg;
11778 SMLoc SRegLoc, ERegLoc;
11779 const bool parseResult = parseRegister(Reg, SRegLoc, ERegLoc);
11780 if (check(parseResult, SRegLoc, "register name expected") || parseEOL())
11781 return true;
11782
11783 if (RegisterReqs.insert(std::make_pair(Name, Reg)).first->second != Reg)
11784 return Error(SRegLoc,
11785 "redefinition of '" + Name + "' does not match original.");
11786
11787 return false;
11788}
11789
11790/// parseDirectiveUneq
11791/// ::= .unreq registername
11792bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
11793 MCAsmParser &Parser = getParser();
11794 if (Parser.getTok().isNot(AsmToken::Identifier))
11795 return Error(L, "unexpected input in .unreq directive.");
11796 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
11797 Parser.Lex(); // Eat the identifier.
11798 return parseEOL();
11799}
11800
11801// After changing arch/CPU, try to put the ARM/Thumb mode back to what it was
11802// before, if supported by the new target, or emit mapping symbols for the mode
11803// switch.
11804void ARMAsmParser::FixModeAfterArchChange(bool WasThumb, SMLoc Loc) {
11805 if (WasThumb != isThumb()) {
11806 if (WasThumb && hasThumb()) {
11807 // Stay in Thumb mode
11808 SwitchMode();
11809 } else if (!WasThumb && hasARM()) {
11810 // Stay in ARM mode
11811 SwitchMode();
11812 } else {
11813 // Mode switch forced, because the new arch doesn't support the old mode.
11814 if (isThumb())
11815 getTargetStreamer().emitCode16();
11816 else
11817 getTargetStreamer().emitCode32();
11818 // Warn about the implicit mode switch. GAS does not switch modes here,
11819 // but instead stays in the old mode, reporting an error on any following
11820 // instructions as the mode does not exist on the target.
11821 Warning(Loc, Twine("new target does not support ") +
11822 (WasThumb ? "thumb" : "arm") + " mode, switching to " +
11823 (!WasThumb ? "thumb" : "arm") + " mode");
11824 }
11825 }
11826}
11827
11828/// parseDirectiveArch
11829/// ::= .arch token
11830bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
11831 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
11833
11834 if (ID == ARM::ArchKind::INVALID)
11835 return Error(L, "Unknown arch name");
11836
11837 bool WasThumb = isThumb();
11838 MCSubtargetInfo &STI = copySTI();
11839 STI.setDefaultFeatures("", /*TuneCPU*/ "",
11840 ("+" + ARM::getArchName(ID)).str());
11841 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
11842 FixModeAfterArchChange(WasThumb, L);
11843
11844 getTargetStreamer().emitArch(ID);
11845 return false;
11846}
11847
11848/// parseDirectiveEabiAttr
11849/// ::= .eabi_attribute int, int [, "str"]
11850/// ::= .eabi_attribute Tag_name, int [, "str"]
11851bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
11852 MCAsmParser &Parser = getParser();
11853 int64_t Tag;
11854 SMLoc TagLoc;
11855 TagLoc = Parser.getTok().getLoc();
11856 if (Parser.getTok().is(AsmToken::Identifier)) {
11857 StringRef Name = Parser.getTok().getIdentifier();
11858 std::optional<unsigned> Ret = ELFAttrs::attrTypeFromString(
11860 if (!Ret) {
11861 Error(TagLoc, "attribute name not recognised: " + Name);
11862 return false;
11863 }
11864 Tag = *Ret;
11865 Parser.Lex();
11866 } else {
11867 const MCExpr *AttrExpr;
11868
11869 TagLoc = Parser.getTok().getLoc();
11870 if (Parser.parseExpression(AttrExpr))
11871 return true;
11872
11873 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
11874 if (check(!CE, TagLoc, "expected numeric constant"))
11875 return true;
11876
11877 Tag = CE->getValue();
11878 }
11879
11880 if (Parser.parseComma())
11881 return true;
11882
11883 StringRef StringValue = "";
11884 bool IsStringValue = false;
11885
11886 int64_t IntegerValue = 0;
11887 bool IsIntegerValue = false;
11888
11890 IsStringValue = true;
11891 else if (Tag == ARMBuildAttrs::compatibility) {
11892 IsStringValue = true;
11893 IsIntegerValue = true;
11894 } else if (Tag < 32 || Tag % 2 == 0)
11895 IsIntegerValue = true;
11896 else if (Tag % 2 == 1)
11897 IsStringValue = true;
11898 else
11899 llvm_unreachable("invalid tag type");
11900
11901 if (IsIntegerValue) {
11902 const MCExpr *ValueExpr;
11903 SMLoc ValueExprLoc = Parser.getTok().getLoc();
11904 if (Parser.parseExpression(ValueExpr))
11905 return true;
11906
11907 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
11908 if (!CE)
11909 return Error(ValueExprLoc, "expected numeric constant");
11910 IntegerValue = CE->getValue();
11911 }
11912
11914 if (Parser.parseComma())
11915 return true;
11916 }
11917
11918 std::string EscapedValue;
11919 if (IsStringValue) {
11920 if (Parser.getTok().isNot(AsmToken::String))
11921 return Error(Parser.getTok().getLoc(), "bad string constant");
11922
11924 if (Parser.parseEscapedString(EscapedValue))
11925 return Error(Parser.getTok().getLoc(), "bad escaped string constant");
11926
11927 StringValue = EscapedValue;
11928 } else {
11929 StringValue = Parser.getTok().getStringContents();
11930 Parser.Lex();
11931 }
11932 }
11933
11934 if (Parser.parseEOL())
11935 return true;
11936
11937 if (IsIntegerValue && IsStringValue) {
11939 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
11940 } else if (IsIntegerValue)
11941 getTargetStreamer().emitAttribute(Tag, IntegerValue);
11942 else if (IsStringValue)
11943 getTargetStreamer().emitTextAttribute(Tag, StringValue);
11944 return false;
11945}
11946
11947/// parseDirectiveCPU
11948/// ::= .cpu str
11949bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
11950 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
11951 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
11952
11953 // FIXME: This is using table-gen data, but should be moved to
11954 // ARMTargetParser once that is table-gen'd.
11955 if (!getSTI().isCPUStringValid(CPU))
11956 return Error(L, "Unknown CPU name");
11957
11958 bool WasThumb = isThumb();
11959 MCSubtargetInfo &STI = copySTI();
11960 STI.setDefaultFeatures(CPU, /*TuneCPU*/ CPU, "");
11961 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
11962 FixModeAfterArchChange(WasThumb, L);
11963
11964 return false;
11965}
11966
11967/// parseDirectiveFPU
11968/// ::= .fpu str
11969bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
11970 SMLoc FPUNameLoc = getTok().getLoc();
11971 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
11972
11974 std::vector<StringRef> Features;
11975 if (!ARM::getFPUFeatures(ID, Features))
11976 return Error(FPUNameLoc, "Unknown FPU name");
11977
11978 MCSubtargetInfo &STI = copySTI();
11979 for (auto Feature : Features)
11980 STI.ApplyFeatureFlag(Feature);
11981 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
11982
11983 getTargetStreamer().emitFPU(ID);
11984 return false;
11985}
11986
11987/// parseDirectiveFnStart
11988/// ::= .fnstart
11989bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
11990 if (parseEOL())
11991 return true;
11992
11993 if (UC.hasFnStart()) {
11994 Error(L, ".fnstart starts before the end of previous one");
11995 UC.emitFnStartLocNotes();
11996 return true;
11997 }
11998
11999 // Reset the unwind directives parser state
12000 UC.reset();
12001
12002 getTargetStreamer().emitFnStart();
12003
12004 UC.recordFnStart(L);
12005 return false;
12006}
12007
12008/// parseDirectiveFnEnd
12009/// ::= .fnend
12010bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
12011 if (parseEOL())
12012 return true;
12013 // Check the ordering of unwind directives
12014 if (!UC.hasFnStart())
12015 return Error(L, ".fnstart must precede .fnend directive");
12016
12017 // Reset the unwind directives parser state
12018 getTargetStreamer().emitFnEnd();
12019
12020 UC.reset();
12021 return false;
12022}
12023
12024/// parseDirectiveCantUnwind
12025/// ::= .cantunwind
12026bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
12027 if (parseEOL())
12028 return true;
12029
12030 UC.recordCantUnwind(L);
12031 // Check the ordering of unwind directives
12032 if (check(!UC.hasFnStart(), L, ".fnstart must precede .cantunwind directive"))
12033 return true;
12034
12035 if (UC.hasHandlerData()) {
12036 Error(L, ".cantunwind can't be used with .handlerdata directive");
12037 UC.emitHandlerDataLocNotes();
12038 return true;
12039 }
12040 if (UC.hasPersonality()) {
12041 Error(L, ".cantunwind can't be used with .personality directive");
12042 UC.emitPersonalityLocNotes();
12043 return true;
12044 }
12045
12046 getTargetStreamer().emitCantUnwind();
12047 return false;
12048}
12049
12050/// parseDirectivePersonality
12051/// ::= .personality name
12052bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
12053 MCAsmParser &Parser = getParser();
12054 bool HasExistingPersonality = UC.hasPersonality();
12055
12056 // Parse the name of the personality routine
12057 if (Parser.getTok().isNot(AsmToken::Identifier))
12058 return Error(L, "unexpected input in .personality directive.");
12059 StringRef Name(Parser.getTok().getIdentifier());
12060 Parser.Lex();
12061
12062 if (parseEOL())
12063 return true;
12064
12065 UC.recordPersonality(L);
12066
12067 // Check the ordering of unwind directives
12068 if (!UC.hasFnStart())
12069 return Error(L, ".fnstart must precede .personality directive");
12070 if (UC.cantUnwind()) {
12071 Error(L, ".personality can't be used with .cantunwind directive");
12072 UC.emitCantUnwindLocNotes();
12073 return true;
12074 }
12075 if (UC.hasHandlerData()) {
12076 Error(L, ".personality must precede .handlerdata directive");
12077 UC.emitHandlerDataLocNotes();
12078 return true;
12079 }
12080 if (HasExistingPersonality) {
12081 Error(L, "multiple personality directives");
12082 UC.emitPersonalityLocNotes();
12083 return true;
12084 }
12085
12086 MCSymbol *PR = getParser().getContext().getOrCreateSymbol(Name);
12087 getTargetStreamer().emitPersonality(PR);
12088 return false;
12089}
12090
12091/// parseDirectiveHandlerData
12092/// ::= .handlerdata
12093bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
12094 if (parseEOL())
12095 return true;
12096
12097 UC.recordHandlerData(L);
12098 // Check the ordering of unwind directives
12099 if (!UC.hasFnStart())
12100 return Error(L, ".fnstart must precede .personality directive");
12101 if (UC.cantUnwind()) {
12102 Error(L, ".handlerdata can't be used with .cantunwind directive");
12103 UC.emitCantUnwindLocNotes();
12104 return true;
12105 }
12106
12107 getTargetStreamer().emitHandlerData();
12108 return false;
12109}
12110
12111/// parseDirectiveSetFP
12112/// ::= .setfp fpreg, spreg [, offset]
12113bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
12114 MCAsmParser &Parser = getParser();
12115 // Check the ordering of unwind directives
12116 if (check(!UC.hasFnStart(), L, ".fnstart must precede .setfp directive") ||
12117 check(UC.hasHandlerData(), L,
12118 ".setfp must precede .handlerdata directive"))
12119 return true;
12120
12121 // Parse fpreg
12122 SMLoc FPRegLoc = Parser.getTok().getLoc();
12123 MCRegister FPReg = tryParseRegister();
12124
12125 if (check(!FPReg, FPRegLoc, "frame pointer register expected") ||
12126 Parser.parseComma())
12127 return true;
12128
12129 // Parse spreg
12130 SMLoc SPRegLoc = Parser.getTok().getLoc();
12131 MCRegister SPReg = tryParseRegister();
12132 if (check(!SPReg, SPRegLoc, "stack pointer register expected") ||
12133 check(SPReg != ARM::SP && SPReg != UC.getFPReg(), SPRegLoc,
12134 "register should be either $sp or the latest fp register"))
12135 return true;
12136
12137 // Update the frame pointer register
12138 UC.saveFPReg(FPReg);
12139
12140 // Parse offset
12141 int64_t Offset = 0;
12142 if (Parser.parseOptionalToken(AsmToken::Comma)) {
12143 if (Parser.getTok().isNot(AsmToken::Hash) &&
12144 Parser.getTok().isNot(AsmToken::Dollar))
12145 return Error(Parser.getTok().getLoc(), "'#' expected");
12146 Parser.Lex(); // skip hash token.
12147
12148 const MCExpr *OffsetExpr;
12149 SMLoc ExLoc = Parser.getTok().getLoc();
12150 SMLoc EndLoc;
12151 if (getParser().parseExpression(OffsetExpr, EndLoc))
12152 return Error(ExLoc, "malformed setfp offset");
12153 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
12154 if (check(!CE, ExLoc, "setfp offset must be an immediate"))
12155 return true;
12156 Offset = CE->getValue();
12157 }
12158
12159 if (Parser.parseEOL())
12160 return true;
12161
12162 getTargetStreamer().emitSetFP(FPReg, SPReg, Offset);
12163 return false;
12164}
12165
12166/// parseDirectivePad
12167/// ::= .pad offset
12168bool ARMAsmParser::parseDirectivePad(SMLoc L) {
12169 MCAsmParser &Parser = getParser();
12170 // Check the ordering of unwind directives
12171 if (!UC.hasFnStart())
12172 return Error(L, ".fnstart must precede .pad directive");
12173 if (UC.hasHandlerData())
12174 return Error(L, ".pad must precede .handlerdata directive");
12175
12176 // Parse the offset
12177 if (Parser.getTok().isNot(AsmToken::Hash) &&
12178 Parser.getTok().isNot(AsmToken::Dollar))
12179 return Error(Parser.getTok().getLoc(), "'#' expected");
12180 Parser.Lex(); // skip hash token.
12181
12182 const MCExpr *OffsetExpr;
12183 SMLoc ExLoc = Parser.getTok().getLoc();
12184 SMLoc EndLoc;
12185 if (getParser().parseExpression(OffsetExpr, EndLoc))
12186 return Error(ExLoc, "malformed pad offset");
12187 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
12188 if (!CE)
12189 return Error(ExLoc, "pad offset must be an immediate");
12190
12191 if (parseEOL())
12192 return true;
12193
12194 getTargetStreamer().emitPad(CE->getValue());
12195 return false;
12196}
12197
12198/// parseDirectiveRegSave
12199/// ::= .save { registers }
12200/// ::= .vsave { registers }
12201bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
12202 // Check the ordering of unwind directives
12203 if (!UC.hasFnStart())
12204 return Error(L, ".fnstart must precede .save or .vsave directives");
12205 if (UC.hasHandlerData())
12206 return Error(L, ".save or .vsave must precede .handlerdata directive");
12207
12208 // RAII object to make sure parsed operands are deleted.
12210
12211 // Parse the register list
12212 if (parseRegisterList(Operands, true, true) || parseEOL())
12213 return true;
12214 ARMOperand &Op = (ARMOperand &)*Operands[0];
12215 if (!IsVector && !Op.isRegList())
12216 return Error(L, ".save expects GPR registers");
12217 if (IsVector && !Op.isDPRRegList())
12218 return Error(L, ".vsave expects DPR registers");
12219
12220 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
12221 return false;
12222}
12223
12224/// parseDirectiveInst
12225/// ::= .inst opcode [, ...]
12226/// ::= .inst.n opcode [, ...]
12227/// ::= .inst.w opcode [, ...]
12228bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
12229 int Width = 4;
12230
12231 if (isThumb()) {
12232 switch (Suffix) {
12233 case 'n':
12234 Width = 2;
12235 break;
12236 case 'w':
12237 break;
12238 default:
12239 Width = 0;
12240 break;
12241 }
12242 } else {
12243 if (Suffix)
12244 return Error(Loc, "width suffixes are invalid in ARM mode");
12245 }
12246
12247 auto parseOne = [&]() -> bool {
12248 const MCExpr *Expr;
12249 if (getParser().parseExpression(Expr))
12250 return true;
12251 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
12252 if (!Value) {
12253 return Error(Loc, "expected constant expression");
12254 }
12255
12256 char CurSuffix = Suffix;
12257 switch (Width) {
12258 case 2:
12259 if (Value->getValue() > 0xffff)
12260 return Error(Loc, "inst.n operand is too big, use inst.w instead");
12261 break;
12262 case 4:
12263 if (Value->getValue() > 0xffffffff)
12264 return Error(Loc, StringRef(Suffix ? "inst.w" : "inst") +
12265 " operand is too big");
12266 break;
12267 case 0:
12268 // Thumb mode, no width indicated. Guess from the opcode, if possible.
12269 if (Value->getValue() < 0xe800)
12270 CurSuffix = 'n';
12271 else if (Value->getValue() >= 0xe8000000)
12272 CurSuffix = 'w';
12273 else
12274 return Error(Loc, "cannot determine Thumb instruction size, "
12275 "use inst.n/inst.w instead");
12276 break;
12277 default:
12278 llvm_unreachable("only supported widths are 2 and 4");
12279 }
12280
12281 getTargetStreamer().emitInst(Value->getValue(), CurSuffix);
12282 forwardITPosition();
12283 forwardVPTPosition();
12284 return false;
12285 };
12286
12287 if (parseOptionalToken(AsmToken::EndOfStatement))
12288 return Error(Loc, "expected expression following directive");
12289 if (parseMany(parseOne))
12290 return true;
12291 return false;
12292}
12293
12294/// parseDirectiveLtorg
12295/// ::= .ltorg | .pool
12296bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
12297 if (parseEOL())
12298 return true;
12299 getTargetStreamer().emitCurrentConstantPool();
12300 return false;
12301}
12302
12303bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
12304 const MCSection *Section = getStreamer().getCurrentSectionOnly();
12305
12306 if (parseEOL())
12307 return true;
12308
12309 if (!Section) {
12310 getStreamer().initSections(getSTI());
12311 Section = getStreamer().getCurrentSectionOnly();
12312 }
12313
12314 assert(Section && "must have section to emit alignment");
12315 if (Section->isText())
12316 getStreamer().emitCodeAlignment(Align(2), getSTI());
12317 else
12318 getStreamer().emitValueToAlignment(Align(2));
12319
12320 return false;
12321}
12322
12323/// parseDirectivePersonalityIndex
12324/// ::= .personalityindex index
12325bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
12326 MCAsmParser &Parser = getParser();
12327 bool HasExistingPersonality = UC.hasPersonality();
12328
12329 const MCExpr *IndexExpression;
12330 SMLoc IndexLoc = Parser.getTok().getLoc();
12331 if (Parser.parseExpression(IndexExpression) || parseEOL()) {
12332 return true;
12333 }
12334
12335 UC.recordPersonalityIndex(L);
12336
12337 if (!UC.hasFnStart()) {
12338 return Error(L, ".fnstart must precede .personalityindex directive");
12339 }
12340 if (UC.cantUnwind()) {
12341 Error(L, ".personalityindex cannot be used with .cantunwind");
12342 UC.emitCantUnwindLocNotes();
12343 return true;
12344 }
12345 if (UC.hasHandlerData()) {
12346 Error(L, ".personalityindex must precede .handlerdata directive");
12347 UC.emitHandlerDataLocNotes();
12348 return true;
12349 }
12350 if (HasExistingPersonality) {
12351 Error(L, "multiple personality directives");
12352 UC.emitPersonalityLocNotes();
12353 return true;
12354 }
12355
12356 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
12357 if (!CE)
12358 return Error(IndexLoc, "index must be a constant number");
12359 if (CE->getValue() < 0 || CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX)
12360 return Error(IndexLoc,
12361 "personality routine index should be in range [0-3]");
12362
12363 getTargetStreamer().emitPersonalityIndex(CE->getValue());
12364 return false;
12365}
12366
12367/// parseDirectiveUnwindRaw
12368/// ::= .unwind_raw offset, opcode [, opcode...]
12369bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
12370 MCAsmParser &Parser = getParser();
12371 int64_t StackOffset;
12372 const MCExpr *OffsetExpr;
12373 SMLoc OffsetLoc = getLexer().getLoc();
12374
12375 if (!UC.hasFnStart())
12376 return Error(L, ".fnstart must precede .unwind_raw directives");
12377 if (getParser().parseExpression(OffsetExpr))
12378 return Error(OffsetLoc, "expected expression");
12379
12380 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
12381 if (!CE)
12382 return Error(OffsetLoc, "offset must be a constant");
12383
12384 StackOffset = CE->getValue();
12385
12386 if (Parser.parseComma())
12387 return true;
12388
12390
12391 auto parseOne = [&]() -> bool {
12392 const MCExpr *OE = nullptr;
12393 SMLoc OpcodeLoc = getLexer().getLoc();
12394 if (check(getLexer().is(AsmToken::EndOfStatement) ||
12395 Parser.parseExpression(OE),
12396 OpcodeLoc, "expected opcode expression"))
12397 return true;
12398 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
12399 if (!OC)
12400 return Error(OpcodeLoc, "opcode value must be a constant");
12401 const int64_t Opcode = OC->getValue();
12402 if (Opcode & ~0xff)
12403 return Error(OpcodeLoc, "invalid opcode");
12404 Opcodes.push_back(uint8_t(Opcode));
12405 return false;
12406 };
12407
12408 // Must have at least 1 element
12409 SMLoc OpcodeLoc = getLexer().getLoc();
12410 if (parseOptionalToken(AsmToken::EndOfStatement))
12411 return Error(OpcodeLoc, "expected opcode expression");
12412 if (parseMany(parseOne))
12413 return true;
12414
12415 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
12416 return false;
12417}
12418
12419/// parseDirectiveTLSDescSeq
12420/// ::= .tlsdescseq tls-variable
12421bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
12422 MCAsmParser &Parser = getParser();
12423
12424 if (getLexer().isNot(AsmToken::Identifier))
12425 return TokError("expected variable after '.tlsdescseq' directive");
12426
12427 auto *Sym = getContext().getOrCreateSymbol(Parser.getTok().getIdentifier());
12428 const auto *SRE =
12430 Lex();
12431
12432 if (parseEOL())
12433 return true;
12434
12435 getTargetStreamer().annotateTLSDescriptorSequence(SRE);
12436 return false;
12437}
12438
12439/// parseDirectiveMovSP
12440/// ::= .movsp reg [, #offset]
12441bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
12442 MCAsmParser &Parser = getParser();
12443 if (!UC.hasFnStart())
12444 return Error(L, ".fnstart must precede .movsp directives");
12445 if (UC.getFPReg() != ARM::SP)
12446 return Error(L, "unexpected .movsp directive");
12447
12448 SMLoc SPRegLoc = Parser.getTok().getLoc();
12449 MCRegister SPReg = tryParseRegister();
12450 if (!SPReg)
12451 return Error(SPRegLoc, "register expected");
12452 if (SPReg == ARM::SP || SPReg == ARM::PC)
12453 return Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
12454
12455 int64_t Offset = 0;
12456 if (Parser.parseOptionalToken(AsmToken::Comma)) {
12457 if (Parser.parseToken(AsmToken::Hash, "expected #constant"))
12458 return true;
12459
12460 const MCExpr *OffsetExpr;
12461 SMLoc OffsetLoc = Parser.getTok().getLoc();
12462
12463 if (Parser.parseExpression(OffsetExpr))
12464 return Error(OffsetLoc, "malformed offset expression");
12465
12466 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
12467 if (!CE)
12468 return Error(OffsetLoc, "offset must be an immediate constant");
12469
12470 Offset = CE->getValue();
12471 }
12472
12473 if (parseEOL())
12474 return true;
12475
12476 getTargetStreamer().emitMovSP(SPReg, Offset);
12477 UC.saveFPReg(SPReg);
12478
12479 return false;
12480}
12481
12482/// parseDirectiveObjectArch
12483/// ::= .object_arch name
12484bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
12485 MCAsmParser &Parser = getParser();
12486 if (getLexer().isNot(AsmToken::Identifier))
12487 return Error(getLexer().getLoc(), "unexpected token");
12488
12489 StringRef Arch = Parser.getTok().getString();
12490 SMLoc ArchLoc = Parser.getTok().getLoc();
12491 Lex();
12492
12494
12495 if (ID == ARM::ArchKind::INVALID)
12496 return Error(ArchLoc, "unknown architecture '" + Arch + "'");
12497 if (parseToken(AsmToken::EndOfStatement))
12498 return true;
12499
12500 getTargetStreamer().emitObjectArch(ID);
12501 return false;
12502}
12503
12504/// parseDirectiveAlign
12505/// ::= .align
12506bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
12507 // NOTE: if this is not the end of the statement, fall back to the target
12508 // agnostic handling for this directive which will correctly handle this.
12509 if (parseOptionalToken(AsmToken::EndOfStatement)) {
12510 // '.align' is target specifically handled to mean 2**2 byte alignment.
12511 const MCSection *Section = getStreamer().getCurrentSectionOnly();
12512 assert(Section && "must have section to emit alignment");
12513 if (Section->isText())
12514 getStreamer().emitCodeAlignment(Align(4), getSTI(), 0);
12515 else
12516 getStreamer().emitValueToAlignment(Align(4), 0, 1, 0);
12517 return false;
12518 }
12519 return true;
12520}
12521
12522/// parseDirectiveThumbSet
12523/// ::= .thumb_set name, value
12524bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
12525 MCAsmParser &Parser = getParser();
12526
12527 StringRef Name;
12528 if (check(Parser.parseIdentifier(Name),
12529 "expected identifier after '.thumb_set'") ||
12530 Parser.parseComma())
12531 return true;
12532
12533 MCSymbol *Sym;
12534 const MCExpr *Value;
12535 if (MCParserUtils::parseAssignmentExpression(Name, /* allow_redef */ true,
12536 Parser, Sym, Value))
12537 return true;
12538
12539 getTargetStreamer().emitThumbSet(Sym, Value);
12540 return false;
12541}
12542
12543/// parseDirectiveSEHAllocStack
12544/// ::= .seh_stackalloc
12545/// ::= .seh_stackalloc_w
12546bool ARMAsmParser::parseDirectiveSEHAllocStack(SMLoc L, bool Wide) {
12547 int64_t Size;
12548 if (parseImmExpr(Size))
12549 return true;
12550 getTargetStreamer().emitARMWinCFIAllocStack(Size, Wide);
12551 return false;
12552}
12553
12554/// parseDirectiveSEHSaveRegs
12555/// ::= .seh_save_regs
12556/// ::= .seh_save_regs_w
12557bool ARMAsmParser::parseDirectiveSEHSaveRegs(SMLoc L, bool Wide) {
12559
12560 if (parseRegisterList(Operands) || parseEOL())
12561 return true;
12562 ARMOperand &Op = (ARMOperand &)*Operands[0];
12563 if (!Op.isRegList())
12564 return Error(L, ".seh_save_regs{_w} expects GPR registers");
12565 const SmallVectorImpl<MCRegister> &RegList = Op.getRegList();
12566 uint32_t Mask = 0;
12567 for (size_t i = 0; i < RegList.size(); ++i) {
12568 unsigned Reg = MRI->getEncodingValue(RegList[i]);
12569 if (Reg == 15) // pc -> lr
12570 Reg = 14;
12571 if (Reg == 13)
12572 return Error(L, ".seh_save_regs{_w} can't include SP");
12573 assert(Reg < 16U && "Register out of range");
12574 unsigned Bit = (1u << Reg);
12575 Mask |= Bit;
12576 }
12577 if (!Wide && (Mask & 0x1f00) != 0)
12578 return Error(L,
12579 ".seh_save_regs cannot save R8-R12, needs .seh_save_regs_w");
12580 getTargetStreamer().emitARMWinCFISaveRegMask(Mask, Wide);
12581 return false;
12582}
12583
12584/// parseDirectiveSEHSaveSP
12585/// ::= .seh_save_sp
12586bool ARMAsmParser::parseDirectiveSEHSaveSP(SMLoc L) {
12587 MCRegister Reg = tryParseRegister();
12588 if (!Reg || !MRI->getRegClass(ARM::GPRRegClassID).contains(Reg))
12589 return Error(L, "expected GPR");
12590 unsigned Index = MRI->getEncodingValue(Reg);
12591 if (Index > 14 || Index == 13)
12592 return Error(L, "invalid register for .seh_save_sp");
12593 getTargetStreamer().emitARMWinCFISaveSP(Index);
12594 return false;
12595}
12596
12597/// parseDirectiveSEHSaveFRegs
12598/// ::= .seh_save_fregs
12599bool ARMAsmParser::parseDirectiveSEHSaveFRegs(SMLoc L) {
12601
12602 if (parseRegisterList(Operands) || parseEOL())
12603 return true;
12604 ARMOperand &Op = (ARMOperand &)*Operands[0];
12605 if (!Op.isDPRRegList())
12606 return Error(L, ".seh_save_fregs expects DPR registers");
12607 const SmallVectorImpl<MCRegister> &RegList = Op.getRegList();
12608 uint32_t Mask = 0;
12609 for (size_t i = 0; i < RegList.size(); ++i) {
12610 unsigned Reg = MRI->getEncodingValue(RegList[i]);
12611 assert(Reg < 32U && "Register out of range");
12612 unsigned Bit = (1u << Reg);
12613 Mask |= Bit;
12614 }
12615
12616 if (Mask == 0)
12617 return Error(L, ".seh_save_fregs missing registers");
12618
12619 unsigned First = 0;
12620 while ((Mask & 1) == 0) {
12621 First++;
12622 Mask >>= 1;
12623 }
12624 if (((Mask + 1) & Mask) != 0)
12625 return Error(L,
12626 ".seh_save_fregs must take a contiguous range of registers");
12627 unsigned Last = First;
12628 while ((Mask & 2) != 0) {
12629 Last++;
12630 Mask >>= 1;
12631 }
12632 if (First < 16 && Last >= 16)
12633 return Error(L, ".seh_save_fregs must be all d0-d15 or d16-d31");
12634 getTargetStreamer().emitARMWinCFISaveFRegs(First, Last);
12635 return false;
12636}
12637
12638/// parseDirectiveSEHSaveLR
12639/// ::= .seh_save_lr
12640bool ARMAsmParser::parseDirectiveSEHSaveLR(SMLoc L) {
12641 int64_t Offset;
12642 if (parseImmExpr(Offset))
12643 return true;
12644 getTargetStreamer().emitARMWinCFISaveLR(Offset);
12645 return false;
12646}
12647
12648/// parseDirectiveSEHPrologEnd
12649/// ::= .seh_endprologue
12650/// ::= .seh_endprologue_fragment
12651bool ARMAsmParser::parseDirectiveSEHPrologEnd(SMLoc L, bool Fragment) {
12652 getTargetStreamer().emitARMWinCFIPrologEnd(Fragment);
12653 return false;
12654}
12655
12656/// parseDirectiveSEHNop
12657/// ::= .seh_nop
12658/// ::= .seh_nop_w
12659bool ARMAsmParser::parseDirectiveSEHNop(SMLoc L, bool Wide) {
12660 getTargetStreamer().emitARMWinCFINop(Wide);
12661 return false;
12662}
12663
12664/// parseDirectiveSEHEpilogStart
12665/// ::= .seh_startepilogue
12666/// ::= .seh_startepilogue_cond
12667bool ARMAsmParser::parseDirectiveSEHEpilogStart(SMLoc L, bool Condition) {
12668 unsigned CC = ARMCC::AL;
12669 if (Condition) {
12670 MCAsmParser &Parser = getParser();
12671 SMLoc S = Parser.getTok().getLoc();
12672 const AsmToken &Tok = Parser.getTok();
12673 if (!Tok.is(AsmToken::Identifier))
12674 return Error(S, ".seh_startepilogue_cond missing condition");
12676 if (CC == ~0U)
12677 return Error(S, "invalid condition");
12678 Parser.Lex(); // Eat the token.
12679 }
12680
12681 getTargetStreamer().emitARMWinCFIEpilogStart(CC);
12682 return false;
12683}
12684
12685/// parseDirectiveSEHEpilogEnd
12686/// ::= .seh_endepilogue
12687bool ARMAsmParser::parseDirectiveSEHEpilogEnd(SMLoc L) {
12688 getTargetStreamer().emitARMWinCFIEpilogEnd();
12689 return false;
12690}
12691
12692/// parseDirectiveSEHCustom
12693/// ::= .seh_custom
12694bool ARMAsmParser::parseDirectiveSEHCustom(SMLoc L) {
12695 unsigned Opcode = 0;
12696 do {
12697 int64_t Byte;
12698 if (parseImmExpr(Byte))
12699 return true;
12700 if (Byte > 0xff || Byte < 0)
12701 return Error(L, "Invalid byte value in .seh_custom");
12702 if (Opcode > 0x00ffffff)
12703 return Error(L, "Too many bytes in .seh_custom");
12704 // Store the bytes as one big endian number in Opcode. In a multi byte
12705 // opcode sequence, the first byte can't be zero.
12706 Opcode = (Opcode << 8) | Byte;
12707 } while (parseOptionalToken(AsmToken::Comma));
12708 getTargetStreamer().emitARMWinCFICustom(Opcode);
12709 return false;
12710}
12711
12712/// Force static initialization.
12719
12720#define GET_REGISTER_MATCHER
12721#define GET_SUBTARGET_FEATURE_NAME
12722#define GET_MATCHER_IMPLEMENTATION
12723#define GET_MNEMONIC_SPELL_CHECKER
12724#include "ARMGenAsmMatcher.inc"
12725
12726// Some diagnostics need to vary with subtarget features, so they are handled
12727// here. For example, the DPR class has either 16 or 32 registers, depending
12728// on the FPU available.
12729const char *
12730ARMAsmParser::getCustomOperandDiag(ARMMatchResultTy MatchError) {
12731 switch (MatchError) {
12732 // rGPR contains sp starting with ARMv8.
12733 case Match_rGPR:
12734 return hasV8Ops() ? "operand must be a register in range [r0, r14]"
12735 : "operand must be a register in range [r0, r12] or r14";
12736 // DPR contains 16 registers for some FPUs, and 32 for others.
12737 case Match_DPR:
12738 return hasD32() ? "operand must be a register in range [d0, d31]"
12739 : "operand must be a register in range [d0, d15]";
12740 case Match_DPR_RegList:
12741 return hasD32() ? "operand must be a list of registers in range [d0, d31]"
12742 : "operand must be a list of registers in range [d0, d15]";
12743
12744 // For all other diags, use the static string from tablegen.
12745 default:
12746 return getMatchKindDiag(MatchError);
12747 }
12748}
12749
12750// Process the list of near-misses, throwing away ones we don't want to report
12751// to the user, and converting the rest to a source location and string that
12752// should be reported.
12753void
12754ARMAsmParser::FilterNearMisses(SmallVectorImpl<NearMissInfo> &NearMissesIn,
12755 SmallVectorImpl<NearMissMessage> &NearMissesOut,
12756 SMLoc IDLoc, OperandVector &Operands) {
12757 // TODO: If operand didn't match, sub in a dummy one and run target
12758 // predicate, so that we can avoid reporting near-misses that are invalid?
12759 // TODO: Many operand types dont have SuperClasses set, so we report
12760 // redundant ones.
12761 // TODO: Some operands are superclasses of registers (e.g.
12762 // MCK_RegShiftedImm), we don't have any way to represent that currently.
12763 // TODO: This is not all ARM-specific, can some of it be factored out?
12764
12765 // Record some information about near-misses that we have already seen, so
12766 // that we can avoid reporting redundant ones. For example, if there are
12767 // variants of an instruction that take 8- and 16-bit immediates, we want
12768 // to only report the widest one.
12769 std::multimap<unsigned, unsigned> OperandMissesSeen;
12770 SmallSet<FeatureBitset, 4> FeatureMissesSeen;
12771 bool ReportedTooFewOperands = false;
12772
12773 unsigned MnemonicOpsEndInd = getMnemonicOpsEndInd(Operands);
12774
12775 // Process the near-misses in reverse order, so that we see more general ones
12776 // first, and so can avoid emitting more specific ones.
12777 for (NearMissInfo &I : reverse(NearMissesIn)) {
12778 switch (I.getKind()) {
12780 SMLoc OperandLoc =
12781 ((ARMOperand &)*Operands[I.getOperandIndex()]).getStartLoc();
12782 const char *OperandDiag =
12783 getCustomOperandDiag((ARMMatchResultTy)I.getOperandError());
12784
12785 // If we have already emitted a message for a superclass, don't also report
12786 // the sub-class. We consider all operand classes that we don't have a
12787 // specialised diagnostic for to be equal for the propose of this check,
12788 // so that we don't report the generic error multiple times on the same
12789 // operand.
12790 unsigned DupCheckMatchClass = OperandDiag ? I.getOperandClass() : ~0U;
12791 auto PrevReports = OperandMissesSeen.equal_range(I.getOperandIndex());
12792 if (std::any_of(PrevReports.first, PrevReports.second,
12793 [DupCheckMatchClass](
12794 const std::pair<unsigned, unsigned> Pair) {
12795 if (DupCheckMatchClass == ~0U || Pair.second == ~0U)
12796 return Pair.second == DupCheckMatchClass;
12797 else
12798 return isSubclass((MatchClassKind)DupCheckMatchClass,
12799 (MatchClassKind)Pair.second);
12800 }))
12801 break;
12802 OperandMissesSeen.insert(
12803 std::make_pair(I.getOperandIndex(), DupCheckMatchClass));
12804
12805 NearMissMessage Message;
12806 Message.Loc = OperandLoc;
12807 if (OperandDiag) {
12808 Message.Message = OperandDiag;
12809 } else if (I.getOperandClass() == InvalidMatchClass) {
12810 Message.Message = "too many operands for instruction";
12811 } else {
12812 Message.Message = "invalid operand for instruction";
12813 LLVM_DEBUG(
12814 dbgs() << "Missing diagnostic string for operand class "
12815 << getMatchClassName((MatchClassKind)I.getOperandClass())
12816 << I.getOperandClass() << ", error " << I.getOperandError()
12817 << ", opcode " << MII.getName(I.getOpcode()) << "\n");
12818 }
12819 NearMissesOut.emplace_back(Message);
12820 break;
12821 }
12823 const FeatureBitset &MissingFeatures = I.getFeatures();
12824 // Don't report the same set of features twice.
12825 if (FeatureMissesSeen.count(MissingFeatures))
12826 break;
12827 FeatureMissesSeen.insert(MissingFeatures);
12828
12829 // Special case: don't report a feature set which includes arm-mode for
12830 // targets that don't have ARM mode.
12831 if (MissingFeatures.test(Feature_IsARMBit) && !hasARM())
12832 break;
12833 // Don't report any near-misses that both require switching instruction
12834 // set, and adding other subtarget features.
12835 if (isThumb() && MissingFeatures.test(Feature_IsARMBit) &&
12836 MissingFeatures.count() > 1)
12837 break;
12838 if (!isThumb() && MissingFeatures.test(Feature_IsThumbBit) &&
12839 MissingFeatures.count() > 1)
12840 break;
12841 if (!isThumb() && MissingFeatures.test(Feature_IsThumb2Bit) &&
12842 (MissingFeatures & ~FeatureBitset({Feature_IsThumb2Bit,
12843 Feature_IsThumbBit})).any())
12844 break;
12845 if (isMClass() && MissingFeatures.test(Feature_HasNEONBit))
12846 break;
12847
12848 NearMissMessage Message;
12849 Message.Loc = IDLoc;
12850 raw_svector_ostream OS(Message.Message);
12851
12852 OS << "instruction requires:";
12853 for (unsigned Feature : MissingFeatures)
12854 OS << ' ' << getSubtargetFeatureName(Feature);
12855
12856 NearMissesOut.emplace_back(Message);
12857
12858 break;
12859 }
12861 NearMissMessage Message;
12862 Message.Loc = IDLoc;
12863 switch (I.getPredicateError()) {
12864 case Match_RequiresNotITBlock:
12865 Message.Message = "flag setting instruction only valid outside IT block";
12866 break;
12867 case Match_RequiresITBlock:
12868 Message.Message = "instruction only valid inside IT block";
12869 break;
12870 case Match_RequiresV6:
12871 Message.Message = "instruction variant requires ARMv6 or later";
12872 break;
12873 case Match_RequiresThumb2:
12874 Message.Message = "instruction variant requires Thumb2";
12875 break;
12876 case Match_RequiresV8:
12877 Message.Message = "instruction variant requires ARMv8 or later";
12878 break;
12879 case Match_RequiresFlagSetting:
12880 Message.Message = "no flag-preserving variant of this instruction available";
12881 break;
12882 case Match_InvalidTiedOperand: {
12883 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[0]);
12884 if (Op.isToken() && Op.getToken() == "mul") {
12885 Message.Message = "destination register must match a source register";
12886 Message.Loc = Operands[MnemonicOpsEndInd]->getStartLoc();
12887 } else {
12888 llvm_unreachable("Match_InvalidTiedOperand only used for tMUL.");
12889 }
12890 break;
12891 }
12892 case Match_InvalidOperand:
12893 Message.Message = "invalid operand for instruction";
12894 break;
12895 default:
12896 llvm_unreachable("Unhandled target predicate error");
12897 break;
12898 }
12899 NearMissesOut.emplace_back(Message);
12900 break;
12901 }
12903 if (!ReportedTooFewOperands) {
12904 SMLoc EndLoc = ((ARMOperand &)*Operands.back()).getEndLoc();
12905 NearMissesOut.emplace_back(NearMissMessage{
12906 EndLoc, StringRef("too few operands for instruction")});
12907 ReportedTooFewOperands = true;
12908 }
12909 break;
12910 }
12912 // This should never leave the matcher.
12913 llvm_unreachable("not a near-miss");
12914 break;
12915 }
12916 }
12917}
12918
12919void ARMAsmParser::ReportNearMisses(SmallVectorImpl<NearMissInfo> &NearMisses,
12920 SMLoc IDLoc, OperandVector &Operands) {
12922 FilterNearMisses(NearMisses, Messages, IDLoc, Operands);
12923
12924 if (Messages.size() == 0) {
12925 // No near-misses were found, so the best we can do is "invalid
12926 // instruction".
12927 Error(IDLoc, "invalid instruction");
12928 } else if (Messages.size() == 1) {
12929 // One near miss was found, report it as the sole error.
12930 Error(Messages[0].Loc, Messages[0].Message);
12931 } else {
12932 // More than one near miss, so report a generic "invalid instruction"
12933 // error, followed by notes for each of the near-misses.
12934 Error(IDLoc, "invalid instruction, any one of the following would fix this:");
12935 for (auto &M : Messages) {
12936 Note(M.Loc, M.Message);
12937 }
12938 }
12939}
12940
12941bool ARMAsmParser::enableArchExtFeature(StringRef Name, SMLoc &ExtLoc) {
12942 // FIXME: This structure should be moved inside ARMTargetParser
12943 // when we start to table-generate them, and we can use the ARM
12944 // flags below, that were generated by table-gen.
12945 static const struct {
12946 const uint64_t Kind;
12947 const FeatureBitset ArchCheck;
12948 const FeatureBitset Features;
12949 } Extensions[] = {
12950 {ARM::AEK_CRC, {Feature_HasV8Bit}, {ARM::FeatureCRC}},
12951 {ARM::AEK_AES,
12952 {Feature_HasV8Bit},
12953 {ARM::FeatureAES, ARM::FeatureNEON, ARM::FeatureFPARMv8}},
12955 {Feature_HasV8Bit},
12956 {ARM::FeatureSHA2, ARM::FeatureNEON, ARM::FeatureFPARMv8}},
12958 {Feature_HasV8Bit},
12959 {ARM::FeatureCrypto, ARM::FeatureNEON, ARM::FeatureFPARMv8}},
12961 {Feature_HasV8_1MMainlineBit},
12962 {ARM::HasMVEFloatOps}},
12963 {ARM::AEK_FP,
12964 {Feature_HasV8Bit},
12965 {ARM::FeatureVFP2_SP, ARM::FeatureFPARMv8}},
12967 {Feature_HasV7Bit, Feature_IsNotMClassBit},
12968 {ARM::FeatureHWDivThumb, ARM::FeatureHWDivARM}},
12969 {ARM::AEK_MP,
12970 {Feature_HasV7Bit, Feature_IsNotMClassBit},
12971 {ARM::FeatureMP}},
12973 {Feature_HasV8Bit},
12974 {ARM::FeatureNEON, ARM::FeatureVFP2_SP, ARM::FeatureFPARMv8}},
12975 {ARM::AEK_SEC, {Feature_HasV6KBit}, {ARM::FeatureTrustZone}},
12976 // FIXME: Only available in A-class, isel not predicated
12977 {ARM::AEK_VIRT, {Feature_HasV7Bit}, {ARM::FeatureVirtualization}},
12979 {Feature_HasV8_2aBit},
12980 {ARM::FeatureFPARMv8, ARM::FeatureFullFP16}},
12981 {ARM::AEK_RAS, {Feature_HasV8Bit}, {ARM::FeatureRAS}},
12982 {ARM::AEK_LOB, {Feature_HasV8_1MMainlineBit}, {ARM::FeatureLOB}},
12983 {ARM::AEK_PACBTI, {Feature_HasV8_1MMainlineBit}, {ARM::FeaturePACBTI}},
12984 // FIXME: Unsupported extensions.
12985 {ARM::AEK_OS, {}, {}},
12986 {ARM::AEK_IWMMXT, {}, {}},
12987 {ARM::AEK_IWMMXT2, {}, {}},
12988 {ARM::AEK_MAVERICK, {}, {}},
12989 {ARM::AEK_XSCALE, {}, {}},
12990 };
12991 bool EnableFeature = !Name.consume_front_insensitive("no");
12993 if (FeatureKind == ARM::AEK_INVALID)
12994 return Error(ExtLoc, "unknown architectural extension: " + Name);
12995
12996 for (const auto &Extension : Extensions) {
12997 if (Extension.Kind != FeatureKind)
12998 continue;
12999
13000 if (Extension.Features.none())
13001 return Error(ExtLoc, "unsupported architectural extension: " + Name);
13002
13003 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck)
13004 return Error(ExtLoc, "architectural extension '" + Name +
13005 "' is not "
13006 "allowed for the current base architecture");
13007
13008 MCSubtargetInfo &STI = copySTI();
13009 if (EnableFeature) {
13011 } else {
13013 }
13014 FeatureBitset Features = ComputeAvailableFeatures(STI.getFeatureBits());
13015 setAvailableFeatures(Features);
13016 return true;
13017 }
13018 return false;
13019}
13020
13021/// parseDirectiveArchExtension
13022/// ::= .arch_extension [no]feature
13023bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
13024
13025 MCAsmParser &Parser = getParser();
13026
13027 if (getLexer().isNot(AsmToken::Identifier))
13028 return Error(getLexer().getLoc(), "expected architecture extension name");
13029
13030 StringRef Name = Parser.getTok().getString();
13031 SMLoc ExtLoc = Parser.getTok().getLoc();
13032 Lex();
13033
13034 if (parseEOL())
13035 return true;
13036
13037 if (Name == "nocrypto") {
13038 enableArchExtFeature("nosha2", ExtLoc);
13039 enableArchExtFeature("noaes", ExtLoc);
13040 }
13041
13042 if (enableArchExtFeature(Name, ExtLoc))
13043 return false;
13044
13045 return Error(ExtLoc, "unknown architectural extension: " + Name);
13046}
13047
13048// Define this matcher function after the auto-generated include so we
13049// have the match class enum definitions.
13050unsigned
13051ARMAsmParser::validateTargetOperandClass(const MCParsedAsmOperand &AsmOp,
13052 unsigned Kind) {
13053 const ARMOperand &Op = static_cast<const ARMOperand &>(AsmOp);
13054 // If the kind is a token for a literal immediate, check if our asm
13055 // operand matches. This is for InstAliases which have a fixed-value
13056 // immediate in the syntax.
13057 switch (Kind) {
13058 default: break;
13059 case MCK__HASH_0:
13060 if (Op.isImm())
13061 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
13062 if (CE->getValue() == 0)
13063 return Match_Success;
13064 break;
13065 case MCK__HASH_8:
13066 if (Op.isImm())
13067 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
13068 if (CE->getValue() == 8)
13069 return Match_Success;
13070 break;
13071 case MCK__HASH_16:
13072 if (Op.isImm())
13073 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
13074 if (CE->getValue() == 16)
13075 return Match_Success;
13076 break;
13077 case MCK_ModImm:
13078 if (Op.isImm()) {
13079 const MCExpr *SOExpr = Op.getImm();
13080 int64_t Value;
13081 if (!SOExpr->evaluateAsAbsolute(Value))
13082 return Match_Success;
13083 assert((Value >= std::numeric_limits<int32_t>::min() &&
13084 Value <= std::numeric_limits<uint32_t>::max()) &&
13085 "expression value must be representable in 32 bits");
13086 }
13087 break;
13088 case MCK_rGPR:
13089 if (hasV8Ops() && Op.isReg() && Op.getReg() == ARM::SP)
13090 return Match_Success;
13091 return Match_rGPR;
13092 }
13093 return Match_InvalidOperand;
13094}
13095
13096bool ARMAsmParser::isMnemonicVPTPredicable(StringRef Mnemonic,
13097 StringRef ExtraToken) {
13098 if (!hasMVE())
13099 return false;
13100
13101 if (MS.isVPTPredicableCDEInstr(Mnemonic) ||
13102 (Mnemonic.starts_with("vldrh") && Mnemonic != "vldrhi") ||
13103 (Mnemonic.starts_with("vmov") &&
13104 !(ExtraToken == ".f16" || ExtraToken == ".32" || ExtraToken == ".16" ||
13105 ExtraToken == ".8")) ||
13106 (Mnemonic.starts_with("vrint") && Mnemonic != "vrintr") ||
13107 (Mnemonic.starts_with("vstrh") && Mnemonic != "vstrhi"))
13108 return true;
13109
13110 const char *predicable_prefixes[] = {
13111 "vabav", "vabd", "vabs", "vadc", "vadd",
13112 "vaddlv", "vaddv", "vand", "vbic", "vbrsr",
13113 "vcadd", "vcls", "vclz", "vcmla", "vcmp",
13114 "vcmul", "vctp", "vcvt", "vddup", "vdup",
13115 "vdwdup", "veor", "vfma", "vfmas", "vfms",
13116 "vhadd", "vhcadd", "vhsub", "vidup", "viwdup",
13117 "vldrb", "vldrd", "vldrw", "vmax", "vmaxa",
13118 "vmaxav", "vmaxnm", "vmaxnma", "vmaxnmav", "vmaxnmv",
13119 "vmaxv", "vmin", "vminav", "vminnm", "vminnmav",
13120 "vminnmv", "vminv", "vmla", "vmladav", "vmlaldav",
13121 "vmlalv", "vmlas", "vmlav", "vmlsdav", "vmlsldav",
13122 "vmovlb", "vmovlt", "vmovnb", "vmovnt", "vmul",
13123 "vmvn", "vneg", "vorn", "vorr", "vpnot",
13124 "vpsel", "vqabs", "vqadd", "vqdmladh", "vqdmlah",
13125 "vqdmlash", "vqdmlsdh", "vqdmulh", "vqdmull", "vqmovn",
13126 "vqmovun", "vqneg", "vqrdmladh", "vqrdmlah", "vqrdmlash",
13127 "vqrdmlsdh", "vqrdmulh", "vqrshl", "vqrshrn", "vqrshrun",
13128 "vqshl", "vqshrn", "vqshrun", "vqsub", "vrev16",
13129 "vrev32", "vrev64", "vrhadd", "vrmlaldavh", "vrmlalvh",
13130 "vrmlsldavh", "vrmulh", "vrshl", "vrshr", "vrshrn",
13131 "vsbc", "vshl", "vshlc", "vshll", "vshr",
13132 "vshrn", "vsli", "vsri", "vstrb", "vstrd",
13133 "vstrw", "vsub"};
13134
13135 return any_of(predicable_prefixes, [&Mnemonic](const char *prefix) {
13136 return Mnemonic.starts_with(prefix);
13137 });
13138}
13139
13140std::unique_ptr<ARMOperand> ARMAsmParser::defaultCondCodeOp() {
13141 return ARMOperand::CreateCondCode(ARMCC::AL, SMLoc(), *this);
13142}
13143
13144std::unique_ptr<ARMOperand> ARMAsmParser::defaultCCOutOp() {
13145 return ARMOperand::CreateCCOut(0, SMLoc(), *this);
13146}
13147
13148std::unique_ptr<ARMOperand> ARMAsmParser::defaultVPTPredOp() {
13149 return ARMOperand::CreateVPTPred(ARMVCC::None, SMLoc(), *this);
13150}
static MCRegister MatchRegisterName(StringRef Name)
static const char * getSubtargetFeatureName(uint64_t Val)
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
static SDValue getCondCode(SelectionDAG &DAG, AArch64CC::CondCode CC)
Like SelectionDAG::getCondCode(), but for AArch64 condition codes.
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
static void applyMnemonicAliases(StringRef &Mnemonic, const FeatureBitset &Features, unsigned VariantID)
uint64_t uint64_t
uint64_t Imm
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
AMDGPU Reserve WWM Registers
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static std::string ARMMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS, unsigned VariantID=0)
static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing)
static bool instIsBreakpoint(const MCInst &Inst)
unsigned findCCOutInd(const OperandVector &Operands, unsigned MnemonicOpsEndInd)
static bool isDataTypeToken(StringRef Tok)
}
static MCRegister getNextRegister(MCRegister Reg)
static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing)
unsigned getRegListInd(const OperandVector &Operands, unsigned MnemonicOpsEndInd)
static bool isVectorPredicable(const MCInstrDesc &MCID)
static bool listContainsReg(const MCInst &Inst, unsigned OpNo, MCRegister Reg)
static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp)
MatchCoprocessorOperandName - Try to parse an coprocessor related instruction with a symbolic operand...
void removeCCOut(OperandVector &Operands, unsigned &MnemonicOpsEndInd)
static bool checkLowRegisterList(const MCInst &Inst, unsigned OpNo, MCRegister Reg, MCRegister HiReg, bool &containsReg)
static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARMAsmParser()
Force static initialization.
static int findFirstVectorPredOperandIdx(const MCInstrDesc &MCID)
static bool isThumbI8Relocation(MCParsedAsmOperand &MCOp)
bool operandsContainWide(OperandVector &Operands, unsigned MnemonicOpsEndInd)
void removeCondCode(OperandVector &Operands, unsigned &MnemonicOpsEndInd)
static bool insertNoDuplicates(SmallVectorImpl< std::pair< unsigned, MCRegister > > &Regs, unsigned Enc, MCRegister Reg)
static unsigned getMnemonicOpsEndInd(const OperandVector &Operands)
static bool isARMMCExpr(MCParsedAsmOperand &MCOp)
unsigned findCondCodeInd(const OperandVector &Operands, unsigned MnemonicOpsEndInd)
void removeVPTCondCode(OperandVector &Operands, unsigned &MnemonicOpsEndInd)
static bool isThumb(const MCSubtargetInfo &STI)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
static uint64_t scale(uint64_t Num, uint32_t N, uint32_t D)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static Register getFPReg(const CSKYSubtarget &STI)
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
#define op(i)
Value * getPointer(Value *Ptr)
static constexpr Value * getValue(Ty &ValueOrUse)
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define RegName(no)
SmallVector< MachineOperand, 4 > Cond
unsigned Opc
#define I(x, y, z)
Definition MD5.cpp:57
static bool containsReg(SmallSetVector< Register, 32 > LocalDefsV, const BitVector &LocalDefsP, Register Reg, const TargetRegisterInfo *TRI)
Check if target reg is contained in given lists, which are: LocalDefsV as given list for virtual regs...
Register Reg
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t High
#define P(N)
static constexpr MCPhysReg FPReg
static constexpr MCPhysReg SPReg
RISCVCC::CondCode CC
MachineRegisterInfo & MRI
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
SI Fold Operands
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
const char * Msg
This file contains some templates that are useful if you are working with the STL at all.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:479
This file implements the SmallBitVector class.
This file defines the SmallSet class.
This file defines the SmallVector class.
StringSet - A set-like wrapper for the StringMap.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
#define LLVM_DEBUG(...)
Definition Debug.h:119
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static const char * getRegisterName(MCRegister Reg, unsigned AltIdx=ARM::NoRegAltName)
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
Definition AsmLexer.h:122
LLVM_ABI SMLoc getLoc() const
Definition AsmLexer.cpp:31
int64_t getIntVal() const
Definition MCAsmMacro.h:108
bool isNot(TokenKind K) const
Definition MCAsmMacro.h:76
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
Definition MCAsmMacro.h:103
StringRef getStringContents() const
Get the contents of a string token (without quotes).
Definition MCAsmMacro.h:83
bool is(TokenKind K) const
Definition MCAsmMacro.h:75
LLVM_ABI SMLoc getEndLoc() const
Definition AsmLexer.cpp:33
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Definition MCAsmMacro.h:92
Implements a dense probed hash-table based set.
Definition DenseSet.h:283
Base class for user error types.
Definition Error.h:354
Container class for subtarget features.
constexpr bool test(unsigned I) const
void printExpr(raw_ostream &, const MCExpr &) const
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
Generic assembler parser interface, for use by target specific assembly parsers.
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
virtual bool parseEscapedString(std::string &Data)=0
Parse the current token as a string which may include escaped characters and return the string conten...
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual bool parseIdentifier(StringRef &Res)=0
Parse an identifier or string (as a quoted identifier) and set Res to the identifier contents.
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
virtual void Note(SMLoc L, const Twine &Msg, SMRange Range={})=0
Emit a note at the location L, with the message Msg.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:339
int64_t getValue() const
Definition MCExpr.h:168
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
@ Constant
Constant expressions.
Definition MCExpr.h:39
SMLoc getLoc() const
Definition MCExpr.h:83
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:187
unsigned getNumOperands() const
Definition MCInst.h:211
void setLoc(SMLoc loc)
Definition MCInst.h:206
unsigned getOpcode() const
Definition MCInst.h:201
LLVM_ABI void dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer=nullptr, StringRef Separator=" ", const MCContext *Ctx=nullptr) const
Dump the MCInst as prettily as possible using the additional MC structures, if given.
Definition MCInst.cpp:90
iterator insert(iterator I, const MCOperand &Op)
Definition MCInst.h:231
void addOperand(const MCOperand Op)
Definition MCInst.h:214
iterator begin()
Definition MCInst.h:226
void setOpcode(unsigned Op)
Definition MCInst.h:200
const MCOperand & getOperand(unsigned i) const
Definition MCInst.h:209
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
bool isIndirectBranch() const
Return true if this is an indirect branch, such as a branch through a register.
int findFirstPredOperandIdx() const
Find the index of the first operand in the operand list that is used to represent the predicate.
bool hasOptionalDef() const
Set if this instruction has an optional definition, e.g.
LLVM_ABI bool hasDefOfPhysReg(const MCInst &MI, MCRegister Reg, const MCRegisterInfo &RI) const
Return true if this instruction defines the specified physical register, either explicitly or implici...
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
bool isPredicable() const
Return true if this instruction has a predicate operand that controls execution.
bool isCall() const
Return true if the instruction is a call.
bool isTerminator() const
Returns true if this instruction part of the terminator for a basic block.
bool isReturn() const
Return true if the instruction is a return.
static MCOperand createExpr(const MCExpr *Val)
Definition MCInst.h:165
int64_t getImm() const
Definition MCInst.h:83
static MCOperand createReg(MCRegister Reg)
Definition MCInst.h:137
static MCOperand createImm(int64_t Val)
Definition MCInst.h:144
bool isImm() const
Definition MCInst.h:65
bool isReg() const
Definition MCInst.h:64
MCRegister getReg() const
Returns the register number.
Definition MCInst.h:72
const MCExpr * getExpr() const
Definition MCInst.h:117
bool isExpr() const
Definition MCInst.h:68
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
virtual SMLoc getStartLoc() const =0
getStartLoc - Get the location of the first token of this operand.
virtual bool isReg() const =0
isReg - Is this a register operand?
virtual MCRegister getReg() const =0
virtual SMLoc getEndLoc() const =0
getEndLoc - Get the location of the last token of this operand.
MCRegisterClass - Base class of TargetRegisterClass.
unsigned getID() const
getID() - Return the register class ID number.
MCRegister getRegister(unsigned i) const
getRegister - Return the specified register in the class.
unsigned getNumRegs() const
getNumRegs - Return the number of registers in this class.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers and target specific virtual registers.
Definition MCRegister.h:42
constexpr unsigned id() const
Definition MCRegister.h:85
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:743
Streaming machine code generation interface.
Definition MCStreamer.h:221
MCTargetStreamer * getTargetStreamer()
Definition MCStreamer.h:339
Generic base class for all target subtargets.
const FeatureBitset & getFeatureBits() const
const FeatureBitset & ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
const FeatureBitset & ApplyFeatureFlag(StringRef FS)
Apply a feature flag and return the re-computed feature bits, including all feature bits implied by t...
void setDefaultFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
Set the features to the default for the given CPU and TuneCPU, with ano appended feature string.
const FeatureBitset & ClearFeatureBitsTransitively(const FeatureBitset &FB)
const FeatureBitset & SetFeatureBitsTransitively(const FeatureBitset &FB)
Set/clear additional feature bits, including all other bits they imply.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:210
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Target specific streamer interface.
Definition MCStreamer.h:94
MCStreamer & getStreamer()
Definition MCStreamer.h:102
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
Ternary parse status returned by various parse* methods.
constexpr bool isFailure() const
static constexpr StatusTy Failure
constexpr bool isSuccess() const
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
Represents a location in source code.
Definition SMLoc.h:22
static SMLoc getFromPointer(const char *Ptr)
Definition SMLoc.h:35
constexpr const char * getPointer() const
Definition SMLoc.h:33
Represents a range in source code.
Definition SMLoc.h:47
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition SmallSet.h:176
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition SmallSet.h:184
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
iterator end()
Definition StringMap.h:214
iterator find(StringRef Key)
Definition StringMap.h:227
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition StringMap.h:275
void erase(iterator I)
Definition StringMap.h:418
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition StringMap.h:311
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static constexpr size_t npos
Definition StringRef.h:58
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:589
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:258
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Definition StringRef.h:712
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
LLVM_ABI std::string lower() const
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition StringRef.h:270
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
Definition StringRef.h:170
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition StringSet.h:27
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition StringSet.h:41
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition DenseSet.h:183
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
LLVM_ABI const TagNameMap & getARMAttributeTags()
static CondCodes getOppositeCondition(CondCodes CC)
Definition ARMBaseInfo.h:49
@ ThumbArithFlagSetting
unsigned getSORegOffset(unsigned Op)
int getSOImmVal(unsigned Arg)
getSOImmVal - Given a 32-bit immediate, if it is something that can fit into an shifter_operand immed...
int getFP32Imm(const APInt &Imm)
getFP32Imm - Return an 8-bit floating-point version of the 32-bit floating-point value.
unsigned encodeNEONi16splat(unsigned Value)
float getFPImmFloat(unsigned Imm)
int getT2SOImmVal(unsigned Arg)
getT2SOImmVal - Given a 32-bit immediate, if it is something that can fit into a Thumb-2 shifter_oper...
unsigned getAM2Opc(AddrOpc Opc, unsigned Imm12, ShiftOpc SO, unsigned IdxMode=0)
unsigned getAM5Opc(AddrOpc Opc, unsigned char Offset)
getAM5Opc - This function encodes the addrmode5 opc field.
ShiftOpc getSORegShOp(unsigned Op)
bool isNEONi16splat(unsigned Value)
Checks if Value is a correct immediate for instructions like VBIC/VORR.
unsigned getAM5FP16Opc(AddrOpc Opc, unsigned char Offset)
getAM5FP16Opc - This function encodes the addrmode5fp16 opc field.
unsigned getAM3Opc(AddrOpc Opc, unsigned char Offset, unsigned IdxMode=0)
getAM3Opc - This function encodes the addrmode3 opc field.
bool isNEONi32splat(unsigned Value)
Checks if Value is a correct immediate for instructions like VBIC/VORR.
unsigned getSORegOpc(ShiftOpc ShOp, unsigned Imm)
StringRef getShiftOpcStr(ShiftOpc Op)
unsigned encodeNEONi32splat(unsigned Value)
Encode NEON 32 bits Splat immediate for instructions like VBIC/VORR.
static const char * IFlagsToString(unsigned val)
Definition ARMBaseInfo.h:37
LLVM_ABI bool getFPUFeatures(FPUKind FPUKind, std::vector< StringRef > &Features)
LLVM_ABI StringRef getArchName(ArchKind AK)
LLVM_ABI uint64_t parseArchExt(StringRef ArchExt)
LLVM_ABI ArchKind parseArch(StringRef Arch)
bool isVpred(OperandType op)
uint16_t Specifier
LLVM_ABI FPUKind parseFPU(StringRef FPU)
bool isCDECoproc(size_t Coproc, const MCSubtargetInfo &STI)
@ D16
Only 16 D registers.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ Entry
Definition COFF.h:862
LLVM_ABI std::optional< unsigned > attrTypeFromString(StringRef tag, TagNameMap tagNameMap)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
LLVM_ABI bool parseAssignmentExpression(StringRef Name, bool allow_redef, MCAsmParser &Parser, MCSymbol *&Symbol, const MCExpr *&Value)
Parse a value expression and return whether it can be assigned to a symbol with the given name.
@ CE
Windows NT (Windows on ARM)
Definition MCAsmInfo.h:51
LLVM_ABI TargetOptions getTargetOptions(const cl::LibraryOptionsContext &LibraryOptions, const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
NodeAddr< FuncNode * > Func
Definition RDFGraph.h:393
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
Definition SFrame.h:77
This is an optimization pass for GlobalISel generic memory operations.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
Definition Threading.h:280
static const char * ARMVPTPredToString(ARMVCC::VPTCodes CC)
@ Offset
Definition DWP.cpp:577
@ Length
Definition DWP.cpp:577
constexpr T rotr(T V, int R)
Definition bit.h:399
static bool isMem(const MachineInstr &MI, unsigned Op)
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
static bool isARMLowRegister(MCRegister Reg)
isARMLowRegister - Returns true if the register is a low register (r0-r7).
@ Load
The value being inserted comes from a load (InsertElement only).
Target & getTheThumbBETarget()
static unsigned ARMCondCodeFromString(StringRef CC)
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
Definition bit.h:156
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition bit.h:204
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition STLExtras.h:1986
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
bool IsCPSRDead< MCInst >(const MCInst *Instr)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
static bool isValidCoprocessorNumber(unsigned Num, const FeatureBitset &featureBits)
isValidCoprocessorNumber - decide whether an explicit coprocessor number is legal in generic instruct...
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1788
static unsigned ARMVectorCondCodeFromString(StringRef CC)
static const char * ARMCondCodeToString(ARMCC::CondCodes CC)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
Definition InstrProf.h:147
Target & getTheARMLETarget()
Target & getTheARMBETarget()
Target & getTheThumbLETarget()
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:881
#define N
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...