blob: f7d397b7f02ed1625678b899b293f5f1dab1962e [file] [log] [blame]
Kevin Enderbyccab3172009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Logan Chien8cbb80d2013-10-28 17:51:12 +000010#include "ARMFPUName.h"
Amara Emerson52cfb6a2013-10-03 09:31:51 +000011#include "ARMFeatures.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000012#include "MCTargetDesc/ARMAddressingModes.h"
Logan Chien439e8f92013-12-11 17:16:25 +000013#include "MCTargetDesc/ARMArchName.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000014#include "MCTargetDesc/ARMBaseInfo.h"
15#include "MCTargetDesc/ARMMCExpr.h"
Evan Cheng11424442011-07-26 00:24:13 +000016#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000017#include "llvm/ADT/SmallVector.h"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000018#include "llvm/ADT/StringExtras.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000019#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000020#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000021#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000022#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000023#include "llvm/MC/MCContext.h"
Tim Northoverd6a729b2014-01-06 14:28:05 +000024#include "llvm/MC/MCDisassembler.h"
Jack Carter718da0b2013-01-30 02:24:33 +000025#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000026#include "llvm/MC/MCExpr.h"
27#include "llvm/MC/MCInst.h"
28#include "llvm/MC/MCInstrDesc.h"
Joey Gouly0e76fa72013-09-12 10:28:05 +000029#include "llvm/MC/MCInstrInfo.h"
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +000030#include "llvm/MC/MCObjectFileInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000031#include "llvm/MC/MCParser/MCAsmLexer.h"
32#include "llvm/MC/MCParser/MCAsmParser.h"
33#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
34#include "llvm/MC/MCRegisterInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000035#include "llvm/MC/MCSection.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000036#include "llvm/MC/MCStreamer.h"
37#include "llvm/MC/MCSubtargetInfo.h"
David Peixottoe407d092013-12-19 18:12:36 +000038#include "llvm/MC/MCSymbol.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000039#include "llvm/MC/MCTargetAsmParser.h"
Saleem Abdulrasool278a9f42014-01-19 08:25:27 +000040#include "llvm/Support/ARMBuildAttributes.h"
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000041#include "llvm/Support/ARMEHABI.h"
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +000042#include "llvm/Support/COFF.h"
Tim Northoverd6a729b2014-01-06 14:28:05 +000043#include "llvm/Support/Debug.h"
Jack Carter718da0b2013-01-30 02:24:33 +000044#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000045#include "llvm/Support/MathExtras.h"
46#include "llvm/Support/SourceMgr.h"
47#include "llvm/Support/TargetRegistry.h"
48#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000049
Kevin Enderbyccab3172009-09-15 00:27:25 +000050using namespace llvm;
51
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000052namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000053
54class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000055
Jim Grosbach04945c42011-12-02 00:35:16 +000056enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000057
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000058class UnwindContext {
59 MCAsmParser &Parser;
60
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000061 typedef SmallVector<SMLoc, 4> Locs;
62
63 Locs FnStartLocs;
64 Locs CantUnwindLocs;
65 Locs PersonalityLocs;
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000066 Locs PersonalityIndexLocs;
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000067 Locs HandlerDataLocs;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000068 int FPReg;
69
70public:
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +000071 UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {}
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000072
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000073 bool hasFnStart() const { return !FnStartLocs.empty(); }
74 bool cantUnwind() const { return !CantUnwindLocs.empty(); }
75 bool hasHandlerData() const { return !HandlerDataLocs.empty(); }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000076 bool hasPersonality() const {
77 return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty());
78 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000079
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000080 void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); }
81 void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); }
82 void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); }
83 void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000084 void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000085
86 void saveFPReg(int Reg) { FPReg = Reg; }
87 int getFPReg() const { return FPReg; }
88
89 void emitFnStartLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000090 for (Locs::const_iterator FI = FnStartLocs.begin(), FE = FnStartLocs.end();
91 FI != FE; ++FI)
92 Parser.Note(*FI, ".fnstart was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000093 }
94 void emitCantUnwindLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000095 for (Locs::const_iterator UI = CantUnwindLocs.begin(),
96 UE = CantUnwindLocs.end(); UI != UE; ++UI)
97 Parser.Note(*UI, ".cantunwind was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000098 }
99 void emitHandlerDataLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000100 for (Locs::const_iterator HI = HandlerDataLocs.begin(),
101 HE = HandlerDataLocs.end(); HI != HE; ++HI)
102 Parser.Note(*HI, ".handlerdata was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000103 }
104 void emitPersonalityLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000105 for (Locs::const_iterator PI = PersonalityLocs.begin(),
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000106 PE = PersonalityLocs.end(),
107 PII = PersonalityIndexLocs.begin(),
108 PIE = PersonalityIndexLocs.end();
109 PI != PE || PII != PIE;) {
110 if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer()))
111 Parser.Note(*PI++, ".personality was specified here");
112 else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer()))
113 Parser.Note(*PII++, ".personalityindex was specified here");
114 else
115 llvm_unreachable(".personality and .personalityindex cannot be "
116 "at the same location");
117 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000118 }
119
120 void reset() {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000121 FnStartLocs = Locs();
122 CantUnwindLocs = Locs();
123 PersonalityLocs = Locs();
124 HandlerDataLocs = Locs();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000125 PersonalityIndexLocs = Locs();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000126 FPReg = ARM::SP;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000127 }
128};
129
Evan Cheng11424442011-07-26 00:24:13 +0000130class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +0000131 MCSubtargetInfo &STI;
Joey Gouly0e76fa72013-09-12 10:28:05 +0000132 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000133 const MCRegisterInfo *MRI;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000134 UnwindContext UC;
David Peixottoe407d092013-12-19 18:12:36 +0000135
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000136 ARMTargetStreamer &getTargetStreamer() {
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +0000137 assert(getParser().getStreamer().getTargetStreamer() &&
138 "do not have a target streamer");
Rafael Espindola4a1a3602014-01-14 01:21:46 +0000139 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000140 return static_cast<ARMTargetStreamer &>(TS);
141 }
142
Jim Grosbachab5830e2011-12-14 02:16:11 +0000143 // Map of register aliases registers via the .req directive.
144 StringMap<unsigned> RegisterReqs;
145
Tim Northover1744d0a2013-10-25 12:49:50 +0000146 bool NextSymbolIsThumb;
147
Jim Grosbached16ec42011-08-29 22:24:09 +0000148 struct {
149 ARMCC::CondCodes Cond; // Condition for IT block.
150 unsigned Mask:4; // Condition mask for instructions.
151 // Starting at first 1 (from lsb).
152 // '1' condition as indicated in IT.
153 // '0' inverse of condition (else).
154 // Count of instructions in IT block is
155 // 4 - trailingzeroes(mask)
156
157 bool FirstCond; // Explicit flag for when we're parsing the
158 // First instruction in the IT block. It's
159 // implied in the mask, so needs special
160 // handling.
161
162 unsigned CurPosition; // Current position in parsing of IT
163 // block. In range [0,3]. Initialized
164 // according to count of instructions in block.
165 // ~0U if no active IT block.
166 } ITState;
Saleem Abdulrasool3a239172014-12-18 05:24:38 +0000167 bool inITBlock() { return ITState.CurPosition != ~0U; }
168 bool lastInITBlock() {
169 return ITState.CurPosition == 4 - countTrailingZeros(ITState.Mask);
170 }
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000171 void forwardITPosition() {
172 if (!inITBlock()) return;
173 // Move to the next instruction in the IT block, if there is one. If not,
174 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000175 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000176 if (++ITState.CurPosition == 5 - TZ)
177 ITState.CurPosition = ~0U; // Done with the IT block after this.
178 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000179
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000180 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000181 return getParser().Note(L, Msg, Ranges);
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000182 }
Benjamin Kramer673824b2012-04-15 17:04:27 +0000183 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000184 ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000185 return getParser().Warning(L, Msg, Ranges);
Benjamin Kramer673824b2012-04-15 17:04:27 +0000186 }
187 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000188 ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000189 return getParser().Error(L, Msg, Ranges);
Benjamin Kramer673824b2012-04-15 17:04:27 +0000190 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000191
Saleem Abdulrasool3a239172014-12-18 05:24:38 +0000192 bool validatetLDMRegList(MCInst Inst, const OperandVector &Operands,
Jyoti Allur5a139142015-01-14 10:48:16 +0000193 unsigned ListNo, bool IsARPop = false);
Saleem Abdulrasool3a239172014-12-18 05:24:38 +0000194 bool validatetSTMRegList(MCInst Inst, const OperandVector &Operands,
195 unsigned ListNo);
196
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000197 int tryParseRegister();
David Blaikie960ea3f2014-06-08 16:18:35 +0000198 bool tryParseRegisterWithWriteBack(OperandVector &);
199 int tryParseShiftRegister(OperandVector &);
200 bool parseRegisterList(OperandVector &);
201 bool parseMemory(OperandVector &);
202 bool parseOperand(OperandVector &, StringRef Mnemonic);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000203 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000204 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
205 unsigned &ShiftAmount);
Saleem Abdulrasool38976512014-02-23 06:22:09 +0000206 bool parseLiteralValues(unsigned Size, SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000207 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000208 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000209 bool parseDirectiveThumbFunc(SMLoc L);
210 bool parseDirectiveCode(SMLoc L);
211 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000212 bool parseDirectiveReq(StringRef Name, SMLoc L);
213 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000214 bool parseDirectiveArch(SMLoc L);
215 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000216 bool parseDirectiveCPU(SMLoc L);
217 bool parseDirectiveFPU(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000218 bool parseDirectiveFnStart(SMLoc L);
219 bool parseDirectiveFnEnd(SMLoc L);
220 bool parseDirectiveCantUnwind(SMLoc L);
221 bool parseDirectivePersonality(SMLoc L);
222 bool parseDirectiveHandlerData(SMLoc L);
223 bool parseDirectiveSetFP(SMLoc L);
224 bool parseDirectivePad(SMLoc L);
225 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000226 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
David Peixotto80c083a2013-12-19 18:26:07 +0000227 bool parseDirectiveLtorg(SMLoc L);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +0000228 bool parseDirectiveEven(SMLoc L);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000229 bool parseDirectivePersonalityIndex(SMLoc L);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000230 bool parseDirectiveUnwindRaw(SMLoc L);
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000231 bool parseDirectiveTLSDescSeq(SMLoc L);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000232 bool parseDirectiveMovSP(SMLoc L);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000233 bool parseDirectiveObjectArch(SMLoc L);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +0000234 bool parseDirectiveArchExtension(SMLoc L);
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +0000235 bool parseDirectiveAlign(SMLoc L);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +0000236 bool parseDirectiveThumbSet(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000237
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000238 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000239 bool &CarrySetting, unsigned &ProcessorIMod,
240 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000241 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
242 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000243 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000244
Evan Cheng4d1ca962011-07-08 01:53:10 +0000245 bool isThumb() const {
246 // FIXME: Can tablegen auto-generate this?
Michael Kupersteinefd7a962015-02-19 11:38:11 +0000247 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000248 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000249 bool isThumbOne() const {
Michael Kupersteinefd7a962015-02-19 11:38:11 +0000250 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000251 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000252 bool isThumbTwo() const {
Michael Kupersteinefd7a962015-02-19 11:38:11 +0000253 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000254 }
Tim Northovera2292d02013-06-10 23:20:58 +0000255 bool hasThumb() const {
Michael Kupersteinefd7a962015-02-19 11:38:11 +0000256 return STI.getFeatureBits() & ARM::HasV4TOps;
Tim Northovera2292d02013-06-10 23:20:58 +0000257 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000258 bool hasV6Ops() const {
Michael Kupersteinefd7a962015-02-19 11:38:11 +0000259 return STI.getFeatureBits() & ARM::HasV6Ops;
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000260 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000261 bool hasV6MOps() const {
Michael Kupersteinefd7a962015-02-19 11:38:11 +0000262 return STI.getFeatureBits() & ARM::HasV6MOps;
Tim Northoverf86d1f02013-10-07 11:10:47 +0000263 }
James Molloy21efa7d2011-09-28 14:21:38 +0000264 bool hasV7Ops() const {
Michael Kupersteinefd7a962015-02-19 11:38:11 +0000265 return STI.getFeatureBits() & ARM::HasV7Ops;
James Molloy21efa7d2011-09-28 14:21:38 +0000266 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000267 bool hasV8Ops() const {
Michael Kupersteinefd7a962015-02-19 11:38:11 +0000268 return STI.getFeatureBits() & ARM::HasV8Ops;
Joey Goulyb3f550e2013-06-26 16:58:26 +0000269 }
Tim Northovera2292d02013-06-10 23:20:58 +0000270 bool hasARM() const {
Michael Kupersteinefd7a962015-02-19 11:38:11 +0000271 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
Tim Northovera2292d02013-06-10 23:20:58 +0000272 }
Renato Golin92c816c2014-09-01 11:25:07 +0000273 bool hasThumb2DSP() const {
Michael Kupersteinefd7a962015-02-19 11:38:11 +0000274 return STI.getFeatureBits() & ARM::FeatureDSPThumb2;
Renato Golin92c816c2014-09-01 11:25:07 +0000275 }
Oliver Stannard9e89d8c2014-11-05 12:06:39 +0000276 bool hasD16() const {
Michael Kupersteinefd7a962015-02-19 11:38:11 +0000277 return STI.getFeatureBits() & ARM::FeatureD16;
Oliver Stannard9e89d8c2014-11-05 12:06:39 +0000278 }
Tim Northovera2292d02013-06-10 23:20:58 +0000279
Evan Cheng284b4672011-07-08 22:36:29 +0000280 void SwitchMode() {
Tim Northover26bb14e2014-08-18 11:49:42 +0000281 uint64_t FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
Evan Cheng91111d22011-07-09 05:47:46 +0000282 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000283 }
James Molloy21efa7d2011-09-28 14:21:38 +0000284 bool isMClass() const {
Michael Kupersteinefd7a962015-02-19 11:38:11 +0000285 return STI.getFeatureBits() & ARM::FeatureMClass;
James Molloy21efa7d2011-09-28 14:21:38 +0000286 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000287
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000288 /// @name Auto-generated Match Functions
289 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000290
Chris Lattner3e4582a2010-09-06 19:11:01 +0000291#define GET_ASSEMBLER_HEADER
292#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000293
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000294 /// }
295
David Blaikie960ea3f2014-06-08 16:18:35 +0000296 OperandMatchResultTy parseITCondCode(OperandVector &);
297 OperandMatchResultTy parseCoprocNumOperand(OperandVector &);
298 OperandMatchResultTy parseCoprocRegOperand(OperandVector &);
299 OperandMatchResultTy parseCoprocOptionOperand(OperandVector &);
300 OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &);
301 OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &);
302 OperandMatchResultTy parseProcIFlagsOperand(OperandVector &);
303 OperandMatchResultTy parseMSRMaskOperand(OperandVector &);
Tim Northoveree843ef2014-08-15 10:47:12 +0000304 OperandMatchResultTy parseBankedRegOperand(OperandVector &);
David Blaikie960ea3f2014-06-08 16:18:35 +0000305 OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low,
306 int High);
307 OperandMatchResultTy parsePKHLSLImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000308 return parsePKHImm(O, "lsl", 0, 31);
309 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000310 OperandMatchResultTy parsePKHASRImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000311 return parsePKHImm(O, "asr", 1, 32);
312 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000313 OperandMatchResultTy parseSetEndImm(OperandVector &);
314 OperandMatchResultTy parseShifterImm(OperandVector &);
315 OperandMatchResultTy parseRotImm(OperandVector &);
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000316 OperandMatchResultTy parseModImm(OperandVector &);
David Blaikie960ea3f2014-06-08 16:18:35 +0000317 OperandMatchResultTy parseBitfield(OperandVector &);
318 OperandMatchResultTy parsePostIdxReg(OperandVector &);
319 OperandMatchResultTy parseAM3Offset(OperandVector &);
320 OperandMatchResultTy parseFPImm(OperandVector &);
321 OperandMatchResultTy parseVectorList(OperandVector &);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000322 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
323 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000324
325 // Asm Match Converter Methods
David Blaikie960ea3f2014-06-08 16:18:35 +0000326 void cvtThumbMultiply(MCInst &Inst, const OperandVector &);
327 void cvtThumbBranches(MCInst &Inst, const OperandVector &);
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +0000328
David Blaikie960ea3f2014-06-08 16:18:35 +0000329 bool validateInstruction(MCInst &Inst, const OperandVector &Ops);
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +0000330 bool processInstruction(MCInst &Inst, const OperandVector &Ops, MCStreamer &Out);
David Blaikie960ea3f2014-06-08 16:18:35 +0000331 bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands);
332 bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands);
333
Kevin Enderbyccab3172009-09-15 00:27:25 +0000334public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000335 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000336 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000337 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000338 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000339 Match_RequiresThumb2,
340#define GET_OPERAND_DIAGNOSTIC_TYPES
341#include "ARMGenAsmMatcher.inc"
342
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000343 };
344
David Blaikie9f380a32015-03-16 18:06:57 +0000345 ARMAsmParser(MCSubtargetInfo &STI, MCAsmParser &Parser,
Rafael Espindola961d4692014-11-11 05:18:41 +0000346 const MCInstrInfo &MII, const MCTargetOptions &Options)
David Blaikie9f380a32015-03-16 18:06:57 +0000347 : STI(STI), MII(MII), UC(Parser) {
348 MCAsmParserExtension::Initialize(Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000349
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000350 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000351 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000352
Evan Cheng4d1ca962011-07-08 01:53:10 +0000353 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000354 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000355
356 // Not in an ITBlock to start with.
357 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000358
359 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000360 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000361
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000362 // Implementation of the MCTargetAsmParser interface:
Craig Topperca7e3e52014-03-10 03:19:03 +0000363 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
David Blaikie960ea3f2014-06-08 16:18:35 +0000364 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
365 SMLoc NameLoc, OperandVector &Operands) override;
Craig Topperca7e3e52014-03-10 03:19:03 +0000366 bool ParseDirective(AsmToken DirectiveID) override;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000367
David Blaikie960ea3f2014-06-08 16:18:35 +0000368 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
Craig Topperca7e3e52014-03-10 03:19:03 +0000369 unsigned Kind) override;
370 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000371
Chad Rosier49963552012-10-13 00:26:04 +0000372 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
David Blaikie960ea3f2014-06-08 16:18:35 +0000373 OperandVector &Operands, MCStreamer &Out,
Tim Northover26bb14e2014-08-18 11:49:42 +0000374 uint64_t &ErrorInfo,
Craig Topperca7e3e52014-03-10 03:19:03 +0000375 bool MatchingInlineAsm) override;
376 void onLabelParsed(MCSymbol *Symbol) override;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000377};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000378} // end anonymous namespace
379
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000380namespace {
381
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000382/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000383/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000384class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000385 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000386 k_CondCode,
387 k_CCOut,
388 k_ITCondMask,
389 k_CoprocNum,
390 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000391 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000392 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000393 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000394 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000395 k_Memory,
396 k_PostIndexRegister,
397 k_MSRMask,
Tim Northoveree843ef2014-08-15 10:47:12 +0000398 k_BankedReg,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000399 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000400 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000401 k_Register,
402 k_RegisterList,
403 k_DPRRegisterList,
404 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000405 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000406 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000407 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000408 k_ShiftedRegister,
409 k_ShiftedImmediate,
410 k_ShifterImmediate,
411 k_RotateImmediate,
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000412 k_ModifiedImmediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000413 k_BitfieldDescriptor,
414 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000415 } Kind;
416
Kevin Enderby488f20b2014-04-10 20:18:58 +0000417 SMLoc StartLoc, EndLoc, AlignmentLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000418 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000419
Eric Christopher8996c5d2013-03-15 00:42:55 +0000420 struct CCOp {
421 ARMCC::CondCodes Val;
422 };
423
424 struct CopOp {
425 unsigned Val;
426 };
427
428 struct CoprocOptionOp {
429 unsigned Val;
430 };
431
432 struct ITMaskOp {
433 unsigned Mask:4;
434 };
435
436 struct MBOptOp {
437 ARM_MB::MemBOpt Val;
438 };
439
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000440 struct ISBOptOp {
441 ARM_ISB::InstSyncBOpt Val;
442 };
443
Eric Christopher8996c5d2013-03-15 00:42:55 +0000444 struct IFlagsOp {
445 ARM_PROC::IFlags Val;
446 };
447
448 struct MMaskOp {
449 unsigned Val;
450 };
451
Tim Northoveree843ef2014-08-15 10:47:12 +0000452 struct BankedRegOp {
453 unsigned Val;
454 };
455
Eric Christopher8996c5d2013-03-15 00:42:55 +0000456 struct TokOp {
457 const char *Data;
458 unsigned Length;
459 };
460
461 struct RegOp {
462 unsigned RegNum;
463 };
464
465 // A vector register list is a sequential list of 1 to 4 registers.
466 struct VectorListOp {
467 unsigned RegNum;
468 unsigned Count;
469 unsigned LaneIndex;
470 bool isDoubleSpaced;
471 };
472
473 struct VectorIndexOp {
474 unsigned Val;
475 };
476
477 struct ImmOp {
478 const MCExpr *Val;
479 };
480
481 /// Combined record for all forms of ARM address expressions.
482 struct MemoryOp {
483 unsigned BaseRegNum;
484 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
485 // was specified.
486 const MCConstantExpr *OffsetImm; // Offset immediate value
487 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
488 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
489 unsigned ShiftImm; // shift for OffsetReg.
490 unsigned Alignment; // 0 = no alignment specified
491 // n = alignment in bytes (2, 4, 8, 16, or 32)
492 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
493 };
494
495 struct PostIdxRegOp {
496 unsigned RegNum;
497 bool isAdd;
498 ARM_AM::ShiftOpc ShiftTy;
499 unsigned ShiftImm;
500 };
501
502 struct ShifterImmOp {
503 bool isASR;
504 unsigned Imm;
505 };
506
507 struct RegShiftedRegOp {
508 ARM_AM::ShiftOpc ShiftTy;
509 unsigned SrcReg;
510 unsigned ShiftReg;
511 unsigned ShiftImm;
512 };
513
514 struct RegShiftedImmOp {
515 ARM_AM::ShiftOpc ShiftTy;
516 unsigned SrcReg;
517 unsigned ShiftImm;
518 };
519
520 struct RotImmOp {
521 unsigned Imm;
522 };
523
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000524 struct ModImmOp {
525 unsigned Bits;
526 unsigned Rot;
527 };
528
Eric Christopher8996c5d2013-03-15 00:42:55 +0000529 struct BitfieldOp {
530 unsigned LSB;
531 unsigned Width;
532 };
533
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000534 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000535 struct CCOp CC;
536 struct CopOp Cop;
537 struct CoprocOptionOp CoprocOption;
538 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000539 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000540 struct ITMaskOp ITMask;
541 struct IFlagsOp IFlags;
542 struct MMaskOp MMask;
Tim Northoveree843ef2014-08-15 10:47:12 +0000543 struct BankedRegOp BankedReg;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000544 struct TokOp Tok;
545 struct RegOp Reg;
546 struct VectorListOp VectorList;
547 struct VectorIndexOp VectorIndex;
548 struct ImmOp Imm;
549 struct MemoryOp Memory;
550 struct PostIdxRegOp PostIdxReg;
551 struct ShifterImmOp ShifterImm;
552 struct RegShiftedRegOp RegShiftedReg;
553 struct RegShiftedImmOp RegShiftedImm;
554 struct RotImmOp RotImm;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000555 struct ModImmOp ModImm;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000556 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000557 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000558
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000559public:
David Blaikie960ea3f2014-06-08 16:18:35 +0000560 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000561 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
562 Kind = o.Kind;
563 StartLoc = o.StartLoc;
564 EndLoc = o.EndLoc;
565 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000566 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000567 CC = o.CC;
568 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000569 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000570 ITMask = o.ITMask;
571 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000572 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000573 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000574 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000575 case k_CCOut:
576 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000577 Reg = o.Reg;
578 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000579 case k_RegisterList:
580 case k_DPRRegisterList:
581 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000582 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000583 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000584 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000585 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000586 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000587 VectorList = o.VectorList;
588 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000589 case k_CoprocNum:
590 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000591 Cop = o.Cop;
592 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000593 case k_CoprocOption:
594 CoprocOption = o.CoprocOption;
595 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000596 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000597 Imm = o.Imm;
598 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000599 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000600 MBOpt = o.MBOpt;
601 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000602 case k_InstSyncBarrierOpt:
603 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000604 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000605 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000606 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000607 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000608 PostIdxReg = o.PostIdxReg;
609 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000610 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000611 MMask = o.MMask;
612 break;
Tim Northoveree843ef2014-08-15 10:47:12 +0000613 case k_BankedReg:
614 BankedReg = o.BankedReg;
615 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000616 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000617 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000618 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000619 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000620 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000621 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000622 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000623 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000624 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000625 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000626 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000627 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000628 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000629 RotImm = o.RotImm;
630 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000631 case k_ModifiedImmediate:
632 ModImm = o.ModImm;
633 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000634 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000635 Bitfield = o.Bitfield;
636 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000637 case k_VectorIndex:
638 VectorIndex = o.VectorIndex;
639 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000640 }
641 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000642
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000643 /// getStartLoc - Get the location of the first token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000644 SMLoc getStartLoc() const override { return StartLoc; }
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000645 /// getEndLoc - Get the location of the last token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000646 SMLoc getEndLoc() const override { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000647 /// getLocRange - Get the range between the first and last token of this
648 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000649 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
650
Kevin Enderby488f20b2014-04-10 20:18:58 +0000651 /// getAlignmentLoc - Get the location of the Alignment token of this operand.
652 SMLoc getAlignmentLoc() const {
653 assert(Kind == k_Memory && "Invalid access!");
654 return AlignmentLoc;
655 }
656
Daniel Dunbard8042b72010-08-11 06:36:53 +0000657 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000658 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000659 return CC.Val;
660 }
661
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000662 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000663 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000664 return Cop.Val;
665 }
666
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000667 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000668 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000669 return StringRef(Tok.Data, Tok.Length);
670 }
671
Craig Topperca7e3e52014-03-10 03:19:03 +0000672 unsigned getReg() const override {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000673 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000674 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000675 }
676
Bill Wendlingbed94652010-11-09 23:28:44 +0000677 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000678 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
679 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000680 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000681 }
682
Kevin Enderbyf5079942009-10-13 22:19:02 +0000683 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000684 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000685 return Imm.Val;
686 }
687
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000688 unsigned getVectorIndex() const {
689 assert(Kind == k_VectorIndex && "Invalid access!");
690 return VectorIndex.Val;
691 }
692
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000693 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000694 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000695 return MBOpt.Val;
696 }
697
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000698 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
699 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
700 return ISBOpt.Val;
701 }
702
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000703 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000704 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000705 return IFlags.Val;
706 }
707
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000708 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000709 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000710 return MMask.Val;
711 }
712
Tim Northoveree843ef2014-08-15 10:47:12 +0000713 unsigned getBankedReg() const {
714 assert(Kind == k_BankedReg && "Invalid access!");
715 return BankedReg.Val;
716 }
717
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000718 bool isCoprocNum() const { return Kind == k_CoprocNum; }
719 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000720 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000721 bool isCondCode() const { return Kind == k_CondCode; }
722 bool isCCOut() const { return Kind == k_CCOut; }
723 bool isITMask() const { return Kind == k_ITCondMask; }
724 bool isITCondCode() const { return Kind == k_CondCode; }
Craig Topperca7e3e52014-03-10 03:19:03 +0000725 bool isImm() const override { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000726 // checks whether this operand is an unsigned offset which fits is a field
727 // of specified width and scaled by a specific number of bits
728 template<unsigned width, unsigned scale>
729 bool isUnsignedOffset() const {
730 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000731 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000732 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
733 int64_t Val = CE->getValue();
734 int64_t Align = 1LL << scale;
735 int64_t Max = Align * ((1LL << width) - 1);
736 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
737 }
738 return false;
739 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000740 // checks whether this operand is an signed offset which fits is a field
741 // of specified width and scaled by a specific number of bits
742 template<unsigned width, unsigned scale>
743 bool isSignedOffset() const {
744 if (!isImm()) return false;
745 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
746 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
747 int64_t Val = CE->getValue();
748 int64_t Align = 1LL << scale;
749 int64_t Max = Align * ((1LL << (width-1)) - 1);
750 int64_t Min = -Align * (1LL << (width-1));
751 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
752 }
753 return false;
754 }
755
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000756 // checks whether this operand is a memory operand computed as an offset
757 // applied to PC. the offset may have 8 bits of magnitude and is represented
758 // with two bits of shift. textually it may be either [pc, #imm], #imm or
759 // relocable expression...
760 bool isThumbMemPC() const {
761 int64_t Val = 0;
762 if (isImm()) {
763 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
764 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
765 if (!CE) return false;
766 Val = CE->getValue();
767 }
768 else if (isMem()) {
769 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
770 if(Memory.BaseRegNum != ARM::PC) return false;
771 Val = Memory.OffsetImm->getValue();
772 }
773 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000774 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000775 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000776 bool isFPImm() const {
777 if (!isImm()) return false;
778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
779 if (!CE) return false;
780 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
781 return Val != -1;
782 }
Jim Grosbachea231912011-12-22 22:19:05 +0000783 bool isFBits16() const {
784 if (!isImm()) return false;
785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
786 if (!CE) return false;
787 int64_t Value = CE->getValue();
788 return Value >= 0 && Value <= 16;
789 }
790 bool isFBits32() const {
791 if (!isImm()) return false;
792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
793 if (!CE) return false;
794 int64_t Value = CE->getValue();
795 return Value >= 1 && Value <= 32;
796 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000797 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000798 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000799 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
800 if (!CE) return false;
801 int64_t Value = CE->getValue();
802 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
803 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000804 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000805 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
807 if (!CE) return false;
808 int64_t Value = CE->getValue();
809 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
810 }
811 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000812 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000813 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
814 if (!CE) return false;
815 int64_t Value = CE->getValue();
816 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
817 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000818 bool isImm0_508s4Neg() const {
819 if (!isImm()) return false;
820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
821 if (!CE) return false;
822 int64_t Value = -CE->getValue();
823 // explicitly exclude zero. we want that to use the normal 0_508 version.
824 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
825 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000826 bool isImm0_239() const {
827 if (!isImm()) return false;
828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
829 if (!CE) return false;
830 int64_t Value = CE->getValue();
831 return Value >= 0 && Value < 240;
832 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000833 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000834 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
836 if (!CE) return false;
837 int64_t Value = CE->getValue();
838 return Value >= 0 && Value < 256;
839 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000840 bool isImm0_4095() const {
841 if (!isImm()) return false;
842 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
843 if (!CE) return false;
844 int64_t Value = CE->getValue();
845 return Value >= 0 && Value < 4096;
846 }
847 bool isImm0_4095Neg() const {
848 if (!isImm()) return false;
849 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
850 if (!CE) return false;
851 int64_t Value = -CE->getValue();
852 return Value > 0 && Value < 4096;
853 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000854 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000855 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000856 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
857 if (!CE) return false;
858 int64_t Value = CE->getValue();
859 return Value >= 0 && Value < 2;
860 }
861 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000862 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000863 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
864 if (!CE) return false;
865 int64_t Value = CE->getValue();
866 return Value >= 0 && Value < 4;
867 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000868 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000869 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000870 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
871 if (!CE) return false;
872 int64_t Value = CE->getValue();
873 return Value >= 0 && Value < 8;
874 }
875 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000876 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000877 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
878 if (!CE) return false;
879 int64_t Value = CE->getValue();
880 return Value >= 0 && Value < 16;
881 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000882 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000883 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000884 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
885 if (!CE) return false;
886 int64_t Value = CE->getValue();
887 return Value >= 0 && Value < 32;
888 }
Jim Grosbach00326402011-12-08 01:30:04 +0000889 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000890 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000891 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
892 if (!CE) return false;
893 int64_t Value = CE->getValue();
894 return Value >= 0 && Value < 64;
895 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000896 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000897 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000898 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
899 if (!CE) return false;
900 int64_t Value = CE->getValue();
901 return Value == 8;
902 }
903 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000904 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000905 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
906 if (!CE) return false;
907 int64_t Value = CE->getValue();
908 return Value == 16;
909 }
910 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000911 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000912 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
913 if (!CE) return false;
914 int64_t Value = CE->getValue();
915 return Value == 32;
916 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000917 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000918 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000919 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
920 if (!CE) return false;
921 int64_t Value = CE->getValue();
922 return Value > 0 && Value <= 8;
923 }
924 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000925 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000926 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
927 if (!CE) return false;
928 int64_t Value = CE->getValue();
929 return Value > 0 && Value <= 16;
930 }
931 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000932 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000933 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
934 if (!CE) return false;
935 int64_t Value = CE->getValue();
936 return Value > 0 && Value <= 32;
937 }
938 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000939 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000940 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
941 if (!CE) return false;
942 int64_t Value = CE->getValue();
943 return Value > 0 && Value <= 64;
944 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000945 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000946 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000947 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
948 if (!CE) return false;
949 int64_t Value = CE->getValue();
950 return Value > 0 && Value < 8;
951 }
952 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000953 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000954 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
955 if (!CE) return false;
956 int64_t Value = CE->getValue();
957 return Value > 0 && Value < 16;
958 }
959 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000960 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000961 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
962 if (!CE) return false;
963 int64_t Value = CE->getValue();
964 return Value > 0 && Value < 32;
965 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000966 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000967 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000968 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
969 if (!CE) return false;
970 int64_t Value = CE->getValue();
971 return Value > 0 && Value < 17;
972 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000973 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000974 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000975 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
976 if (!CE) return false;
977 int64_t Value = CE->getValue();
978 return Value > 0 && Value < 33;
979 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000980 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000981 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000982 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
983 if (!CE) return false;
984 int64_t Value = CE->getValue();
985 return Value >= 0 && Value < 33;
986 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000987 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000988 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000989 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
990 if (!CE) return false;
991 int64_t Value = CE->getValue();
992 return Value >= 0 && Value < 65536;
993 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000994 bool isImm256_65535Expr() const {
995 if (!isImm()) return false;
996 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
997 // If it's not a constant expression, it'll generate a fixup and be
998 // handled later.
999 if (!CE) return true;
1000 int64_t Value = CE->getValue();
1001 return Value >= 256 && Value < 65536;
1002 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00001003 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001004 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00001005 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1006 // If it's not a constant expression, it'll generate a fixup and be
1007 // handled later.
1008 if (!CE) return true;
1009 int64_t Value = CE->getValue();
1010 return Value >= 0 && Value < 65536;
1011 }
Jim Grosbachf1637842011-07-26 16:24:27 +00001012 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001013 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +00001014 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1015 if (!CE) return false;
1016 int64_t Value = CE->getValue();
1017 return Value >= 0 && Value <= 0xffffff;
1018 }
Jim Grosbach46dd4132011-08-17 21:51:27 +00001019 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001020 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +00001021 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1022 if (!CE) return false;
1023 int64_t Value = CE->getValue();
1024 return Value > 0 && Value < 33;
1025 }
Jim Grosbach27c1e252011-07-21 17:23:04 +00001026 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001027 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001028 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1029 if (!CE) return false;
1030 int64_t Value = CE->getValue();
1031 return Value >= 0 && Value < 32;
1032 }
1033 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001034 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001035 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1036 if (!CE) return false;
1037 int64_t Value = CE->getValue();
1038 return Value > 0 && Value <= 32;
1039 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001040 bool isAdrLabel() const {
1041 // If we have an immediate that's not a constant, treat it as a label
Asiri Rathnayake52376ac2015-01-06 15:55:09 +00001042 // reference needing a fixup.
1043 if (isImm() && !isa<MCConstantExpr>(getImm()))
1044 return true;
1045
1046 // If it is a constant, it must fit into a modified immediate encoding.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001047 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1049 if (!CE) return false;
1050 int64_t Value = CE->getValue();
Asiri Rathnayake52376ac2015-01-06 15:55:09 +00001051 return (ARM_AM::getSOImmVal(Value) != -1 ||
Asiri Rathnayake77436f82015-01-07 11:22:58 +00001052 ARM_AM::getSOImmVal(-Value) != -1);;
Jim Grosbach30506252011-12-08 00:31:07 +00001053 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001054 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001055 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001056 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1057 if (!CE) return false;
1058 int64_t Value = CE->getValue();
1059 return ARM_AM::getT2SOImmVal(Value) != -1;
1060 }
Jim Grosbachb009a872011-10-28 22:36:30 +00001061 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001062 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +00001063 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1064 if (!CE) return false;
1065 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +00001066 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1067 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +00001068 }
Jim Grosbach30506252011-12-08 00:31:07 +00001069 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001070 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001071 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1072 if (!CE) return false;
1073 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001074 // Only use this when not representable as a plain so_imm.
1075 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1076 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001077 }
Jim Grosbach0a547702011-07-22 17:44:50 +00001078 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001079 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +00001080 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1081 if (!CE) return false;
1082 int64_t Value = CE->getValue();
1083 return Value == 1 || Value == 0;
1084 }
Craig Topperca7e3e52014-03-10 03:19:03 +00001085 bool isReg() const override { return Kind == k_Register; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001086 bool isRegList() const { return Kind == k_RegisterList; }
1087 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1088 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001089 bool isToken() const override { return Kind == k_Token; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001090 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001091 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001092 bool isMem() const override { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001093 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1094 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1095 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1096 bool isRotImm() const { return Kind == k_RotateImmediate; }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001097 bool isModImm() const { return Kind == k_ModifiedImmediate; }
1098 bool isModImmNot() const {
1099 if (!isImm()) return false;
1100 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1101 if (!CE) return false;
1102 int64_t Value = CE->getValue();
1103 return ARM_AM::getSOImmVal(~Value) != -1;
1104 }
1105 bool isModImmNeg() const {
1106 if (!isImm()) return false;
1107 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1108 if (!CE) return false;
1109 int64_t Value = CE->getValue();
1110 return ARM_AM::getSOImmVal(Value) == -1 &&
1111 ARM_AM::getSOImmVal(-Value) != -1;
1112 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001113 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1114 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001115 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001116 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001117 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001118 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const {
Chad Rosier41099832012-09-11 23:02:35 +00001119 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001120 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001121 // No offset of any kind.
Craig Topper062a2ba2014-04-25 05:30:21 +00001122 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
Kevin Enderby488f20b2014-04-10 20:18:58 +00001123 (alignOK || Memory.Alignment == Alignment);
Jim Grosbacha95ec992011-10-11 17:29:55 +00001124 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001125 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001126 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001127 return false;
1128 // Base register must be PC.
1129 if (Memory.BaseRegNum != ARM::PC)
1130 return false;
1131 // Immediate offset in range [-4095, 4095].
1132 if (!Memory.OffsetImm) return true;
1133 int64_t Val = Memory.OffsetImm->getValue();
1134 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1135 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001136 bool isAlignedMemory() const {
1137 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001138 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001139 bool isAlignedMemoryNone() const {
1140 return isMemNoOffset(false, 0);
1141 }
1142 bool isDupAlignedMemoryNone() const {
1143 return isMemNoOffset(false, 0);
1144 }
1145 bool isAlignedMemory16() const {
1146 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1147 return true;
1148 return isMemNoOffset(false, 0);
1149 }
1150 bool isDupAlignedMemory16() const {
1151 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1152 return true;
1153 return isMemNoOffset(false, 0);
1154 }
1155 bool isAlignedMemory32() const {
1156 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1157 return true;
1158 return isMemNoOffset(false, 0);
1159 }
1160 bool isDupAlignedMemory32() const {
1161 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1162 return true;
1163 return isMemNoOffset(false, 0);
1164 }
1165 bool isAlignedMemory64() const {
1166 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1167 return true;
1168 return isMemNoOffset(false, 0);
1169 }
1170 bool isDupAlignedMemory64() const {
1171 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1172 return true;
1173 return isMemNoOffset(false, 0);
1174 }
1175 bool isAlignedMemory64or128() const {
1176 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1177 return true;
1178 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1179 return true;
1180 return isMemNoOffset(false, 0);
1181 }
1182 bool isDupAlignedMemory64or128() const {
1183 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1184 return true;
1185 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1186 return true;
1187 return isMemNoOffset(false, 0);
1188 }
1189 bool isAlignedMemory64or128or256() const {
1190 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1191 return true;
1192 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1193 return true;
1194 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
1195 return true;
1196 return isMemNoOffset(false, 0);
1197 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001198 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001199 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001200 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001201 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001202 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001203 if (!Memory.OffsetImm) return true;
1204 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001205 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001206 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001207 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001208 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001209 // Immediate offset in range [-4095, 4095].
1210 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1211 if (!CE) return false;
1212 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001213 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001214 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001215 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001216 // If we have an immediate that's not a constant, treat it as a label
1217 // reference needing a fixup. If it is a constant, it's something else
1218 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001219 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001220 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001221 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001222 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001223 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001224 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001225 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001226 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001227 if (!Memory.OffsetImm) return true;
1228 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001229 // The #-0 offset is encoded as INT32_MIN, and we have to check
1230 // for this too.
1231 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001232 }
1233 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001234 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001235 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001236 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001237 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1238 // Immediate offset in range [-255, 255].
1239 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1240 if (!CE) return false;
1241 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001242 // Special case, #-0 is INT32_MIN.
1243 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001244 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001245 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001246 // If we have an immediate that's not a constant, treat it as a label
1247 // reference needing a fixup. If it is a constant, it's something else
1248 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001249 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001250 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001251 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001252 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001253 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001254 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001255 if (!Memory.OffsetImm) return true;
1256 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001257 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001258 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001259 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001260 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001261 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001262 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001263 return false;
1264 return true;
1265 }
1266 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001267 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001268 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1269 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001270 return false;
1271 return true;
1272 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001273 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001274 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001275 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001276 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001277 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001278 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001279 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001280 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001281 return false;
1282 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001283 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001284 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001285 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001286 return false;
1287 return true;
1288 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001289 bool isMemThumbRR() const {
1290 // Thumb reg+reg addressing is simple. Just two registers, a base and
1291 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001292 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001293 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001294 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001295 return isARMLowRegister(Memory.BaseRegNum) &&
1296 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001297 }
1298 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001299 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001300 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001301 return false;
1302 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001303 if (!Memory.OffsetImm) return true;
1304 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001305 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1306 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001307 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001308 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001309 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001310 return false;
1311 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001312 if (!Memory.OffsetImm) return true;
1313 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001314 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1315 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001316 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001317 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001318 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001319 return false;
1320 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001321 if (!Memory.OffsetImm) return true;
1322 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001323 return Val >= 0 && Val <= 31;
1324 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001325 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001326 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001327 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001328 return false;
1329 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001330 if (!Memory.OffsetImm) return true;
1331 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001332 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001333 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001334 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001335 // If we have an immediate that's not a constant, treat it as a label
1336 // reference needing a fixup. If it is a constant, it's something else
1337 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001338 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001339 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001340 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001341 return false;
1342 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001343 if (!Memory.OffsetImm) return true;
1344 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001345 // Special case, #-0 is INT32_MIN.
1346 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001347 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001348 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001349 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001350 return false;
1351 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001352 if (!Memory.OffsetImm) return true;
1353 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001354 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1355 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001356 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001357 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001358 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001359 // Base reg of PC isn't allowed for these encodings.
1360 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001361 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001362 if (!Memory.OffsetImm) return true;
1363 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001364 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001365 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001366 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001367 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001368 return false;
1369 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001370 if (!Memory.OffsetImm) return true;
1371 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001372 return Val >= 0 && Val < 256;
1373 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001374 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001375 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001376 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001377 // Base reg of PC isn't allowed for these encodings.
1378 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001379 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001380 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001381 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001382 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001383 }
1384 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001385 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001386 return false;
1387 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001388 if (!Memory.OffsetImm) return true;
1389 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001390 return (Val >= 0 && Val < 4096);
1391 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001392 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001393 // If we have an immediate that's not a constant, treat it as a label
1394 // reference needing a fixup. If it is a constant, it's something else
1395 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001396 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001397 return true;
1398
Chad Rosier41099832012-09-11 23:02:35 +00001399 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001400 return false;
1401 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001402 if (!Memory.OffsetImm) return true;
1403 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001404 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001405 }
1406 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001407 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001408 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1409 if (!CE) return false;
1410 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001411 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001412 }
Jim Grosbach93981412011-10-11 21:55:36 +00001413 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001414 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001415 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1416 if (!CE) return false;
1417 int64_t Val = CE->getValue();
1418 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1419 (Val == INT32_MIN);
1420 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001421
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001422 bool isMSRMask() const { return Kind == k_MSRMask; }
Tim Northoveree843ef2014-08-15 10:47:12 +00001423 bool isBankedReg() const { return Kind == k_BankedReg; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001424 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001425
Jim Grosbach741cd732011-10-17 22:26:03 +00001426 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001427 bool isSingleSpacedVectorList() const {
1428 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1429 }
1430 bool isDoubleSpacedVectorList() const {
1431 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1432 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001433 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001434 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001435 return VectorList.Count == 1;
1436 }
1437
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001438 bool isVecListDPair() const {
1439 if (!isSingleSpacedVectorList()) return false;
1440 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1441 .contains(VectorList.RegNum));
1442 }
1443
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001444 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001445 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001446 return VectorList.Count == 3;
1447 }
1448
Jim Grosbach846bcff2011-10-21 20:35:01 +00001449 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001450 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001451 return VectorList.Count == 4;
1452 }
1453
Jim Grosbache5307f92012-03-05 21:43:40 +00001454 bool isVecListDPairSpaced() const {
Kevin Enderby56113982014-03-26 21:54:11 +00001455 if (Kind != k_VectorList) return false;
Kevin Enderby816ca272012-03-20 17:41:51 +00001456 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001457 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1458 .contains(VectorList.RegNum));
1459 }
1460
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001461 bool isVecListThreeQ() const {
1462 if (!isDoubleSpacedVectorList()) return false;
1463 return VectorList.Count == 3;
1464 }
1465
Jim Grosbach1e946a42012-01-24 00:43:12 +00001466 bool isVecListFourQ() const {
1467 if (!isDoubleSpacedVectorList()) return false;
1468 return VectorList.Count == 4;
1469 }
1470
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001471 bool isSingleSpacedVectorAllLanes() const {
1472 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1473 }
1474 bool isDoubleSpacedVectorAllLanes() const {
1475 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1476 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001477 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001478 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001479 return VectorList.Count == 1;
1480 }
1481
Jim Grosbach13a292c2012-03-06 22:01:44 +00001482 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001483 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001484 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1485 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001486 }
1487
Jim Grosbached428bc2012-03-06 23:10:38 +00001488 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001489 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001490 return VectorList.Count == 2;
1491 }
1492
Jim Grosbachb78403c2012-01-24 23:47:04 +00001493 bool isVecListThreeDAllLanes() const {
1494 if (!isSingleSpacedVectorAllLanes()) return false;
1495 return VectorList.Count == 3;
1496 }
1497
1498 bool isVecListThreeQAllLanes() const {
1499 if (!isDoubleSpacedVectorAllLanes()) return false;
1500 return VectorList.Count == 3;
1501 }
1502
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001503 bool isVecListFourDAllLanes() const {
1504 if (!isSingleSpacedVectorAllLanes()) return false;
1505 return VectorList.Count == 4;
1506 }
1507
1508 bool isVecListFourQAllLanes() const {
1509 if (!isDoubleSpacedVectorAllLanes()) return false;
1510 return VectorList.Count == 4;
1511 }
1512
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001513 bool isSingleSpacedVectorIndexed() const {
1514 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1515 }
1516 bool isDoubleSpacedVectorIndexed() const {
1517 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1518 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001519 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001520 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001521 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1522 }
1523
Jim Grosbachda511042011-12-14 23:35:06 +00001524 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001525 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001526 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1527 }
1528
1529 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001530 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001531 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1532 }
1533
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001534 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001535 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001536 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1537 }
1538
Jim Grosbachda511042011-12-14 23:35:06 +00001539 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001540 if (!isSingleSpacedVectorIndexed()) return false;
1541 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1542 }
1543
1544 bool isVecListTwoQWordIndexed() const {
1545 if (!isDoubleSpacedVectorIndexed()) return false;
1546 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1547 }
1548
1549 bool isVecListTwoQHWordIndexed() const {
1550 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001551 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1552 }
1553
1554 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001555 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001556 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1557 }
1558
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001559 bool isVecListThreeDByteIndexed() const {
1560 if (!isSingleSpacedVectorIndexed()) return false;
1561 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1562 }
1563
1564 bool isVecListThreeDHWordIndexed() const {
1565 if (!isSingleSpacedVectorIndexed()) return false;
1566 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1567 }
1568
1569 bool isVecListThreeQWordIndexed() const {
1570 if (!isDoubleSpacedVectorIndexed()) return false;
1571 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1572 }
1573
1574 bool isVecListThreeQHWordIndexed() const {
1575 if (!isDoubleSpacedVectorIndexed()) return false;
1576 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1577 }
1578
1579 bool isVecListThreeDWordIndexed() const {
1580 if (!isSingleSpacedVectorIndexed()) return false;
1581 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1582 }
1583
Jim Grosbach14952a02012-01-24 18:37:25 +00001584 bool isVecListFourDByteIndexed() const {
1585 if (!isSingleSpacedVectorIndexed()) return false;
1586 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1587 }
1588
1589 bool isVecListFourDHWordIndexed() const {
1590 if (!isSingleSpacedVectorIndexed()) return false;
1591 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1592 }
1593
1594 bool isVecListFourQWordIndexed() const {
1595 if (!isDoubleSpacedVectorIndexed()) return false;
1596 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1597 }
1598
1599 bool isVecListFourQHWordIndexed() const {
1600 if (!isDoubleSpacedVectorIndexed()) return false;
1601 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1602 }
1603
1604 bool isVecListFourDWordIndexed() const {
1605 if (!isSingleSpacedVectorIndexed()) return false;
1606 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1607 }
1608
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001609 bool isVectorIndex8() const {
1610 if (Kind != k_VectorIndex) return false;
1611 return VectorIndex.Val < 8;
1612 }
1613 bool isVectorIndex16() const {
1614 if (Kind != k_VectorIndex) return false;
1615 return VectorIndex.Val < 4;
1616 }
1617 bool isVectorIndex32() const {
1618 if (Kind != k_VectorIndex) return false;
1619 return VectorIndex.Val < 2;
1620 }
1621
Jim Grosbach741cd732011-10-17 22:26:03 +00001622 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001623 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001624 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1625 // Must be a constant.
1626 if (!CE) return false;
1627 int64_t Value = CE->getValue();
1628 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1629 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001630 return Value >= 0 && Value < 256;
1631 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001632
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001633 bool isNEONi16splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001634 if (isNEONByteReplicate(2))
1635 return false; // Leave that for bytes replication and forbid by default.
1636 if (!isImm())
1637 return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001638 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1639 // Must be a constant.
1640 if (!CE) return false;
Renato Golinf5dd1da2014-09-25 11:31:24 +00001641 unsigned Value = CE->getValue();
1642 return ARM_AM::isNEONi16splat(Value);
1643 }
1644
1645 bool isNEONi16splatNot() const {
1646 if (!isImm())
1647 return false;
1648 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1649 // Must be a constant.
1650 if (!CE) return false;
1651 unsigned Value = CE->getValue();
1652 return ARM_AM::isNEONi16splat(~Value & 0xffff);
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001653 }
1654
Jim Grosbach8211c052011-10-18 00:22:00 +00001655 bool isNEONi32splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001656 if (isNEONByteReplicate(4))
1657 return false; // Leave that for bytes replication and forbid by default.
1658 if (!isImm())
1659 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001660 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1661 // Must be a constant.
1662 if (!CE) return false;
Renato Golinf5dd1da2014-09-25 11:31:24 +00001663 unsigned Value = CE->getValue();
1664 return ARM_AM::isNEONi32splat(Value);
1665 }
1666
1667 bool isNEONi32splatNot() const {
1668 if (!isImm())
1669 return false;
1670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1671 // Must be a constant.
1672 if (!CE) return false;
1673 unsigned Value = CE->getValue();
1674 return ARM_AM::isNEONi32splat(~Value);
Jim Grosbach8211c052011-10-18 00:22:00 +00001675 }
1676
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001677 bool isNEONByteReplicate(unsigned NumBytes) const {
1678 if (!isImm())
1679 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001680 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1681 // Must be a constant.
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001682 if (!CE)
1683 return false;
1684 int64_t Value = CE->getValue();
1685 if (!Value)
1686 return false; // Don't bother with zero.
1687
1688 unsigned char B = Value & 0xff;
1689 for (unsigned i = 1; i < NumBytes; ++i) {
1690 Value >>= 8;
1691 if ((Value & 0xff) != B)
1692 return false;
1693 }
1694 return true;
1695 }
1696 bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); }
1697 bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); }
1698 bool isNEONi32vmov() const {
1699 if (isNEONByteReplicate(4))
1700 return false; // Let it to be classified as byte-replicate case.
1701 if (!isImm())
1702 return false;
1703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1704 // Must be a constant.
1705 if (!CE)
1706 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001707 int64_t Value = CE->getValue();
1708 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1709 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
Renato Golinf5dd1da2014-09-25 11:31:24 +00001710 // FIXME: This is probably wrong and a copy and paste from previous example
Jim Grosbach8211c052011-10-18 00:22:00 +00001711 return (Value >= 0 && Value < 256) ||
1712 (Value >= 0x0100 && Value <= 0xff00) ||
1713 (Value >= 0x010000 && Value <= 0xff0000) ||
1714 (Value >= 0x01000000 && Value <= 0xff000000) ||
1715 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1716 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1717 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001718 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001719 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1721 // Must be a constant.
1722 if (!CE) return false;
1723 int64_t Value = ~CE->getValue();
1724 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1725 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
Renato Golinf5dd1da2014-09-25 11:31:24 +00001726 // FIXME: This is probably wrong and a copy and paste from previous example
Jim Grosbach045b6c72011-12-19 23:51:07 +00001727 return (Value >= 0 && Value < 256) ||
1728 (Value >= 0x0100 && Value <= 0xff00) ||
1729 (Value >= 0x010000 && Value <= 0xff0000) ||
1730 (Value >= 0x01000000 && Value <= 0xff000000) ||
1731 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1732 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1733 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001734
Jim Grosbache4454e02011-10-18 16:18:11 +00001735 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001736 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001737 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1738 // Must be a constant.
1739 if (!CE) return false;
1740 uint64_t Value = CE->getValue();
1741 // i64 value with each byte being either 0 or 0xff.
1742 for (unsigned i = 0; i < 8; ++i)
1743 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1744 return true;
1745 }
1746
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001747 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001748 // Add as immediates when possible. Null MCExpr = 0.
Craig Topper062a2ba2014-04-25 05:30:21 +00001749 if (!Expr)
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001750 Inst.addOperand(MCOperand::CreateImm(0));
1751 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001752 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1753 else
1754 Inst.addOperand(MCOperand::CreateExpr(Expr));
1755 }
1756
Daniel Dunbard8042b72010-08-11 06:36:53 +00001757 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001758 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001759 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001760 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1761 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001762 }
1763
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001764 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1765 assert(N == 1 && "Invalid number of operands!");
1766 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1767 }
1768
Jim Grosbach48399582011-10-12 17:34:41 +00001769 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1770 assert(N == 1 && "Invalid number of operands!");
1771 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1772 }
1773
1774 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1775 assert(N == 1 && "Invalid number of operands!");
1776 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1777 }
1778
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001779 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1780 assert(N == 1 && "Invalid number of operands!");
1781 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1782 }
1783
1784 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1785 assert(N == 1 && "Invalid number of operands!");
1786 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1787 }
1788
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001789 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1790 assert(N == 1 && "Invalid number of operands!");
1791 Inst.addOperand(MCOperand::CreateReg(getReg()));
1792 }
1793
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001794 void addRegOperands(MCInst &Inst, unsigned N) const {
1795 assert(N == 1 && "Invalid number of operands!");
1796 Inst.addOperand(MCOperand::CreateReg(getReg()));
1797 }
1798
Jim Grosbachac798e12011-07-25 20:49:51 +00001799 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001800 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001801 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001802 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001803 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1804 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001805 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001806 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001807 }
1808
Jim Grosbachac798e12011-07-25 20:49:51 +00001809 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001810 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001811 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001812 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001813 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001814 // Shift of #32 is encoded as 0 where permitted
1815 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001816 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001817 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001818 }
1819
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001820 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001821 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001822 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1823 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001824 }
1825
Bill Wendling8d2aa032010-11-08 23:49:57 +00001826 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001827 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001828 const SmallVectorImpl<unsigned> &RegList = getRegList();
1829 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001830 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1831 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001832 }
1833
Bill Wendling9898ac92010-11-17 04:32:08 +00001834 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1835 addRegListOperands(Inst, N);
1836 }
1837
1838 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1839 addRegListOperands(Inst, N);
1840 }
1841
Jim Grosbach833b9d32011-07-27 20:15:40 +00001842 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1843 assert(N == 1 && "Invalid number of operands!");
1844 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1845 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1846 }
1847
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001848 void addModImmOperands(MCInst &Inst, unsigned N) const {
1849 assert(N == 1 && "Invalid number of operands!");
1850
1851 // Support for fixups (MCFixup)
1852 if (isImm())
1853 return addImmOperands(Inst, N);
1854
Asiri Rathnayake7835e9b2014-12-09 13:14:58 +00001855 Inst.addOperand(MCOperand::CreateImm(ModImm.Bits | (ModImm.Rot << 7)));
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001856 }
1857
1858 void addModImmNotOperands(MCInst &Inst, unsigned N) const {
1859 assert(N == 1 && "Invalid number of operands!");
1860 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1861 uint32_t Enc = ARM_AM::getSOImmVal(~CE->getValue());
1862 Inst.addOperand(MCOperand::CreateImm(Enc));
1863 }
1864
1865 void addModImmNegOperands(MCInst &Inst, unsigned N) const {
1866 assert(N == 1 && "Invalid number of operands!");
1867 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1868 uint32_t Enc = ARM_AM::getSOImmVal(-CE->getValue());
1869 Inst.addOperand(MCOperand::CreateImm(Enc));
1870 }
1871
Jim Grosbach864b6092011-07-28 21:34:26 +00001872 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1873 assert(N == 1 && "Invalid number of operands!");
1874 // Munge the lsb/width into a bitfield mask.
1875 unsigned lsb = Bitfield.LSB;
1876 unsigned width = Bitfield.Width;
1877 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1878 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1879 (32 - (lsb + width)));
1880 Inst.addOperand(MCOperand::CreateImm(Mask));
1881 }
1882
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001883 void addImmOperands(MCInst &Inst, unsigned N) const {
1884 assert(N == 1 && "Invalid number of operands!");
1885 addExpr(Inst, getImm());
1886 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001887
Jim Grosbachea231912011-12-22 22:19:05 +00001888 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1889 assert(N == 1 && "Invalid number of operands!");
1890 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1891 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1892 }
1893
1894 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1895 assert(N == 1 && "Invalid number of operands!");
1896 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1897 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1898 }
1899
Jim Grosbache7fbce72011-10-03 23:38:36 +00001900 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1901 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001902 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1903 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1904 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001905 }
1906
Jim Grosbach7db8d692011-09-08 22:07:06 +00001907 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1908 assert(N == 1 && "Invalid number of operands!");
1909 // FIXME: We really want to scale the value here, but the LDRD/STRD
1910 // instruction don't encode operands that way yet.
1911 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1912 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1913 }
1914
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001915 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1916 assert(N == 1 && "Invalid number of operands!");
1917 // The immediate is scaled by four in the encoding and is stored
1918 // in the MCInst as such. Lop off the low two bits here.
1919 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1920 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1921 }
1922
Jim Grosbach930f2f62012-04-05 20:57:13 +00001923 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1924 assert(N == 1 && "Invalid number of operands!");
1925 // The immediate is scaled by four in the encoding and is stored
1926 // in the MCInst as such. Lop off the low two bits here.
1927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1928 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1929 }
1930
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001931 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1932 assert(N == 1 && "Invalid number of operands!");
1933 // The immediate is scaled by four in the encoding and is stored
1934 // in the MCInst as such. Lop off the low two bits here.
1935 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1936 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1937 }
1938
Jim Grosbach475c6db2011-07-25 23:09:14 +00001939 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1940 assert(N == 1 && "Invalid number of operands!");
1941 // The constant encodes as the immediate-1, and we store in the instruction
1942 // the bits as encoded, so subtract off one here.
1943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1944 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1945 }
1946
Jim Grosbach801e0a32011-07-22 23:16:18 +00001947 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1948 assert(N == 1 && "Invalid number of operands!");
1949 // The constant encodes as the immediate-1, and we store in the instruction
1950 // the bits as encoded, so subtract off one here.
1951 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1952 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1953 }
1954
Jim Grosbach46dd4132011-08-17 21:51:27 +00001955 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1956 assert(N == 1 && "Invalid number of operands!");
1957 // The constant encodes as the immediate, except for 32, which encodes as
1958 // zero.
1959 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1960 unsigned Imm = CE->getValue();
1961 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1962 }
1963
Jim Grosbach27c1e252011-07-21 17:23:04 +00001964 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1965 assert(N == 1 && "Invalid number of operands!");
1966 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1967 // the instruction as well.
1968 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1969 int Val = CE->getValue();
1970 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1971 }
1972
Jim Grosbachb009a872011-10-28 22:36:30 +00001973 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1974 assert(N == 1 && "Invalid number of operands!");
1975 // The operand is actually a t2_so_imm, but we have its bitwise
1976 // negation in the assembly source, so twiddle it here.
1977 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1978 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1979 }
1980
Jim Grosbach30506252011-12-08 00:31:07 +00001981 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1982 assert(N == 1 && "Invalid number of operands!");
1983 // The operand is actually a t2_so_imm, but we have its
1984 // negation in the assembly source, so twiddle it here.
1985 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1986 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1987 }
1988
Jim Grosbach930f2f62012-04-05 20:57:13 +00001989 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1990 assert(N == 1 && "Invalid number of operands!");
1991 // The operand is actually an imm0_4095, but we have its
1992 // negation in the assembly source, so twiddle it here.
1993 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1994 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1995 }
1996
Mihai Popad36cbaa2013-07-03 09:21:44 +00001997 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1998 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1999 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
2000 return;
2001 }
2002
2003 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
2004 assert(SR && "Unknown value type!");
2005 Inst.addOperand(MCOperand::CreateExpr(SR));
2006 }
2007
Mihai Popa8a9da5b2013-07-22 15:49:36 +00002008 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
2009 assert(N == 1 && "Invalid number of operands!");
2010 if (isImm()) {
2011 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2012 if (CE) {
2013 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
2014 return;
2015 }
2016
2017 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
2018 assert(SR && "Unknown value type!");
2019 Inst.addOperand(MCOperand::CreateExpr(SR));
2020 return;
2021 }
2022
2023 assert(isMem() && "Unknown value type!");
2024 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
2025 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
2026 }
2027
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002028 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
2029 assert(N == 1 && "Invalid number of operands!");
2030 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
2031 }
2032
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002033 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
2034 assert(N == 1 && "Invalid number of operands!");
2035 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
2036 }
2037
Jim Grosbachd3595712011-08-03 23:50:40 +00002038 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
2039 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002040 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00002041 }
2042
Jim Grosbach94298a92012-01-18 22:46:46 +00002043 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
2044 assert(N == 1 && "Invalid number of operands!");
2045 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00002046 Inst.addOperand(MCOperand::CreateImm(Imm));
2047 }
2048
Jiangning Liu10dd40e2012-08-02 08:13:13 +00002049 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
2050 assert(N == 1 && "Invalid number of operands!");
2051 assert(isImm() && "Not an immediate!");
2052
2053 // If we have an immediate that's not a constant, treat it as a label
2054 // reference needing a fixup.
2055 if (!isa<MCConstantExpr>(getImm())) {
2056 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2057 return;
2058 }
2059
2060 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2061 int Val = CE->getValue();
2062 Inst.addOperand(MCOperand::CreateImm(Val));
2063 }
2064
Jim Grosbacha95ec992011-10-11 17:29:55 +00002065 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
2066 assert(N == 2 && "Invalid number of operands!");
2067 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2068 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
2069 }
2070
Kevin Enderby488f20b2014-04-10 20:18:58 +00002071 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2072 addAlignedMemoryOperands(Inst, N);
2073 }
2074
2075 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2076 addAlignedMemoryOperands(Inst, N);
2077 }
2078
2079 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2080 addAlignedMemoryOperands(Inst, N);
2081 }
2082
2083 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2084 addAlignedMemoryOperands(Inst, N);
2085 }
2086
2087 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2088 addAlignedMemoryOperands(Inst, N);
2089 }
2090
2091 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2092 addAlignedMemoryOperands(Inst, N);
2093 }
2094
2095 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2096 addAlignedMemoryOperands(Inst, N);
2097 }
2098
2099 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2100 addAlignedMemoryOperands(Inst, N);
2101 }
2102
2103 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2104 addAlignedMemoryOperands(Inst, N);
2105 }
2106
2107 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2108 addAlignedMemoryOperands(Inst, N);
2109 }
2110
2111 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
2112 addAlignedMemoryOperands(Inst, N);
2113 }
2114
Jim Grosbachd3595712011-08-03 23:50:40 +00002115 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
2116 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002117 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2118 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00002119 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2120 // Special case for #-0
2121 if (Val == INT32_MIN) Val = 0;
2122 if (Val < 0) Val = -Val;
2123 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2124 } else {
2125 // For register offset, we encode the shift type and negation flag
2126 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002127 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2128 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002129 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002130 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2131 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002132 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002133 }
2134
Jim Grosbachcd17c122011-08-04 23:01:30 +00002135 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
2136 assert(N == 2 && "Invalid number of operands!");
2137 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2138 assert(CE && "non-constant AM2OffsetImm operand!");
2139 int32_t Val = CE->getValue();
2140 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2141 // Special case for #-0
2142 if (Val == INT32_MIN) Val = 0;
2143 if (Val < 0) Val = -Val;
2144 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2145 Inst.addOperand(MCOperand::CreateReg(0));
2146 Inst.addOperand(MCOperand::CreateImm(Val));
2147 }
2148
Jim Grosbach5b96b802011-08-10 20:29:19 +00002149 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
2150 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002151 // If we have an immediate that's not a constant, treat it as a label
2152 // reference needing a fixup. If it is a constant, it's something else
2153 // and we reject it.
2154 if (isImm()) {
2155 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2156 Inst.addOperand(MCOperand::CreateReg(0));
2157 Inst.addOperand(MCOperand::CreateImm(0));
2158 return;
2159 }
2160
Jim Grosbach871dff72011-10-11 15:59:20 +00002161 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2162 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002163 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2164 // Special case for #-0
2165 if (Val == INT32_MIN) Val = 0;
2166 if (Val < 0) Val = -Val;
2167 Val = ARM_AM::getAM3Opc(AddSub, Val);
2168 } else {
2169 // For register offset, we encode the shift type and negation flag
2170 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002171 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002172 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002173 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2174 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00002175 Inst.addOperand(MCOperand::CreateImm(Val));
2176 }
2177
2178 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
2179 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002180 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002181 int32_t Val =
2182 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
2183 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2184 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002185 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00002186 }
2187
2188 // Constant offset.
2189 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2190 int32_t Val = CE->getValue();
2191 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2192 // Special case for #-0
2193 if (Val == INT32_MIN) Val = 0;
2194 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002195 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002196 Inst.addOperand(MCOperand::CreateReg(0));
2197 Inst.addOperand(MCOperand::CreateImm(Val));
2198 }
2199
Jim Grosbachd3595712011-08-03 23:50:40 +00002200 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2201 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00002202 // If we have an immediate that's not a constant, treat it as a label
2203 // reference needing a fixup. If it is a constant, it's something else
2204 // and we reject it.
2205 if (isImm()) {
2206 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2207 Inst.addOperand(MCOperand::CreateImm(0));
2208 return;
2209 }
2210
Jim Grosbachd3595712011-08-03 23:50:40 +00002211 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002212 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002213 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2214 // Special case for #-0
2215 if (Val == INT32_MIN) Val = 0;
2216 if (Val < 0) Val = -Val;
2217 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002218 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002219 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002220 }
2221
Jim Grosbach7db8d692011-09-08 22:07:06 +00002222 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2223 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002224 // If we have an immediate that's not a constant, treat it as a label
2225 // reference needing a fixup. If it is a constant, it's something else
2226 // and we reject it.
2227 if (isImm()) {
2228 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2229 Inst.addOperand(MCOperand::CreateImm(0));
2230 return;
2231 }
2232
Jim Grosbach871dff72011-10-11 15:59:20 +00002233 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2234 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002235 Inst.addOperand(MCOperand::CreateImm(Val));
2236 }
2237
Jim Grosbacha05627e2011-09-09 18:37:27 +00002238 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2239 assert(N == 2 && "Invalid number of operands!");
2240 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002241 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2242 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002243 Inst.addOperand(MCOperand::CreateImm(Val));
2244 }
2245
Jim Grosbachd3595712011-08-03 23:50:40 +00002246 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2247 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002248 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2249 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002250 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002251 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002252
Jim Grosbach2392c532011-09-07 23:39:14 +00002253 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2254 addMemImm8OffsetOperands(Inst, N);
2255 }
2256
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002257 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002258 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002259 }
2260
2261 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2262 assert(N == 2 && "Invalid number of operands!");
2263 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002264 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002265 addExpr(Inst, getImm());
2266 Inst.addOperand(MCOperand::CreateImm(0));
2267 return;
2268 }
2269
2270 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002271 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2272 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002273 Inst.addOperand(MCOperand::CreateImm(Val));
2274 }
2275
Jim Grosbachd3595712011-08-03 23:50:40 +00002276 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2277 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002278 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002279 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002280 addExpr(Inst, getImm());
2281 Inst.addOperand(MCOperand::CreateImm(0));
2282 return;
2283 }
2284
2285 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002286 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2287 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002288 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002289 }
Bill Wendling811c9362010-11-30 07:44:32 +00002290
Jim Grosbach05541f42011-09-19 22:21:13 +00002291 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2292 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002293 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2294 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002295 }
2296
2297 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2298 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002299 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2300 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002301 }
2302
Jim Grosbachd3595712011-08-03 23:50:40 +00002303 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2304 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002305 unsigned Val =
2306 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2307 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002308 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2309 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002310 Inst.addOperand(MCOperand::CreateImm(Val));
2311 }
2312
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002313 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2314 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002315 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2316 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2317 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002318 }
2319
Jim Grosbachd3595712011-08-03 23:50:40 +00002320 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2321 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002322 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2323 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002324 }
2325
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002326 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2327 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002328 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2329 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002330 Inst.addOperand(MCOperand::CreateImm(Val));
2331 }
2332
Jim Grosbach26d35872011-08-19 18:55:51 +00002333 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2334 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002335 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2336 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002337 Inst.addOperand(MCOperand::CreateImm(Val));
2338 }
2339
Jim Grosbacha32c7532011-08-19 18:49:59 +00002340 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2341 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002342 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2343 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002344 Inst.addOperand(MCOperand::CreateImm(Val));
2345 }
2346
Jim Grosbach23983d62011-08-19 18:13:48 +00002347 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2348 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002349 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2350 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002351 Inst.addOperand(MCOperand::CreateImm(Val));
2352 }
2353
Jim Grosbachd3595712011-08-03 23:50:40 +00002354 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2355 assert(N == 1 && "Invalid number of operands!");
2356 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2357 assert(CE && "non-constant post-idx-imm8 operand!");
2358 int Imm = CE->getValue();
2359 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002360 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002361 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2362 Inst.addOperand(MCOperand::CreateImm(Imm));
2363 }
2364
Jim Grosbach93981412011-10-11 21:55:36 +00002365 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2366 assert(N == 1 && "Invalid number of operands!");
2367 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2368 assert(CE && "non-constant post-idx-imm8s4 operand!");
2369 int Imm = CE->getValue();
2370 bool isAdd = Imm >= 0;
2371 if (Imm == INT32_MIN) Imm = 0;
2372 // Immediate is scaled by 4.
2373 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2374 Inst.addOperand(MCOperand::CreateImm(Imm));
2375 }
2376
Jim Grosbachd3595712011-08-03 23:50:40 +00002377 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2378 assert(N == 2 && "Invalid number of operands!");
2379 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002380 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2381 }
2382
2383 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2384 assert(N == 2 && "Invalid number of operands!");
2385 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2386 // The sign, shift type, and shift amount are encoded in a single operand
2387 // using the AM2 encoding helpers.
2388 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2389 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2390 PostIdxReg.ShiftTy);
2391 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002392 }
2393
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002394 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2395 assert(N == 1 && "Invalid number of operands!");
2396 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2397 }
2398
Tim Northoveree843ef2014-08-15 10:47:12 +00002399 void addBankedRegOperands(MCInst &Inst, unsigned N) const {
2400 assert(N == 1 && "Invalid number of operands!");
2401 Inst.addOperand(MCOperand::CreateImm(unsigned(getBankedReg())));
2402 }
2403
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002404 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2405 assert(N == 1 && "Invalid number of operands!");
2406 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2407 }
2408
Jim Grosbach182b6a02011-11-29 23:51:09 +00002409 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002410 assert(N == 1 && "Invalid number of operands!");
2411 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2412 }
2413
Jim Grosbach04945c42011-12-02 00:35:16 +00002414 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2415 assert(N == 2 && "Invalid number of operands!");
2416 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2417 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2418 }
2419
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002420 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2421 assert(N == 1 && "Invalid number of operands!");
2422 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2423 }
2424
2425 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2426 assert(N == 1 && "Invalid number of operands!");
2427 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2428 }
2429
2430 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2431 assert(N == 1 && "Invalid number of operands!");
2432 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2433 }
2434
Jim Grosbach741cd732011-10-17 22:26:03 +00002435 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2436 assert(N == 1 && "Invalid number of operands!");
2437 // The immediate encodes the type of constant as well as the value.
2438 // Mask in that this is an i8 splat.
2439 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2440 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2441 }
2442
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002443 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2444 assert(N == 1 && "Invalid number of operands!");
2445 // The immediate encodes the type of constant as well as the value.
2446 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2447 unsigned Value = CE->getValue();
Renato Golinf5dd1da2014-09-25 11:31:24 +00002448 Value = ARM_AM::encodeNEONi16splat(Value);
2449 Inst.addOperand(MCOperand::CreateImm(Value));
2450 }
2451
2452 void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const {
2453 assert(N == 1 && "Invalid number of operands!");
2454 // The immediate encodes the type of constant as well as the value.
2455 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2456 unsigned Value = CE->getValue();
2457 Value = ARM_AM::encodeNEONi16splat(~Value & 0xffff);
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002458 Inst.addOperand(MCOperand::CreateImm(Value));
2459 }
2460
Jim Grosbach8211c052011-10-18 00:22:00 +00002461 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2462 assert(N == 1 && "Invalid number of operands!");
2463 // The immediate encodes the type of constant as well as the value.
2464 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2465 unsigned Value = CE->getValue();
Renato Golinf5dd1da2014-09-25 11:31:24 +00002466 Value = ARM_AM::encodeNEONi32splat(Value);
2467 Inst.addOperand(MCOperand::CreateImm(Value));
2468 }
2469
2470 void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const {
2471 assert(N == 1 && "Invalid number of operands!");
2472 // The immediate encodes the type of constant as well as the value.
2473 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2474 unsigned Value = CE->getValue();
2475 Value = ARM_AM::encodeNEONi32splat(~Value);
Jim Grosbach8211c052011-10-18 00:22:00 +00002476 Inst.addOperand(MCOperand::CreateImm(Value));
2477 }
2478
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002479 void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const {
2480 assert(N == 1 && "Invalid number of operands!");
2481 // The immediate encodes the type of constant as well as the value.
2482 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2483 unsigned Value = CE->getValue();
2484 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2485 Inst.getOpcode() == ARM::VMOVv16i8) &&
2486 "All vmvn instructions that wants to replicate non-zero byte "
2487 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2488 unsigned B = ((~Value) & 0xff);
2489 B |= 0xe00; // cmode = 0b1110
2490 Inst.addOperand(MCOperand::CreateImm(B));
2491 }
Jim Grosbach8211c052011-10-18 00:22:00 +00002492 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2493 assert(N == 1 && "Invalid number of operands!");
2494 // The immediate encodes the type of constant as well as the value.
2495 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2496 unsigned Value = CE->getValue();
2497 if (Value >= 256 && Value <= 0xffff)
2498 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2499 else if (Value > 0xffff && Value <= 0xffffff)
2500 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2501 else if (Value > 0xffffff)
2502 Value = (Value >> 24) | 0x600;
2503 Inst.addOperand(MCOperand::CreateImm(Value));
2504 }
2505
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002506 void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const {
2507 assert(N == 1 && "Invalid number of operands!");
2508 // The immediate encodes the type of constant as well as the value.
2509 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2510 unsigned Value = CE->getValue();
2511 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2512 Inst.getOpcode() == ARM::VMOVv16i8) &&
2513 "All instructions that wants to replicate non-zero byte "
2514 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2515 unsigned B = Value & 0xff;
2516 B |= 0xe00; // cmode = 0b1110
2517 Inst.addOperand(MCOperand::CreateImm(B));
2518 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00002519 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2520 assert(N == 1 && "Invalid number of operands!");
2521 // The immediate encodes the type of constant as well as the value.
2522 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2523 unsigned Value = ~CE->getValue();
2524 if (Value >= 256 && Value <= 0xffff)
2525 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2526 else if (Value > 0xffff && Value <= 0xffffff)
2527 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2528 else if (Value > 0xffffff)
2529 Value = (Value >> 24) | 0x600;
2530 Inst.addOperand(MCOperand::CreateImm(Value));
2531 }
2532
Jim Grosbache4454e02011-10-18 16:18:11 +00002533 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2534 assert(N == 1 && "Invalid number of operands!");
2535 // The immediate encodes the type of constant as well as the value.
2536 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2537 uint64_t Value = CE->getValue();
2538 unsigned Imm = 0;
2539 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2540 Imm |= (Value & 1) << i;
2541 }
2542 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2543 }
2544
Craig Topperca7e3e52014-03-10 03:19:03 +00002545 void print(raw_ostream &OS) const override;
Daniel Dunbarebace222010-08-11 06:37:04 +00002546
David Blaikie960ea3f2014-06-08 16:18:35 +00002547 static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) {
2548 auto Op = make_unique<ARMOperand>(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002549 Op->ITMask.Mask = Mask;
2550 Op->StartLoc = S;
2551 Op->EndLoc = S;
2552 return Op;
2553 }
2554
David Blaikie960ea3f2014-06-08 16:18:35 +00002555 static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC,
2556 SMLoc S) {
2557 auto Op = make_unique<ARMOperand>(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002558 Op->CC.Val = CC;
2559 Op->StartLoc = S;
2560 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002561 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002562 }
2563
David Blaikie960ea3f2014-06-08 16:18:35 +00002564 static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) {
2565 auto Op = make_unique<ARMOperand>(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002566 Op->Cop.Val = CopVal;
2567 Op->StartLoc = S;
2568 Op->EndLoc = S;
2569 return Op;
2570 }
2571
David Blaikie960ea3f2014-06-08 16:18:35 +00002572 static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) {
2573 auto Op = make_unique<ARMOperand>(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002574 Op->Cop.Val = CopVal;
2575 Op->StartLoc = S;
2576 Op->EndLoc = S;
2577 return Op;
2578 }
2579
David Blaikie960ea3f2014-06-08 16:18:35 +00002580 static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S,
2581 SMLoc E) {
2582 auto Op = make_unique<ARMOperand>(k_CoprocOption);
Jim Grosbach48399582011-10-12 17:34:41 +00002583 Op->Cop.Val = Val;
2584 Op->StartLoc = S;
2585 Op->EndLoc = E;
2586 return Op;
2587 }
2588
David Blaikie960ea3f2014-06-08 16:18:35 +00002589 static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) {
2590 auto Op = make_unique<ARMOperand>(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002591 Op->Reg.RegNum = RegNum;
2592 Op->StartLoc = S;
2593 Op->EndLoc = S;
2594 return Op;
2595 }
2596
David Blaikie960ea3f2014-06-08 16:18:35 +00002597 static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) {
2598 auto Op = make_unique<ARMOperand>(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002599 Op->Tok.Data = Str.data();
2600 Op->Tok.Length = Str.size();
2601 Op->StartLoc = S;
2602 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002603 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002604 }
2605
David Blaikie960ea3f2014-06-08 16:18:35 +00002606 static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S,
2607 SMLoc E) {
2608 auto Op = make_unique<ARMOperand>(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002609 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002610 Op->StartLoc = S;
2611 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002612 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002613 }
2614
David Blaikie960ea3f2014-06-08 16:18:35 +00002615 static std::unique_ptr<ARMOperand>
2616 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2617 unsigned ShiftReg, unsigned ShiftImm, SMLoc S,
2618 SMLoc E) {
2619 auto Op = make_unique<ARMOperand>(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002620 Op->RegShiftedReg.ShiftTy = ShTy;
2621 Op->RegShiftedReg.SrcReg = SrcReg;
2622 Op->RegShiftedReg.ShiftReg = ShiftReg;
2623 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002624 Op->StartLoc = S;
2625 Op->EndLoc = E;
2626 return Op;
2627 }
2628
David Blaikie960ea3f2014-06-08 16:18:35 +00002629 static std::unique_ptr<ARMOperand>
2630 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2631 unsigned ShiftImm, SMLoc S, SMLoc E) {
2632 auto Op = make_unique<ARMOperand>(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002633 Op->RegShiftedImm.ShiftTy = ShTy;
2634 Op->RegShiftedImm.SrcReg = SrcReg;
2635 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002636 Op->StartLoc = S;
2637 Op->EndLoc = E;
2638 return Op;
2639 }
2640
David Blaikie960ea3f2014-06-08 16:18:35 +00002641 static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm,
2642 SMLoc S, SMLoc E) {
2643 auto Op = make_unique<ARMOperand>(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002644 Op->ShifterImm.isASR = isASR;
2645 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002646 Op->StartLoc = S;
2647 Op->EndLoc = E;
2648 return Op;
2649 }
2650
David Blaikie960ea3f2014-06-08 16:18:35 +00002651 static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S,
2652 SMLoc E) {
2653 auto Op = make_unique<ARMOperand>(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002654 Op->RotImm.Imm = Imm;
2655 Op->StartLoc = S;
2656 Op->EndLoc = E;
2657 return Op;
2658 }
2659
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00002660 static std::unique_ptr<ARMOperand> CreateModImm(unsigned Bits, unsigned Rot,
2661 SMLoc S, SMLoc E) {
2662 auto Op = make_unique<ARMOperand>(k_ModifiedImmediate);
2663 Op->ModImm.Bits = Bits;
2664 Op->ModImm.Rot = Rot;
2665 Op->StartLoc = S;
2666 Op->EndLoc = E;
2667 return Op;
2668 }
2669
David Blaikie960ea3f2014-06-08 16:18:35 +00002670 static std::unique_ptr<ARMOperand>
2671 CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) {
2672 auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002673 Op->Bitfield.LSB = LSB;
2674 Op->Bitfield.Width = Width;
2675 Op->StartLoc = S;
2676 Op->EndLoc = E;
2677 return Op;
2678 }
2679
David Blaikie960ea3f2014-06-08 16:18:35 +00002680 static std::unique_ptr<ARMOperand>
2681 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002682 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002683 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002684 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002685
Chad Rosierfa705ee2013-07-01 20:49:23 +00002686 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002687 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002688 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002689 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002690 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002691
Chad Rosierfa705ee2013-07-01 20:49:23 +00002692 // Sort based on the register encoding values.
2693 array_pod_sort(Regs.begin(), Regs.end());
2694
David Blaikie960ea3f2014-06-08 16:18:35 +00002695 auto Op = make_unique<ARMOperand>(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002696 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002697 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002698 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002699 Op->StartLoc = StartLoc;
2700 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002701 return Op;
2702 }
2703
David Blaikie960ea3f2014-06-08 16:18:35 +00002704 static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum,
2705 unsigned Count,
2706 bool isDoubleSpaced,
2707 SMLoc S, SMLoc E) {
2708 auto Op = make_unique<ARMOperand>(k_VectorList);
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002709 Op->VectorList.RegNum = RegNum;
2710 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002711 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002712 Op->StartLoc = S;
2713 Op->EndLoc = E;
2714 return Op;
2715 }
2716
David Blaikie960ea3f2014-06-08 16:18:35 +00002717 static std::unique_ptr<ARMOperand>
2718 CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced,
2719 SMLoc S, SMLoc E) {
2720 auto Op = make_unique<ARMOperand>(k_VectorListAllLanes);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002721 Op->VectorList.RegNum = RegNum;
2722 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002723 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002724 Op->StartLoc = S;
2725 Op->EndLoc = E;
2726 return Op;
2727 }
2728
David Blaikie960ea3f2014-06-08 16:18:35 +00002729 static std::unique_ptr<ARMOperand>
2730 CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index,
2731 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2732 auto Op = make_unique<ARMOperand>(k_VectorListIndexed);
Jim Grosbach04945c42011-12-02 00:35:16 +00002733 Op->VectorList.RegNum = RegNum;
2734 Op->VectorList.Count = Count;
2735 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002736 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002737 Op->StartLoc = S;
2738 Op->EndLoc = E;
2739 return Op;
2740 }
2741
David Blaikie960ea3f2014-06-08 16:18:35 +00002742 static std::unique_ptr<ARMOperand>
2743 CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) {
2744 auto Op = make_unique<ARMOperand>(k_VectorIndex);
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002745 Op->VectorIndex.Val = Idx;
2746 Op->StartLoc = S;
2747 Op->EndLoc = E;
2748 return Op;
2749 }
2750
David Blaikie960ea3f2014-06-08 16:18:35 +00002751 static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S,
2752 SMLoc E) {
2753 auto Op = make_unique<ARMOperand>(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002754 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002755 Op->StartLoc = S;
2756 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002757 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002758 }
2759
David Blaikie960ea3f2014-06-08 16:18:35 +00002760 static std::unique_ptr<ARMOperand>
2761 CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm,
2762 unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType,
2763 unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S,
2764 SMLoc E, SMLoc AlignmentLoc = SMLoc()) {
2765 auto Op = make_unique<ARMOperand>(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002766 Op->Memory.BaseRegNum = BaseRegNum;
2767 Op->Memory.OffsetImm = OffsetImm;
2768 Op->Memory.OffsetRegNum = OffsetRegNum;
2769 Op->Memory.ShiftType = ShiftType;
2770 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002771 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002772 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002773 Op->StartLoc = S;
2774 Op->EndLoc = E;
Kevin Enderby488f20b2014-04-10 20:18:58 +00002775 Op->AlignmentLoc = AlignmentLoc;
Jim Grosbachd3595712011-08-03 23:50:40 +00002776 return Op;
2777 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002778
David Blaikie960ea3f2014-06-08 16:18:35 +00002779 static std::unique_ptr<ARMOperand>
2780 CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy,
2781 unsigned ShiftImm, SMLoc S, SMLoc E) {
2782 auto Op = make_unique<ARMOperand>(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002783 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002784 Op->PostIdxReg.isAdd = isAdd;
2785 Op->PostIdxReg.ShiftTy = ShiftTy;
2786 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002787 Op->StartLoc = S;
2788 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002789 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002790 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002791
David Blaikie960ea3f2014-06-08 16:18:35 +00002792 static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt,
2793 SMLoc S) {
2794 auto Op = make_unique<ARMOperand>(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002795 Op->MBOpt.Val = Opt;
2796 Op->StartLoc = S;
2797 Op->EndLoc = S;
2798 return Op;
2799 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002800
David Blaikie960ea3f2014-06-08 16:18:35 +00002801 static std::unique_ptr<ARMOperand>
2802 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) {
2803 auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002804 Op->ISBOpt.Val = Opt;
2805 Op->StartLoc = S;
2806 Op->EndLoc = S;
2807 return Op;
2808 }
2809
David Blaikie960ea3f2014-06-08 16:18:35 +00002810 static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags,
2811 SMLoc S) {
2812 auto Op = make_unique<ARMOperand>(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002813 Op->IFlags.Val = IFlags;
2814 Op->StartLoc = S;
2815 Op->EndLoc = S;
2816 return Op;
2817 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002818
David Blaikie960ea3f2014-06-08 16:18:35 +00002819 static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) {
2820 auto Op = make_unique<ARMOperand>(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002821 Op->MMask.Val = MMask;
2822 Op->StartLoc = S;
2823 Op->EndLoc = S;
2824 return Op;
2825 }
Tim Northoveree843ef2014-08-15 10:47:12 +00002826
2827 static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) {
2828 auto Op = make_unique<ARMOperand>(k_BankedReg);
2829 Op->BankedReg.Val = Reg;
2830 Op->StartLoc = S;
2831 Op->EndLoc = S;
2832 return Op;
2833 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002834};
2835
2836} // end anonymous namespace.
2837
Jim Grosbach602aa902011-07-13 15:34:57 +00002838void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002839 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002840 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002841 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002842 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002843 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002844 OS << "<ccout " << getReg() << ">";
2845 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002846 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002847 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002848 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2849 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2850 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002851 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2852 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2853 break;
2854 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002855 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002856 OS << "<coprocessor number: " << getCoproc() << ">";
2857 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002858 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002859 OS << "<coprocessor register: " << getCoproc() << ">";
2860 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002861 case k_CoprocOption:
2862 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2863 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002864 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002865 OS << "<mask: " << getMSRMask() << ">";
2866 break;
Tim Northoveree843ef2014-08-15 10:47:12 +00002867 case k_BankedReg:
2868 OS << "<banked reg: " << getBankedReg() << ">";
2869 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002870 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002871 getImm()->print(OS);
2872 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002873 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002874 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002875 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002876 case k_InstSyncBarrierOpt:
2877 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2878 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002879 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002880 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002881 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002882 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002883 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002884 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002885 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2886 << PostIdxReg.RegNum;
2887 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2888 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2889 << PostIdxReg.ShiftImm;
2890 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002891 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002892 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002893 OS << "<ARM_PROC::";
2894 unsigned IFlags = getProcIFlags();
2895 for (int i=2; i >= 0; --i)
2896 if (IFlags & (1 << i))
2897 OS << ARM_PROC::IFlagsToString(1 << i);
2898 OS << ">";
2899 break;
2900 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002901 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002902 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002903 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002904 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002905 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2906 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002907 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002908 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002909 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002910 << RegShiftedReg.SrcReg << " "
2911 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2912 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002913 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002914 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002915 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002916 << RegShiftedImm.SrcReg << " "
2917 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2918 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002919 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002920 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002921 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2922 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00002923 case k_ModifiedImmediate:
2924 OS << "<mod_imm #" << ModImm.Bits << ", #"
2925 << ModImm.Rot << ")>";
2926 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002927 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002928 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2929 << ", width: " << Bitfield.Width << ">";
2930 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002931 case k_RegisterList:
2932 case k_DPRRegisterList:
2933 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002934 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002935
Bill Wendlingbed94652010-11-09 23:28:44 +00002936 const SmallVectorImpl<unsigned> &RegList = getRegList();
2937 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002938 I = RegList.begin(), E = RegList.end(); I != E; ) {
2939 OS << *I;
2940 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002941 }
2942
2943 OS << ">";
2944 break;
2945 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002946 case k_VectorList:
2947 OS << "<vector_list " << VectorList.Count << " * "
2948 << VectorList.RegNum << ">";
2949 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002950 case k_VectorListAllLanes:
2951 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2952 << VectorList.RegNum << ">";
2953 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002954 case k_VectorListIndexed:
2955 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2956 << VectorList.Count << " * " << VectorList.RegNum << ">";
2957 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002958 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002959 OS << "'" << getToken() << "'";
2960 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002961 case k_VectorIndex:
2962 OS << "<vectorindex " << getVectorIndex() << ">";
2963 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002964 }
2965}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002966
2967/// @name Auto-generated Match Functions
2968/// {
2969
2970static unsigned MatchRegisterName(StringRef Name);
2971
2972/// }
2973
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002974bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2975 SMLoc &StartLoc, SMLoc &EndLoc) {
Rafael Espindola961d4692014-11-11 05:18:41 +00002976 const AsmToken &Tok = getParser().getTok();
2977 StartLoc = Tok.getLoc();
2978 EndLoc = Tok.getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002979 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002980
2981 return (RegNo == (unsigned)-1);
2982}
2983
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002984/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002985/// and if it is a register name the token is eaten and the register number is
2986/// returned. Otherwise return -1.
2987///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002988int ARMAsmParser::tryParseRegister() {
Rafael Espindola961d4692014-11-11 05:18:41 +00002989 MCAsmParser &Parser = getParser();
Chris Lattner44e5981c2010-10-30 04:09:10 +00002990 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002991 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002992
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002993 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002994 unsigned RegNum = MatchRegisterName(lowerCase);
2995 if (!RegNum) {
2996 RegNum = StringSwitch<unsigned>(lowerCase)
2997 .Case("r13", ARM::SP)
2998 .Case("r14", ARM::LR)
2999 .Case("r15", ARM::PC)
3000 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00003001 // Additional register name aliases for 'gas' compatibility.
3002 .Case("a1", ARM::R0)
3003 .Case("a2", ARM::R1)
3004 .Case("a3", ARM::R2)
3005 .Case("a4", ARM::R3)
3006 .Case("v1", ARM::R4)
3007 .Case("v2", ARM::R5)
3008 .Case("v3", ARM::R6)
3009 .Case("v4", ARM::R7)
3010 .Case("v5", ARM::R8)
3011 .Case("v6", ARM::R9)
3012 .Case("v7", ARM::R10)
3013 .Case("v8", ARM::R11)
3014 .Case("sb", ARM::R9)
3015 .Case("sl", ARM::R10)
3016 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00003017 .Default(0);
3018 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00003019 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00003020 // Check for aliases registered via .req. Canonicalize to lower case.
3021 // That's more consistent since register names are case insensitive, and
3022 // it's how the original entry was passed in from MC/MCParser/AsmParser.
3023 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00003024 // If no match, return failure.
3025 if (Entry == RegisterReqs.end())
3026 return -1;
3027 Parser.Lex(); // Eat identifier token.
3028 return Entry->getValue();
3029 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00003030
Oliver Stannard9e89d8c2014-11-05 12:06:39 +00003031 // Some FPUs only have 16 D registers, so D16-D31 are invalid
3032 if (hasD16() && RegNum >= ARM::D16 && RegNum <= ARM::D31)
3033 return -1;
3034
Chris Lattner44e5981c2010-10-30 04:09:10 +00003035 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003036
Chris Lattner44e5981c2010-10-30 04:09:10 +00003037 return RegNum;
3038}
Jim Grosbach99710a82010-11-01 16:44:21 +00003039
Jim Grosbachbb24c592011-07-13 18:49:30 +00003040// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
3041// If a recoverable error occurs, return 1. If an irrecoverable error
3042// occurs, return -1. An irrecoverable error is one where tokens have been
3043// consumed in the process of trying to parse the shifter (i.e., when it is
3044// indeed a shifter operand, but malformed).
David Blaikie960ea3f2014-06-08 16:18:35 +00003045int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003046 MCAsmParser &Parser = getParser();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003047 SMLoc S = Parser.getTok().getLoc();
3048 const AsmToken &Tok = Parser.getTok();
Kevin Enderby62873712014-02-17 21:45:27 +00003049 if (Tok.isNot(AsmToken::Identifier))
3050 return -1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003051
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003052 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003053 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00003054 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003055 .Case("lsl", ARM_AM::lsl)
3056 .Case("lsr", ARM_AM::lsr)
3057 .Case("asr", ARM_AM::asr)
3058 .Case("ror", ARM_AM::ror)
3059 .Case("rrx", ARM_AM::rrx)
3060 .Default(ARM_AM::no_shift);
3061
3062 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00003063 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003064
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003065 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003066
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003067 // The source register for the shift has already been added to the
3068 // operand list, so we need to pop it off and combine it into the shifted
3069 // register operand instead.
David Blaikie960ea3f2014-06-08 16:18:35 +00003070 std::unique_ptr<ARMOperand> PrevOp(
3071 (ARMOperand *)Operands.pop_back_val().release());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003072 if (!PrevOp->isReg())
3073 return Error(PrevOp->getStartLoc(), "shift must be of a register");
3074 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003075
3076 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003077 int64_t Imm = 0;
3078 int ShiftReg = 0;
3079 if (ShiftTy == ARM_AM::rrx) {
3080 // RRX Doesn't have an explicit shift amount. The encoder expects
3081 // the shift register to be the same as the source register. Seems odd,
3082 // but OK.
3083 ShiftReg = SrcReg;
3084 } else {
3085 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003086 if (Parser.getTok().is(AsmToken::Hash) ||
3087 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003088 Parser.Lex(); // Eat hash.
3089 SMLoc ImmLoc = Parser.getTok().getLoc();
Craig Topper062a2ba2014-04-25 05:30:21 +00003090 const MCExpr *ShiftExpr = nullptr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003091 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003092 Error(ImmLoc, "invalid immediate shift value");
3093 return -1;
3094 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003095 // The expression must be evaluatable as an immediate.
3096 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00003097 if (!CE) {
3098 Error(ImmLoc, "invalid immediate shift value");
3099 return -1;
3100 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003101 // Range check the immediate.
3102 // lsl, ror: 0 <= imm <= 31
3103 // lsr, asr: 0 <= imm <= 32
3104 Imm = CE->getValue();
3105 if (Imm < 0 ||
3106 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
3107 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003108 Error(ImmLoc, "immediate shift value out of range");
3109 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003110 }
Jim Grosbach21488b82011-12-22 17:37:00 +00003111 // shift by zero is a nop. Always send it through as lsl.
3112 // ('as' compatibility)
3113 if (Imm == 0)
3114 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003115 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003116 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003117 EndLoc = Parser.getTok().getEndLoc();
3118 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00003119 if (ShiftReg == -1) {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003120 Error(L, "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003121 return -1;
3122 }
3123 } else {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003124 Error(Parser.getTok().getLoc(),
3125 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003126 return -1;
3127 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003128 }
3129
Owen Andersonb595ed02011-07-21 18:54:16 +00003130 if (ShiftReg && ShiftTy != ARM_AM::rrx)
3131 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00003132 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003133 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00003134 else
3135 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003136 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003137
Jim Grosbachbb24c592011-07-13 18:49:30 +00003138 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003139}
3140
3141
Bill Wendling2063b842010-11-18 23:43:05 +00003142/// Try to parse a register name. The token must be an Identifier when called.
3143/// If it's a register, an AsmOperand is created. Another AsmOperand is created
3144/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00003145///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00003146/// TODO this is likely to change to allow different register types and or to
3147/// parse for a specific register type.
David Blaikie960ea3f2014-06-08 16:18:35 +00003148bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003149 MCAsmParser &Parser = getParser();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003150 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003151 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00003152 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00003153 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00003154
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003155 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
3156 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003157
Chris Lattner44e5981c2010-10-30 04:09:10 +00003158 const AsmToken &ExclaimTok = Parser.getTok();
3159 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00003160 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
3161 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00003162 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003163 return false;
3164 }
3165
3166 // Also check for an index operand. This is only legal for vector registers,
3167 // but that'll get caught OK in operand matching, so we don't need to
3168 // explicitly filter everything else out here.
3169 if (Parser.getTok().is(AsmToken::LBrac)) {
3170 SMLoc SIdx = Parser.getTok().getLoc();
3171 Parser.Lex(); // Eat left bracket token.
3172
3173 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003174 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00003175 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003176 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003177 if (!MCE)
3178 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003179
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003180 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003181 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003182
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003183 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003184 Parser.Lex(); // Eat right bracket token.
3185
3186 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
3187 SIdx, E,
3188 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00003189 }
3190
Bill Wendling2063b842010-11-18 23:43:05 +00003191 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003192}
3193
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003194/// MatchCoprocessorOperandName - Try to parse an coprocessor related
Renato Golinac561c32014-06-26 13:10:53 +00003195/// instruction with a symbolic operand name.
3196/// We accept "crN" syntax for GAS compatibility.
3197/// <operand-name> ::= <prefix><number>
3198/// If CoprocOp is 'c', then:
3199/// <prefix> ::= c | cr
3200/// If CoprocOp is 'p', then :
3201/// <prefix> ::= p
3202/// <number> ::= integer in range [0, 15]
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003203static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003204 // Use the same layout as the tablegen'erated register name matcher. Ugly,
3205 // but efficient.
Renato Golinac561c32014-06-26 13:10:53 +00003206 if (Name.size() < 2 || Name[0] != CoprocOp)
3207 return -1;
3208 Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front();
3209
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003210 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00003211 default: return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003212 case 1:
3213 switch (Name[0]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003214 default: return -1;
3215 case '0': return 0;
3216 case '1': return 1;
3217 case '2': return 2;
3218 case '3': return 3;
3219 case '4': return 4;
3220 case '5': return 5;
3221 case '6': return 6;
3222 case '7': return 7;
3223 case '8': return 8;
3224 case '9': return 9;
3225 }
Renato Golinac561c32014-06-26 13:10:53 +00003226 case 2:
3227 if (Name[0] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003228 return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003229 switch (Name[1]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003230 default: return -1;
Renato Golinbc0b0372014-08-04 23:21:56 +00003231 // CP10 and CP11 are VFP/NEON and so vector instructions should be used.
3232 // However, old cores (v5/v6) did use them in that way.
3233 case '0': return 10;
3234 case '1': return 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003235 case '2': return 12;
3236 case '3': return 13;
3237 case '4': return 14;
3238 case '5': return 15;
3239 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003240 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003241}
3242
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003243/// parseITCondCode - Try to parse a condition code for an IT instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003244ARMAsmParser::OperandMatchResultTy
3245ARMAsmParser::parseITCondCode(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003246 MCAsmParser &Parser = getParser();
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003247 SMLoc S = Parser.getTok().getLoc();
3248 const AsmToken &Tok = Parser.getTok();
3249 if (!Tok.is(AsmToken::Identifier))
3250 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00003251 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003252 .Case("eq", ARMCC::EQ)
3253 .Case("ne", ARMCC::NE)
3254 .Case("hs", ARMCC::HS)
3255 .Case("cs", ARMCC::HS)
3256 .Case("lo", ARMCC::LO)
3257 .Case("cc", ARMCC::LO)
3258 .Case("mi", ARMCC::MI)
3259 .Case("pl", ARMCC::PL)
3260 .Case("vs", ARMCC::VS)
3261 .Case("vc", ARMCC::VC)
3262 .Case("hi", ARMCC::HI)
3263 .Case("ls", ARMCC::LS)
3264 .Case("ge", ARMCC::GE)
3265 .Case("lt", ARMCC::LT)
3266 .Case("gt", ARMCC::GT)
3267 .Case("le", ARMCC::LE)
3268 .Case("al", ARMCC::AL)
3269 .Default(~0U);
3270 if (CC == ~0U)
3271 return MatchOperand_NoMatch;
3272 Parser.Lex(); // Eat the token.
3273
3274 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3275
3276 return MatchOperand_Success;
3277}
3278
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003279/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003280/// token must be an Identifier when called, and if it is a coprocessor
3281/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003282ARMAsmParser::OperandMatchResultTy
3283ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003284 MCAsmParser &Parser = getParser();
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003285 SMLoc S = Parser.getTok().getLoc();
3286 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003287 if (Tok.isNot(AsmToken::Identifier))
3288 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003289
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003290 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003291 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003292 return MatchOperand_NoMatch;
Renato Golinbc0b0372014-08-04 23:21:56 +00003293 // ARMv7 and v8 don't allow cp10/cp11 due to VFP/NEON specific instructions
3294 if ((hasV7Ops() || hasV8Ops()) && (Num == 10 || Num == 11))
3295 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003296
3297 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003298 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003299 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003300}
3301
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003302/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003303/// token must be an Identifier when called, and if it is a coprocessor
3304/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003305ARMAsmParser::OperandMatchResultTy
3306ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003307 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003308 SMLoc S = Parser.getTok().getLoc();
3309 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003310 if (Tok.isNot(AsmToken::Identifier))
3311 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003312
3313 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3314 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003315 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003316
3317 Parser.Lex(); // Eat identifier token.
3318 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003319 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003320}
3321
Jim Grosbach48399582011-10-12 17:34:41 +00003322/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3323/// coproc_option : '{' imm0_255 '}'
David Blaikie960ea3f2014-06-08 16:18:35 +00003324ARMAsmParser::OperandMatchResultTy
3325ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003326 MCAsmParser &Parser = getParser();
Jim Grosbach48399582011-10-12 17:34:41 +00003327 SMLoc S = Parser.getTok().getLoc();
3328
3329 // If this isn't a '{', this isn't a coprocessor immediate operand.
3330 if (Parser.getTok().isNot(AsmToken::LCurly))
3331 return MatchOperand_NoMatch;
3332 Parser.Lex(); // Eat the '{'
3333
3334 const MCExpr *Expr;
3335 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003336 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003337 Error(Loc, "illegal expression");
3338 return MatchOperand_ParseFail;
3339 }
3340 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3341 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3342 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3343 return MatchOperand_ParseFail;
3344 }
3345 int Val = CE->getValue();
3346
3347 // Check for and consume the closing '}'
3348 if (Parser.getTok().isNot(AsmToken::RCurly))
3349 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003350 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003351 Parser.Lex(); // Eat the '}'
3352
3353 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3354 return MatchOperand_Success;
3355}
3356
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003357// For register list parsing, we need to map from raw GPR register numbering
3358// to the enumeration values. The enumeration values aren't sorted by
3359// register number due to our using "sp", "lr" and "pc" as canonical names.
3360static unsigned getNextRegister(unsigned Reg) {
3361 // If this is a GPR, we need to do it manually, otherwise we can rely
3362 // on the sort ordering of the enumeration since the other reg-classes
3363 // are sane.
3364 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3365 return Reg + 1;
3366 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003367 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003368 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3369 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3370 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3371 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3372 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3373 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3374 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3375 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3376 }
3377}
3378
Jim Grosbach85a23432011-11-11 21:27:40 +00003379// Return the low-subreg of a given Q register.
3380static unsigned getDRegFromQReg(unsigned QReg) {
3381 switch (QReg) {
3382 default: llvm_unreachable("expected a Q register!");
3383 case ARM::Q0: return ARM::D0;
3384 case ARM::Q1: return ARM::D2;
3385 case ARM::Q2: return ARM::D4;
3386 case ARM::Q3: return ARM::D6;
3387 case ARM::Q4: return ARM::D8;
3388 case ARM::Q5: return ARM::D10;
3389 case ARM::Q6: return ARM::D12;
3390 case ARM::Q7: return ARM::D14;
3391 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003392 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003393 case ARM::Q10: return ARM::D20;
3394 case ARM::Q11: return ARM::D22;
3395 case ARM::Q12: return ARM::D24;
3396 case ARM::Q13: return ARM::D26;
3397 case ARM::Q14: return ARM::D28;
3398 case ARM::Q15: return ARM::D30;
3399 }
3400}
3401
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003402/// Parse a register list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003403bool ARMAsmParser::parseRegisterList(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003404 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00003405 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003406 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003407 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003408 Parser.Lex(); // Eat '{' token.
3409 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003410
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003411 // Check the first register in the list to see what register class
3412 // this is a list of.
3413 int Reg = tryParseRegister();
3414 if (Reg == -1)
3415 return Error(RegLoc, "register expected");
3416
Jim Grosbach85a23432011-11-11 21:27:40 +00003417 // The reglist instructions have at most 16 registers, so reserve
3418 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003419 int EReg = 0;
3420 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003421
3422 // Allow Q regs and just interpret them as the two D sub-registers.
3423 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3424 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003425 EReg = MRI->getEncodingValue(Reg);
3426 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003427 ++Reg;
3428 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003429 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003430 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3431 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3432 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3433 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3434 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3435 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3436 else
3437 return Error(RegLoc, "invalid register in register list");
3438
Jim Grosbach85a23432011-11-11 21:27:40 +00003439 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003440 EReg = MRI->getEncodingValue(Reg);
3441 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003442
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003443 // This starts immediately after the first register token in the list,
3444 // so we can see either a comma or a minus (range separator) as a legal
3445 // next token.
3446 while (Parser.getTok().is(AsmToken::Comma) ||
3447 Parser.getTok().is(AsmToken::Minus)) {
3448 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003449 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003450 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003451 int EndReg = tryParseRegister();
3452 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003453 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003454 // Allow Q regs and just interpret them as the two D sub-registers.
3455 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3456 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003457 // If the register is the same as the start reg, there's nothing
3458 // more to do.
3459 if (Reg == EndReg)
3460 continue;
3461 // The register must be in the same register class as the first.
3462 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003463 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003464 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003465 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003466 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003467
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003468 // Add all the registers in the range to the register list.
3469 while (Reg != EndReg) {
3470 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003471 EReg = MRI->getEncodingValue(Reg);
3472 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003473 }
3474 continue;
3475 }
3476 Parser.Lex(); // Eat the comma.
3477 RegLoc = Parser.getTok().getLoc();
3478 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003479 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003480 Reg = tryParseRegister();
3481 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003482 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003483 // Allow Q regs and just interpret them as the two D sub-registers.
3484 bool isQReg = false;
3485 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3486 Reg = getDRegFromQReg(Reg);
3487 isQReg = true;
3488 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003489 // The register must be in the same register class as the first.
3490 if (!RC->contains(Reg))
3491 return Error(RegLoc, "invalid register in register list");
3492 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003493 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003494 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3495 Warning(RegLoc, "register list not in ascending order");
3496 else
3497 return Error(RegLoc, "register list not in ascending order");
3498 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003499 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003500 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3501 ") in register list");
3502 continue;
3503 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003504 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003505 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3506 Reg != OldReg + 1)
3507 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003508 EReg = MRI->getEncodingValue(Reg);
3509 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3510 if (isQReg) {
3511 EReg = MRI->getEncodingValue(++Reg);
3512 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3513 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003514 }
3515
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003516 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003517 return Error(Parser.getTok().getLoc(), "'}' expected");
3518 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003519 Parser.Lex(); // Eat '}' token.
3520
Jim Grosbach18bf3632011-12-13 21:48:29 +00003521 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003522 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003523
3524 // The ARM system instruction variants for LDM/STM have a '^' token here.
3525 if (Parser.getTok().is(AsmToken::Caret)) {
3526 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3527 Parser.Lex(); // Eat '^' token.
3528 }
3529
Bill Wendling2063b842010-11-18 23:43:05 +00003530 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003531}
3532
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003533// Helper function to parse the lane index for vector lists.
3534ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003535parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003536 MCAsmParser &Parser = getParser();
Jim Grosbach04945c42011-12-02 00:35:16 +00003537 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003538 if (Parser.getTok().is(AsmToken::LBrac)) {
3539 Parser.Lex(); // Eat the '['.
3540 if (Parser.getTok().is(AsmToken::RBrac)) {
3541 // "Dn[]" is the 'all lanes' syntax.
3542 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003543 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003544 Parser.Lex(); // Eat the ']'.
3545 return MatchOperand_Success;
3546 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003547
3548 // There's an optional '#' token here. Normally there wouldn't be, but
3549 // inline assemble puts one in, and it's friendly to accept that.
3550 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003551 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003552
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003553 const MCExpr *LaneIndex;
3554 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003555 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003556 Error(Loc, "illegal expression");
3557 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003558 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003559 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3560 if (!CE) {
3561 Error(Loc, "lane index must be empty or an integer");
3562 return MatchOperand_ParseFail;
3563 }
3564 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3565 Error(Parser.getTok().getLoc(), "']' expected");
3566 return MatchOperand_ParseFail;
3567 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003568 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003569 Parser.Lex(); // Eat the ']'.
3570 int64_t Val = CE->getValue();
3571
3572 // FIXME: Make this range check context sensitive for .8, .16, .32.
3573 if (Val < 0 || Val > 7) {
3574 Error(Parser.getTok().getLoc(), "lane index out of range");
3575 return MatchOperand_ParseFail;
3576 }
3577 Index = Val;
3578 LaneKind = IndexedLane;
3579 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003580 }
3581 LaneKind = NoLanes;
3582 return MatchOperand_Success;
3583}
3584
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003585// parse a vector register list
David Blaikie960ea3f2014-06-08 16:18:35 +00003586ARMAsmParser::OperandMatchResultTy
3587ARMAsmParser::parseVectorList(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003588 MCAsmParser &Parser = getParser();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003589 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003590 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003591 SMLoc S = Parser.getTok().getLoc();
3592 // As an extension (to match gas), support a plain D register or Q register
3593 // (without encosing curly braces) as a single or double entry list,
3594 // respectively.
3595 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003596 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003597 int Reg = tryParseRegister();
3598 if (Reg == -1)
3599 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003600 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003601 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003602 if (Res != MatchOperand_Success)
3603 return Res;
3604 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003605 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003606 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003607 break;
3608 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003609 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3610 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003611 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003612 case IndexedLane:
3613 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003614 LaneIndex,
3615 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003616 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003617 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003618 return MatchOperand_Success;
3619 }
3620 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3621 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003622 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003623 if (Res != MatchOperand_Success)
3624 return Res;
3625 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003626 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003627 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003628 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003629 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003630 break;
3631 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003632 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3633 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003634 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3635 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003636 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003637 case IndexedLane:
3638 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003639 LaneIndex,
3640 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003641 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003642 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003643 return MatchOperand_Success;
3644 }
3645 Error(S, "vector register expected");
3646 return MatchOperand_ParseFail;
3647 }
3648
3649 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003650 return MatchOperand_NoMatch;
3651
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003652 Parser.Lex(); // Eat '{' token.
3653 SMLoc RegLoc = Parser.getTok().getLoc();
3654
3655 int Reg = tryParseRegister();
3656 if (Reg == -1) {
3657 Error(RegLoc, "register expected");
3658 return MatchOperand_ParseFail;
3659 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003660 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003661 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003662 unsigned FirstReg = Reg;
3663 // The list is of D registers, but we also allow Q regs and just interpret
3664 // them as the two D sub-registers.
3665 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3666 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003667 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3668 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003669 ++Reg;
3670 ++Count;
3671 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003672
3673 SMLoc E;
3674 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003675 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003676
Jim Grosbache891fe82011-11-15 23:19:15 +00003677 while (Parser.getTok().is(AsmToken::Comma) ||
3678 Parser.getTok().is(AsmToken::Minus)) {
3679 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003680 if (!Spacing)
3681 Spacing = 1; // Register range implies a single spaced list.
3682 else if (Spacing == 2) {
3683 Error(Parser.getTok().getLoc(),
3684 "sequential registers in double spaced list");
3685 return MatchOperand_ParseFail;
3686 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003687 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003688 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003689 int EndReg = tryParseRegister();
3690 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003691 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003692 return MatchOperand_ParseFail;
3693 }
3694 // Allow Q regs and just interpret them as the two D sub-registers.
3695 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3696 EndReg = getDRegFromQReg(EndReg) + 1;
3697 // If the register is the same as the start reg, there's nothing
3698 // more to do.
3699 if (Reg == EndReg)
3700 continue;
3701 // The register must be in the same register class as the first.
3702 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003703 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003704 return MatchOperand_ParseFail;
3705 }
3706 // Ranges must go from low to high.
3707 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003708 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003709 return MatchOperand_ParseFail;
3710 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003711 // Parse the lane specifier if present.
3712 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003713 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003714 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3715 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003716 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003717 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003718 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003719 return MatchOperand_ParseFail;
3720 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003721
3722 // Add all the registers in the range to the register list.
3723 Count += EndReg - Reg;
3724 Reg = EndReg;
3725 continue;
3726 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003727 Parser.Lex(); // Eat the comma.
3728 RegLoc = Parser.getTok().getLoc();
3729 int OldReg = Reg;
3730 Reg = tryParseRegister();
3731 if (Reg == -1) {
3732 Error(RegLoc, "register expected");
3733 return MatchOperand_ParseFail;
3734 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003735 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003736 // It's OK to use the enumeration values directly here rather, as the
3737 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003738 //
3739 // The list is of D registers, but we also allow Q regs and just interpret
3740 // them as the two D sub-registers.
3741 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003742 if (!Spacing)
3743 Spacing = 1; // Register range implies a single spaced list.
3744 else if (Spacing == 2) {
3745 Error(RegLoc,
3746 "invalid register in double-spaced list (must be 'D' register')");
3747 return MatchOperand_ParseFail;
3748 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003749 Reg = getDRegFromQReg(Reg);
3750 if (Reg != OldReg + 1) {
3751 Error(RegLoc, "non-contiguous register range");
3752 return MatchOperand_ParseFail;
3753 }
3754 ++Reg;
3755 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003756 // Parse the lane specifier if present.
3757 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003758 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003759 SMLoc LaneLoc = Parser.getTok().getLoc();
3760 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3761 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003762 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003763 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003764 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003765 return MatchOperand_ParseFail;
3766 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003767 continue;
3768 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003769 // Normal D register.
3770 // Figure out the register spacing (single or double) of the list if
3771 // we don't know it already.
3772 if (!Spacing)
3773 Spacing = 1 + (Reg == OldReg + 2);
3774
3775 // Just check that it's contiguous and keep going.
3776 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003777 Error(RegLoc, "non-contiguous register range");
3778 return MatchOperand_ParseFail;
3779 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003780 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003781 // Parse the lane specifier if present.
3782 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003783 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003784 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003785 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003786 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003787 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003788 Error(EndLoc, "mismatched lane index in register list");
3789 return MatchOperand_ParseFail;
3790 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003791 }
3792
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003793 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003794 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003795 return MatchOperand_ParseFail;
3796 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003797 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003798 Parser.Lex(); // Eat '}' token.
3799
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003800 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003801 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003802 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003803 // composite register classes.
3804 if (Count == 2) {
3805 const MCRegisterClass *RC = (Spacing == 1) ?
3806 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3807 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3808 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3809 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003810
Jim Grosbach2f50e922011-12-15 21:44:33 +00003811 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3812 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003813 break;
3814 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003815 // Two-register operands have been converted to the
3816 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003817 if (Count == 2) {
3818 const MCRegisterClass *RC = (Spacing == 1) ?
3819 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3820 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003821 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3822 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003823 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003824 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003825 S, E));
3826 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003827 case IndexedLane:
3828 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003829 LaneIndex,
3830 (Spacing == 2),
3831 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003832 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003833 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003834 return MatchOperand_Success;
3835}
3836
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003837/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003838ARMAsmParser::OperandMatchResultTy
3839ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003840 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003841 SMLoc S = Parser.getTok().getLoc();
3842 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003843 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003844
Jiangning Liu288e1af2012-08-02 08:21:27 +00003845 if (Tok.is(AsmToken::Identifier)) {
3846 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003847
Jiangning Liu288e1af2012-08-02 08:21:27 +00003848 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3849 .Case("sy", ARM_MB::SY)
3850 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003851 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003852 .Case("sh", ARM_MB::ISH)
3853 .Case("ish", ARM_MB::ISH)
3854 .Case("shst", ARM_MB::ISHST)
3855 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003856 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003857 .Case("nsh", ARM_MB::NSH)
3858 .Case("un", ARM_MB::NSH)
3859 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003860 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003861 .Case("unst", ARM_MB::NSHST)
3862 .Case("osh", ARM_MB::OSH)
3863 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003864 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003865 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003866
Joey Gouly926d3f52013-09-05 15:35:24 +00003867 // ishld, oshld, nshld and ld are only available from ARMv8.
3868 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3869 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3870 Opt = ~0U;
3871
Jiangning Liu288e1af2012-08-02 08:21:27 +00003872 if (Opt == ~0U)
3873 return MatchOperand_NoMatch;
3874
3875 Parser.Lex(); // Eat identifier token.
3876 } else if (Tok.is(AsmToken::Hash) ||
3877 Tok.is(AsmToken::Dollar) ||
3878 Tok.is(AsmToken::Integer)) {
3879 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003880 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003881 SMLoc Loc = Parser.getTok().getLoc();
3882
3883 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003884 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003885 Error(Loc, "illegal expression");
3886 return MatchOperand_ParseFail;
3887 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00003888
Jiangning Liu288e1af2012-08-02 08:21:27 +00003889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3890 if (!CE) {
3891 Error(Loc, "constant expression expected");
3892 return MatchOperand_ParseFail;
3893 }
3894
3895 int Val = CE->getValue();
3896 if (Val & ~0xf) {
3897 Error(Loc, "immediate value out of range");
3898 return MatchOperand_ParseFail;
3899 }
3900
3901 Opt = ARM_MB::RESERVED_0 + Val;
3902 } else
3903 return MatchOperand_ParseFail;
3904
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003905 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003906 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003907}
3908
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003909/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003910ARMAsmParser::OperandMatchResultTy
3911ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003912 MCAsmParser &Parser = getParser();
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003913 SMLoc S = Parser.getTok().getLoc();
3914 const AsmToken &Tok = Parser.getTok();
3915 unsigned Opt;
3916
3917 if (Tok.is(AsmToken::Identifier)) {
3918 StringRef OptStr = Tok.getString();
3919
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003920 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003921 Opt = ARM_ISB::SY;
3922 else
3923 return MatchOperand_NoMatch;
3924
3925 Parser.Lex(); // Eat identifier token.
3926 } else if (Tok.is(AsmToken::Hash) ||
3927 Tok.is(AsmToken::Dollar) ||
3928 Tok.is(AsmToken::Integer)) {
3929 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003930 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003931 SMLoc Loc = Parser.getTok().getLoc();
3932
3933 const MCExpr *ISBarrierID;
3934 if (getParser().parseExpression(ISBarrierID)) {
3935 Error(Loc, "illegal expression");
3936 return MatchOperand_ParseFail;
3937 }
3938
3939 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3940 if (!CE) {
3941 Error(Loc, "constant expression expected");
3942 return MatchOperand_ParseFail;
3943 }
3944
3945 int Val = CE->getValue();
3946 if (Val & ~0xf) {
3947 Error(Loc, "immediate value out of range");
3948 return MatchOperand_ParseFail;
3949 }
3950
3951 Opt = ARM_ISB::RESERVED_0 + Val;
3952 } else
3953 return MatchOperand_ParseFail;
3954
3955 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3956 (ARM_ISB::InstSyncBOpt)Opt, S));
3957 return MatchOperand_Success;
3958}
3959
3960
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003961/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003962ARMAsmParser::OperandMatchResultTy
3963ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003964 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003965 SMLoc S = Parser.getTok().getLoc();
3966 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003967 if (!Tok.is(AsmToken::Identifier))
3968 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003969 StringRef IFlagsStr = Tok.getString();
3970
Owen Anderson10c5b122011-10-05 17:16:40 +00003971 // An iflags string of "none" is interpreted to mean that none of the AIF
3972 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003973 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003974 if (IFlagsStr != "none") {
3975 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3976 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3977 .Case("a", ARM_PROC::A)
3978 .Case("i", ARM_PROC::I)
3979 .Case("f", ARM_PROC::F)
3980 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003981
Owen Anderson10c5b122011-10-05 17:16:40 +00003982 // If some specific iflag is already set, it means that some letter is
3983 // present more than once, this is not acceptable.
3984 if (Flag == ~0U || (IFlags & Flag))
3985 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003986
Owen Anderson10c5b122011-10-05 17:16:40 +00003987 IFlags |= Flag;
3988 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003989 }
3990
3991 Parser.Lex(); // Eat identifier token.
3992 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3993 return MatchOperand_Success;
3994}
3995
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003996/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003997ARMAsmParser::OperandMatchResultTy
3998ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003999 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004000 SMLoc S = Parser.getTok().getLoc();
4001 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00004002 if (!Tok.is(AsmToken::Identifier))
4003 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004004 StringRef Mask = Tok.getString();
4005
James Molloy21efa7d2011-09-28 14:21:38 +00004006 if (isMClass()) {
4007 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00004008 std::string Name = Mask.lower();
4009 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00004010 // Note: in the documentation:
4011 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
4012 // for MSR APSR_nzcvq.
4013 // but we do make it an alias here. This is so to get the "mask encoding"
4014 // bits correct on MSR APSR writes.
4015 //
4016 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
4017 // should really only be allowed when writing a special register. Note
4018 // they get dropped in the MRS instruction reading a special register as
4019 // the SYSm field is only 8 bits.
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00004020 .Case("apsr", 0x800)
4021 .Case("apsr_nzcvq", 0x800)
4022 .Case("apsr_g", 0x400)
4023 .Case("apsr_nzcvqg", 0xc00)
4024 .Case("iapsr", 0x801)
4025 .Case("iapsr_nzcvq", 0x801)
4026 .Case("iapsr_g", 0x401)
4027 .Case("iapsr_nzcvqg", 0xc01)
4028 .Case("eapsr", 0x802)
4029 .Case("eapsr_nzcvq", 0x802)
4030 .Case("eapsr_g", 0x402)
4031 .Case("eapsr_nzcvqg", 0xc02)
4032 .Case("xpsr", 0x803)
4033 .Case("xpsr_nzcvq", 0x803)
4034 .Case("xpsr_g", 0x403)
4035 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00004036 .Case("ipsr", 0x805)
4037 .Case("epsr", 0x806)
4038 .Case("iepsr", 0x807)
4039 .Case("msp", 0x808)
4040 .Case("psp", 0x809)
4041 .Case("primask", 0x810)
4042 .Case("basepri", 0x811)
4043 .Case("basepri_max", 0x812)
4044 .Case("faultmask", 0x813)
4045 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00004046 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00004047
James Molloy21efa7d2011-09-28 14:21:38 +00004048 if (FlagsVal == ~0U)
4049 return MatchOperand_NoMatch;
4050
Renato Golin92c816c2014-09-01 11:25:07 +00004051 if (!hasThumb2DSP() && (FlagsVal & 0x400))
4052 // The _g and _nzcvqg versions are only valid if the DSP extension is
4053 // available.
4054 return MatchOperand_NoMatch;
4055
Kevin Enderby6c7279e2012-06-15 22:14:44 +00004056 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00004057 // basepri, basepri_max and faultmask only valid for V7m.
4058 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00004059
James Molloy21efa7d2011-09-28 14:21:38 +00004060 Parser.Lex(); // Eat identifier token.
4061 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4062 return MatchOperand_Success;
4063 }
4064
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004065 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
4066 size_t Start = 0, Next = Mask.find('_');
4067 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004068 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004069 if (Next != StringRef::npos)
4070 Flags = Mask.slice(Next+1, Mask.size());
4071
4072 // FlagsVal contains the complete mask:
4073 // 3-0: Mask
4074 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4075 unsigned FlagsVal = 0;
4076
4077 if (SpecReg == "apsr") {
4078 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00004079 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004080 .Case("g", 0x4) // same as CPSR_s
4081 .Case("nzcvqg", 0xc) // same as CPSR_fs
4082 .Default(~0U);
4083
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00004084 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004085 if (!Flags.empty())
4086 return MatchOperand_NoMatch;
4087 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00004088 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00004089 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004090 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00004091 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
4092 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00004093 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004094 for (int i = 0, e = Flags.size(); i != e; ++i) {
4095 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
4096 .Case("c", 1)
4097 .Case("x", 2)
4098 .Case("s", 4)
4099 .Case("f", 8)
4100 .Default(~0U);
4101
4102 // If some specific flag is already set, it means that some letter is
4103 // present more than once, this is not acceptable.
4104 if (FlagsVal == ~0U || (FlagsVal & Flag))
4105 return MatchOperand_NoMatch;
4106 FlagsVal |= Flag;
4107 }
4108 } else // No match for special register.
4109 return MatchOperand_NoMatch;
4110
Owen Anderson03a173e2011-10-21 18:43:28 +00004111 // Special register without flags is NOT equivalent to "fc" flags.
4112 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
4113 // two lines would enable gas compatibility at the expense of breaking
4114 // round-tripping.
4115 //
4116 // if (!FlagsVal)
4117 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004118
4119 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4120 if (SpecReg == "spsr")
4121 FlagsVal |= 16;
4122
4123 Parser.Lex(); // Eat identifier token.
4124 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4125 return MatchOperand_Success;
4126}
4127
Tim Northoveree843ef2014-08-15 10:47:12 +00004128/// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for
4129/// use in the MRS/MSR instructions added to support virtualization.
4130ARMAsmParser::OperandMatchResultTy
4131ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004132 MCAsmParser &Parser = getParser();
Tim Northoveree843ef2014-08-15 10:47:12 +00004133 SMLoc S = Parser.getTok().getLoc();
4134 const AsmToken &Tok = Parser.getTok();
4135 if (!Tok.is(AsmToken::Identifier))
4136 return MatchOperand_NoMatch;
4137 StringRef RegName = Tok.getString();
4138
4139 // The values here come from B9.2.3 of the ARM ARM, where bits 4-0 are SysM
4140 // and bit 5 is R.
4141 unsigned Encoding = StringSwitch<unsigned>(RegName.lower())
4142 .Case("r8_usr", 0x00)
4143 .Case("r9_usr", 0x01)
4144 .Case("r10_usr", 0x02)
4145 .Case("r11_usr", 0x03)
4146 .Case("r12_usr", 0x04)
4147 .Case("sp_usr", 0x05)
4148 .Case("lr_usr", 0x06)
4149 .Case("r8_fiq", 0x08)
4150 .Case("r9_fiq", 0x09)
4151 .Case("r10_fiq", 0x0a)
4152 .Case("r11_fiq", 0x0b)
4153 .Case("r12_fiq", 0x0c)
4154 .Case("sp_fiq", 0x0d)
4155 .Case("lr_fiq", 0x0e)
4156 .Case("lr_irq", 0x10)
4157 .Case("sp_irq", 0x11)
4158 .Case("lr_svc", 0x12)
4159 .Case("sp_svc", 0x13)
4160 .Case("lr_abt", 0x14)
4161 .Case("sp_abt", 0x15)
4162 .Case("lr_und", 0x16)
4163 .Case("sp_und", 0x17)
4164 .Case("lr_mon", 0x1c)
4165 .Case("sp_mon", 0x1d)
4166 .Case("elr_hyp", 0x1e)
4167 .Case("sp_hyp", 0x1f)
4168 .Case("spsr_fiq", 0x2e)
4169 .Case("spsr_irq", 0x30)
4170 .Case("spsr_svc", 0x32)
4171 .Case("spsr_abt", 0x34)
4172 .Case("spsr_und", 0x36)
4173 .Case("spsr_mon", 0x3c)
4174 .Case("spsr_hyp", 0x3e)
4175 .Default(~0U);
4176
4177 if (Encoding == ~0U)
4178 return MatchOperand_NoMatch;
4179
4180 Parser.Lex(); // Eat identifier token.
4181 Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S));
4182 return MatchOperand_Success;
4183}
4184
David Blaikie960ea3f2014-06-08 16:18:35 +00004185ARMAsmParser::OperandMatchResultTy
4186ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low,
4187 int High) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004188 MCAsmParser &Parser = getParser();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004189 const AsmToken &Tok = Parser.getTok();
4190 if (Tok.isNot(AsmToken::Identifier)) {
4191 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4192 return MatchOperand_ParseFail;
4193 }
4194 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004195 std::string LowerOp = Op.lower();
4196 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004197 if (ShiftName != LowerOp && ShiftName != UpperOp) {
4198 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4199 return MatchOperand_ParseFail;
4200 }
4201 Parser.Lex(); // Eat shift type token.
4202
4203 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004204 if (Parser.getTok().isNot(AsmToken::Hash) &&
4205 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004206 Error(Parser.getTok().getLoc(), "'#' expected");
4207 return MatchOperand_ParseFail;
4208 }
4209 Parser.Lex(); // Eat hash token.
4210
4211 const MCExpr *ShiftAmount;
4212 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004213 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004214 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004215 Error(Loc, "illegal expression");
4216 return MatchOperand_ParseFail;
4217 }
4218 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4219 if (!CE) {
4220 Error(Loc, "constant expression expected");
4221 return MatchOperand_ParseFail;
4222 }
4223 int Val = CE->getValue();
4224 if (Val < Low || Val > High) {
4225 Error(Loc, "immediate value out of range");
4226 return MatchOperand_ParseFail;
4227 }
4228
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004229 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00004230
4231 return MatchOperand_Success;
4232}
4233
David Blaikie960ea3f2014-06-08 16:18:35 +00004234ARMAsmParser::OperandMatchResultTy
4235ARMAsmParser::parseSetEndImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004236 MCAsmParser &Parser = getParser();
Jim Grosbach0a547702011-07-22 17:44:50 +00004237 const AsmToken &Tok = Parser.getTok();
4238 SMLoc S = Tok.getLoc();
4239 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004240 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004241 return MatchOperand_ParseFail;
4242 }
Tim Northover4d141442013-05-31 15:58:45 +00004243 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00004244 .Case("be", 1)
4245 .Case("le", 0)
4246 .Default(-1);
4247 Parser.Lex(); // Eat the token.
4248
4249 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004250 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004251 return MatchOperand_ParseFail;
4252 }
4253 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4254 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004255 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00004256 return MatchOperand_Success;
4257}
4258
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004259/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
4260/// instructions. Legal values are:
4261/// lsl #n 'n' in [0,31]
4262/// asr #n 'n' in [1,32]
4263/// n == 32 encoded as n == 0.
David Blaikie960ea3f2014-06-08 16:18:35 +00004264ARMAsmParser::OperandMatchResultTy
4265ARMAsmParser::parseShifterImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004266 MCAsmParser &Parser = getParser();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004267 const AsmToken &Tok = Parser.getTok();
4268 SMLoc S = Tok.getLoc();
4269 if (Tok.isNot(AsmToken::Identifier)) {
4270 Error(S, "shift operator 'asr' or 'lsl' expected");
4271 return MatchOperand_ParseFail;
4272 }
4273 StringRef ShiftName = Tok.getString();
4274 bool isASR;
4275 if (ShiftName == "lsl" || ShiftName == "LSL")
4276 isASR = false;
4277 else if (ShiftName == "asr" || ShiftName == "ASR")
4278 isASR = true;
4279 else {
4280 Error(S, "shift operator 'asr' or 'lsl' expected");
4281 return MatchOperand_ParseFail;
4282 }
4283 Parser.Lex(); // Eat the operator.
4284
4285 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004286 if (Parser.getTok().isNot(AsmToken::Hash) &&
4287 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004288 Error(Parser.getTok().getLoc(), "'#' expected");
4289 return MatchOperand_ParseFail;
4290 }
4291 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004292 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004293
4294 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004295 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004296 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004297 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004298 return MatchOperand_ParseFail;
4299 }
4300 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4301 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004302 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004303 return MatchOperand_ParseFail;
4304 }
4305
4306 int64_t Val = CE->getValue();
4307 if (isASR) {
4308 // Shift amount must be in [1,32]
4309 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004310 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004311 return MatchOperand_ParseFail;
4312 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00004313 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4314 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004315 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00004316 return MatchOperand_ParseFail;
4317 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004318 if (Val == 32) Val = 0;
4319 } else {
4320 // Shift amount must be in [1,32]
4321 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004322 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004323 return MatchOperand_ParseFail;
4324 }
4325 }
4326
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004327 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004328
4329 return MatchOperand_Success;
4330}
4331
Jim Grosbach833b9d32011-07-27 20:15:40 +00004332/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4333/// of instructions. Legal values are:
4334/// ror #n 'n' in {0, 8, 16, 24}
David Blaikie960ea3f2014-06-08 16:18:35 +00004335ARMAsmParser::OperandMatchResultTy
4336ARMAsmParser::parseRotImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004337 MCAsmParser &Parser = getParser();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004338 const AsmToken &Tok = Parser.getTok();
4339 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00004340 if (Tok.isNot(AsmToken::Identifier))
4341 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004342 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00004343 if (ShiftName != "ror" && ShiftName != "ROR")
4344 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004345 Parser.Lex(); // Eat the operator.
4346
4347 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004348 if (Parser.getTok().isNot(AsmToken::Hash) &&
4349 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004350 Error(Parser.getTok().getLoc(), "'#' expected");
4351 return MatchOperand_ParseFail;
4352 }
4353 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004354 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004355
4356 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004357 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004358 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004359 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004360 return MatchOperand_ParseFail;
4361 }
4362 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4363 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004364 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004365 return MatchOperand_ParseFail;
4366 }
4367
4368 int64_t Val = CE->getValue();
4369 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4370 // normally, zero is represented in asm by omitting the rotate operand
4371 // entirely.
4372 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004373 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004374 return MatchOperand_ParseFail;
4375 }
4376
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004377 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004378
4379 return MatchOperand_Success;
4380}
4381
David Blaikie960ea3f2014-06-08 16:18:35 +00004382ARMAsmParser::OperandMatchResultTy
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004383ARMAsmParser::parseModImm(OperandVector &Operands) {
4384 MCAsmParser &Parser = getParser();
4385 MCAsmLexer &Lexer = getLexer();
4386 int64_t Imm1, Imm2;
4387
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004388 SMLoc S = Parser.getTok().getLoc();
4389
Asiri Rathnayake13cef352014-12-04 19:34:59 +00004390 // 1) A mod_imm operand can appear in the place of a register name:
4391 // add r0, #mod_imm
4392 // add r0, r0, #mod_imm
4393 // to correctly handle the latter, we bail out as soon as we see an
4394 // identifier.
4395 //
4396 // 2) Similarly, we do not want to parse into complex operands:
4397 // mov r0, #mod_imm
4398 // mov r0, :lower16:(_foo)
4399 if (Parser.getTok().is(AsmToken::Identifier) ||
4400 Parser.getTok().is(AsmToken::Colon))
4401 return MatchOperand_NoMatch;
4402
4403 // Hash (dollar) is optional as per the ARMARM
4404 if (Parser.getTok().is(AsmToken::Hash) ||
4405 Parser.getTok().is(AsmToken::Dollar)) {
4406 // Avoid parsing into complex operands (#:)
4407 if (Lexer.peekTok().is(AsmToken::Colon))
4408 return MatchOperand_NoMatch;
4409
4410 // Eat the hash (dollar)
4411 Parser.Lex();
4412 }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004413
4414 SMLoc Sx1, Ex1;
4415 Sx1 = Parser.getTok().getLoc();
4416 const MCExpr *Imm1Exp;
4417 if (getParser().parseExpression(Imm1Exp, Ex1)) {
4418 Error(Sx1, "malformed expression");
4419 return MatchOperand_ParseFail;
4420 }
4421
4422 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm1Exp);
4423
4424 if (CE) {
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004425 // Immediate must fit within 32-bits
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004426 Imm1 = CE->getValue();
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004427 int Enc = ARM_AM::getSOImmVal(Imm1);
4428 if (Enc != -1 && Parser.getTok().is(AsmToken::EndOfStatement)) {
4429 // We have a match!
4430 Operands.push_back(ARMOperand::CreateModImm((Enc & 0xFF),
4431 (Enc & 0xF00) >> 7,
4432 Sx1, Ex1));
4433 return MatchOperand_Success;
4434 }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004435
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004436 // We have parsed an immediate which is not for us, fallback to a plain
4437 // immediate. This can happen for instruction aliases. For an example,
4438 // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform
4439 // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite
4440 // instruction with a mod_imm operand. The alias is defined such that the
4441 // parser method is shared, that's why we have to do this here.
4442 if (Parser.getTok().is(AsmToken::EndOfStatement)) {
4443 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4444 return MatchOperand_Success;
4445 }
4446 } else {
4447 // Operands like #(l1 - l2) can only be evaluated at a later stage (via an
4448 // MCFixup). Fallback to a plain immediate.
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004449 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4450 return MatchOperand_Success;
4451 }
4452
4453 // From this point onward, we expect the input to be a (#bits, #rot) pair
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004454 if (Parser.getTok().isNot(AsmToken::Comma)) {
4455 Error(Sx1, "expected modified immediate operand: #[0, 255], #even[0-30]");
4456 return MatchOperand_ParseFail;
4457 }
4458
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004459 if (Imm1 & ~0xFF) {
4460 Error(Sx1, "immediate operand must a number in the range [0, 255]");
4461 return MatchOperand_ParseFail;
4462 }
4463
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004464 // Eat the comma
4465 Parser.Lex();
4466
4467 // Repeat for #rot
4468 SMLoc Sx2, Ex2;
4469 Sx2 = Parser.getTok().getLoc();
4470
Asiri Rathnayake13cef352014-12-04 19:34:59 +00004471 // Eat the optional hash (dollar)
4472 if (Parser.getTok().is(AsmToken::Hash) ||
4473 Parser.getTok().is(AsmToken::Dollar))
4474 Parser.Lex();
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004475
4476 const MCExpr *Imm2Exp;
4477 if (getParser().parseExpression(Imm2Exp, Ex2)) {
4478 Error(Sx2, "malformed expression");
4479 return MatchOperand_ParseFail;
4480 }
4481
4482 CE = dyn_cast<MCConstantExpr>(Imm2Exp);
4483
4484 if (CE) {
4485 Imm2 = CE->getValue();
4486 if (!(Imm2 & ~0x1E)) {
4487 // We have a match!
4488 Operands.push_back(ARMOperand::CreateModImm(Imm1, Imm2, S, Ex2));
4489 return MatchOperand_Success;
4490 }
4491 Error(Sx2, "immediate operand must an even number in the range [0, 30]");
4492 return MatchOperand_ParseFail;
4493 } else {
4494 Error(Sx2, "constant expression expected");
4495 return MatchOperand_ParseFail;
4496 }
4497}
4498
4499ARMAsmParser::OperandMatchResultTy
David Blaikie960ea3f2014-06-08 16:18:35 +00004500ARMAsmParser::parseBitfield(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004501 MCAsmParser &Parser = getParser();
Jim Grosbach864b6092011-07-28 21:34:26 +00004502 SMLoc S = Parser.getTok().getLoc();
4503 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004504 if (Parser.getTok().isNot(AsmToken::Hash) &&
4505 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004506 Error(Parser.getTok().getLoc(), "'#' expected");
4507 return MatchOperand_ParseFail;
4508 }
4509 Parser.Lex(); // Eat hash token.
4510
4511 const MCExpr *LSBExpr;
4512 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004513 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004514 Error(E, "malformed immediate expression");
4515 return MatchOperand_ParseFail;
4516 }
4517 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4518 if (!CE) {
4519 Error(E, "'lsb' operand must be an immediate");
4520 return MatchOperand_ParseFail;
4521 }
4522
4523 int64_t LSB = CE->getValue();
4524 // The LSB must be in the range [0,31]
4525 if (LSB < 0 || LSB > 31) {
4526 Error(E, "'lsb' operand must be in the range [0,31]");
4527 return MatchOperand_ParseFail;
4528 }
4529 E = Parser.getTok().getLoc();
4530
4531 // Expect another immediate operand.
4532 if (Parser.getTok().isNot(AsmToken::Comma)) {
4533 Error(Parser.getTok().getLoc(), "too few operands");
4534 return MatchOperand_ParseFail;
4535 }
4536 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004537 if (Parser.getTok().isNot(AsmToken::Hash) &&
4538 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004539 Error(Parser.getTok().getLoc(), "'#' expected");
4540 return MatchOperand_ParseFail;
4541 }
4542 Parser.Lex(); // Eat hash token.
4543
4544 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004545 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004546 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004547 Error(E, "malformed immediate expression");
4548 return MatchOperand_ParseFail;
4549 }
4550 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4551 if (!CE) {
4552 Error(E, "'width' operand must be an immediate");
4553 return MatchOperand_ParseFail;
4554 }
4555
4556 int64_t Width = CE->getValue();
4557 // The LSB must be in the range [1,32-lsb]
4558 if (Width < 1 || Width > 32 - LSB) {
4559 Error(E, "'width' operand must be in the range [1,32-lsb]");
4560 return MatchOperand_ParseFail;
4561 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004562
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004563 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004564
4565 return MatchOperand_Success;
4566}
4567
David Blaikie960ea3f2014-06-08 16:18:35 +00004568ARMAsmParser::OperandMatchResultTy
4569ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
Jim Grosbachd3595712011-08-03 23:50:40 +00004570 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004571 // postidx_reg := '+' register {, shift}
4572 // | '-' register {, shift}
4573 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004574
4575 // This method must return MatchOperand_NoMatch without consuming any tokens
4576 // in the case where there is no match, as other alternatives take other
4577 // parse methods.
Rafael Espindola961d4692014-11-11 05:18:41 +00004578 MCAsmParser &Parser = getParser();
Jim Grosbachd3595712011-08-03 23:50:40 +00004579 AsmToken Tok = Parser.getTok();
4580 SMLoc S = Tok.getLoc();
4581 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004582 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004583 if (Tok.is(AsmToken::Plus)) {
4584 Parser.Lex(); // Eat the '+' token.
4585 haveEaten = true;
4586 } else if (Tok.is(AsmToken::Minus)) {
4587 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004588 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004589 haveEaten = true;
4590 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004591
4592 SMLoc E = Parser.getTok().getEndLoc();
4593 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004594 if (Reg == -1) {
4595 if (!haveEaten)
4596 return MatchOperand_NoMatch;
4597 Error(Parser.getTok().getLoc(), "register expected");
4598 return MatchOperand_ParseFail;
4599 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004600
Jim Grosbachc320c852011-08-05 21:28:30 +00004601 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4602 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004603 if (Parser.getTok().is(AsmToken::Comma)) {
4604 Parser.Lex(); // Eat the ','.
4605 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4606 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004607
4608 // FIXME: Only approximates end...may include intervening whitespace.
4609 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004610 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004611
4612 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4613 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004614
4615 return MatchOperand_Success;
4616}
4617
David Blaikie960ea3f2014-06-08 16:18:35 +00004618ARMAsmParser::OperandMatchResultTy
4619ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004620 // Check for a post-index addressing register operand. Specifically:
4621 // am3offset := '+' register
4622 // | '-' register
4623 // | register
4624 // | # imm
4625 // | # + imm
4626 // | # - imm
4627
4628 // This method must return MatchOperand_NoMatch without consuming any tokens
4629 // in the case where there is no match, as other alternatives take other
4630 // parse methods.
Rafael Espindola961d4692014-11-11 05:18:41 +00004631 MCAsmParser &Parser = getParser();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004632 AsmToken Tok = Parser.getTok();
4633 SMLoc S = Tok.getLoc();
4634
4635 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004636 if (Parser.getTok().is(AsmToken::Hash) ||
4637 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004638 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004639 // Explicitly look for a '-', as we need to encode negative zero
4640 // differently.
4641 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4642 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004643 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004644 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004645 return MatchOperand_ParseFail;
4646 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4647 if (!CE) {
4648 Error(S, "constant expression expected");
4649 return MatchOperand_ParseFail;
4650 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004651 // Negative zero is encoded as the flag value INT32_MIN.
4652 int32_t Val = CE->getValue();
4653 if (isNegative && Val == 0)
4654 Val = INT32_MIN;
4655
4656 Operands.push_back(
4657 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4658
4659 return MatchOperand_Success;
4660 }
4661
4662
4663 bool haveEaten = false;
4664 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004665 if (Tok.is(AsmToken::Plus)) {
4666 Parser.Lex(); // Eat the '+' token.
4667 haveEaten = true;
4668 } else if (Tok.is(AsmToken::Minus)) {
4669 Parser.Lex(); // Eat the '-' token.
4670 isAdd = false;
4671 haveEaten = true;
4672 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004673
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004674 Tok = Parser.getTok();
4675 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004676 if (Reg == -1) {
4677 if (!haveEaten)
4678 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004679 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004680 return MatchOperand_ParseFail;
4681 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004682
4683 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004684 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004685
4686 return MatchOperand_Success;
4687}
4688
Tim Northovereb5e4d52013-07-22 09:06:12 +00004689/// Convert parsed operands to MCInst. Needed here because this instruction
4690/// only has two register operands, but multiplication is commutative so
4691/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
David Blaikie960ea3f2014-06-08 16:18:35 +00004692void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
4693 const OperandVector &Operands) {
4694 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1);
4695 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004696 // If we have a three-operand form, make sure to set Rn to be the operand
4697 // that isn't the same as Rd.
4698 unsigned RegOp = 4;
4699 if (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00004700 ((ARMOperand &)*Operands[4]).getReg() ==
4701 ((ARMOperand &)*Operands[3]).getReg())
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004702 RegOp = 5;
David Blaikie960ea3f2014-06-08 16:18:35 +00004703 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004704 Inst.addOperand(Inst.getOperand(0));
David Blaikie960ea3f2014-06-08 16:18:35 +00004705 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004706}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004707
David Blaikie960ea3f2014-06-08 16:18:35 +00004708void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
4709 const OperandVector &Operands) {
Mihai Popaad18d3c2013-08-09 10:38:32 +00004710 int CondOp = -1, ImmOp = -1;
4711 switch(Inst.getOpcode()) {
4712 case ARM::tB:
4713 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4714
4715 case ARM::t2B:
4716 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4717
4718 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4719 }
4720 // first decide whether or not the branch should be conditional
4721 // by looking at it's location relative to an IT block
4722 if(inITBlock()) {
4723 // inside an IT block we cannot have any conditional branches. any
4724 // such instructions needs to be converted to unconditional form
4725 switch(Inst.getOpcode()) {
4726 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4727 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4728 }
4729 } else {
4730 // outside IT blocks we can only have unconditional branches with AL
4731 // condition code or conditional branches with non-AL condition code
David Blaikie960ea3f2014-06-08 16:18:35 +00004732 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode();
Mihai Popaad18d3c2013-08-09 10:38:32 +00004733 switch(Inst.getOpcode()) {
4734 case ARM::tB:
4735 case ARM::tBcc:
4736 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4737 break;
4738 case ARM::t2B:
4739 case ARM::t2Bcc:
4740 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4741 break;
4742 }
4743 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004744
Mihai Popaad18d3c2013-08-09 10:38:32 +00004745 // now decide on encoding size based on branch target range
4746 switch(Inst.getOpcode()) {
4747 // classify tB as either t2B or t1B based on range of immediate operand
4748 case ARM::tB: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004749 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4750 if (!op.isSignedOffset<11, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004751 Inst.setOpcode(ARM::t2B);
4752 break;
4753 }
4754 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4755 case ARM::tBcc: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004756 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4757 if (!op.isSignedOffset<8, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004758 Inst.setOpcode(ARM::t2Bcc);
4759 break;
4760 }
4761 }
David Blaikie960ea3f2014-06-08 16:18:35 +00004762 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1);
4763 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2);
Mihai Popaad18d3c2013-08-09 10:38:32 +00004764}
4765
Bill Wendlinge18980a2010-11-06 22:36:58 +00004766/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004767/// or an error. The first token must be a '[' when called.
David Blaikie960ea3f2014-06-08 16:18:35 +00004768bool ARMAsmParser::parseMemory(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004769 MCAsmParser &Parser = getParser();
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004770 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004771 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004772 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004773 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004774 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004775
Sean Callanan936b0d32010-01-19 21:44:56 +00004776 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004777 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004778 if (BaseRegNum == -1)
4779 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004780
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004781 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004782 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004783 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4784 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004785 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004786
Jim Grosbachd3595712011-08-03 23:50:40 +00004787 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004788 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004789 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004790
Craig Topper062a2ba2014-04-25 05:30:21 +00004791 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4792 ARM_AM::no_shift, 0, 0, false,
4793 S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004794
Jim Grosbach40700e02011-09-19 18:42:21 +00004795 // If there's a pre-indexing writeback marker, '!', just add it as a token
4796 // operand. It's rather odd, but syntactically valid.
4797 if (Parser.getTok().is(AsmToken::Exclaim)) {
4798 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4799 Parser.Lex(); // Eat the '!'.
4800 }
4801
Jim Grosbachd3595712011-08-03 23:50:40 +00004802 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004803 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004804
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004805 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4806 "Lost colon or comma in memory operand?!");
4807 if (Tok.is(AsmToken::Comma)) {
4808 Parser.Lex(); // Eat the comma.
4809 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004810
Jim Grosbacha95ec992011-10-11 17:29:55 +00004811 // If we have a ':', it's an alignment specifier.
4812 if (Parser.getTok().is(AsmToken::Colon)) {
4813 Parser.Lex(); // Eat the ':'.
4814 E = Parser.getTok().getLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00004815 SMLoc AlignmentLoc = Tok.getLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004816
4817 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004818 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004819 return true;
4820
4821 // The expression has to be a constant. Memory references with relocations
4822 // don't come through here, as they use the <label> forms of the relevant
4823 // instructions.
4824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4825 if (!CE)
4826 return Error (E, "constant expression expected");
4827
4828 unsigned Align = 0;
4829 switch (CE->getValue()) {
4830 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004831 return Error(E,
4832 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4833 case 16: Align = 2; break;
4834 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004835 case 64: Align = 8; break;
4836 case 128: Align = 16; break;
4837 case 256: Align = 32; break;
4838 }
4839
4840 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004841 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004842 return Error(Parser.getTok().getLoc(), "']' expected");
4843 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004844 Parser.Lex(); // Eat right bracket token.
4845
4846 // Don't worry about range checking the value here. That's handled by
4847 // the is*() predicates.
Craig Topper062a2ba2014-04-25 05:30:21 +00004848 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004849 ARM_AM::no_shift, 0, Align,
Kevin Enderby488f20b2014-04-10 20:18:58 +00004850 false, S, E, AlignmentLoc));
Jim Grosbacha95ec992011-10-11 17:29:55 +00004851
4852 // If there's a pre-indexing writeback marker, '!', just add it as a token
4853 // operand.
4854 if (Parser.getTok().is(AsmToken::Exclaim)) {
4855 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4856 Parser.Lex(); // Eat the '!'.
4857 }
4858
4859 return false;
4860 }
4861
4862 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004863 // offset. Be friendly and also accept a plain integer (without a leading
4864 // hash) for gas compatibility.
4865 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004866 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004867 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004868 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004869 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004870 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004871
Owen Anderson967674d2011-08-29 19:36:44 +00004872 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004873 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004874 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004875 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004876
4877 // The expression has to be a constant. Memory references with relocations
4878 // don't come through here, as they use the <label> forms of the relevant
4879 // instructions.
4880 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4881 if (!CE)
4882 return Error (E, "constant expression expected");
4883
Owen Anderson967674d2011-08-29 19:36:44 +00004884 // If the constant was #-0, represent it as INT32_MIN.
4885 int32_t Val = CE->getValue();
4886 if (isNegative && Val == 0)
4887 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4888
Jim Grosbachd3595712011-08-03 23:50:40 +00004889 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004890 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004891 return Error(Parser.getTok().getLoc(), "']' expected");
4892 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004893 Parser.Lex(); // Eat right bracket token.
4894
4895 // Don't worry about range checking the value here. That's handled by
4896 // the is*() predicates.
4897 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004898 ARM_AM::no_shift, 0, 0,
4899 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004900
4901 // If there's a pre-indexing writeback marker, '!', just add it as a token
4902 // operand.
4903 if (Parser.getTok().is(AsmToken::Exclaim)) {
4904 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4905 Parser.Lex(); // Eat the '!'.
4906 }
4907
4908 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004909 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004910
4911 // The register offset is optionally preceded by a '+' or '-'
4912 bool isNegative = false;
4913 if (Parser.getTok().is(AsmToken::Minus)) {
4914 isNegative = true;
4915 Parser.Lex(); // Eat the '-'.
4916 } else if (Parser.getTok().is(AsmToken::Plus)) {
4917 // Nothing to do.
4918 Parser.Lex(); // Eat the '+'.
4919 }
4920
4921 E = Parser.getTok().getLoc();
4922 int OffsetRegNum = tryParseRegister();
4923 if (OffsetRegNum == -1)
4924 return Error(E, "register expected");
4925
4926 // If there's a shift operator, handle it.
4927 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004928 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004929 if (Parser.getTok().is(AsmToken::Comma)) {
4930 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004931 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004932 return true;
4933 }
4934
4935 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004936 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004937 return Error(Parser.getTok().getLoc(), "']' expected");
4938 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004939 Parser.Lex(); // Eat right bracket token.
4940
Craig Topper062a2ba2014-04-25 05:30:21 +00004941 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004942 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004943 S, E));
4944
Jim Grosbachc320c852011-08-05 21:28:30 +00004945 // If there's a pre-indexing writeback marker, '!', just add it as a token
4946 // operand.
4947 if (Parser.getTok().is(AsmToken::Exclaim)) {
4948 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4949 Parser.Lex(); // Eat the '!'.
4950 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004951
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004952 return false;
4953}
4954
Jim Grosbachd3595712011-08-03 23:50:40 +00004955/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004956/// ( lsl | lsr | asr | ror ) , # shift_amount
4957/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004958/// return true if it parses a shift otherwise it returns false.
4959bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4960 unsigned &Amount) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004961 MCAsmParser &Parser = getParser();
Jim Grosbachd3595712011-08-03 23:50:40 +00004962 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004963 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004964 if (Tok.isNot(AsmToken::Identifier))
4965 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004966 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004967 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4968 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004969 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004970 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004971 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004972 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004973 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004974 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004975 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004976 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004977 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004978 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004979 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004980 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004981
Jim Grosbachd3595712011-08-03 23:50:40 +00004982 // rrx stands alone.
4983 Amount = 0;
4984 if (St != ARM_AM::rrx) {
4985 Loc = Parser.getTok().getLoc();
4986 // A '#' and a shift amount.
4987 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004988 if (HashTok.isNot(AsmToken::Hash) &&
4989 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004990 return Error(HashTok.getLoc(), "'#' expected");
4991 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004992
Jim Grosbachd3595712011-08-03 23:50:40 +00004993 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004994 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004995 return true;
4996 // Range check the immediate.
4997 // lsl, ror: 0 <= imm <= 31
4998 // lsr, asr: 0 <= imm <= 32
4999 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
5000 if (!CE)
5001 return Error(Loc, "shift amount must be an immediate");
5002 int64_t Imm = CE->getValue();
5003 if (Imm < 0 ||
5004 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
5005 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
5006 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00005007 // If <ShiftTy> #0, turn it into a no_shift.
5008 if (Imm == 0)
5009 St = ARM_AM::lsl;
5010 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
5011 if (Imm == 32)
5012 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00005013 Amount = Imm;
5014 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005015
5016 return false;
5017}
5018
Jim Grosbache7fbce72011-10-03 23:38:36 +00005019/// parseFPImm - A floating point immediate expression operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005020ARMAsmParser::OperandMatchResultTy
5021ARMAsmParser::parseFPImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005022 MCAsmParser &Parser = getParser();
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005023 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005024 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005025 // integer only.
5026 //
5027 // This routine still creates a generic Immediate operand, containing
5028 // a bitcast of the 64-bit floating point value. The various operands
5029 // that accept floats can check whether the value is valid for them
5030 // via the standard is*() predicates.
5031
Jim Grosbache7fbce72011-10-03 23:38:36 +00005032 SMLoc S = Parser.getTok().getLoc();
5033
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005034 if (Parser.getTok().isNot(AsmToken::Hash) &&
5035 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00005036 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00005037
5038 // Disambiguate the VMOV forms that can accept an FP immediate.
5039 // vmov.f32 <sreg>, #imm
5040 // vmov.f64 <dreg>, #imm
5041 // vmov.f32 <dreg>, #imm @ vector f32x2
5042 // vmov.f32 <qreg>, #imm @ vector f32x4
5043 //
5044 // There are also the NEON VMOV instructions which expect an
5045 // integer constant. Make sure we don't try to parse an FPImm
5046 // for these:
5047 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
David Blaikie960ea3f2014-06-08 16:18:35 +00005048 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]);
5049 bool isVmovf = TyOp.isToken() &&
5050 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64");
5051 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
5052 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
5053 Mnemonic.getToken() == "fconsts");
David Peixottoa872e0e2014-01-07 18:19:23 +00005054 if (!(isVmovf || isFconst))
Jim Grosbach741cd732011-10-17 22:26:03 +00005055 return MatchOperand_NoMatch;
5056
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00005057 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00005058
5059 // Handle negation, as that still comes through as a separate token.
5060 bool isNegative = false;
5061 if (Parser.getTok().is(AsmToken::Minus)) {
5062 isNegative = true;
5063 Parser.Lex();
5064 }
5065 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00005066 SMLoc Loc = Tok.getLoc();
David Peixottoa872e0e2014-01-07 18:19:23 +00005067 if (Tok.is(AsmToken::Real) && isVmovf) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005068 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00005069 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
5070 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005071 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00005072 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005073 Operands.push_back(ARMOperand::CreateImm(
5074 MCConstantExpr::Create(IntVal, getContext()),
5075 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00005076 return MatchOperand_Success;
5077 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005078 // Also handle plain integers. Instructions which allow floating point
5079 // immediates also allow a raw encoded 8-bit value.
David Peixottoa872e0e2014-01-07 18:19:23 +00005080 if (Tok.is(AsmToken::Integer) && isFconst) {
Jim Grosbache7fbce72011-10-03 23:38:36 +00005081 int64_t Val = Tok.getIntVal();
5082 Parser.Lex(); // Eat the token.
5083 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00005084 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00005085 return MatchOperand_ParseFail;
5086 }
David Peixottoa872e0e2014-01-07 18:19:23 +00005087 float RealVal = ARM_AM::getFPImmFloat(Val);
5088 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
5089
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005090 Operands.push_back(ARMOperand::CreateImm(
5091 MCConstantExpr::Create(Val, getContext()), S,
5092 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00005093 return MatchOperand_Success;
5094 }
5095
Jim Grosbach235c8d22012-01-19 02:47:30 +00005096 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00005097 return MatchOperand_ParseFail;
5098}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005099
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005100/// Parse a arm instruction operand. For now this parses the operand regardless
5101/// of the mnemonic.
David Blaikie960ea3f2014-06-08 16:18:35 +00005102bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005103 MCAsmParser &Parser = getParser();
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005104 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005105
5106 // Check if the current operand has a custom associated parser, if so, try to
5107 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00005108 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
5109 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005110 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00005111 // If there wasn't a custom match, try the generic matcher below. Otherwise,
5112 // there was a match, but an error occurred, in which case, just return that
5113 // the operand parsing failed.
5114 if (ResTy == MatchOperand_ParseFail)
5115 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005116
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005117 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005118 default:
5119 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00005120 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00005121 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00005122 // If we've seen a branch mnemonic, the next operand must be a label. This
5123 // is true even if the label is a register name. So "br r1" means branch to
5124 // label "r1".
5125 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
5126 if (!ExpectLabel) {
5127 if (!tryParseRegisterWithWriteBack(Operands))
5128 return false;
5129 int Res = tryParseShiftRegister(Operands);
5130 if (Res == 0) // success
5131 return false;
5132 else if (Res == -1) // irrecoverable error
5133 return true;
5134 // If this is VMRS, check for the apsr_nzcv operand.
5135 if (Mnemonic == "vmrs" &&
5136 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
5137 S = Parser.getTok().getLoc();
5138 Parser.Lex();
5139 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
5140 return false;
5141 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00005142 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00005143
5144 // Fall though for the Identifier case that is not a register or a
5145 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00005146 }
Jim Grosbach4e380352011-10-26 21:14:08 +00005147 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00005148 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00005149 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00005150 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00005151 // This was not a register so parse other operands that start with an
5152 // identifier (like labels) as expressions and create them as immediates.
5153 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005154 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005155 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00005156 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005157 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00005158 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
5159 return false;
5160 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005161 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005162 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00005163 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005164 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005165 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00005166 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00005167 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005168 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00005169 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00005170
5171 if (Parser.getTok().isNot(AsmToken::Colon)) {
5172 bool isNegative = Parser.getTok().is(AsmToken::Minus);
5173 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005174 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00005175 return true;
5176 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
5177 if (CE) {
5178 int32_t Val = CE->getValue();
5179 if (isNegative && Val == 0)
5180 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
5181 }
5182 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5183 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00005184
5185 // There can be a trailing '!' on operands that we want as a separate
Saleem Abdulrasool83e37702013-12-28 03:07:12 +00005186 // '!' Token operand. Handle that here. For example, the compatibility
Jim Grosbach9be2d712013-02-23 00:52:09 +00005187 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
5188 if (Parser.getTok().is(AsmToken::Exclaim)) {
5189 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
5190 Parser.getTok().getLoc()));
5191 Parser.Lex(); // Eat exclaim token
5192 }
Jim Grosbach003607f2012-04-16 21:18:46 +00005193 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00005194 }
Jim Grosbach003607f2012-04-16 21:18:46 +00005195 // w/ a ':' after the '#', it's just like a plain ':'.
5196 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00005197 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005198 case AsmToken::Colon: {
5199 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00005200 // FIXME: Check it's an expression prefix,
5201 // e.g. (FOO - :lower16:BAR) isn't legal.
5202 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005203 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00005204 return true;
5205
Evan Cheng965b3c72011-01-13 07:58:56 +00005206 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005207 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00005208 return true;
5209
Evan Cheng965b3c72011-01-13 07:58:56 +00005210 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00005211 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00005212 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00005213 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00005214 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005215 }
David Peixottoe407d092013-12-19 18:12:36 +00005216 case AsmToken::Equal: {
5217 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
5218 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
5219
David Peixottoe407d092013-12-19 18:12:36 +00005220 Parser.Lex(); // Eat '='
5221 const MCExpr *SubExprVal;
5222 if (getParser().parseExpression(SubExprVal))
5223 return true;
5224 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5225
David Peixottob9b73622014-02-04 17:22:40 +00005226 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
David Peixottoe407d092013-12-19 18:12:36 +00005227 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
5228 return false;
5229 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005230 }
5231}
5232
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005233// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00005234// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005235bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005236 MCAsmParser &Parser = getParser();
Evan Cheng965b3c72011-01-13 07:58:56 +00005237 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005238
Saleem Abdulrasool435f4562014-01-10 04:38:40 +00005239 // consume an optional '#' (GNU compatibility)
5240 if (getLexer().is(AsmToken::Hash))
5241 Parser.Lex();
5242
Jason W Kim1f7bc072011-01-11 23:53:41 +00005243 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00005244 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00005245 Parser.Lex(); // Eat ':'
5246
5247 if (getLexer().isNot(AsmToken::Identifier)) {
5248 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
5249 return true;
5250 }
5251
Saleem Abdulrasoolfaa4f072015-01-13 03:22:49 +00005252 enum {
5253 COFF = (1 << MCObjectFileInfo::IsCOFF),
5254 ELF = (1 << MCObjectFileInfo::IsELF),
5255 MACHO = (1 << MCObjectFileInfo::IsMachO)
5256 };
5257 static const struct PrefixEntry {
5258 const char *Spelling;
5259 ARMMCExpr::VariantKind VariantKind;
5260 uint8_t SupportedFormats;
5261 } PrefixEntries[] = {
5262 { "lower16", ARMMCExpr::VK_ARM_LO16, COFF | ELF | MACHO },
5263 { "upper16", ARMMCExpr::VK_ARM_HI16, COFF | ELF | MACHO },
5264 };
5265
Jason W Kim1f7bc072011-01-11 23:53:41 +00005266 StringRef IDVal = Parser.getTok().getIdentifier();
Saleem Abdulrasoolfaa4f072015-01-13 03:22:49 +00005267
5268 const auto &Prefix =
5269 std::find_if(std::begin(PrefixEntries), std::end(PrefixEntries),
5270 [&IDVal](const PrefixEntry &PE) {
5271 return PE.Spelling == IDVal;
5272 });
5273 if (Prefix == std::end(PrefixEntries)) {
Jason W Kim1f7bc072011-01-11 23:53:41 +00005274 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
5275 return true;
5276 }
Saleem Abdulrasoolfaa4f072015-01-13 03:22:49 +00005277
5278 uint8_t CurrentFormat;
5279 switch (getContext().getObjectFileInfo()->getObjectFileType()) {
5280 case MCObjectFileInfo::IsMachO:
5281 CurrentFormat = MACHO;
5282 break;
5283 case MCObjectFileInfo::IsELF:
5284 CurrentFormat = ELF;
5285 break;
5286 case MCObjectFileInfo::IsCOFF:
5287 CurrentFormat = COFF;
5288 break;
5289 }
5290
5291 if (~Prefix->SupportedFormats & CurrentFormat) {
5292 Error(Parser.getTok().getLoc(),
5293 "cannot represent relocation in the current file format");
5294 return true;
5295 }
5296
5297 RefKind = Prefix->VariantKind;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005298 Parser.Lex();
5299
5300 if (getLexer().isNot(AsmToken::Colon)) {
5301 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
5302 return true;
5303 }
5304 Parser.Lex(); // Eat the last ':'
Saleem Abdulrasoolfaa4f072015-01-13 03:22:49 +00005305
Jason W Kim1f7bc072011-01-11 23:53:41 +00005306 return false;
5307}
5308
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005309/// \brief Given a mnemonic, split out possible predication code and carry
5310/// setting letters to form a canonical mnemonic and flags.
5311//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005312// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005313// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005314StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005315 unsigned &PredicationCode,
5316 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005317 unsigned &ProcessorIMod,
5318 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005319 PredicationCode = ARMCC::AL;
5320 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005321 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005322
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005323 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005324 //
5325 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005326 if ((Mnemonic == "movs" && isThumb()) ||
5327 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
5328 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
5329 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
5330 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00005331 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005332 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
5333 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00005334 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00005335 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005336 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
5337 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
Charlie Turner4d88ae22014-12-01 08:33:28 +00005338 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic == "hvc" ||
5339 Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005340 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005341
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005342 // First, split out any predication code. Ignore mnemonics we know aren't
5343 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00005344 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00005345 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00005346 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00005347 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005348 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
5349 .Case("eq", ARMCC::EQ)
5350 .Case("ne", ARMCC::NE)
5351 .Case("hs", ARMCC::HS)
5352 .Case("cs", ARMCC::HS)
5353 .Case("lo", ARMCC::LO)
5354 .Case("cc", ARMCC::LO)
5355 .Case("mi", ARMCC::MI)
5356 .Case("pl", ARMCC::PL)
5357 .Case("vs", ARMCC::VS)
5358 .Case("vc", ARMCC::VC)
5359 .Case("hi", ARMCC::HI)
5360 .Case("ls", ARMCC::LS)
5361 .Case("ge", ARMCC::GE)
5362 .Case("lt", ARMCC::LT)
5363 .Case("gt", ARMCC::GT)
5364 .Case("le", ARMCC::LE)
5365 .Case("al", ARMCC::AL)
5366 .Default(~0U);
5367 if (CC != ~0U) {
5368 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
5369 PredicationCode = CC;
5370 }
Bill Wendling193961b2010-10-29 23:50:21 +00005371 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005372
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005373 // Next, determine if we have a carry setting bit. We explicitly ignore all
5374 // the instructions we know end in 's'.
5375 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00005376 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005377 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
5378 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
5379 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00005380 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00005381 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00005382 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00005383 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
David Peixottoa872e0e2014-01-07 18:19:23 +00005384 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00005385 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005386 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
5387 CarrySetting = true;
5388 }
5389
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005390 // The "cps" instruction can have a interrupt mode operand which is glued into
5391 // the mnemonic. Check if this is the case, split it and parse the imod op
5392 if (Mnemonic.startswith("cps")) {
5393 // Split out any imod code.
5394 unsigned IMod =
5395 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
5396 .Case("ie", ARM_PROC::IE)
5397 .Case("id", ARM_PROC::ID)
5398 .Default(~0U);
5399 if (IMod != ~0U) {
5400 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5401 ProcessorIMod = IMod;
5402 }
5403 }
5404
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005405 // The "it" instruction has the condition mask on the end of the mnemonic.
5406 if (Mnemonic.startswith("it")) {
5407 ITMask = Mnemonic.slice(2, Mnemonic.size());
5408 Mnemonic = Mnemonic.slice(0, 2);
5409 }
5410
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005411 return Mnemonic;
5412}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005413
5414/// \brief Given a canonical mnemonic, determine if the instruction ever allows
5415/// inclusion of carry set or predication code operands.
5416//
5417// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00005418void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00005419getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5420 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005421 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5422 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005423 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005424 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005425 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005426 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005427 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00005428 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005429 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005430 Mnemonic == "mla" || Mnemonic == "smlal" ||
5431 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005432 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00005433 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00005434 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005435
Tim Northover2c45a382013-06-26 16:52:40 +00005436 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5437 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00005438 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
5439 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
5440 Mnemonic.startswith("vsel") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00005441 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005442 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
5443 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Charlie Turner4d88ae22014-12-01 08:33:28 +00005444 Mnemonic == "vrintm" || Mnemonic.startswith("aes") || Mnemonic == "hvc" ||
Amara Emerson33089092013-09-19 11:59:01 +00005445 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5446 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00005447 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005448 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005449 } else if (!isThumb()) {
5450 // Some instructions are only predicable in Thumb mode
5451 CanAcceptPredicationCode
5452 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5453 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5454 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5455 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5456 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5457 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5458 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5459 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00005460 if (hasV6MOps())
5461 CanAcceptPredicationCode = Mnemonic != "movs";
5462 else
5463 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005464 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005465 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005466}
5467
Jim Grosbach7283da92011-08-16 21:12:37 +00005468bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
David Blaikie960ea3f2014-06-08 16:18:35 +00005469 OperandVector &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005470 // FIXME: This is all horribly hacky. We really need a better way to deal
5471 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005472
5473 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5474 // another does not. Specifically, the MOVW instruction does not. So we
5475 // special case it here and remove the defaulted (non-setting) cc_out
5476 // operand if that's the instruction we're trying to match.
5477 //
5478 // We do this as post-processing of the explicit operands rather than just
5479 // conditionally adding the cc_out in the first place because we need
5480 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005481 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Asiri Rathnayake52376ac2015-01-06 15:55:09 +00005482 !static_cast<ARMOperand &>(*Operands[4]).isModImm() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005483 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
5484 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach7283da92011-08-16 21:12:37 +00005485 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005486
5487 // Register-register 'add' for thumb does not have a cc_out operand
5488 // when there are only two register operands.
5489 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005490 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5491 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5492 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005493 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005494 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005495 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5496 // have to check the immediate range here since Thumb2 has a variant
5497 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005498 if (((isThumb() && Mnemonic == "add") ||
5499 (isThumbTwo() && Mnemonic == "sub")) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005500 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5501 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5502 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
5503 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5504 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
5505 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005506 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005507 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5508 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005509 // selecting via the generic "add" mnemonic, so to know that we
5510 // should remove the cc_out operand, we have to explicitly check that
5511 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005512 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005513 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5514 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5515 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005516 // Nest conditions rather than one big 'if' statement for readability.
5517 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005518 // If both registers are low, we're in an IT block, and the immediate is
5519 // in range, we should use encoding T1 instead, which has a cc_out.
5520 if (inITBlock() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005521 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
5522 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
5523 static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005524 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005525 // Check against T3. If the second register is the PC, this is an
5526 // alternate form of ADR, which uses encoding T4, so check for that too.
David Blaikie960ea3f2014-06-08 16:18:35 +00005527 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
5528 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm())
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005529 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005530
5531 // Otherwise, we use encoding T4, which does not have a cc_out
5532 // operand.
5533 return true;
5534 }
5535
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005536 // The thumb2 multiply instruction doesn't have a CCOut register, so
5537 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5538 // use the 16-bit encoding or not.
5539 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005540 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5541 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5542 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5543 static_cast<ARMOperand &>(*Operands[5]).isReg() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005544 // If the registers aren't low regs, the destination reg isn't the
5545 // same as one of the source regs, or the cc_out operand is zero
5546 // outside of an IT block, we have to use the 32-bit encoding, so
5547 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005548 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5549 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5550 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
5551 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5552 static_cast<ARMOperand &>(*Operands[5]).getReg() &&
5553 static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5554 static_cast<ARMOperand &>(*Operands[4]).getReg())))
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005555 return true;
5556
Jim Grosbachefa7e952011-11-15 19:55:16 +00005557 // Also check the 'mul' syntax variant that doesn't specify an explicit
5558 // destination register.
5559 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005560 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5561 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5562 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
Jim Grosbachefa7e952011-11-15 19:55:16 +00005563 // If the registers aren't low regs or the cc_out operand is zero
5564 // outside of an IT block, we have to use the 32-bit encoding, so
5565 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005566 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5567 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
Jim Grosbachefa7e952011-11-15 19:55:16 +00005568 !inITBlock()))
5569 return true;
5570
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005571
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005572
Jim Grosbach4b701af2011-08-24 21:42:27 +00005573 // Register-register 'add/sub' for thumb does not have a cc_out operand
5574 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5575 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5576 // right, this will result in better diagnostics (which operand is off)
5577 // anyway.
5578 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5579 (Operands.size() == 5 || Operands.size() == 6) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005580 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5581 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
5582 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5583 (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005584 (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005585 static_cast<ARMOperand &>(*Operands[5]).isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005586 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005587
Jim Grosbach7283da92011-08-16 21:12:37 +00005588 return false;
5589}
5590
David Blaikie960ea3f2014-06-08 16:18:35 +00005591bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
5592 OperandVector &Operands) {
Joey Goulye8602552013-07-19 16:34:16 +00005593 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5594 unsigned RegIdx = 3;
5595 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005596 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") {
5597 if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5598 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32")
Joey Goulye8602552013-07-19 16:34:16 +00005599 RegIdx = 4;
5600
David Blaikie960ea3f2014-06-08 16:18:35 +00005601 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
5602 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
5603 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
5604 ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
5605 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
Joey Goulye8602552013-07-19 16:34:16 +00005606 return true;
5607 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005608 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005609}
5610
Jim Grosbach12952fe2011-11-11 23:08:10 +00005611static bool isDataTypeToken(StringRef Tok) {
5612 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5613 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5614 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5615 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5616 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5617 Tok == ".f" || Tok == ".d";
5618}
5619
5620// FIXME: This bit should probably be handled via an explicit match class
5621// in the .td files that matches the suffix instead of having it be
5622// a literal string token the way it is now.
5623static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5624 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5625}
Tim Northover26bb14e2014-08-18 11:49:42 +00005626static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features,
Chad Rosier9f7a2212013-04-18 22:35:36 +00005627 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005628
5629static bool RequiresVFPRegListValidation(StringRef Inst,
5630 bool &AcceptSinglePrecisionOnly,
5631 bool &AcceptDoublePrecisionOnly) {
5632 if (Inst.size() < 7)
5633 return false;
5634
5635 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5636 StringRef AddressingMode = Inst.substr(4, 2);
5637 if (AddressingMode == "ia" || AddressingMode == "db" ||
5638 AddressingMode == "ea" || AddressingMode == "fd") {
5639 AcceptSinglePrecisionOnly = Inst[6] == 's';
5640 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5641 return true;
5642 }
5643 }
5644
5645 return false;
5646}
5647
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005648/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005649bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
David Blaikie960ea3f2014-06-08 16:18:35 +00005650 SMLoc NameLoc, OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005651 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005652 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005653 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005654 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005655 bool AcceptDoublePrecisionOnly;
5656 RequireVFPRegisterListCheck =
5657 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5658 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005659
Jim Grosbach8be2f652011-12-09 23:34:09 +00005660 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005661 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005662 // The generic tblgen'erated code does this later, at the start of
5663 // MatchInstructionImpl(), but that's too late for aliases that include
5664 // any sort of suffix.
Tim Northover26bb14e2014-08-18 11:49:42 +00005665 uint64_t AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005666 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5667 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005668
Jim Grosbachab5830e2011-12-14 02:16:11 +00005669 // First check for the ARM-specific .req directive.
5670 if (Parser.getTok().is(AsmToken::Identifier) &&
5671 Parser.getTok().getIdentifier() == ".req") {
5672 parseDirectiveReq(Name, NameLoc);
5673 // We always return 'error' for this, as we're done with this
5674 // statement and don't need to match the 'instruction."
5675 return true;
5676 }
5677
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005678 // Create the leading tokens for the mnemonic, split by '.' characters.
5679 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005680 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005681
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005682 // Split out the predication code and carry setting flag from the mnemonic.
5683 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005684 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005685 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005686 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005687 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005688 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005689
Jim Grosbach1c171b12011-08-25 17:23:55 +00005690 // In Thumb1, only the branch (B) instruction can be predicated.
5691 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005692 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005693 return Error(NameLoc, "conditional execution not supported in Thumb1");
5694 }
5695
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005696 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5697
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005698 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5699 // is the mask as it will be for the IT encoding if the conditional
5700 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5701 // where the conditional bit0 is zero, the instruction post-processing
5702 // will adjust the mask accordingly.
5703 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005704 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5705 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005706 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005707 return Error(Loc, "too many conditions on IT instruction");
5708 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005709 unsigned Mask = 8;
5710 for (unsigned i = ITMask.size(); i != 0; --i) {
5711 char pos = ITMask[i - 1];
5712 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005713 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005714 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005715 }
5716 Mask >>= 1;
5717 if (ITMask[i - 1] == 't')
5718 Mask |= 8;
5719 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005720 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005721 }
5722
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005723 // FIXME: This is all a pretty gross hack. We should automatically handle
5724 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005725
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005726 // Next, add the CCOut and ConditionCode operands, if needed.
5727 //
5728 // For mnemonics which can ever incorporate a carry setting bit or predication
5729 // code, our matching model involves us always generating CCOut and
5730 // ConditionCode operands to match the mnemonic "as written" and then we let
5731 // the matcher deal with finding the right instruction or generating an
5732 // appropriate error.
5733 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005734 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005735
Jim Grosbach03a8a162011-07-14 22:04:21 +00005736 // If we had a carry-set on an instruction that can't do that, issue an
5737 // error.
5738 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005739 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005740 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005741 "' can not set flags, but 's' suffix specified");
5742 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005743 // If we had a predication code on an instruction that can't do that, issue an
5744 // error.
5745 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005746 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005747 return Error(NameLoc, "instruction '" + Mnemonic +
5748 "' is not predicable, but condition code specified");
5749 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005750
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005751 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005752 if (CanAcceptCarrySet) {
5753 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005754 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005755 Loc));
5756 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005757
5758 // Add the predication code operand, if necessary.
5759 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005760 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5761 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005762 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005763 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005764 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005765
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005766 // Add the processor imod operand, if necessary.
5767 if (ProcessorIMod) {
5768 Operands.push_back(ARMOperand::CreateImm(
5769 MCConstantExpr::Create(ProcessorIMod, getContext()),
5770 NameLoc, NameLoc));
Oliver Stannard1ae8b472014-09-24 14:20:01 +00005771 } else if (Mnemonic == "cps" && isMClass()) {
5772 return Error(NameLoc, "instruction 'cps' requires effect for M-class");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005773 }
5774
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005775 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005776 while (Next != StringRef::npos) {
5777 Start = Next;
5778 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005779 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005780
Jim Grosbach12952fe2011-11-11 23:08:10 +00005781 // Some NEON instructions have an optional datatype suffix that is
5782 // completely ignored. Check for that.
5783 if (isDataTypeToken(ExtraToken) &&
5784 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5785 continue;
5786
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005787 // For for ARM mode generate an error if the .n qualifier is used.
5788 if (ExtraToken == ".n" && !isThumb()) {
5789 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005790 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005791 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5792 "arm mode");
5793 }
5794
5795 // The .n qualifier is always discarded as that is what the tables
5796 // and matcher expect. In ARM mode the .w qualifier has no effect,
5797 // so discard it to avoid errors that can be caused by the matcher.
5798 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005799 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5800 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5801 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005802 }
5803
5804 // Read the remaining operands.
5805 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005806 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005807 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005808 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005809 return true;
5810 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005811
5812 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005813 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005814
5815 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005816 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005817 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005818 return true;
5819 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005820 }
5821 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005822
Chris Lattnera2a9d162010-09-11 16:18:25 +00005823 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005824 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005825 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005826 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005827 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005828
Chris Lattner91689c12010-09-08 05:10:46 +00005829 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005830
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005831 if (RequireVFPRegisterListCheck) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005832 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back());
5833 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList())
5834 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005835 "VFP/Neon single precision register expected");
David Blaikie960ea3f2014-06-08 16:18:35 +00005836 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList())
5837 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005838 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005839 }
5840
Jim Grosbach7283da92011-08-16 21:12:37 +00005841 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5842 // do and don't have a cc_out optional-def operand. With some spot-checks
5843 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005844 // parse and adjust accordingly before actually matching. We shouldn't ever
5845 // try to remove a cc_out operand that was explicitly set on the the
5846 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5847 // table driven matcher doesn't fit well with the ARM instruction set.
David Blaikie960ea3f2014-06-08 16:18:35 +00005848 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005849 Operands.erase(Operands.begin() + 1);
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005850
Joey Goulye8602552013-07-19 16:34:16 +00005851 // Some instructions have the same mnemonic, but don't always
5852 // have a predicate. Distinguish them here and delete the
5853 // predicate if needed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005854 if (shouldOmitPredicateOperand(Mnemonic, Operands))
Joey Goulye8602552013-07-19 16:34:16 +00005855 Operands.erase(Operands.begin() + 1);
Joey Goulye8602552013-07-19 16:34:16 +00005856
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005857 // ARM mode 'blx' need special handling, as the register operand version
5858 // is predicable, but the label operand version is not. So, we can't rely
5859 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005860 // a k_CondCode operand in the list. If we're trying to match the label
5861 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005862 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005863 static_cast<ARMOperand &>(*Operands[2]).isImm())
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005864 Operands.erase(Operands.begin() + 1);
Jim Grosbach8cffa282011-08-11 23:51:13 +00005865
Weiming Zhao8f56f882012-11-16 21:55:34 +00005866 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5867 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5868 // a single GPRPair reg operand is used in the .td file to replace the two
5869 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5870 // expressed as a GPRPair, so we have to manually merge them.
5871 // FIXME: We would really like to be able to tablegen'erate this.
5872 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005873 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5874 Mnemonic == "stlexd")) {
5875 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005876 unsigned Idx = isLoad ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005877 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
5878 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005879
5880 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5881 // Adjust only if Op1 and Op2 are GPRs.
David Blaikie960ea3f2014-06-08 16:18:35 +00005882 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
5883 MRC.contains(Op2.getReg())) {
5884 unsigned Reg1 = Op1.getReg();
5885 unsigned Reg2 = Op2.getReg();
Weiming Zhao8f56f882012-11-16 21:55:34 +00005886 unsigned Rt = MRI->getEncodingValue(Reg1);
5887 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5888
5889 // Rt2 must be Rt + 1 and Rt must be even.
5890 if (Rt + 1 != Rt2 || (Rt & 1)) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005891 Error(Op2.getStartLoc(), isLoad
5892 ? "destination operands must be sequential"
5893 : "source operands must be sequential");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005894 return true;
5895 }
5896 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5897 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
David Blaikie960ea3f2014-06-08 16:18:35 +00005898 Operands[Idx] =
5899 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
5900 Operands.erase(Operands.begin() + Idx + 1);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005901 }
5902 }
5903
Renato Golin36c626e2014-09-26 16:14:29 +00005904 // If first 2 operands of a 3 operand instruction are the same
5905 // then transform to 2 operand version of the same instruction
5906 // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1'
5907 // FIXME: We would really like to be able to tablegen'erate this.
5908 if (isThumbOne() && Operands.size() == 6 &&
5909 (Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" ||
5910 Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5911 Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" ||
5912 Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic")) {
5913 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5914 ARMOperand &Op4 = static_cast<ARMOperand &>(*Operands[4]);
5915 ARMOperand &Op5 = static_cast<ARMOperand &>(*Operands[5]);
5916
5917 // If both registers are the same then remove one of them from
5918 // the operand list.
5919 if (Op3.isReg() && Op4.isReg() && Op3.getReg() == Op4.getReg()) {
5920 // If 3rd operand (variable Op5) is a register and the instruction is adds/sub
5921 // then do not transform as the backend already handles this instruction
5922 // correctly.
5923 if (!Op5.isReg() || !((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub")) {
5924 Operands.erase(Operands.begin() + 3);
5925 if (Mnemonic == "add" && !CarrySetting) {
5926 // Special case for 'add' (not 'adds') instruction must
5927 // remove the CCOut operand as well.
5928 Operands.erase(Operands.begin() + 1);
5929 }
5930 }
5931 }
5932 }
5933
5934 // If instruction is 'add' and first two register operands
5935 // use SP register, then remove one of the SP registers from
5936 // the instruction.
5937 // FIXME: We would really like to be able to tablegen'erate this.
5938 if (isThumbOne() && Operands.size() == 5 && Mnemonic == "add" && !CarrySetting) {
5939 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5940 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5941 if (Op2.isReg() && Op3.isReg() && Op2.getReg() == ARM::SP && Op3.getReg() == ARM::SP) {
5942 Operands.erase(Operands.begin() + 2);
5943 }
5944 }
5945
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005946 // GNU Assembler extension (compatibility)
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005947 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005948 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5949 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5950 if (Op3.isMem()) {
5951 assert(Op2.isReg() && "expected register argument");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005952
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005953 unsigned SuperReg = MRI->getMatchingSuperReg(
David Blaikie960ea3f2014-06-08 16:18:35 +00005954 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005955
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005956 assert(SuperReg && "expected register pair");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005957
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005958 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005959
David Blaikie960ea3f2014-06-08 16:18:35 +00005960 Operands.insert(
5961 Operands.begin() + 3,
5962 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005963 }
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005964 }
5965
Kevin Enderby78f95722013-07-31 21:05:30 +00005966 // FIXME: As said above, this is all a pretty gross hack. This instruction
5967 // does not fit with other "subs" and tblgen.
5968 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5969 // so the Mnemonic is the original name "subs" and delete the predicate
5970 // operand so it will match the table entry.
5971 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005972 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5973 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
5974 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5975 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
5976 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5977 Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
Kevin Enderby78f95722013-07-31 21:05:30 +00005978 Operands.erase(Operands.begin() + 1);
Kevin Enderby78f95722013-07-31 21:05:30 +00005979 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005980 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005981}
5982
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005983// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005984
5985// return 'true' if register list contains non-low GPR registers,
5986// 'false' otherwise. If Reg is in the register list or is HiReg, set
5987// 'containsReg' to true.
5988static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5989 unsigned HiReg, bool &containsReg) {
5990 containsReg = false;
5991 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5992 unsigned OpReg = Inst.getOperand(i).getReg();
5993 if (OpReg == Reg)
5994 containsReg = true;
5995 // Anything other than a low register isn't legal here.
5996 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5997 return true;
5998 }
5999 return false;
6000}
6001
Rafael Espindola5403da42014-12-04 14:10:20 +00006002// Check if the specified regisgter is in the register list of the inst,
Jim Grosbacha31f2232011-09-07 18:05:34 +00006003// starting at the indicated operand number.
Rafael Espindola5403da42014-12-04 14:10:20 +00006004static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
Jim Grosbacha31f2232011-09-07 18:05:34 +00006005 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
6006 unsigned OpReg = Inst.getOperand(i).getReg();
Rafael Espindola5403da42014-12-04 14:10:20 +00006007 if (OpReg == Reg)
6008 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00006009 }
6010 return false;
6011}
6012
Richard Barton8d519fe2013-09-05 14:14:19 +00006013// Return true if instruction has the interesting property of being
6014// allowed in IT blocks, but not being predicable.
6015static bool instIsBreakpoint(const MCInst &Inst) {
6016 return Inst.getOpcode() == ARM::tBKPT ||
6017 Inst.getOpcode() == ARM::BKPT ||
6018 Inst.getOpcode() == ARM::tHLT ||
6019 Inst.getOpcode() == ARM::HLT;
6020
6021}
6022
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006023bool ARMAsmParser::validatetLDMRegList(MCInst Inst,
6024 const OperandVector &Operands,
Jyoti Allur5a139142015-01-14 10:48:16 +00006025 unsigned ListNo, bool IsARPop) {
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006026 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]);
6027 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!";
6028
6029 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP);
6030 bool ListContainsLR = listContainsReg(Inst, ListNo, ARM::LR);
6031 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC);
6032
Jyoti Allur5a139142015-01-14 10:48:16 +00006033 if (!IsARPop && ListContainsSP)
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006034 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6035 "SP may not be in the register list");
6036 else if (ListContainsPC && ListContainsLR)
6037 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6038 "PC and LR may not be in the register list simultaneously");
6039 else if (inITBlock() && !lastInITBlock() && ListContainsPC)
6040 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6041 "instruction must be outside of IT block or the last "
6042 "instruction in an IT block");
6043 return false;
6044}
6045
6046bool ARMAsmParser::validatetSTMRegList(MCInst Inst,
6047 const OperandVector &Operands,
6048 unsigned ListNo) {
6049 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]);
6050 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!";
6051
6052 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP);
6053 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC);
6054
6055 if (ListContainsSP && ListContainsPC)
6056 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6057 "SP and PC may not be in the register list");
6058 else if (ListContainsSP)
6059 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6060 "SP may not be in the register list");
6061 else if (ListContainsPC)
6062 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6063 "PC may not be in the register list");
6064 return false;
6065}
6066
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006067// FIXME: We would really like to be able to tablegen'erate this.
David Blaikie960ea3f2014-06-08 16:18:35 +00006068bool ARMAsmParser::validateInstruction(MCInst &Inst,
6069 const OperandVector &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00006070 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00006071 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00006072
Jim Grosbached16ec42011-08-29 22:24:09 +00006073 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00006074 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00006075 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00006076 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006077 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006078 if (ITState.FirstCond)
6079 ITState.FirstCond = false;
6080 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00006081 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006082 // The instruction must be predicable.
6083 if (!MCID.isPredicable())
6084 return Error(Loc, "instructions in IT block must be predicable");
6085 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00006086 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00006087 ARMCC::getOppositeCondition(ITState.Cond);
6088 if (Cond != ITCond) {
6089 // Find the condition code Operand to get its SMLoc information.
6090 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00006091 for (unsigned I = 1; I < Operands.size(); ++I)
David Blaikie960ea3f2014-06-08 16:18:35 +00006092 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006093 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00006094 return Error(CondLoc, "incorrect condition in IT block; got '" +
6095 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
6096 "', but expected '" +
6097 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
6098 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00006099 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00006100 } else if (isThumbTwo() && MCID.isPredicable() &&
6101 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00006102 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
6103 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00006104 return Error(Loc, "predicated instructions must be in IT block");
6105
Tilmann Scheller255722b2013-09-30 16:11:48 +00006106 const unsigned Opcode = Inst.getOpcode();
6107 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00006108 case ARM::LDRD:
6109 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006110 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00006111 const unsigned RtReg = Inst.getOperand(0).getReg();
6112
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006113 // Rt can't be R14.
6114 if (RtReg == ARM::LR)
6115 return Error(Operands[3]->getStartLoc(),
6116 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006117
6118 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006119 // Rt must be even-numbered.
6120 if ((Rt & 1) == 1)
6121 return Error(Operands[3]->getStartLoc(),
6122 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006123
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006124 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00006125 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006126 if (Rt2 != Rt + 1)
6127 return Error(Operands[3]->getStartLoc(),
6128 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006129
6130 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
6131 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
6132 // For addressing modes with writeback, the base register needs to be
6133 // different from the destination registers.
6134 if (Rn == Rt || Rn == Rt2)
6135 return Error(Operands[3]->getStartLoc(),
6136 "base register needs to be different from destination "
6137 "registers");
6138 }
6139
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006140 return false;
6141 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006142 case ARM::t2LDRDi8:
6143 case ARM::t2LDRD_PRE:
6144 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00006145 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006146 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6147 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6148 if (Rt2 == Rt)
6149 return Error(Operands[3]->getStartLoc(),
6150 "destination operands can't be identical");
6151 return false;
6152 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00006153 case ARM::STRD: {
6154 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006155 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6156 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00006157 if (Rt2 != Rt + 1)
6158 return Error(Operands[3]->getStartLoc(),
6159 "source operands must be sequential");
6160 return false;
6161 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00006162 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006163 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006164 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006165 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6166 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006167 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00006168 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006169 "source operands must be sequential");
6170 return false;
6171 }
Tilmann Scheller3352a582014-07-23 12:38:17 +00006172 case ARM::STR_PRE_IMM:
6173 case ARM::STR_PRE_REG:
6174 case ARM::STR_POST_IMM:
Tilmann Scheller27272792014-07-23 13:03:47 +00006175 case ARM::STR_POST_REG:
Tilmann Scheller96ef72e2014-07-24 09:55:46 +00006176 case ARM::STRH_PRE:
6177 case ARM::STRH_POST:
Tilmann Scheller27272792014-07-23 13:03:47 +00006178 case ARM::STRB_PRE_IMM:
6179 case ARM::STRB_PRE_REG:
6180 case ARM::STRB_POST_IMM:
6181 case ARM::STRB_POST_REG: {
Tilmann Scheller3352a582014-07-23 12:38:17 +00006182 // Rt must be different from Rn.
6183 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6184 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6185
6186 if (Rt == Rn)
6187 return Error(Operands[3]->getStartLoc(),
6188 "source register and base register can't be identical");
6189 return false;
6190 }
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006191 case ARM::LDR_PRE_IMM:
6192 case ARM::LDR_PRE_REG:
6193 case ARM::LDR_POST_IMM:
Tilmann Scheller8ff079c2014-08-01 11:33:47 +00006194 case ARM::LDR_POST_REG:
6195 case ARM::LDRH_PRE:
6196 case ARM::LDRH_POST:
6197 case ARM::LDRSH_PRE:
Tilmann Scheller7cc0ed42014-08-01 12:08:04 +00006198 case ARM::LDRSH_POST:
6199 case ARM::LDRB_PRE_IMM:
6200 case ARM::LDRB_PRE_REG:
6201 case ARM::LDRB_POST_IMM:
6202 case ARM::LDRB_POST_REG:
6203 case ARM::LDRSB_PRE:
6204 case ARM::LDRSB_POST: {
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006205 // Rt must be different from Rn.
6206 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6207 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6208
6209 if (Rt == Rn)
6210 return Error(Operands[3]->getStartLoc(),
6211 "destination register and base register can't be identical");
6212 return false;
6213 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00006214 case ARM::SBFX:
6215 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006216 // Width must be in range [1, 32-lsb].
6217 unsigned LSB = Inst.getOperand(2).getImm();
6218 unsigned Widthm1 = Inst.getOperand(3).getImm();
6219 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00006220 return Error(Operands[5]->getStartLoc(),
6221 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00006222 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00006223 }
Rafael Espindola5403da42014-12-04 14:10:20 +00006224 // Notionally handles ARM::tLDMIA_UPD too.
6225 case ARM::tLDMIA: {
6226 // If we're parsing Thumb2, the .w variant is available and handles
6227 // most cases that are normally illegal for a Thumb1 LDM instruction.
6228 // We'll make the transformation in processInstruction() if necessary.
6229 //
6230 // Thumb LDM instructions are writeback iff the base register is not
6231 // in the register list.
6232 unsigned Rn = Inst.getOperand(0).getReg();
6233 bool HasWritebackToken =
6234 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
6235 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
6236 bool ListContainsBase;
6237 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
6238 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
6239 "registers must be in range r0-r7");
6240 // If we should have writeback, then there should be a '!' token.
6241 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
6242 return Error(Operands[2]->getStartLoc(),
6243 "writeback operator '!' expected");
6244 // If we should not have writeback, there must not be a '!'. This is
6245 // true even for the 32-bit wide encodings.
6246 if (ListContainsBase && HasWritebackToken)
6247 return Error(Operands[3]->getStartLoc(),
6248 "writeback operator '!' not allowed when base register "
6249 "in register list");
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006250
6251 if (validatetLDMRegList(Inst, Operands, 3))
6252 return true;
Rafael Espindola5403da42014-12-04 14:10:20 +00006253 break;
6254 }
Tim Northover08a86602013-10-22 19:00:39 +00006255 case ARM::LDMIA_UPD:
6256 case ARM::LDMDB_UPD:
6257 case ARM::LDMIB_UPD:
6258 case ARM::LDMDA_UPD:
6259 // ARM variants loading and updating the same register are only officially
6260 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
6261 if (!hasV7Ops())
6262 break;
Rafael Espindola5403da42014-12-04 14:10:20 +00006263 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6264 return Error(Operands.back()->getStartLoc(),
6265 "writeback register not allowed in register list");
6266 break;
Jyoti Allur3b686072014-10-22 10:41:14 +00006267 case ARM::t2LDMIA:
6268 case ARM::t2LDMDB:
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006269 if (validatetLDMRegList(Inst, Operands, 3))
6270 return true;
Rafael Espindola5403da42014-12-04 14:10:20 +00006271 break;
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006272 case ARM::t2STMIA:
6273 case ARM::t2STMDB:
6274 if (validatetSTMRegList(Inst, Operands, 3))
6275 return true;
6276 break;
Tim Northover08a86602013-10-22 19:00:39 +00006277 case ARM::t2LDMIA_UPD:
6278 case ARM::t2LDMDB_UPD:
6279 case ARM::t2STMIA_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006280 case ARM::t2STMDB_UPD: {
6281 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6282 return Error(Operands.back()->getStartLoc(),
6283 "writeback register not allowed in register list");
6284
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006285 if (Opcode == ARM::t2LDMIA_UPD || Opcode == ARM::t2LDMDB_UPD) {
Saleem Abdulrasool0b5a8522014-12-18 16:16:53 +00006286 if (validatetLDMRegList(Inst, Operands, 3))
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006287 return true;
6288 } else {
Saleem Abdulrasool0b5a8522014-12-18 16:16:53 +00006289 if (validatetSTMRegList(Inst, Operands, 3))
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006290 return true;
6291 }
Rafael Espindola5403da42014-12-04 14:10:20 +00006292 break;
6293 }
Tim Northover8eaf1542013-11-12 21:32:41 +00006294 case ARM::sysLDMIA_UPD:
6295 case ARM::sysLDMDA_UPD:
6296 case ARM::sysLDMDB_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006297 case ARM::sysLDMIB_UPD:
6298 if (!listContainsReg(Inst, 3, ARM::PC))
6299 return Error(Operands[4]->getStartLoc(),
6300 "writeback register only allowed on system LDM "
6301 "if PC in register-list");
Tim Northover8eaf1542013-11-12 21:32:41 +00006302 break;
6303 case ARM::sysSTMIA_UPD:
6304 case ARM::sysSTMDA_UPD:
6305 case ARM::sysSTMDB_UPD:
6306 case ARM::sysSTMIB_UPD:
6307 return Error(Operands[2]->getStartLoc(),
6308 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006309 case ARM::tMUL: {
6310 // The second source operand must be the same register as the destination
6311 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00006312 //
6313 // In this case, we must directly check the parsed operands because the
6314 // cvtThumbMultiply() function is written in such a way that it guarantees
6315 // this first statement is always true for the new Inst. Essentially, the
6316 // destination is unconditionally copied into the second source operand
6317 // without checking to see if it matches what we actually parsed.
David Blaikie960ea3f2014-06-08 16:18:35 +00006318 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
6319 ((ARMOperand &)*Operands[5]).getReg()) &&
6320 (((ARMOperand &)*Operands[3]).getReg() !=
6321 ((ARMOperand &)*Operands[4]).getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00006322 return Error(Operands[3]->getStartLoc(),
6323 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006324 }
6325 break;
6326 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00006327 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
6328 // so only issue a diagnostic for thumb1. The instructions will be
6329 // switched to the t2 encodings in processInstruction() if necessary.
Rafael Espindola5403da42014-12-04 14:10:20 +00006330 case ARM::tPOP: {
6331 bool ListContainsBase;
6332 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
6333 !isThumbTwo())
6334 return Error(Operands[2]->getStartLoc(),
6335 "registers must be in range r0-r7 or pc");
Jyoti Allur5a139142015-01-14 10:48:16 +00006336 if (validatetLDMRegList(Inst, Operands, 2, !isMClass()))
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006337 return true;
Rafael Espindola5403da42014-12-04 14:10:20 +00006338 break;
6339 }
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006340 case ARM::tPUSH: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006341 bool ListContainsBase;
6342 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
6343 !isThumbTwo())
6344 return Error(Operands[2]->getStartLoc(),
6345 "registers must be in range r0-r7 or lr");
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006346 if (validatetSTMRegList(Inst, Operands, 2))
6347 return true;
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006348 break;
6349 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00006350 case ARM::tSTMIA_UPD: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006351 bool ListContainsBase, InvalidLowList;
6352 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
6353 0, ListContainsBase);
6354 if (InvalidLowList && !isThumbTwo())
6355 return Error(Operands[4]->getStartLoc(),
6356 "registers must be in range r0-r7");
6357
6358 // This would be converted to a 32-bit stm, but that's not valid if the
6359 // writeback register is in the list.
6360 if (InvalidLowList && ListContainsBase)
6361 return Error(Operands[4]->getStartLoc(),
6362 "writeback operator '!' not allowed when base register "
6363 "in register list");
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006364
6365 if (validatetSTMRegList(Inst, Operands, 4))
6366 return true;
Jim Grosbachd80d1692011-08-23 18:15:37 +00006367 break;
6368 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00006369 case ARM::tADDrSP: {
6370 // If the non-SP source operand and the destination operand are not the
6371 // same, we need thumb2 (for the wide encoding), or we have an error.
6372 if (!isThumbTwo() &&
6373 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
6374 return Error(Operands[4]->getStartLoc(),
6375 "source register must be the same as destination");
6376 }
6377 break;
6378 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006379 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006380 case ARM::tB:
David Blaikie960ea3f2014-06-08 16:18:35 +00006381 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006382 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006383 break;
6384 case ARM::t2B: {
6385 int op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006386 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006387 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006388 break;
6389 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006390 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006391 case ARM::tBcc:
David Blaikie960ea3f2014-06-08 16:18:35 +00006392 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006393 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006394 break;
6395 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006396 int Op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006397 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006398 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006399 break;
6400 }
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006401 case ARM::MOVi16:
6402 case ARM::t2MOVi16:
6403 case ARM::t2MOVTi16:
6404 {
6405 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
6406 // especially when we turn it into a movw and the expression <symbol> does
6407 // not have a :lower16: or :upper16 as part of the expression. We don't
6408 // want the behavior of silently truncating, which can be unexpected and
6409 // lead to bugs that are difficult to find since this is an easy mistake
6410 // to make.
6411 int i = (Operands[3]->isImm()) ? 3 : 4;
David Blaikie960ea3f2014-06-08 16:18:35 +00006412 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
6413 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006414 if (CE) break;
David Blaikie960ea3f2014-06-08 16:18:35 +00006415 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006416 if (!E) break;
6417 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
6418 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006419 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
6420 return Error(
6421 Op.getStartLoc(),
6422 "immediate expression for mov requires :lower16: or :upper16");
6423 break;
6424 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006425 }
6426
6427 return false;
6428}
6429
Jim Grosbach1a747242012-01-23 23:45:44 +00006430static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00006431 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006432 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006433 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006434 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6435 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6436 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6437 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6438 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6439 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6440 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
6441 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
6442 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006443
6444 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006445 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6446 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6447 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6448 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6449 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006450
Jim Grosbach1e946a42012-01-24 00:43:12 +00006451 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6452 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6453 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6454 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6455 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006456
Jim Grosbach1e946a42012-01-24 00:43:12 +00006457 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
6458 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
6459 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
6460 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
6461 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00006462
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006463 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006464 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6465 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6466 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6467 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
6468 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6469 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6470 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6471 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6472 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
6473 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6474 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
6475 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
6476 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
6477 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
6478 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006479
Jim Grosbach1a747242012-01-23 23:45:44 +00006480 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006481 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6482 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6483 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6484 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6485 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6486 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6487 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6488 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6489 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6490 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6491 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6492 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6493 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
6494 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
6495 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
6496 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
6497 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
6498 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00006499
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006500 // VST4LN
6501 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6502 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6503 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6504 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
6505 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6506 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6507 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6508 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6509 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
6510 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6511 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
6512 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
6513 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
6514 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
6515 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
6516
Jim Grosbachda70eac2012-01-24 00:58:13 +00006517 // VST4
6518 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6519 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6520 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6521 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6522 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6523 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6524 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6525 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6526 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6527 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6528 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6529 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6530 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6531 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6532 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6533 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6534 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6535 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00006536 }
6537}
6538
Jim Grosbach1a747242012-01-23 23:45:44 +00006539static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00006540 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006541 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006542 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006543 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6544 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6545 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6546 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6547 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6548 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6549 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6550 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6551 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006552
6553 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006554 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6555 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6556 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6557 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6558 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6559 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6560 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6561 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6562 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6563 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6564 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6565 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6566 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6567 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6568 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006569
Jim Grosbachb78403c2012-01-24 23:47:04 +00006570 // VLD3DUP
6571 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6572 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6573 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6574 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
Kevin Enderbyd88fec32014-04-08 18:00:52 +00006575 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
Jim Grosbachb78403c2012-01-24 23:47:04 +00006576 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6577 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6578 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6579 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6580 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6581 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6582 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6583 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6584 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6585 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6586 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6587 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6588 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6589
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006590 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006591 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6592 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6593 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6594 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6595 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6596 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6597 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6598 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6599 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6600 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6601 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6602 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6603 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6604 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6605 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006606
6607 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006608 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6609 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6610 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6611 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6612 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6613 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6614 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6615 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6616 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6617 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6618 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6619 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6620 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6621 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6622 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6623 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6624 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6625 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00006626
Jim Grosbach14952a02012-01-24 18:37:25 +00006627 // VLD4LN
6628 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6629 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6630 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00006631 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00006632 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6633 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6634 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6635 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6636 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6637 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6638 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6639 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6640 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6641 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6642 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6643
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006644 // VLD4DUP
6645 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6646 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6647 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6648 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6649 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6650 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6651 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6652 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6653 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6654 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6655 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6656 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6657 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6658 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6659 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6660 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6661 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6662 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6663
Jim Grosbached561fc2012-01-24 00:43:17 +00006664 // VLD4
6665 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6666 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6667 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6668 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6669 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6670 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6671 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6672 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6673 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6674 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6675 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6676 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6677 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6678 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6679 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6680 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6681 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6682 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006683 }
6684}
6685
David Blaikie960ea3f2014-06-08 16:18:35 +00006686bool ARMAsmParser::processInstruction(MCInst &Inst,
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006687 const OperandVector &Operands,
6688 MCStreamer &Out) {
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006689 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006690 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6691 case ARM::LDRT_POST:
6692 case ARM::LDRBT_POST: {
6693 const unsigned Opcode =
6694 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6695 : ARM::LDRBT_POST_IMM;
6696 MCInst TmpInst;
6697 TmpInst.setOpcode(Opcode);
6698 TmpInst.addOperand(Inst.getOperand(0));
6699 TmpInst.addOperand(Inst.getOperand(1));
6700 TmpInst.addOperand(Inst.getOperand(1));
6701 TmpInst.addOperand(MCOperand::CreateReg(0));
6702 TmpInst.addOperand(MCOperand::CreateImm(0));
6703 TmpInst.addOperand(Inst.getOperand(2));
6704 TmpInst.addOperand(Inst.getOperand(3));
6705 Inst = TmpInst;
6706 return true;
6707 }
6708 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6709 case ARM::STRT_POST:
6710 case ARM::STRBT_POST: {
6711 const unsigned Opcode =
6712 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6713 : ARM::STRBT_POST_IMM;
6714 MCInst TmpInst;
6715 TmpInst.setOpcode(Opcode);
6716 TmpInst.addOperand(Inst.getOperand(1));
6717 TmpInst.addOperand(Inst.getOperand(0));
6718 TmpInst.addOperand(Inst.getOperand(1));
6719 TmpInst.addOperand(MCOperand::CreateReg(0));
6720 TmpInst.addOperand(MCOperand::CreateImm(0));
6721 TmpInst.addOperand(Inst.getOperand(2));
6722 TmpInst.addOperand(Inst.getOperand(3));
6723 Inst = TmpInst;
6724 return true;
6725 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006726 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6727 case ARM::ADDri: {
6728 if (Inst.getOperand(1).getReg() != ARM::PC ||
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006729 Inst.getOperand(5).getReg() != 0 ||
6730 !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm()))
Jim Grosbache974a6a2012-09-25 00:08:13 +00006731 return false;
6732 MCInst TmpInst;
6733 TmpInst.setOpcode(ARM::ADR);
6734 TmpInst.addOperand(Inst.getOperand(0));
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006735 if (Inst.getOperand(2).isImm()) {
Asiri Rathnayake7835e9b2014-12-09 13:14:58 +00006736 // Immediate (mod_imm) will be in its encoded form, we must unencode it
6737 // before passing it to the ADR instruction.
6738 unsigned Enc = Inst.getOperand(2).getImm();
6739 TmpInst.addOperand(MCOperand::CreateImm(
6740 ARM_AM::rotr32(Enc & 0xFF, (Enc & 0xF00) >> 7)));
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006741 } else {
6742 // Turn PC-relative expression into absolute expression.
6743 // Reading PC provides the start of the current instruction + 8 and
6744 // the transform to adr is biased by that.
6745 MCSymbol *Dot = getContext().CreateTempSymbol();
6746 Out.EmitLabel(Dot);
6747 const MCExpr *OpExpr = Inst.getOperand(2).getExpr();
6748 const MCExpr *InstPC = MCSymbolRefExpr::Create(Dot,
6749 MCSymbolRefExpr::VK_None,
6750 getContext());
6751 const MCExpr *Const8 = MCConstantExpr::Create(8, getContext());
6752 const MCExpr *ReadPC = MCBinaryExpr::CreateAdd(InstPC, Const8,
6753 getContext());
6754 const MCExpr *FixupAddr = MCBinaryExpr::CreateAdd(ReadPC, OpExpr,
6755 getContext());
6756 TmpInst.addOperand(MCOperand::CreateExpr(FixupAddr));
6757 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006758 TmpInst.addOperand(Inst.getOperand(3));
6759 TmpInst.addOperand(Inst.getOperand(4));
6760 Inst = TmpInst;
6761 return true;
6762 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006763 // Aliases for alternate PC+imm syntax of LDR instructions.
6764 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006765 // Select the narrow version if the immediate will fit.
6766 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006767 Inst.getOperand(1).getImm() <= 0xff &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006768 !(static_cast<ARMOperand &>(*Operands[2]).isToken() &&
6769 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006770 Inst.setOpcode(ARM::tLDRpci);
6771 else
6772 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006773 return true;
6774 case ARM::t2LDRBpcrel:
6775 Inst.setOpcode(ARM::t2LDRBpci);
6776 return true;
6777 case ARM::t2LDRHpcrel:
6778 Inst.setOpcode(ARM::t2LDRHpci);
6779 return true;
6780 case ARM::t2LDRSBpcrel:
6781 Inst.setOpcode(ARM::t2LDRSBpci);
6782 return true;
6783 case ARM::t2LDRSHpcrel:
6784 Inst.setOpcode(ARM::t2LDRSHpci);
6785 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006786 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006787 case ARM::VST1LNdWB_register_Asm_8:
6788 case ARM::VST1LNdWB_register_Asm_16:
6789 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006790 MCInst TmpInst;
6791 // Shuffle the operands around so the lane index operand is in the
6792 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006793 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006794 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006795 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6796 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6797 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6798 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6799 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6800 TmpInst.addOperand(Inst.getOperand(1)); // lane
6801 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6802 TmpInst.addOperand(Inst.getOperand(6));
6803 Inst = TmpInst;
6804 return true;
6805 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006806
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006807 case ARM::VST2LNdWB_register_Asm_8:
6808 case ARM::VST2LNdWB_register_Asm_16:
6809 case ARM::VST2LNdWB_register_Asm_32:
6810 case ARM::VST2LNqWB_register_Asm_16:
6811 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006812 MCInst TmpInst;
6813 // Shuffle the operands around so the lane index operand is in the
6814 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006815 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006816 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006817 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6818 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6819 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6820 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6821 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006822 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6823 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006824 TmpInst.addOperand(Inst.getOperand(1)); // lane
6825 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6826 TmpInst.addOperand(Inst.getOperand(6));
6827 Inst = TmpInst;
6828 return true;
6829 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006830
6831 case ARM::VST3LNdWB_register_Asm_8:
6832 case ARM::VST3LNdWB_register_Asm_16:
6833 case ARM::VST3LNdWB_register_Asm_32:
6834 case ARM::VST3LNqWB_register_Asm_16:
6835 case ARM::VST3LNqWB_register_Asm_32: {
6836 MCInst TmpInst;
6837 // Shuffle the operands around so the lane index operand is in the
6838 // right place.
6839 unsigned Spacing;
6840 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6841 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6842 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6843 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6844 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6845 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6846 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6847 Spacing));
6848 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6849 Spacing * 2));
6850 TmpInst.addOperand(Inst.getOperand(1)); // lane
6851 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6852 TmpInst.addOperand(Inst.getOperand(6));
6853 Inst = TmpInst;
6854 return true;
6855 }
6856
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006857 case ARM::VST4LNdWB_register_Asm_8:
6858 case ARM::VST4LNdWB_register_Asm_16:
6859 case ARM::VST4LNdWB_register_Asm_32:
6860 case ARM::VST4LNqWB_register_Asm_16:
6861 case ARM::VST4LNqWB_register_Asm_32: {
6862 MCInst TmpInst;
6863 // Shuffle the operands around so the lane index operand is in the
6864 // right place.
6865 unsigned Spacing;
6866 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6867 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6868 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6869 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6870 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6871 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6872 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6873 Spacing));
6874 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6875 Spacing * 2));
6876 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6877 Spacing * 3));
6878 TmpInst.addOperand(Inst.getOperand(1)); // lane
6879 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6880 TmpInst.addOperand(Inst.getOperand(6));
6881 Inst = TmpInst;
6882 return true;
6883 }
6884
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006885 case ARM::VST1LNdWB_fixed_Asm_8:
6886 case ARM::VST1LNdWB_fixed_Asm_16:
6887 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006888 MCInst TmpInst;
6889 // Shuffle the operands around so the lane index operand is in the
6890 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006891 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006892 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006893 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6894 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6895 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6896 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6897 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6898 TmpInst.addOperand(Inst.getOperand(1)); // lane
6899 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6900 TmpInst.addOperand(Inst.getOperand(5));
6901 Inst = TmpInst;
6902 return true;
6903 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006904
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006905 case ARM::VST2LNdWB_fixed_Asm_8:
6906 case ARM::VST2LNdWB_fixed_Asm_16:
6907 case ARM::VST2LNdWB_fixed_Asm_32:
6908 case ARM::VST2LNqWB_fixed_Asm_16:
6909 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006910 MCInst TmpInst;
6911 // Shuffle the operands around so the lane index operand is in the
6912 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006913 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006914 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006915 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6916 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6917 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6918 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6919 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006920 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6921 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006922 TmpInst.addOperand(Inst.getOperand(1)); // lane
6923 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6924 TmpInst.addOperand(Inst.getOperand(5));
6925 Inst = TmpInst;
6926 return true;
6927 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006928
6929 case ARM::VST3LNdWB_fixed_Asm_8:
6930 case ARM::VST3LNdWB_fixed_Asm_16:
6931 case ARM::VST3LNdWB_fixed_Asm_32:
6932 case ARM::VST3LNqWB_fixed_Asm_16:
6933 case ARM::VST3LNqWB_fixed_Asm_32: {
6934 MCInst TmpInst;
6935 // Shuffle the operands around so the lane index operand is in the
6936 // right place.
6937 unsigned Spacing;
6938 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6939 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6940 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6941 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6942 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6943 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6944 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6945 Spacing));
6946 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6947 Spacing * 2));
6948 TmpInst.addOperand(Inst.getOperand(1)); // lane
6949 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6950 TmpInst.addOperand(Inst.getOperand(5));
6951 Inst = TmpInst;
6952 return true;
6953 }
6954
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006955 case ARM::VST4LNdWB_fixed_Asm_8:
6956 case ARM::VST4LNdWB_fixed_Asm_16:
6957 case ARM::VST4LNdWB_fixed_Asm_32:
6958 case ARM::VST4LNqWB_fixed_Asm_16:
6959 case ARM::VST4LNqWB_fixed_Asm_32: {
6960 MCInst TmpInst;
6961 // Shuffle the operands around so the lane index operand is in the
6962 // right place.
6963 unsigned Spacing;
6964 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6965 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6966 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6967 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6968 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6969 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6970 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6971 Spacing));
6972 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6973 Spacing * 2));
6974 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6975 Spacing * 3));
6976 TmpInst.addOperand(Inst.getOperand(1)); // lane
6977 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6978 TmpInst.addOperand(Inst.getOperand(5));
6979 Inst = TmpInst;
6980 return true;
6981 }
6982
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006983 case ARM::VST1LNdAsm_8:
6984 case ARM::VST1LNdAsm_16:
6985 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006986 MCInst TmpInst;
6987 // Shuffle the operands around so the lane index operand is in the
6988 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006989 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006990 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006991 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6992 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6993 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6994 TmpInst.addOperand(Inst.getOperand(1)); // lane
6995 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6996 TmpInst.addOperand(Inst.getOperand(5));
6997 Inst = TmpInst;
6998 return true;
6999 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007000
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007001 case ARM::VST2LNdAsm_8:
7002 case ARM::VST2LNdAsm_16:
7003 case ARM::VST2LNdAsm_32:
7004 case ARM::VST2LNqAsm_16:
7005 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007006 MCInst TmpInst;
7007 // Shuffle the operands around so the lane index operand is in the
7008 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00007009 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007010 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007011 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7012 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7013 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00007014 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7015 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007016 TmpInst.addOperand(Inst.getOperand(1)); // lane
7017 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7018 TmpInst.addOperand(Inst.getOperand(5));
7019 Inst = TmpInst;
7020 return true;
7021 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00007022
7023 case ARM::VST3LNdAsm_8:
7024 case ARM::VST3LNdAsm_16:
7025 case ARM::VST3LNdAsm_32:
7026 case ARM::VST3LNqAsm_16:
7027 case ARM::VST3LNqAsm_32: {
7028 MCInst TmpInst;
7029 // Shuffle the operands around so the lane index operand is in the
7030 // right place.
7031 unsigned Spacing;
7032 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7033 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7034 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7035 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7036 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7037 Spacing));
7038 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7039 Spacing * 2));
7040 TmpInst.addOperand(Inst.getOperand(1)); // lane
7041 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7042 TmpInst.addOperand(Inst.getOperand(5));
7043 Inst = TmpInst;
7044 return true;
7045 }
7046
Jim Grosbach8e2722c2012-01-24 18:53:13 +00007047 case ARM::VST4LNdAsm_8:
7048 case ARM::VST4LNdAsm_16:
7049 case ARM::VST4LNdAsm_32:
7050 case ARM::VST4LNqAsm_16:
7051 case ARM::VST4LNqAsm_32: {
7052 MCInst TmpInst;
7053 // Shuffle the operands around so the lane index operand is in the
7054 // right place.
7055 unsigned Spacing;
7056 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7057 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7058 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7059 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7060 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7061 Spacing));
7062 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7063 Spacing * 2));
7064 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7065 Spacing * 3));
7066 TmpInst.addOperand(Inst.getOperand(1)); // lane
7067 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7068 TmpInst.addOperand(Inst.getOperand(5));
7069 Inst = TmpInst;
7070 return true;
7071 }
7072
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007073 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007074 case ARM::VLD1LNdWB_register_Asm_8:
7075 case ARM::VLD1LNdWB_register_Asm_16:
7076 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007077 MCInst TmpInst;
7078 // Shuffle the operands around so the lane index operand is in the
7079 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007080 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007081 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007082 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7083 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7084 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7085 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7086 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7087 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7088 TmpInst.addOperand(Inst.getOperand(1)); // lane
7089 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7090 TmpInst.addOperand(Inst.getOperand(6));
7091 Inst = TmpInst;
7092 return true;
7093 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007094
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007095 case ARM::VLD2LNdWB_register_Asm_8:
7096 case ARM::VLD2LNdWB_register_Asm_16:
7097 case ARM::VLD2LNdWB_register_Asm_32:
7098 case ARM::VLD2LNqWB_register_Asm_16:
7099 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007100 MCInst TmpInst;
7101 // Shuffle the operands around so the lane index operand is in the
7102 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007103 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007104 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007105 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007106 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7107 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007108 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7109 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7110 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7111 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7112 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007113 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7114 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007115 TmpInst.addOperand(Inst.getOperand(1)); // lane
7116 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7117 TmpInst.addOperand(Inst.getOperand(6));
7118 Inst = TmpInst;
7119 return true;
7120 }
7121
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007122 case ARM::VLD3LNdWB_register_Asm_8:
7123 case ARM::VLD3LNdWB_register_Asm_16:
7124 case ARM::VLD3LNdWB_register_Asm_32:
7125 case ARM::VLD3LNqWB_register_Asm_16:
7126 case ARM::VLD3LNqWB_register_Asm_32: {
7127 MCInst TmpInst;
7128 // Shuffle the operands around so the lane index operand is in the
7129 // right place.
7130 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007131 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007132 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7133 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7134 Spacing));
7135 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007136 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007137 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7138 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7139 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7140 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7141 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7143 Spacing));
7144 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007145 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007146 TmpInst.addOperand(Inst.getOperand(1)); // lane
7147 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7148 TmpInst.addOperand(Inst.getOperand(6));
7149 Inst = TmpInst;
7150 return true;
7151 }
7152
Jim Grosbach14952a02012-01-24 18:37:25 +00007153 case ARM::VLD4LNdWB_register_Asm_8:
7154 case ARM::VLD4LNdWB_register_Asm_16:
7155 case ARM::VLD4LNdWB_register_Asm_32:
7156 case ARM::VLD4LNqWB_register_Asm_16:
7157 case ARM::VLD4LNqWB_register_Asm_32: {
7158 MCInst TmpInst;
7159 // Shuffle the operands around so the lane index operand is in the
7160 // right place.
7161 unsigned Spacing;
7162 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7163 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7164 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7165 Spacing));
7166 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7167 Spacing * 2));
7168 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7169 Spacing * 3));
7170 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7171 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7172 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7173 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7174 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7175 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7176 Spacing));
7177 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7178 Spacing * 2));
7179 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7180 Spacing * 3));
7181 TmpInst.addOperand(Inst.getOperand(1)); // lane
7182 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7183 TmpInst.addOperand(Inst.getOperand(6));
7184 Inst = TmpInst;
7185 return true;
7186 }
7187
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007188 case ARM::VLD1LNdWB_fixed_Asm_8:
7189 case ARM::VLD1LNdWB_fixed_Asm_16:
7190 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007191 MCInst TmpInst;
7192 // Shuffle the operands around so the lane index operand is in the
7193 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007194 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007195 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007196 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7197 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7198 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7199 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7200 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7201 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7202 TmpInst.addOperand(Inst.getOperand(1)); // lane
7203 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7204 TmpInst.addOperand(Inst.getOperand(5));
7205 Inst = TmpInst;
7206 return true;
7207 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007208
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007209 case ARM::VLD2LNdWB_fixed_Asm_8:
7210 case ARM::VLD2LNdWB_fixed_Asm_16:
7211 case ARM::VLD2LNdWB_fixed_Asm_32:
7212 case ARM::VLD2LNqWB_fixed_Asm_16:
7213 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007214 MCInst TmpInst;
7215 // Shuffle the operands around so the lane index operand is in the
7216 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007217 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007218 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007219 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007220 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7221 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007222 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7223 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7224 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7225 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7226 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007227 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7228 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007229 TmpInst.addOperand(Inst.getOperand(1)); // lane
7230 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7231 TmpInst.addOperand(Inst.getOperand(5));
7232 Inst = TmpInst;
7233 return true;
7234 }
7235
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007236 case ARM::VLD3LNdWB_fixed_Asm_8:
7237 case ARM::VLD3LNdWB_fixed_Asm_16:
7238 case ARM::VLD3LNdWB_fixed_Asm_32:
7239 case ARM::VLD3LNqWB_fixed_Asm_16:
7240 case ARM::VLD3LNqWB_fixed_Asm_32: {
7241 MCInst TmpInst;
7242 // Shuffle the operands around so the lane index operand is in the
7243 // right place.
7244 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007245 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007246 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7247 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7248 Spacing));
7249 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007250 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007251 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7252 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7253 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7254 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7255 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7256 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7257 Spacing));
7258 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007259 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007260 TmpInst.addOperand(Inst.getOperand(1)); // lane
7261 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7262 TmpInst.addOperand(Inst.getOperand(5));
7263 Inst = TmpInst;
7264 return true;
7265 }
7266
Jim Grosbach14952a02012-01-24 18:37:25 +00007267 case ARM::VLD4LNdWB_fixed_Asm_8:
7268 case ARM::VLD4LNdWB_fixed_Asm_16:
7269 case ARM::VLD4LNdWB_fixed_Asm_32:
7270 case ARM::VLD4LNqWB_fixed_Asm_16:
7271 case ARM::VLD4LNqWB_fixed_Asm_32: {
7272 MCInst TmpInst;
7273 // Shuffle the operands around so the lane index operand is in the
7274 // right place.
7275 unsigned Spacing;
7276 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7277 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7278 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7279 Spacing));
7280 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7281 Spacing * 2));
7282 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7283 Spacing * 3));
7284 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7285 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7286 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7287 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7288 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7289 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7290 Spacing));
7291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7292 Spacing * 2));
7293 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7294 Spacing * 3));
7295 TmpInst.addOperand(Inst.getOperand(1)); // lane
7296 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7297 TmpInst.addOperand(Inst.getOperand(5));
7298 Inst = TmpInst;
7299 return true;
7300 }
7301
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007302 case ARM::VLD1LNdAsm_8:
7303 case ARM::VLD1LNdAsm_16:
7304 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00007305 MCInst TmpInst;
7306 // Shuffle the operands around so the lane index operand is in the
7307 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007308 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007309 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00007310 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7311 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7312 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7313 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7314 TmpInst.addOperand(Inst.getOperand(1)); // lane
7315 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7316 TmpInst.addOperand(Inst.getOperand(5));
7317 Inst = TmpInst;
7318 return true;
7319 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007320
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007321 case ARM::VLD2LNdAsm_8:
7322 case ARM::VLD2LNdAsm_16:
7323 case ARM::VLD2LNdAsm_32:
7324 case ARM::VLD2LNqAsm_16:
7325 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007326 MCInst TmpInst;
7327 // Shuffle the operands around so the lane index operand is in the
7328 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007329 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007330 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007331 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007332 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7333 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007334 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7335 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7336 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007337 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7338 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007339 TmpInst.addOperand(Inst.getOperand(1)); // lane
7340 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7341 TmpInst.addOperand(Inst.getOperand(5));
7342 Inst = TmpInst;
7343 return true;
7344 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007345
7346 case ARM::VLD3LNdAsm_8:
7347 case ARM::VLD3LNdAsm_16:
7348 case ARM::VLD3LNdAsm_32:
7349 case ARM::VLD3LNqAsm_16:
7350 case ARM::VLD3LNqAsm_32: {
7351 MCInst TmpInst;
7352 // Shuffle the operands around so the lane index operand is in the
7353 // right place.
7354 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007355 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007356 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7357 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7358 Spacing));
7359 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007360 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007361 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7362 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7363 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7365 Spacing));
7366 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007367 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007368 TmpInst.addOperand(Inst.getOperand(1)); // lane
7369 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7370 TmpInst.addOperand(Inst.getOperand(5));
7371 Inst = TmpInst;
7372 return true;
7373 }
7374
Jim Grosbach14952a02012-01-24 18:37:25 +00007375 case ARM::VLD4LNdAsm_8:
7376 case ARM::VLD4LNdAsm_16:
7377 case ARM::VLD4LNdAsm_32:
7378 case ARM::VLD4LNqAsm_16:
7379 case ARM::VLD4LNqAsm_32: {
7380 MCInst TmpInst;
7381 // Shuffle the operands around so the lane index operand is in the
7382 // right place.
7383 unsigned Spacing;
7384 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7385 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7386 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7387 Spacing));
7388 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7389 Spacing * 2));
7390 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7391 Spacing * 3));
7392 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7393 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7394 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7395 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7396 Spacing));
7397 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7398 Spacing * 2));
7399 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7400 Spacing * 3));
7401 TmpInst.addOperand(Inst.getOperand(1)); // lane
7402 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7403 TmpInst.addOperand(Inst.getOperand(5));
7404 Inst = TmpInst;
7405 return true;
7406 }
7407
Jim Grosbachb78403c2012-01-24 23:47:04 +00007408 // VLD3DUP single 3-element structure to all lanes instructions.
7409 case ARM::VLD3DUPdAsm_8:
7410 case ARM::VLD3DUPdAsm_16:
7411 case ARM::VLD3DUPdAsm_32:
7412 case ARM::VLD3DUPqAsm_8:
7413 case ARM::VLD3DUPqAsm_16:
7414 case ARM::VLD3DUPqAsm_32: {
7415 MCInst TmpInst;
7416 unsigned Spacing;
7417 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7418 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7419 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7420 Spacing));
7421 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7422 Spacing * 2));
7423 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7424 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7425 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7426 TmpInst.addOperand(Inst.getOperand(4));
7427 Inst = TmpInst;
7428 return true;
7429 }
7430
7431 case ARM::VLD3DUPdWB_fixed_Asm_8:
7432 case ARM::VLD3DUPdWB_fixed_Asm_16:
7433 case ARM::VLD3DUPdWB_fixed_Asm_32:
7434 case ARM::VLD3DUPqWB_fixed_Asm_8:
7435 case ARM::VLD3DUPqWB_fixed_Asm_16:
7436 case ARM::VLD3DUPqWB_fixed_Asm_32: {
7437 MCInst TmpInst;
7438 unsigned Spacing;
7439 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7440 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7441 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7442 Spacing));
7443 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7444 Spacing * 2));
7445 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7446 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7447 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7448 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7449 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7450 TmpInst.addOperand(Inst.getOperand(4));
7451 Inst = TmpInst;
7452 return true;
7453 }
7454
7455 case ARM::VLD3DUPdWB_register_Asm_8:
7456 case ARM::VLD3DUPdWB_register_Asm_16:
7457 case ARM::VLD3DUPdWB_register_Asm_32:
7458 case ARM::VLD3DUPqWB_register_Asm_8:
7459 case ARM::VLD3DUPqWB_register_Asm_16:
7460 case ARM::VLD3DUPqWB_register_Asm_32: {
7461 MCInst TmpInst;
7462 unsigned Spacing;
7463 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7464 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7465 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7466 Spacing));
7467 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7468 Spacing * 2));
7469 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7470 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7471 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7472 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7473 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7474 TmpInst.addOperand(Inst.getOperand(5));
7475 Inst = TmpInst;
7476 return true;
7477 }
7478
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007479 // VLD3 multiple 3-element structure instructions.
7480 case ARM::VLD3dAsm_8:
7481 case ARM::VLD3dAsm_16:
7482 case ARM::VLD3dAsm_32:
7483 case ARM::VLD3qAsm_8:
7484 case ARM::VLD3qAsm_16:
7485 case ARM::VLD3qAsm_32: {
7486 MCInst TmpInst;
7487 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007488 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007489 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7490 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7491 Spacing));
7492 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7493 Spacing * 2));
7494 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7495 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7496 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7497 TmpInst.addOperand(Inst.getOperand(4));
7498 Inst = TmpInst;
7499 return true;
7500 }
7501
7502 case ARM::VLD3dWB_fixed_Asm_8:
7503 case ARM::VLD3dWB_fixed_Asm_16:
7504 case ARM::VLD3dWB_fixed_Asm_32:
7505 case ARM::VLD3qWB_fixed_Asm_8:
7506 case ARM::VLD3qWB_fixed_Asm_16:
7507 case ARM::VLD3qWB_fixed_Asm_32: {
7508 MCInst TmpInst;
7509 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007510 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007511 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7512 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7513 Spacing));
7514 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7515 Spacing * 2));
7516 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7517 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7518 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7519 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7520 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7521 TmpInst.addOperand(Inst.getOperand(4));
7522 Inst = TmpInst;
7523 return true;
7524 }
7525
7526 case ARM::VLD3dWB_register_Asm_8:
7527 case ARM::VLD3dWB_register_Asm_16:
7528 case ARM::VLD3dWB_register_Asm_32:
7529 case ARM::VLD3qWB_register_Asm_8:
7530 case ARM::VLD3qWB_register_Asm_16:
7531 case ARM::VLD3qWB_register_Asm_32: {
7532 MCInst TmpInst;
7533 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007534 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007535 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7536 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7537 Spacing));
7538 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7539 Spacing * 2));
7540 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7541 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7542 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7543 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7544 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7545 TmpInst.addOperand(Inst.getOperand(5));
7546 Inst = TmpInst;
7547 return true;
7548 }
7549
Jim Grosbach086cbfa2012-01-25 00:01:08 +00007550 // VLD4DUP single 3-element structure to all lanes instructions.
7551 case ARM::VLD4DUPdAsm_8:
7552 case ARM::VLD4DUPdAsm_16:
7553 case ARM::VLD4DUPdAsm_32:
7554 case ARM::VLD4DUPqAsm_8:
7555 case ARM::VLD4DUPqAsm_16:
7556 case ARM::VLD4DUPqAsm_32: {
7557 MCInst TmpInst;
7558 unsigned Spacing;
7559 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7560 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7561 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7562 Spacing));
7563 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7564 Spacing * 2));
7565 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7566 Spacing * 3));
7567 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7568 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7569 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7570 TmpInst.addOperand(Inst.getOperand(4));
7571 Inst = TmpInst;
7572 return true;
7573 }
7574
7575 case ARM::VLD4DUPdWB_fixed_Asm_8:
7576 case ARM::VLD4DUPdWB_fixed_Asm_16:
7577 case ARM::VLD4DUPdWB_fixed_Asm_32:
7578 case ARM::VLD4DUPqWB_fixed_Asm_8:
7579 case ARM::VLD4DUPqWB_fixed_Asm_16:
7580 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7581 MCInst TmpInst;
7582 unsigned Spacing;
7583 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7584 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7585 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7586 Spacing));
7587 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7588 Spacing * 2));
7589 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7590 Spacing * 3));
7591 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7592 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7593 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7594 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7595 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7596 TmpInst.addOperand(Inst.getOperand(4));
7597 Inst = TmpInst;
7598 return true;
7599 }
7600
7601 case ARM::VLD4DUPdWB_register_Asm_8:
7602 case ARM::VLD4DUPdWB_register_Asm_16:
7603 case ARM::VLD4DUPdWB_register_Asm_32:
7604 case ARM::VLD4DUPqWB_register_Asm_8:
7605 case ARM::VLD4DUPqWB_register_Asm_16:
7606 case ARM::VLD4DUPqWB_register_Asm_32: {
7607 MCInst TmpInst;
7608 unsigned Spacing;
7609 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7610 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7611 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7612 Spacing));
7613 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7614 Spacing * 2));
7615 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7616 Spacing * 3));
7617 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7618 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7619 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7620 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7621 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7622 TmpInst.addOperand(Inst.getOperand(5));
7623 Inst = TmpInst;
7624 return true;
7625 }
7626
7627 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00007628 case ARM::VLD4dAsm_8:
7629 case ARM::VLD4dAsm_16:
7630 case ARM::VLD4dAsm_32:
7631 case ARM::VLD4qAsm_8:
7632 case ARM::VLD4qAsm_16:
7633 case ARM::VLD4qAsm_32: {
7634 MCInst TmpInst;
7635 unsigned Spacing;
7636 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7637 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7638 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7639 Spacing));
7640 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7641 Spacing * 2));
7642 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7643 Spacing * 3));
7644 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7645 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7646 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7647 TmpInst.addOperand(Inst.getOperand(4));
7648 Inst = TmpInst;
7649 return true;
7650 }
7651
7652 case ARM::VLD4dWB_fixed_Asm_8:
7653 case ARM::VLD4dWB_fixed_Asm_16:
7654 case ARM::VLD4dWB_fixed_Asm_32:
7655 case ARM::VLD4qWB_fixed_Asm_8:
7656 case ARM::VLD4qWB_fixed_Asm_16:
7657 case ARM::VLD4qWB_fixed_Asm_32: {
7658 MCInst TmpInst;
7659 unsigned Spacing;
7660 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7661 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7662 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7663 Spacing));
7664 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7665 Spacing * 2));
7666 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7667 Spacing * 3));
7668 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7669 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7670 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7671 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7672 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7673 TmpInst.addOperand(Inst.getOperand(4));
7674 Inst = TmpInst;
7675 return true;
7676 }
7677
7678 case ARM::VLD4dWB_register_Asm_8:
7679 case ARM::VLD4dWB_register_Asm_16:
7680 case ARM::VLD4dWB_register_Asm_32:
7681 case ARM::VLD4qWB_register_Asm_8:
7682 case ARM::VLD4qWB_register_Asm_16:
7683 case ARM::VLD4qWB_register_Asm_32: {
7684 MCInst TmpInst;
7685 unsigned Spacing;
7686 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7687 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7688 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7689 Spacing));
7690 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7691 Spacing * 2));
7692 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7693 Spacing * 3));
7694 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7695 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7696 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7697 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7698 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7699 TmpInst.addOperand(Inst.getOperand(5));
7700 Inst = TmpInst;
7701 return true;
7702 }
7703
Jim Grosbach1a747242012-01-23 23:45:44 +00007704 // VST3 multiple 3-element structure instructions.
7705 case ARM::VST3dAsm_8:
7706 case ARM::VST3dAsm_16:
7707 case ARM::VST3dAsm_32:
7708 case ARM::VST3qAsm_8:
7709 case ARM::VST3qAsm_16:
7710 case ARM::VST3qAsm_32: {
7711 MCInst TmpInst;
7712 unsigned Spacing;
7713 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7714 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7715 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7716 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7717 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7718 Spacing));
7719 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7720 Spacing * 2));
7721 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7722 TmpInst.addOperand(Inst.getOperand(4));
7723 Inst = TmpInst;
7724 return true;
7725 }
7726
7727 case ARM::VST3dWB_fixed_Asm_8:
7728 case ARM::VST3dWB_fixed_Asm_16:
7729 case ARM::VST3dWB_fixed_Asm_32:
7730 case ARM::VST3qWB_fixed_Asm_8:
7731 case ARM::VST3qWB_fixed_Asm_16:
7732 case ARM::VST3qWB_fixed_Asm_32: {
7733 MCInst TmpInst;
7734 unsigned Spacing;
7735 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7736 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7737 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7738 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7739 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7740 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7741 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7742 Spacing));
7743 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7744 Spacing * 2));
7745 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7746 TmpInst.addOperand(Inst.getOperand(4));
7747 Inst = TmpInst;
7748 return true;
7749 }
7750
7751 case ARM::VST3dWB_register_Asm_8:
7752 case ARM::VST3dWB_register_Asm_16:
7753 case ARM::VST3dWB_register_Asm_32:
7754 case ARM::VST3qWB_register_Asm_8:
7755 case ARM::VST3qWB_register_Asm_16:
7756 case ARM::VST3qWB_register_Asm_32: {
7757 MCInst TmpInst;
7758 unsigned Spacing;
7759 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7760 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7761 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7762 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7763 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7764 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7765 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7766 Spacing));
7767 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7768 Spacing * 2));
7769 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7770 TmpInst.addOperand(Inst.getOperand(5));
7771 Inst = TmpInst;
7772 return true;
7773 }
7774
Jim Grosbachda70eac2012-01-24 00:58:13 +00007775 // VST4 multiple 3-element structure instructions.
7776 case ARM::VST4dAsm_8:
7777 case ARM::VST4dAsm_16:
7778 case ARM::VST4dAsm_32:
7779 case ARM::VST4qAsm_8:
7780 case ARM::VST4qAsm_16:
7781 case ARM::VST4qAsm_32: {
7782 MCInst TmpInst;
7783 unsigned Spacing;
7784 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7785 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7786 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7787 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7788 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7789 Spacing));
7790 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7791 Spacing * 2));
7792 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7793 Spacing * 3));
7794 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7795 TmpInst.addOperand(Inst.getOperand(4));
7796 Inst = TmpInst;
7797 return true;
7798 }
7799
7800 case ARM::VST4dWB_fixed_Asm_8:
7801 case ARM::VST4dWB_fixed_Asm_16:
7802 case ARM::VST4dWB_fixed_Asm_32:
7803 case ARM::VST4qWB_fixed_Asm_8:
7804 case ARM::VST4qWB_fixed_Asm_16:
7805 case ARM::VST4qWB_fixed_Asm_32: {
7806 MCInst TmpInst;
7807 unsigned Spacing;
7808 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7809 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7810 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7811 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7812 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7813 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7814 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7815 Spacing));
7816 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7817 Spacing * 2));
7818 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7819 Spacing * 3));
7820 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7821 TmpInst.addOperand(Inst.getOperand(4));
7822 Inst = TmpInst;
7823 return true;
7824 }
7825
7826 case ARM::VST4dWB_register_Asm_8:
7827 case ARM::VST4dWB_register_Asm_16:
7828 case ARM::VST4dWB_register_Asm_32:
7829 case ARM::VST4qWB_register_Asm_8:
7830 case ARM::VST4qWB_register_Asm_16:
7831 case ARM::VST4qWB_register_Asm_32: {
7832 MCInst TmpInst;
7833 unsigned Spacing;
7834 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7835 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7836 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7837 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7838 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7839 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7840 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7841 Spacing));
7842 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7843 Spacing * 2));
7844 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7845 Spacing * 3));
7846 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7847 TmpInst.addOperand(Inst.getOperand(5));
7848 Inst = TmpInst;
7849 return true;
7850 }
7851
Jim Grosbachad66de12012-04-11 00:15:16 +00007852 // Handle encoding choice for the shift-immediate instructions.
7853 case ARM::t2LSLri:
7854 case ARM::t2LSRri:
7855 case ARM::t2ASRri: {
7856 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7857 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7858 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007859 !(static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7860 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) {
Jim Grosbachad66de12012-04-11 00:15:16 +00007861 unsigned NewOpc;
7862 switch (Inst.getOpcode()) {
7863 default: llvm_unreachable("unexpected opcode");
7864 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7865 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7866 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7867 }
7868 // The Thumb1 operands aren't in the same order. Awesome, eh?
7869 MCInst TmpInst;
7870 TmpInst.setOpcode(NewOpc);
7871 TmpInst.addOperand(Inst.getOperand(0));
7872 TmpInst.addOperand(Inst.getOperand(5));
7873 TmpInst.addOperand(Inst.getOperand(1));
7874 TmpInst.addOperand(Inst.getOperand(2));
7875 TmpInst.addOperand(Inst.getOperand(3));
7876 TmpInst.addOperand(Inst.getOperand(4));
7877 Inst = TmpInst;
7878 return true;
7879 }
7880 return false;
7881 }
7882
Jim Grosbach485e5622011-12-13 22:45:11 +00007883 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007884 case ARM::t2MOVsr:
7885 case ARM::t2MOVSsr: {
7886 // Which instruction to expand to depends on the CCOut operand and
7887 // whether we're in an IT block if the register operands are low
7888 // registers.
7889 bool isNarrow = false;
7890 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7891 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7892 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7893 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7894 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7895 isNarrow = true;
7896 MCInst TmpInst;
7897 unsigned newOpc;
7898 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7899 default: llvm_unreachable("unexpected opcode!");
7900 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7901 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7902 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7903 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7904 }
7905 TmpInst.setOpcode(newOpc);
7906 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7907 if (isNarrow)
7908 TmpInst.addOperand(MCOperand::CreateReg(
7909 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7910 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7911 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7912 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7913 TmpInst.addOperand(Inst.getOperand(5));
7914 if (!isNarrow)
7915 TmpInst.addOperand(MCOperand::CreateReg(
7916 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7917 Inst = TmpInst;
7918 return true;
7919 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007920 case ARM::t2MOVsi:
7921 case ARM::t2MOVSsi: {
7922 // Which instruction to expand to depends on the CCOut operand and
7923 // whether we're in an IT block if the register operands are low
7924 // registers.
7925 bool isNarrow = false;
7926 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7927 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7928 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7929 isNarrow = true;
7930 MCInst TmpInst;
7931 unsigned newOpc;
7932 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7933 default: llvm_unreachable("unexpected opcode!");
7934 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7935 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7936 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7937 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007938 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007939 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007940 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7941 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007942 TmpInst.setOpcode(newOpc);
7943 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7944 if (isNarrow)
7945 TmpInst.addOperand(MCOperand::CreateReg(
7946 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7947 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007948 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007949 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007950 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7951 TmpInst.addOperand(Inst.getOperand(4));
7952 if (!isNarrow)
7953 TmpInst.addOperand(MCOperand::CreateReg(
7954 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7955 Inst = TmpInst;
7956 return true;
7957 }
7958 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007959 case ARM::ASRr:
7960 case ARM::LSRr:
7961 case ARM::LSLr:
7962 case ARM::RORr: {
7963 ARM_AM::ShiftOpc ShiftTy;
7964 switch(Inst.getOpcode()) {
7965 default: llvm_unreachable("unexpected opcode!");
7966 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7967 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7968 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7969 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7970 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007971 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7972 MCInst TmpInst;
7973 TmpInst.setOpcode(ARM::MOVsr);
7974 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7975 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7976 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7977 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7978 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7979 TmpInst.addOperand(Inst.getOperand(4));
7980 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7981 Inst = TmpInst;
7982 return true;
7983 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007984 case ARM::ASRi:
7985 case ARM::LSRi:
7986 case ARM::LSLi:
7987 case ARM::RORi: {
7988 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007989 switch(Inst.getOpcode()) {
7990 default: llvm_unreachable("unexpected opcode!");
7991 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7992 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7993 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7994 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7995 }
7996 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007997 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007998 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007999 // A shift by 32 should be encoded as 0 when permitted
8000 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
8001 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00008002 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00008003 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00008004 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00008005 TmpInst.addOperand(Inst.getOperand(0)); // Rd
8006 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00008007 if (Opc == ARM::MOVsi)
8008 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00008009 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
8010 TmpInst.addOperand(Inst.getOperand(4));
8011 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
8012 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008013 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00008014 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00008015 case ARM::RRXi: {
8016 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
8017 MCInst TmpInst;
8018 TmpInst.setOpcode(ARM::MOVsi);
8019 TmpInst.addOperand(Inst.getOperand(0)); // Rd
8020 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8021 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
8022 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8023 TmpInst.addOperand(Inst.getOperand(3));
8024 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
8025 Inst = TmpInst;
8026 return true;
8027 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00008028 case ARM::t2LDMIA_UPD: {
8029 // If this is a load of a single register, then we should use
8030 // a post-indexed LDR instruction instead, per the ARM ARM.
8031 if (Inst.getNumOperands() != 5)
8032 return false;
8033 MCInst TmpInst;
8034 TmpInst.setOpcode(ARM::t2LDR_POST);
8035 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8036 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8037 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8038 TmpInst.addOperand(MCOperand::CreateImm(4));
8039 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8040 TmpInst.addOperand(Inst.getOperand(3));
8041 Inst = TmpInst;
8042 return true;
8043 }
8044 case ARM::t2STMDB_UPD: {
8045 // If this is a store of a single register, then we should use
8046 // a pre-indexed STR instruction instead, per the ARM ARM.
8047 if (Inst.getNumOperands() != 5)
8048 return false;
8049 MCInst TmpInst;
8050 TmpInst.setOpcode(ARM::t2STR_PRE);
8051 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8052 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8053 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8054 TmpInst.addOperand(MCOperand::CreateImm(-4));
8055 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8056 TmpInst.addOperand(Inst.getOperand(3));
8057 Inst = TmpInst;
8058 return true;
8059 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008060 case ARM::LDMIA_UPD:
8061 // If this is a load of a single register via a 'pop', then we should use
8062 // a post-indexed LDR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008063 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008064 Inst.getNumOperands() == 5) {
8065 MCInst TmpInst;
8066 TmpInst.setOpcode(ARM::LDR_POST_IMM);
8067 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8068 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8069 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8070 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
8071 TmpInst.addOperand(MCOperand::CreateImm(4));
8072 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8073 TmpInst.addOperand(Inst.getOperand(3));
8074 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008075 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008076 }
8077 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008078 case ARM::STMDB_UPD:
8079 // If this is a store of a single register via a 'push', then we should use
8080 // a pre-indexed STR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008081 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008082 Inst.getNumOperands() == 5) {
8083 MCInst TmpInst;
8084 TmpInst.setOpcode(ARM::STR_PRE_IMM);
8085 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8086 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8087 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
8088 TmpInst.addOperand(MCOperand::CreateImm(-4));
8089 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8090 TmpInst.addOperand(Inst.getOperand(3));
8091 Inst = TmpInst;
8092 }
8093 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00008094 case ARM::t2ADDri12:
8095 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
8096 // mnemonic was used (not "addw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008097 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008098 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8099 break;
8100 Inst.setOpcode(ARM::t2ADDri);
8101 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8102 break;
8103 case ARM::t2SUBri12:
8104 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
8105 // mnemonic was used (not "subw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008106 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008107 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8108 break;
8109 Inst.setOpcode(ARM::t2SUBri);
8110 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8111 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008112 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008113 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00008114 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8115 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8116 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008117 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008118 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008119 return true;
8120 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008121 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008122 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008123 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008124 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8125 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8126 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008127 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008128 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008129 return true;
8130 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008131 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00008132 case ARM::t2ADDri:
8133 case ARM::t2SUBri: {
8134 // If the destination and first source operand are the same, and
8135 // the flags are compatible with the current IT status, use encoding T2
8136 // instead of T3. For compatibility with the system 'as'. Make sure the
8137 // wide encoding wasn't explicit.
8138 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00008139 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00008140 (unsigned)Inst.getOperand(2).getImm() > 255 ||
8141 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008142 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
8143 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8144 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbachdef5e342012-03-30 17:20:40 +00008145 break;
8146 MCInst TmpInst;
8147 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
8148 ARM::tADDi8 : ARM::tSUBi8);
8149 TmpInst.addOperand(Inst.getOperand(0));
8150 TmpInst.addOperand(Inst.getOperand(5));
8151 TmpInst.addOperand(Inst.getOperand(0));
8152 TmpInst.addOperand(Inst.getOperand(2));
8153 TmpInst.addOperand(Inst.getOperand(3));
8154 TmpInst.addOperand(Inst.getOperand(4));
8155 Inst = TmpInst;
8156 return true;
8157 }
Jim Grosbache489bab2011-12-05 22:16:39 +00008158 case ARM::t2ADDrr: {
8159 // If the destination and first source operand are the same, and
8160 // there's no setting of the flags, use encoding T2 instead of T3.
8161 // Note that this is only for ADD, not SUB. This mirrors the system
8162 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
8163 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
8164 Inst.getOperand(5).getReg() != 0 ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008165 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8166 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00008167 break;
8168 MCInst TmpInst;
8169 TmpInst.setOpcode(ARM::tADDhirr);
8170 TmpInst.addOperand(Inst.getOperand(0));
8171 TmpInst.addOperand(Inst.getOperand(0));
8172 TmpInst.addOperand(Inst.getOperand(2));
8173 TmpInst.addOperand(Inst.getOperand(3));
8174 TmpInst.addOperand(Inst.getOperand(4));
8175 Inst = TmpInst;
8176 return true;
8177 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00008178 case ARM::tADDrSP: {
8179 // If the non-SP source operand and the destination operand are not the
8180 // same, we need to use the 32-bit encoding if it's available.
8181 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
8182 Inst.setOpcode(ARM::t2ADDrr);
8183 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8184 return true;
8185 }
8186 break;
8187 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008188 case ARM::tB:
8189 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008190 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008191 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008192 return true;
8193 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008194 break;
8195 case ARM::t2B:
8196 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008197 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008198 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008199 return true;
8200 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008201 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00008202 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008203 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00008204 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00008205 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00008206 return true;
8207 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00008208 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008209 case ARM::tBcc:
8210 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00008211 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008212 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00008213 return true;
8214 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00008215 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008216 case ARM::tLDMIA: {
8217 // If the register list contains any high registers, or if the writeback
8218 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
8219 // instead if we're in Thumb2. Otherwise, this should have generated
8220 // an error in validateInstruction().
8221 unsigned Rn = Inst.getOperand(0).getReg();
8222 bool hasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00008223 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8224 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Jim Grosbacha31f2232011-09-07 18:05:34 +00008225 bool listContainsBase;
8226 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
8227 (!listContainsBase && !hasWritebackToken) ||
8228 (listContainsBase && hasWritebackToken)) {
8229 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8230 assert (isThumbTwo());
8231 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
8232 // If we're switching to the updating version, we need to insert
8233 // the writeback tied operand.
8234 if (hasWritebackToken)
8235 Inst.insert(Inst.begin(),
8236 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00008237 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008238 }
8239 break;
8240 }
Jim Grosbach099c9762011-09-16 20:50:13 +00008241 case ARM::tSTMIA_UPD: {
8242 // If the register list contains any high registers, we need to use
8243 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8244 // should have generated an error in validateInstruction().
8245 unsigned Rn = Inst.getOperand(0).getReg();
8246 bool listContainsBase;
8247 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
8248 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8249 assert (isThumbTwo());
8250 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00008251 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00008252 }
8253 break;
8254 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008255 case ARM::tPOP: {
8256 bool listContainsBase;
8257 // If the register list contains any high registers, we need to use
8258 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8259 // should have generated an error in validateInstruction().
8260 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008261 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008262 assert (isThumbTwo());
8263 Inst.setOpcode(ARM::t2LDMIA_UPD);
8264 // Add the base register and writeback operands.
8265 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8266 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008267 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008268 }
8269 case ARM::tPUSH: {
8270 bool listContainsBase;
8271 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008272 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008273 assert (isThumbTwo());
8274 Inst.setOpcode(ARM::t2STMDB_UPD);
8275 // Add the base register and writeback operands.
8276 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8277 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008278 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008279 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008280 case ARM::t2MOVi: {
8281 // If we can use the 16-bit encoding and the user didn't explicitly
8282 // request the 32-bit variant, transform it here.
8283 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00008284 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00008285 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008286 Inst.getOperand(4).getReg() == ARM::CPSR) ||
8287 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
8288 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8289 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008290 // The operands aren't in the same order for tMOVi8...
8291 MCInst TmpInst;
8292 TmpInst.setOpcode(ARM::tMOVi8);
8293 TmpInst.addOperand(Inst.getOperand(0));
8294 TmpInst.addOperand(Inst.getOperand(4));
8295 TmpInst.addOperand(Inst.getOperand(1));
8296 TmpInst.addOperand(Inst.getOperand(2));
8297 TmpInst.addOperand(Inst.getOperand(3));
8298 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008299 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008300 }
8301 break;
8302 }
8303 case ARM::t2MOVr: {
8304 // If we can use the 16-bit encoding and the user didn't explicitly
8305 // request the 32-bit variant, transform it here.
8306 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8307 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8308 Inst.getOperand(2).getImm() == ARMCC::AL &&
8309 Inst.getOperand(4).getReg() == ARM::CPSR &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008310 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8311 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008312 // The operands aren't the same for tMOV[S]r... (no cc_out)
8313 MCInst TmpInst;
8314 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
8315 TmpInst.addOperand(Inst.getOperand(0));
8316 TmpInst.addOperand(Inst.getOperand(1));
8317 TmpInst.addOperand(Inst.getOperand(2));
8318 TmpInst.addOperand(Inst.getOperand(3));
8319 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008320 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008321 }
8322 break;
8323 }
Jim Grosbach82213192011-09-19 20:29:33 +00008324 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00008325 case ARM::t2SXTB:
8326 case ARM::t2UXTH:
8327 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00008328 // If we can use the 16-bit encoding and the user didn't explicitly
8329 // request the 32-bit variant, transform it here.
8330 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8331 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8332 Inst.getOperand(2).getImm() == 0 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008333 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8334 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00008335 unsigned NewOpc;
8336 switch (Inst.getOpcode()) {
8337 default: llvm_unreachable("Illegal opcode!");
8338 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
8339 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
8340 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
8341 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
8342 }
Jim Grosbach82213192011-09-19 20:29:33 +00008343 // The operands aren't the same for thumb1 (no rotate operand).
8344 MCInst TmpInst;
8345 TmpInst.setOpcode(NewOpc);
8346 TmpInst.addOperand(Inst.getOperand(0));
8347 TmpInst.addOperand(Inst.getOperand(1));
8348 TmpInst.addOperand(Inst.getOperand(3));
8349 TmpInst.addOperand(Inst.getOperand(4));
8350 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008351 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00008352 }
8353 break;
8354 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008355 case ARM::MOVsi: {
8356 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00008357 // rrx shifts and asr/lsr of #32 is encoded as 0
8358 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
8359 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008360 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
8361 // Shifting by zero is accepted as a vanilla 'MOVr'
8362 MCInst TmpInst;
8363 TmpInst.setOpcode(ARM::MOVr);
8364 TmpInst.addOperand(Inst.getOperand(0));
8365 TmpInst.addOperand(Inst.getOperand(1));
8366 TmpInst.addOperand(Inst.getOperand(3));
8367 TmpInst.addOperand(Inst.getOperand(4));
8368 TmpInst.addOperand(Inst.getOperand(5));
8369 Inst = TmpInst;
8370 return true;
8371 }
8372 return false;
8373 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00008374 case ARM::ANDrsi:
8375 case ARM::ORRrsi:
8376 case ARM::EORrsi:
8377 case ARM::BICrsi:
8378 case ARM::SUBrsi:
8379 case ARM::ADDrsi: {
8380 unsigned newOpc;
8381 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
8382 if (SOpc == ARM_AM::rrx) return false;
8383 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00008384 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00008385 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
8386 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
8387 case ARM::EORrsi: newOpc = ARM::EORrr; break;
8388 case ARM::BICrsi: newOpc = ARM::BICrr; break;
8389 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
8390 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
8391 }
8392 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00008393 // The exception is for right shifts, where 0 == 32
8394 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
8395 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00008396 MCInst TmpInst;
8397 TmpInst.setOpcode(newOpc);
8398 TmpInst.addOperand(Inst.getOperand(0));
8399 TmpInst.addOperand(Inst.getOperand(1));
8400 TmpInst.addOperand(Inst.getOperand(2));
8401 TmpInst.addOperand(Inst.getOperand(4));
8402 TmpInst.addOperand(Inst.getOperand(5));
8403 TmpInst.addOperand(Inst.getOperand(6));
8404 Inst = TmpInst;
8405 return true;
8406 }
8407 return false;
8408 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00008409 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008410 case ARM::t2IT: {
8411 // The mask bits for all but the first condition are represented as
8412 // the low bit of the condition code value implies 't'. We currently
8413 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00008414 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008415 MCOperand &MO = Inst.getOperand(1);
8416 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00008417 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00008418 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008419 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008420 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00008421 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00008422 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008423 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00008424
8425 // Set up the IT block state according to the IT instruction we just
8426 // matched.
8427 assert(!inITBlock() && "nested IT blocks?!");
8428 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
8429 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
8430 ITState.CurPosition = 0;
8431 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008432 break;
8433 }
Richard Bartona39625e2012-07-09 16:12:24 +00008434 case ARM::t2LSLrr:
8435 case ARM::t2LSRrr:
8436 case ARM::t2ASRrr:
8437 case ARM::t2SBCrr:
8438 case ARM::t2RORrr:
8439 case ARM::t2BICrr:
8440 {
Richard Bartond5660372012-07-09 16:14:28 +00008441 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008442 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8443 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8444 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008445 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008446 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8447 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8448 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8449 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008450 unsigned NewOpc;
8451 switch (Inst.getOpcode()) {
8452 default: llvm_unreachable("unexpected opcode");
8453 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
8454 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
8455 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
8456 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
8457 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
8458 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
8459 }
8460 MCInst TmpInst;
8461 TmpInst.setOpcode(NewOpc);
8462 TmpInst.addOperand(Inst.getOperand(0));
8463 TmpInst.addOperand(Inst.getOperand(5));
8464 TmpInst.addOperand(Inst.getOperand(1));
8465 TmpInst.addOperand(Inst.getOperand(2));
8466 TmpInst.addOperand(Inst.getOperand(3));
8467 TmpInst.addOperand(Inst.getOperand(4));
8468 Inst = TmpInst;
8469 return true;
8470 }
8471 return false;
8472 }
8473 case ARM::t2ANDrr:
8474 case ARM::t2EORrr:
8475 case ARM::t2ADCrr:
8476 case ARM::t2ORRrr:
8477 {
Richard Bartond5660372012-07-09 16:14:28 +00008478 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008479 // These instructions are special in that they are commutable, so shorter encodings
8480 // are available more often.
8481 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8482 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8483 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
8484 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008485 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008486 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8487 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8488 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8489 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008490 unsigned NewOpc;
8491 switch (Inst.getOpcode()) {
8492 default: llvm_unreachable("unexpected opcode");
8493 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
8494 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
8495 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
8496 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
8497 }
8498 MCInst TmpInst;
8499 TmpInst.setOpcode(NewOpc);
8500 TmpInst.addOperand(Inst.getOperand(0));
8501 TmpInst.addOperand(Inst.getOperand(5));
8502 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
8503 TmpInst.addOperand(Inst.getOperand(1));
8504 TmpInst.addOperand(Inst.getOperand(2));
8505 } else {
8506 TmpInst.addOperand(Inst.getOperand(2));
8507 TmpInst.addOperand(Inst.getOperand(1));
8508 }
8509 TmpInst.addOperand(Inst.getOperand(3));
8510 TmpInst.addOperand(Inst.getOperand(4));
8511 Inst = TmpInst;
8512 return true;
8513 }
8514 return false;
8515 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008516 }
Jim Grosbachafad0532011-11-10 23:42:14 +00008517 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008518}
8519
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008520unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
8521 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
8522 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008523 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00008524 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008525 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
8526 assert(MCID.hasOptionalDef() &&
8527 "optionally flag setting instruction missing optional def operand");
8528 assert(MCID.NumOperands == Inst.getNumOperands() &&
8529 "operand count mismatch!");
8530 // Find the optional-def operand (cc_out).
8531 unsigned OpNo;
8532 for (OpNo = 0;
8533 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
8534 ++OpNo)
8535 ;
8536 // If we're parsing Thumb1, reject it completely.
8537 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
8538 return Match_MnemonicFail;
8539 // If we're parsing Thumb2, which form is legal depends on whether we're
8540 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00008541 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
8542 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008543 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00008544 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8545 inITBlock())
8546 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008547 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008548 // Some high-register supporting Thumb1 encodings only allow both registers
8549 // to be from r0-r7 when in Thumb2.
Renato Golin36c626e2014-09-26 16:14:29 +00008550 else if (Opc == ARM::tADDhirr && isThumbOne() && !hasV6MOps() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008551 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8552 isARMLowRegister(Inst.getOperand(2).getReg()))
8553 return Match_RequiresThumb2;
8554 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00008555 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008556 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8557 isARMLowRegister(Inst.getOperand(1).getReg()))
8558 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008559 return Match_Success;
8560}
8561
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008562namespace llvm {
8563template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008564 return true; // In an assembly source, no need to second-guess
8565}
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008566}
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008567
Tim Northover26bb14e2014-08-18 11:49:42 +00008568static const char *getSubtargetFeatureName(uint64_t Val);
David Blaikie960ea3f2014-06-08 16:18:35 +00008569bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
8570 OperandVector &Operands,
Tim Northover26bb14e2014-08-18 11:49:42 +00008571 MCStreamer &Out, uint64_t &ErrorInfo,
David Blaikie960ea3f2014-06-08 16:18:35 +00008572 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00008573 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00008574 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00008575
Chad Rosier2f480a82012-10-12 22:53:36 +00008576 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00008577 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00008578 switch (MatchResult) {
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008579 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008580 // Context sensitive operand constraints aren't handled by the matcher,
8581 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008582 if (validateInstruction(Inst, Operands)) {
8583 // Still progress the IT block, otherwise one wrong condition causes
8584 // nasty cascading errors.
8585 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008586 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008587 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008588
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008589 { // processInstruction() updates inITBlock state, we need to save it away
8590 bool wasInITBlock = inITBlock();
8591
8592 // Some instructions need post-processing to, for example, tweak which
8593 // encoding is selected. Loop on it while changes happen so the
8594 // individual transformations can chain off each other. E.g.,
8595 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00008596 while (processInstruction(Inst, Operands, Out))
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008597 ;
8598
8599 // Only after the instruction is fully processed, we can validate it
8600 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00008601 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008602 Warning(IDLoc, "deprecated instruction in IT block");
8603 }
8604 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008605
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008606 // Only move forward at the very end so that everything in validate
8607 // and process gets a consistent answer about whether we're in an IT
8608 // block.
8609 forwardITPosition();
8610
Jim Grosbach82f76d12012-01-25 19:52:01 +00008611 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8612 // doesn't actually encode.
8613 if (Inst.getOpcode() == ARM::ITasm)
8614 return false;
8615
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00008616 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00008617 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00008618 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008619 case Match_MissingFeature: {
8620 assert(ErrorInfo && "Unknown missing feature!");
8621 // Special case the error message for the very common case where only
8622 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8623 std::string Msg = "instruction requires:";
Tim Northover26bb14e2014-08-18 11:49:42 +00008624 uint64_t Mask = 1;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008625 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8626 if (ErrorInfo & Mask) {
8627 Msg += " ";
8628 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8629 }
8630 Mask <<= 1;
8631 }
8632 return Error(IDLoc, Msg);
8633 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008634 case Match_InvalidOperand: {
8635 SMLoc ErrorLoc = IDLoc;
Tim Northover26bb14e2014-08-18 11:49:42 +00008636 if (ErrorInfo != ~0ULL) {
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008637 if (ErrorInfo >= Operands.size())
8638 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00008639
David Blaikie960ea3f2014-06-08 16:18:35 +00008640 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008641 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8642 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008643
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008644 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00008645 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008646 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00008647 return Error(IDLoc, "invalid instruction",
David Blaikie960ea3f2014-06-08 16:18:35 +00008648 ((ARMOperand &)*Operands[0]).getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00008649 case Match_RequiresNotITBlock:
8650 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008651 case Match_RequiresITBlock:
8652 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008653 case Match_RequiresV6:
8654 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8655 case Match_RequiresThumb2:
8656 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00008657 case Match_ImmRange0_15: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008658 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Jim Grosbach087affe2012-06-22 23:56:48 +00008659 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8660 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8661 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008662 case Match_ImmRange0_239: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008663 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008664 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8665 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8666 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00008667 case Match_AlignedMemoryRequiresNone:
8668 case Match_DupAlignedMemoryRequiresNone:
8669 case Match_AlignedMemoryRequires16:
8670 case Match_DupAlignedMemoryRequires16:
8671 case Match_AlignedMemoryRequires32:
8672 case Match_DupAlignedMemoryRequires32:
8673 case Match_AlignedMemoryRequires64:
8674 case Match_DupAlignedMemoryRequires64:
8675 case Match_AlignedMemoryRequires64or128:
8676 case Match_DupAlignedMemoryRequires64or128:
8677 case Match_AlignedMemoryRequires64or128or256:
8678 {
David Blaikie960ea3f2014-06-08 16:18:35 +00008679 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00008680 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8681 switch (MatchResult) {
8682 default:
8683 llvm_unreachable("Missing Match_Aligned type");
8684 case Match_AlignedMemoryRequiresNone:
8685 case Match_DupAlignedMemoryRequiresNone:
8686 return Error(ErrorLoc, "alignment must be omitted");
8687 case Match_AlignedMemoryRequires16:
8688 case Match_DupAlignedMemoryRequires16:
8689 return Error(ErrorLoc, "alignment must be 16 or omitted");
8690 case Match_AlignedMemoryRequires32:
8691 case Match_DupAlignedMemoryRequires32:
8692 return Error(ErrorLoc, "alignment must be 32 or omitted");
8693 case Match_AlignedMemoryRequires64:
8694 case Match_DupAlignedMemoryRequires64:
8695 return Error(ErrorLoc, "alignment must be 64 or omitted");
8696 case Match_AlignedMemoryRequires64or128:
8697 case Match_DupAlignedMemoryRequires64or128:
8698 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8699 case Match_AlignedMemoryRequires64or128or256:
8700 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8701 }
8702 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008703 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008704
Eric Christopher91d7b902010-10-29 09:26:59 +00008705 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00008706}
8707
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008708/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00008709bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008710 const MCObjectFileInfo::Environment Format =
8711 getContext().getObjectFileInfo()->getObjectFileType();
8712 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008713 bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008714
Kevin Enderbyccab3172009-09-15 00:27:25 +00008715 StringRef IDVal = DirectiveID.getIdentifier();
8716 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008717 return parseLiteralValues(4, DirectiveID.getLoc());
8718 else if (IDVal == ".short" || IDVal == ".hword")
8719 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008720 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008721 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00008722 else if (IDVal == ".arm")
8723 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008724 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008725 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008726 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008727 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008728 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008729 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008730 else if (IDVal == ".unreq")
8731 return parseDirectiveUnreq(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00008732 else if (IDVal == ".fnend")
8733 return parseDirectiveFnEnd(DirectiveID.getLoc());
8734 else if (IDVal == ".cantunwind")
8735 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8736 else if (IDVal == ".personality")
8737 return parseDirectivePersonality(DirectiveID.getLoc());
8738 else if (IDVal == ".handlerdata")
8739 return parseDirectiveHandlerData(DirectiveID.getLoc());
8740 else if (IDVal == ".setfp")
8741 return parseDirectiveSetFP(DirectiveID.getLoc());
8742 else if (IDVal == ".pad")
8743 return parseDirectivePad(DirectiveID.getLoc());
8744 else if (IDVal == ".save")
8745 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8746 else if (IDVal == ".vsave")
8747 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008748 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008749 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008750 else if (IDVal == ".even")
8751 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008752 else if (IDVal == ".personalityindex")
8753 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008754 else if (IDVal == ".unwind_raw")
8755 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008756 else if (IDVal == ".movsp")
8757 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008758 else if (IDVal == ".arch_extension")
8759 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008760 else if (IDVal == ".align")
8761 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008762 else if (IDVal == ".thumb_set")
8763 return parseDirectiveThumbSet(DirectiveID.getLoc());
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008764
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008765 if (!IsMachO && !IsCOFF) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008766 if (IDVal == ".arch")
8767 return parseDirectiveArch(DirectiveID.getLoc());
8768 else if (IDVal == ".cpu")
8769 return parseDirectiveCPU(DirectiveID.getLoc());
8770 else if (IDVal == ".eabi_attribute")
8771 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8772 else if (IDVal == ".fpu")
8773 return parseDirectiveFPU(DirectiveID.getLoc());
8774 else if (IDVal == ".fnstart")
8775 return parseDirectiveFnStart(DirectiveID.getLoc());
8776 else if (IDVal == ".inst")
8777 return parseDirectiveInst(DirectiveID.getLoc());
8778 else if (IDVal == ".inst.n")
8779 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8780 else if (IDVal == ".inst.w")
8781 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8782 else if (IDVal == ".object_arch")
8783 return parseDirectiveObjectArch(DirectiveID.getLoc());
8784 else if (IDVal == ".tlsdescseq")
8785 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8786 }
8787
Kevin Enderbyccab3172009-09-15 00:27:25 +00008788 return true;
8789}
8790
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008791/// parseLiteralValues
8792/// ::= .hword expression [, expression]*
8793/// ::= .short expression [, expression]*
8794/// ::= .word expression [, expression]*
8795bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008796 MCAsmParser &Parser = getParser();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008797 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8798 for (;;) {
8799 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008800 if (getParser().parseExpression(Value)) {
8801 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008802 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008803 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008804
Eric Christopherbf7bc492013-01-09 03:52:05 +00008805 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008806
8807 if (getLexer().is(AsmToken::EndOfStatement))
8808 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008809
Kevin Enderbyccab3172009-09-15 00:27:25 +00008810 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008811 if (getLexer().isNot(AsmToken::Comma)) {
8812 Error(L, "unexpected token in directive");
8813 return false;
8814 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008815 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008816 }
8817 }
8818
Sean Callanana83fd7d2010-01-19 20:27:46 +00008819 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008820 return false;
8821}
8822
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008823/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008824/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008825bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008826 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008827 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8828 Error(L, "unexpected token in directive");
8829 return false;
8830 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008831 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008832
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008833 if (!hasThumb()) {
8834 Error(L, "target does not support Thumb mode");
8835 return false;
8836 }
Tim Northovera2292d02013-06-10 23:20:58 +00008837
Jim Grosbach7f882392011-12-07 18:04:19 +00008838 if (!isThumb())
8839 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008840
Jim Grosbach7f882392011-12-07 18:04:19 +00008841 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8842 return false;
8843}
8844
8845/// parseDirectiveARM
8846/// ::= .arm
8847bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008848 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008849 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8850 Error(L, "unexpected token in directive");
8851 return false;
8852 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008853 Parser.Lex();
8854
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008855 if (!hasARM()) {
8856 Error(L, "target does not support ARM mode");
8857 return false;
8858 }
Tim Northovera2292d02013-06-10 23:20:58 +00008859
Jim Grosbach7f882392011-12-07 18:04:19 +00008860 if (isThumb())
8861 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008862
Jim Grosbach7f882392011-12-07 18:04:19 +00008863 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008864 return false;
8865}
8866
Tim Northover1744d0a2013-10-25 12:49:50 +00008867void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8868 if (NextSymbolIsThumb) {
8869 getParser().getStreamer().EmitThumbFunc(Symbol);
8870 NextSymbolIsThumb = false;
8871 }
8872}
8873
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008874/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008875/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008876bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008877 MCAsmParser &Parser = getParser();
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008878 const auto Format = getContext().getObjectFileInfo()->getObjectFileType();
8879 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008880
Jim Grosbach1152cc02011-12-21 22:30:16 +00008881 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008882 // ELF doesn't
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008883 if (IsMachO) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008884 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008885 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008886 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8887 Error(L, "unexpected token in .thumb_func directive");
8888 return false;
8889 }
8890
Tim Northover1744d0a2013-10-25 12:49:50 +00008891 MCSymbol *Func =
8892 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8893 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008894 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008895 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008896 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008897 }
8898
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008899 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008900 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8901 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008902 return false;
8903 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008904
Tim Northover1744d0a2013-10-25 12:49:50 +00008905 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008906 return false;
8907}
8908
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008909/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008910/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008911bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008912 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008913 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008914 if (Tok.isNot(AsmToken::Identifier)) {
8915 Error(L, "unexpected token in .syntax directive");
8916 return false;
8917 }
8918
Benjamin Kramer92d89982010-07-14 22:38:02 +00008919 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008920 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008921 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008922 } else if (Mode == "divided" || Mode == "DIVIDED") {
8923 Error(L, "'.syntax divided' arm asssembly not supported");
8924 return false;
8925 } else {
8926 Error(L, "unrecognized syntax mode in .syntax directive");
8927 return false;
8928 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008929
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008930 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8931 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8932 return false;
8933 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008934 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008935
8936 // TODO tell the MC streamer the mode
8937 // getParser().getStreamer().Emit???();
8938 return false;
8939}
8940
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008941/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008942/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008943bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008944 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008945 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008946 if (Tok.isNot(AsmToken::Integer)) {
8947 Error(L, "unexpected token in .code directive");
8948 return false;
8949 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008950 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008951 if (Val != 16 && Val != 32) {
8952 Error(L, "invalid operand to .code directive");
8953 return false;
8954 }
8955 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008956
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008957 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8958 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8959 return false;
8960 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008961 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008962
Evan Cheng284b4672011-07-08 22:36:29 +00008963 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008964 if (!hasThumb()) {
8965 Error(L, "target does not support Thumb mode");
8966 return false;
8967 }
Tim Northovera2292d02013-06-10 23:20:58 +00008968
Jim Grosbachf471ac32011-09-06 18:46:23 +00008969 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008970 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008971 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008972 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008973 if (!hasARM()) {
8974 Error(L, "target does not support ARM mode");
8975 return false;
8976 }
Tim Northovera2292d02013-06-10 23:20:58 +00008977
Jim Grosbachf471ac32011-09-06 18:46:23 +00008978 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008979 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008980 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008981 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008982
Kevin Enderby146dcf22009-10-15 20:48:48 +00008983 return false;
8984}
8985
Jim Grosbachab5830e2011-12-14 02:16:11 +00008986/// parseDirectiveReq
8987/// ::= name .req registername
8988bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008989 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008990 Parser.Lex(); // Eat the '.req' token.
8991 unsigned Reg;
8992 SMLoc SRegLoc, ERegLoc;
8993 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008994 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008995 Error(SRegLoc, "register name expected");
8996 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008997 }
8998
8999 // Shouldn't be anything else.
9000 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00009001 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009002 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
9003 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00009004 }
9005
9006 Parser.Lex(); // Consume the EndOfStatement
9007
Frederic Rissb61f01f2015-02-04 03:10:03 +00009008 if (RegisterReqs.insert(std::make_pair(Name, Reg)).first->second != Reg) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009009 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
9010 return false;
9011 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00009012
9013 return false;
9014}
9015
9016/// parseDirectiveUneq
9017/// ::= .unreq registername
9018bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009019 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00009020 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00009021 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009022 Error(L, "unexpected input in .unreq directive.");
9023 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00009024 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00009025 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00009026 Parser.Lex(); // Eat the identifier.
9027 return false;
9028}
9029
Jason W Kim135d2442011-12-20 17:38:12 +00009030/// parseDirectiveArch
9031/// ::= .arch token
9032bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00009033 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
9034
9035 unsigned ID = StringSwitch<unsigned>(Arch)
9036#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9037 .Case(NAME, ARM::ID)
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +00009038#define ARM_ARCH_ALIAS(NAME, ID) \
9039 .Case(NAME, ARM::ID)
Logan Chien439e8f92013-12-11 17:16:25 +00009040#include "MCTargetDesc/ARMArchName.def"
9041 .Default(ARM::INVALID_ARCH);
9042
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009043 if (ID == ARM::INVALID_ARCH) {
9044 Error(L, "Unknown arch name");
9045 return false;
9046 }
Logan Chien439e8f92013-12-11 17:16:25 +00009047
9048 getTargetStreamer().emitArch(ID);
9049 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00009050}
9051
9052/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009053/// ::= .eabi_attribute int, int [, "str"]
9054/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00009055bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009056 MCAsmParser &Parser = getParser();
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009057 int64_t Tag;
9058 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009059 TagLoc = Parser.getTok().getLoc();
9060 if (Parser.getTok().is(AsmToken::Identifier)) {
9061 StringRef Name = Parser.getTok().getIdentifier();
9062 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
9063 if (Tag == -1) {
9064 Error(TagLoc, "attribute name not recognised: " + Name);
9065 Parser.eatToEndOfStatement();
9066 return false;
9067 }
9068 Parser.Lex();
9069 } else {
9070 const MCExpr *AttrExpr;
9071
9072 TagLoc = Parser.getTok().getLoc();
9073 if (Parser.parseExpression(AttrExpr)) {
9074 Parser.eatToEndOfStatement();
9075 return false;
9076 }
9077
9078 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
9079 if (!CE) {
9080 Error(TagLoc, "expected numeric constant");
9081 Parser.eatToEndOfStatement();
9082 return false;
9083 }
9084
9085 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009086 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009087
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009088 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009089 Error(Parser.getTok().getLoc(), "comma expected");
9090 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009091 return false;
9092 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009093 Parser.Lex(); // skip comma
9094
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009095 StringRef StringValue = "";
9096 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00009097
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009098 int64_t IntegerValue = 0;
9099 bool IsIntegerValue = false;
9100
9101 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
9102 IsStringValue = true;
9103 else if (Tag == ARMBuildAttrs::compatibility) {
9104 IsStringValue = true;
9105 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00009106 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009107 IsIntegerValue = true;
9108 else if (Tag % 2 == 1)
9109 IsStringValue = true;
9110 else
9111 llvm_unreachable("invalid tag type");
9112
9113 if (IsIntegerValue) {
9114 const MCExpr *ValueExpr;
9115 SMLoc ValueExprLoc = Parser.getTok().getLoc();
9116 if (Parser.parseExpression(ValueExpr)) {
9117 Parser.eatToEndOfStatement();
9118 return false;
9119 }
9120
9121 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
9122 if (!CE) {
9123 Error(ValueExprLoc, "expected numeric constant");
9124 Parser.eatToEndOfStatement();
9125 return false;
9126 }
9127
9128 IntegerValue = CE->getValue();
9129 }
9130
9131 if (Tag == ARMBuildAttrs::compatibility) {
9132 if (Parser.getTok().isNot(AsmToken::Comma))
9133 IsStringValue = false;
Charlie Turner6632d1f2015-01-05 13:26:37 +00009134 if (Parser.getTok().isNot(AsmToken::Comma)) {
9135 Error(Parser.getTok().getLoc(), "comma expected");
9136 Parser.eatToEndOfStatement();
9137 return false;
9138 } else {
9139 Parser.Lex();
9140 }
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009141 }
9142
9143 if (IsStringValue) {
9144 if (Parser.getTok().isNot(AsmToken::String)) {
9145 Error(Parser.getTok().getLoc(), "bad string constant");
9146 Parser.eatToEndOfStatement();
9147 return false;
9148 }
9149
9150 StringValue = Parser.getTok().getStringContents();
9151 Parser.Lex();
9152 }
9153
9154 if (IsIntegerValue && IsStringValue) {
9155 assert(Tag == ARMBuildAttrs::compatibility);
9156 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
9157 } else if (IsIntegerValue)
9158 getTargetStreamer().emitAttribute(Tag, IntegerValue);
9159 else if (IsStringValue)
9160 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00009161 return false;
9162}
9163
9164/// parseDirectiveCPU
9165/// ::= .cpu str
9166bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
9167 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
9168 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
Roman Divacky7e6b5952014-12-02 20:03:22 +00009169
Roman Divackyfdf05602014-12-03 18:39:44 +00009170 if (!STI.isCPUStringValid(CPU)) {
Roman Divacky7e6b5952014-12-02 20:03:22 +00009171 Error(L, "Unknown CPU name");
9172 return false;
9173 }
9174
Roman Divacky6fd64ff2014-12-04 21:39:24 +00009175 // FIXME: This switches the CPU features globally, therefore it might
9176 // happen that code you would not expect to assemble will. For details
9177 // see: http://llvm.org/bugs/show_bug.cgi?id=20757
Roman Divacky7e6b5952014-12-02 20:03:22 +00009178 STI.InitMCProcessorInfo(CPU, "");
9179 STI.InitCPUSchedModel(CPU);
Bradley Smith9f4cd592015-02-04 16:23:24 +00009180 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Roman Divacky7e6b5952014-12-02 20:03:22 +00009181
Logan Chien8cbb80d2013-10-28 17:51:12 +00009182 return false;
9183}
9184
Nico Weberae050bb2014-08-16 05:37:51 +00009185// FIXME: This is duplicated in getARMFPUFeatures() in
9186// tools/clang/lib/Driver/Tools.cpp
9187static const struct {
Saleem Abdulrasool206d1162015-01-30 17:58:25 +00009188 const unsigned ID;
Michael Kupersteinefd7a962015-02-19 11:38:11 +00009189 const uint64_t Enabled;
9190 const uint64_t Disabled;
Saleem Abdulrasool206d1162015-01-30 17:58:25 +00009191} FPUs[] = {
Michael Kupersteinefd7a962015-02-19 11:38:11 +00009192 {/* ID */ ARM::VFP,
9193 /* Enabled */ ARM::FeatureVFP2,
9194 /* Disabled */ ARM::FeatureNEON},
9195 {/* ID */ ARM::VFPV2,
9196 /* Enabled */ ARM::FeatureVFP2,
9197 /* Disabled */ ARM::FeatureNEON},
9198 {/* ID */ ARM::VFPV3,
9199 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3,
9200 /* Disabled */ ARM::FeatureNEON | ARM::FeatureD16},
9201 {/* ID */ ARM::VFPV3_D16,
9202 /* Enable */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureD16,
9203 /* Disabled */ ARM::FeatureNEON},
9204 {/* ID */ ARM::VFPV4,
9205 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4,
9206 /* Disabled */ ARM::FeatureNEON | ARM::FeatureD16},
9207 {/* ID */ ARM::VFPV4_D16,
9208 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9209 ARM::FeatureD16,
9210 /* Disabled */ ARM::FeatureNEON},
9211 {/* ID */ ARM::FPV5_D16,
9212 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9213 ARM::FeatureFPARMv8 | ARM::FeatureD16,
9214 /* Disabled */ ARM::FeatureNEON | ARM::FeatureCrypto},
9215 {/* ID */ ARM::FP_ARMV8,
9216 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9217 ARM::FeatureFPARMv8,
9218 /* Disabled */ ARM::FeatureNEON | ARM::FeatureCrypto | ARM::FeatureD16},
9219 {/* ID */ ARM::NEON,
9220 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureNEON,
9221 /* Disabled */ ARM::FeatureD16},
9222 {/* ID */ ARM::NEON_VFPV4,
9223 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9224 ARM::FeatureNEON,
9225 /* Disabled */ ARM::FeatureD16},
9226 {/* ID */ ARM::NEON_FP_ARMV8,
9227 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9228 ARM::FeatureFPARMv8 | ARM::FeatureNEON,
9229 /* Disabled */ ARM::FeatureCrypto | ARM::FeatureD16},
9230 {/* ID */ ARM::CRYPTO_NEON_FP_ARMV8,
9231 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9232 ARM::FeatureFPARMv8 | ARM::FeatureNEON | ARM::FeatureCrypto,
9233 /* Disabled */ ARM::FeatureD16},
9234 {ARM::SOFTVFP, 0, 0},
Nico Weberae050bb2014-08-16 05:37:51 +00009235};
9236
Logan Chien8cbb80d2013-10-28 17:51:12 +00009237/// parseDirectiveFPU
9238/// ::= .fpu str
9239bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
Saleem Abdulrasool07b7c032015-01-30 18:42:10 +00009240 SMLoc FPUNameLoc = getTok().getLoc();
Logan Chien8cbb80d2013-10-28 17:51:12 +00009241 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
9242
9243 unsigned ID = StringSwitch<unsigned>(FPU)
9244#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
9245#include "ARMFPUName.def"
9246 .Default(ARM::INVALID_FPU);
9247
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009248 if (ID == ARM::INVALID_FPU) {
Saleem Abdulrasool07b7c032015-01-30 18:42:10 +00009249 Error(FPUNameLoc, "Unknown FPU name");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009250 return false;
9251 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009252
Saleem Abdulrasool206d1162015-01-30 17:58:25 +00009253 for (const auto &Entry : FPUs) {
9254 if (Entry.ID != ID)
Nico Weberae050bb2014-08-16 05:37:51 +00009255 continue;
9256
9257 // Need to toggle features that should be on but are off and that
9258 // should off but are on.
Michael Kupersteinefd7a962015-02-19 11:38:11 +00009259 uint64_t Toggle = (Entry.Enabled & ~STI.getFeatureBits()) |
9260 (Entry.Disabled & STI.getFeatureBits());
Nico Weberae050bb2014-08-16 05:37:51 +00009261 setAvailableFeatures(ComputeAvailableFeatures(STI.ToggleFeature(Toggle)));
9262 break;
9263 }
9264
Logan Chien8cbb80d2013-10-28 17:51:12 +00009265 getTargetStreamer().emitFPU(ID);
9266 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00009267}
9268
Logan Chien4ea23b52013-05-10 16:17:24 +00009269/// parseDirectiveFnStart
9270/// ::= .fnstart
9271bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009272 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009273 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009274 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009275 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009276 }
9277
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009278 // Reset the unwind directives parser state
9279 UC.reset();
9280
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009281 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009282
9283 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00009284 return false;
9285}
9286
9287/// parseDirectiveFnEnd
9288/// ::= .fnend
9289bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
9290 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009291 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009292 Error(L, ".fnstart must precede .fnend directive");
9293 return false;
9294 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009295
9296 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009297 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009298
9299 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00009300 return false;
9301}
9302
9303/// parseDirectiveCantUnwind
9304/// ::= .cantunwind
9305bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009306 UC.recordCantUnwind(L);
9307
Logan Chien4ea23b52013-05-10 16:17:24 +00009308 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009309 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009310 Error(L, ".fnstart must precede .cantunwind directive");
9311 return false;
9312 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009313 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009314 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009315 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009316 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009317 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009318 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009319 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009320 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009321 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009322 }
9323
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009324 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00009325 return false;
9326}
9327
9328/// parseDirectivePersonality
9329/// ::= .personality name
9330bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009331 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009332 bool HasExistingPersonality = UC.hasPersonality();
9333
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009334 UC.recordPersonality(L);
9335
Logan Chien4ea23b52013-05-10 16:17:24 +00009336 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009337 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009338 Error(L, ".fnstart must precede .personality directive");
9339 return false;
9340 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009341 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009342 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009343 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009344 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009345 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009346 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009347 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009348 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009349 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009350 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009351 if (HasExistingPersonality) {
9352 Parser.eatToEndOfStatement();
9353 Error(L, "multiple personality directives");
9354 UC.emitPersonalityLocNotes();
9355 return false;
9356 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009357
9358 // Parse the name of the personality routine
9359 if (Parser.getTok().isNot(AsmToken::Identifier)) {
9360 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009361 Error(L, "unexpected input in .personality directive.");
9362 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009363 }
9364 StringRef Name(Parser.getTok().getIdentifier());
9365 Parser.Lex();
9366
9367 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009368 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00009369 return false;
9370}
9371
9372/// parseDirectiveHandlerData
9373/// ::= .handlerdata
9374bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009375 UC.recordHandlerData(L);
9376
Logan Chien4ea23b52013-05-10 16:17:24 +00009377 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009378 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009379 Error(L, ".fnstart must precede .personality directive");
9380 return false;
9381 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009382 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009383 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009384 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009385 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009386 }
9387
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009388 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00009389 return false;
9390}
9391
9392/// parseDirectiveSetFP
9393/// ::= .setfp fpreg, spreg [, offset]
9394bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009395 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009396 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009397 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009398 Error(L, ".fnstart must precede .setfp directive");
9399 return false;
9400 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009401 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009402 Error(L, ".setfp must precede .handlerdata directive");
9403 return false;
9404 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009405
9406 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009407 SMLoc FPRegLoc = Parser.getTok().getLoc();
9408 int FPReg = tryParseRegister();
9409 if (FPReg == -1) {
9410 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009411 return false;
9412 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009413
9414 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009415 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009416 Error(Parser.getTok().getLoc(), "comma expected");
9417 return false;
9418 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009419 Parser.Lex(); // skip comma
9420
9421 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009422 SMLoc SPRegLoc = Parser.getTok().getLoc();
9423 int SPReg = tryParseRegister();
9424 if (SPReg == -1) {
9425 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009426 return false;
9427 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009428
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009429 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
9430 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009431 return false;
9432 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009433
9434 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009435 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00009436
9437 // Parse offset
9438 int64_t Offset = 0;
9439 if (Parser.getTok().is(AsmToken::Comma)) {
9440 Parser.Lex(); // skip comma
9441
9442 if (Parser.getTok().isNot(AsmToken::Hash) &&
9443 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009444 Error(Parser.getTok().getLoc(), "'#' expected");
9445 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009446 }
9447 Parser.Lex(); // skip hash token.
9448
9449 const MCExpr *OffsetExpr;
9450 SMLoc ExLoc = Parser.getTok().getLoc();
9451 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009452 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9453 Error(ExLoc, "malformed setfp offset");
9454 return false;
9455 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009456 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009457 if (!CE) {
9458 Error(ExLoc, "setfp offset must be an immediate");
9459 return false;
9460 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009461
9462 Offset = CE->getValue();
9463 }
9464
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009465 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
9466 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00009467 return false;
9468}
9469
9470/// parseDirective
9471/// ::= .pad offset
9472bool ARMAsmParser::parseDirectivePad(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009473 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009474 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009475 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009476 Error(L, ".fnstart must precede .pad directive");
9477 return false;
9478 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009479 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009480 Error(L, ".pad must precede .handlerdata directive");
9481 return false;
9482 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009483
9484 // Parse the offset
9485 if (Parser.getTok().isNot(AsmToken::Hash) &&
9486 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009487 Error(Parser.getTok().getLoc(), "'#' expected");
9488 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009489 }
9490 Parser.Lex(); // skip hash token.
9491
9492 const MCExpr *OffsetExpr;
9493 SMLoc ExLoc = Parser.getTok().getLoc();
9494 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009495 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9496 Error(ExLoc, "malformed pad offset");
9497 return false;
9498 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009499 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009500 if (!CE) {
9501 Error(ExLoc, "pad offset must be an immediate");
9502 return false;
9503 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009504
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009505 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00009506 return false;
9507}
9508
9509/// parseDirectiveRegSave
9510/// ::= .save { registers }
9511/// ::= .vsave { registers }
9512bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
9513 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009514 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009515 Error(L, ".fnstart must precede .save or .vsave directives");
9516 return false;
9517 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009518 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009519 Error(L, ".save or .vsave must precede .handlerdata directive");
9520 return false;
9521 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009522
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009523 // RAII object to make sure parsed operands are deleted.
David Blaikie960ea3f2014-06-08 16:18:35 +00009524 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009525
Logan Chien4ea23b52013-05-10 16:17:24 +00009526 // Parse the register list
David Blaikie960ea3f2014-06-08 16:18:35 +00009527 if (parseRegisterList(Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00009528 return false;
David Blaikie960ea3f2014-06-08 16:18:35 +00009529 ARMOperand &Op = (ARMOperand &)*Operands[0];
9530 if (!IsVector && !Op.isRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009531 Error(L, ".save expects GPR registers");
9532 return false;
9533 }
David Blaikie960ea3f2014-06-08 16:18:35 +00009534 if (IsVector && !Op.isDPRRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009535 Error(L, ".vsave expects DPR registers");
9536 return false;
9537 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009538
David Blaikie960ea3f2014-06-08 16:18:35 +00009539 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00009540 return false;
9541}
9542
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009543/// parseDirectiveInst
9544/// ::= .inst opcode [, ...]
9545/// ::= .inst.n opcode [, ...]
9546/// ::= .inst.w opcode [, ...]
9547bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009548 MCAsmParser &Parser = getParser();
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009549 int Width;
9550
9551 if (isThumb()) {
9552 switch (Suffix) {
9553 case 'n':
9554 Width = 2;
9555 break;
9556 case 'w':
9557 Width = 4;
9558 break;
9559 default:
9560 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009561 Error(Loc, "cannot determine Thumb instruction size, "
9562 "use inst.n/inst.w instead");
9563 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009564 }
9565 } else {
9566 if (Suffix) {
9567 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009568 Error(Loc, "width suffixes are invalid in ARM mode");
9569 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009570 }
9571 Width = 4;
9572 }
9573
9574 if (getLexer().is(AsmToken::EndOfStatement)) {
9575 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009576 Error(Loc, "expected expression following directive");
9577 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009578 }
9579
9580 for (;;) {
9581 const MCExpr *Expr;
9582
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009583 if (getParser().parseExpression(Expr)) {
9584 Error(Loc, "expected expression");
9585 return false;
9586 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009587
9588 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009589 if (!Value) {
9590 Error(Loc, "expected constant expression");
9591 return false;
9592 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009593
9594 switch (Width) {
9595 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009596 if (Value->getValue() > 0xffff) {
9597 Error(Loc, "inst.n operand is too big, use inst.w instead");
9598 return false;
9599 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009600 break;
9601 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009602 if (Value->getValue() > 0xffffffff) {
9603 Error(Loc,
9604 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
9605 return false;
9606 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009607 break;
9608 default:
9609 llvm_unreachable("only supported widths are 2 and 4");
9610 }
9611
9612 getTargetStreamer().emitInst(Value->getValue(), Suffix);
9613
9614 if (getLexer().is(AsmToken::EndOfStatement))
9615 break;
9616
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009617 if (getLexer().isNot(AsmToken::Comma)) {
9618 Error(Loc, "unexpected token in directive");
9619 return false;
9620 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009621
9622 Parser.Lex();
9623 }
9624
9625 Parser.Lex();
9626 return false;
9627}
9628
David Peixotto80c083a2013-12-19 18:26:07 +00009629/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00009630/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00009631bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00009632 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00009633 return false;
9634}
9635
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009636bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9637 const MCSection *Section = getStreamer().getCurrentSection().first;
9638
9639 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9640 TokError("unexpected token in directive");
9641 return false;
9642 }
9643
9644 if (!Section) {
Rafael Espindola7b61ddf2014-10-15 16:12:52 +00009645 getStreamer().InitSections(false);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009646 Section = getStreamer().getCurrentSection().first;
9647 }
9648
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00009649 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009650 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00009651 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009652 else
Rafael Espindola7b514962014-02-04 18:34:04 +00009653 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009654
9655 return false;
9656}
9657
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009658/// parseDirectivePersonalityIndex
9659/// ::= .personalityindex index
9660bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009661 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009662 bool HasExistingPersonality = UC.hasPersonality();
9663
9664 UC.recordPersonalityIndex(L);
9665
9666 if (!UC.hasFnStart()) {
9667 Parser.eatToEndOfStatement();
9668 Error(L, ".fnstart must precede .personalityindex directive");
9669 return false;
9670 }
9671 if (UC.cantUnwind()) {
9672 Parser.eatToEndOfStatement();
9673 Error(L, ".personalityindex cannot be used with .cantunwind");
9674 UC.emitCantUnwindLocNotes();
9675 return false;
9676 }
9677 if (UC.hasHandlerData()) {
9678 Parser.eatToEndOfStatement();
9679 Error(L, ".personalityindex must precede .handlerdata directive");
9680 UC.emitHandlerDataLocNotes();
9681 return false;
9682 }
9683 if (HasExistingPersonality) {
9684 Parser.eatToEndOfStatement();
9685 Error(L, "multiple personality directives");
9686 UC.emitPersonalityLocNotes();
9687 return false;
9688 }
9689
9690 const MCExpr *IndexExpression;
9691 SMLoc IndexLoc = Parser.getTok().getLoc();
9692 if (Parser.parseExpression(IndexExpression)) {
9693 Parser.eatToEndOfStatement();
9694 return false;
9695 }
9696
9697 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9698 if (!CE) {
9699 Parser.eatToEndOfStatement();
9700 Error(IndexLoc, "index must be a constant number");
9701 return false;
9702 }
9703 if (CE->getValue() < 0 ||
9704 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9705 Parser.eatToEndOfStatement();
9706 Error(IndexLoc, "personality routine index should be in range [0-3]");
9707 return false;
9708 }
9709
9710 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9711 return false;
9712}
9713
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009714/// parseDirectiveUnwindRaw
9715/// ::= .unwind_raw offset, opcode [, opcode...]
9716bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009717 MCAsmParser &Parser = getParser();
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009718 if (!UC.hasFnStart()) {
9719 Parser.eatToEndOfStatement();
9720 Error(L, ".fnstart must precede .unwind_raw directives");
9721 return false;
9722 }
9723
9724 int64_t StackOffset;
9725
9726 const MCExpr *OffsetExpr;
9727 SMLoc OffsetLoc = getLexer().getLoc();
9728 if (getLexer().is(AsmToken::EndOfStatement) ||
9729 getParser().parseExpression(OffsetExpr)) {
9730 Error(OffsetLoc, "expected expression");
9731 Parser.eatToEndOfStatement();
9732 return false;
9733 }
9734
9735 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9736 if (!CE) {
9737 Error(OffsetLoc, "offset must be a constant");
9738 Parser.eatToEndOfStatement();
9739 return false;
9740 }
9741
9742 StackOffset = CE->getValue();
9743
9744 if (getLexer().isNot(AsmToken::Comma)) {
9745 Error(getLexer().getLoc(), "expected comma");
9746 Parser.eatToEndOfStatement();
9747 return false;
9748 }
9749 Parser.Lex();
9750
9751 SmallVector<uint8_t, 16> Opcodes;
9752 for (;;) {
9753 const MCExpr *OE;
9754
9755 SMLoc OpcodeLoc = getLexer().getLoc();
9756 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9757 Error(OpcodeLoc, "expected opcode expression");
9758 Parser.eatToEndOfStatement();
9759 return false;
9760 }
9761
9762 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9763 if (!OC) {
9764 Error(OpcodeLoc, "opcode value must be a constant");
9765 Parser.eatToEndOfStatement();
9766 return false;
9767 }
9768
9769 const int64_t Opcode = OC->getValue();
9770 if (Opcode & ~0xff) {
9771 Error(OpcodeLoc, "invalid opcode");
9772 Parser.eatToEndOfStatement();
9773 return false;
9774 }
9775
9776 Opcodes.push_back(uint8_t(Opcode));
9777
9778 if (getLexer().is(AsmToken::EndOfStatement))
9779 break;
9780
9781 if (getLexer().isNot(AsmToken::Comma)) {
9782 Error(getLexer().getLoc(), "unexpected token in directive");
9783 Parser.eatToEndOfStatement();
9784 return false;
9785 }
9786
9787 Parser.Lex();
9788 }
9789
9790 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9791
9792 Parser.Lex();
9793 return false;
9794}
9795
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009796/// parseDirectiveTLSDescSeq
9797/// ::= .tlsdescseq tls-variable
9798bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009799 MCAsmParser &Parser = getParser();
9800
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009801 if (getLexer().isNot(AsmToken::Identifier)) {
9802 TokError("expected variable after '.tlsdescseq' directive");
9803 Parser.eatToEndOfStatement();
9804 return false;
9805 }
9806
9807 const MCSymbolRefExpr *SRE =
9808 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9809 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9810 Lex();
9811
9812 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9813 Error(Parser.getTok().getLoc(), "unexpected token");
9814 Parser.eatToEndOfStatement();
9815 return false;
9816 }
9817
9818 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9819 return false;
9820}
9821
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009822/// parseDirectiveMovSP
9823/// ::= .movsp reg [, #offset]
9824bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009825 MCAsmParser &Parser = getParser();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009826 if (!UC.hasFnStart()) {
9827 Parser.eatToEndOfStatement();
9828 Error(L, ".fnstart must precede .movsp directives");
9829 return false;
9830 }
9831 if (UC.getFPReg() != ARM::SP) {
9832 Parser.eatToEndOfStatement();
9833 Error(L, "unexpected .movsp directive");
9834 return false;
9835 }
9836
9837 SMLoc SPRegLoc = Parser.getTok().getLoc();
9838 int SPReg = tryParseRegister();
9839 if (SPReg == -1) {
9840 Parser.eatToEndOfStatement();
9841 Error(SPRegLoc, "register expected");
9842 return false;
9843 }
9844
9845 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9846 Parser.eatToEndOfStatement();
9847 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9848 return false;
9849 }
9850
9851 int64_t Offset = 0;
9852 if (Parser.getTok().is(AsmToken::Comma)) {
9853 Parser.Lex();
9854
9855 if (Parser.getTok().isNot(AsmToken::Hash)) {
9856 Error(Parser.getTok().getLoc(), "expected #constant");
9857 Parser.eatToEndOfStatement();
9858 return false;
9859 }
9860 Parser.Lex();
9861
9862 const MCExpr *OffsetExpr;
9863 SMLoc OffsetLoc = Parser.getTok().getLoc();
9864 if (Parser.parseExpression(OffsetExpr)) {
9865 Parser.eatToEndOfStatement();
9866 Error(OffsetLoc, "malformed offset expression");
9867 return false;
9868 }
9869
9870 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9871 if (!CE) {
9872 Parser.eatToEndOfStatement();
9873 Error(OffsetLoc, "offset must be an immediate constant");
9874 return false;
9875 }
9876
9877 Offset = CE->getValue();
9878 }
9879
9880 getTargetStreamer().emitMovSP(SPReg, Offset);
9881 UC.saveFPReg(SPReg);
9882
9883 return false;
9884}
9885
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009886/// parseDirectiveObjectArch
9887/// ::= .object_arch name
9888bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009889 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009890 if (getLexer().isNot(AsmToken::Identifier)) {
9891 Error(getLexer().getLoc(), "unexpected token");
9892 Parser.eatToEndOfStatement();
9893 return false;
9894 }
9895
9896 StringRef Arch = Parser.getTok().getString();
9897 SMLoc ArchLoc = Parser.getTok().getLoc();
9898 getLexer().Lex();
9899
9900 unsigned ID = StringSwitch<unsigned>(Arch)
9901#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9902 .Case(NAME, ARM::ID)
9903#define ARM_ARCH_ALIAS(NAME, ID) \
9904 .Case(NAME, ARM::ID)
9905#include "MCTargetDesc/ARMArchName.def"
9906#undef ARM_ARCH_NAME
9907#undef ARM_ARCH_ALIAS
9908 .Default(ARM::INVALID_ARCH);
9909
9910 if (ID == ARM::INVALID_ARCH) {
9911 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9912 Parser.eatToEndOfStatement();
9913 return false;
9914 }
9915
9916 getTargetStreamer().emitObjectArch(ID);
9917
9918 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9919 Error(getLexer().getLoc(), "unexpected token");
9920 Parser.eatToEndOfStatement();
9921 }
9922
9923 return false;
9924}
9925
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009926/// parseDirectiveAlign
9927/// ::= .align
9928bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9929 // NOTE: if this is not the end of the statement, fall back to the target
9930 // agnostic handling for this directive which will correctly handle this.
9931 if (getLexer().isNot(AsmToken::EndOfStatement))
9932 return true;
9933
9934 // '.align' is target specifically handled to mean 2**2 byte alignment.
9935 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9936 getStreamer().EmitCodeAlignment(4, 0);
9937 else
9938 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9939
9940 return false;
9941}
9942
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009943/// parseDirectiveThumbSet
9944/// ::= .thumb_set name, value
9945bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009946 MCAsmParser &Parser = getParser();
9947
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009948 StringRef Name;
9949 if (Parser.parseIdentifier(Name)) {
9950 TokError("expected identifier after '.thumb_set'");
9951 Parser.eatToEndOfStatement();
9952 return false;
9953 }
9954
9955 if (getLexer().isNot(AsmToken::Comma)) {
9956 TokError("expected comma after name '" + Name + "'");
9957 Parser.eatToEndOfStatement();
9958 return false;
9959 }
9960 Lex();
9961
9962 const MCExpr *Value;
9963 if (Parser.parseExpression(Value)) {
9964 TokError("missing expression");
9965 Parser.eatToEndOfStatement();
9966 return false;
9967 }
9968
9969 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9970 TokError("unexpected token");
9971 Parser.eatToEndOfStatement();
9972 return false;
9973 }
9974 Lex();
9975
9976 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
Rafael Espindola466d6632014-04-27 20:23:58 +00009977 getTargetStreamer().emitThumbSet(Alias, Value);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009978 return false;
9979}
9980
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009981/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009982extern "C" void LLVMInitializeARMAsmParser() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00009983 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9984 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9985 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9986 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009987}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009988
Chris Lattner3e4582a2010-09-06 19:11:01 +00009989#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009990#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009991#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009992#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009993
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009994static const struct {
9995 const char *Name;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009996 const unsigned ArchCheck;
Michael Kupersteinefd7a962015-02-19 11:38:11 +00009997 const uint64_t Features;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009998} Extensions[] = {
Michael Kupersteinefd7a962015-02-19 11:38:11 +00009999 { "crc", Feature_HasV8, ARM::FeatureCRC },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010000 { "crypto", Feature_HasV8,
Michael Kupersteinefd7a962015-02-19 11:38:11 +000010001 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
10002 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010003 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
Michael Kupersteinefd7a962015-02-19 11:38:11 +000010004 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010005 // FIXME: iWMMXT not supported
Michael Kupersteinefd7a962015-02-19 11:38:11 +000010006 { "iwmmxt", Feature_None, 0 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010007 // FIXME: iWMMXT2 not supported
Michael Kupersteinefd7a962015-02-19 11:38:11 +000010008 { "iwmmxt2", Feature_None, 0 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010009 // FIXME: Maverick not supported
Michael Kupersteinefd7a962015-02-19 11:38:11 +000010010 { "maverick", Feature_None, 0 },
10011 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010012 // FIXME: ARMv6-m OS Extensions feature not checked
Michael Kupersteinefd7a962015-02-19 11:38:11 +000010013 { "os", Feature_None, 0 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010014 // FIXME: Also available in ARMv6-K
Michael Kupersteinefd7a962015-02-19 11:38:11 +000010015 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
10016 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010017 // FIXME: Only available in A-class, isel not predicated
Michael Kupersteinefd7a962015-02-19 11:38:11 +000010018 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010019 // FIXME: xscale not supported
Michael Kupersteinefd7a962015-02-19 11:38:11 +000010020 { "xscale", Feature_None, 0 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010021};
10022
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010023/// parseDirectiveArchExtension
10024/// ::= .arch_extension [no]feature
10025bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +000010026 MCAsmParser &Parser = getParser();
10027
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010028 if (getLexer().isNot(AsmToken::Identifier)) {
10029 Error(getLexer().getLoc(), "unexpected token");
10030 Parser.eatToEndOfStatement();
10031 return false;
10032 }
10033
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010034 StringRef Name = Parser.getTok().getString();
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010035 SMLoc ExtLoc = Parser.getTok().getLoc();
10036 getLexer().Lex();
10037
10038 bool EnableFeature = true;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010039 if (Name.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010040 EnableFeature = false;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010041 Name = Name.substr(2);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010042 }
10043
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010044 for (const auto &Extension : Extensions) {
10045 if (Extension.Name != Name)
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010046 continue;
10047
Michael Kupersteinefd7a962015-02-19 11:38:11 +000010048 if (!Extension.Features)
Saleem Abdulrasool8988c2a2014-07-27 19:07:09 +000010049 report_fatal_error("unsupported architectural extension: " + Name);
10050
10051 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) {
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010052 Error(ExtLoc, "architectural extension '" + Name + "' is not "
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010053 "allowed for the current base architecture");
10054 return false;
10055 }
10056
Michael Kupersteinefd7a962015-02-19 11:38:11 +000010057 uint64_t ToggleFeatures = EnableFeature
10058 ? (~STI.getFeatureBits() & Extension.Features)
10059 : ( STI.getFeatureBits() & Extension.Features);
Tim Northover26bb14e2014-08-18 11:49:42 +000010060 uint64_t Features =
Saleem Abdulrasool78c44722014-08-17 19:20:38 +000010061 ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
10062 setAvailableFeatures(Features);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010063 return false;
10064 }
10065
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010066 Error(ExtLoc, "unknown architectural extension: " + Name);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010067 Parser.eatToEndOfStatement();
10068 return false;
10069}
10070
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010071// Define this matcher function after the auto-generated include so we
10072// have the match class enum definitions.
David Blaikie960ea3f2014-06-08 16:18:35 +000010073unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010074 unsigned Kind) {
David Blaikie960ea3f2014-06-08 16:18:35 +000010075 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010076 // If the kind is a token for a literal immediate, check if our asm
10077 // operand matches. This is for InstAliases which have a fixed-value
10078 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010079 switch (Kind) {
10080 default: break;
10081 case MCK__35_0:
David Blaikie960ea3f2014-06-08 16:18:35 +000010082 if (Op.isImm())
10083 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010084 if (CE->getValue() == 0)
10085 return Match_Success;
10086 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +000010087 case MCK_ModImm:
David Blaikie960ea3f2014-06-08 16:18:35 +000010088 if (Op.isImm()) {
10089 const MCExpr *SOExpr = Op.getImm();
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010090 int64_t Value;
10091 if (!SOExpr->EvaluateAsAbsolute(Value))
Stepan Dyatkovskiydf657cc2014-03-29 13:12:40 +000010092 return Match_Success;
Richard Barton3db1d582014-05-01 11:37:44 +000010093 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
10094 "expression value must be representable in 32 bits");
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010095 }
10096 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +000010097 case MCK_GPRPair:
David Blaikie960ea3f2014-06-08 16:18:35 +000010098 if (Op.isReg() &&
10099 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +000010100 return Match_Success;
10101 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010102 }
10103 return Match_InvalidOperand;
10104}