blob: e2f7dfb17f96116706642032c30afa315a22ab22 [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;
167 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000168 void forwardITPosition() {
169 if (!inITBlock()) return;
170 // Move to the next instruction in the IT block, if there is one. If not,
171 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000172 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000173 if (++ITState.CurPosition == 5 - TZ)
174 ITState.CurPosition = ~0U; // Done with the IT block after this.
175 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000176
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000177 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000178 return getParser().Note(L, Msg, Ranges);
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000179 }
Benjamin Kramer673824b2012-04-15 17:04:27 +0000180 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000181 ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000182 return getParser().Warning(L, Msg, Ranges);
Benjamin Kramer673824b2012-04-15 17:04:27 +0000183 }
184 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000185 ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000186 return getParser().Error(L, Msg, Ranges);
Benjamin Kramer673824b2012-04-15 17:04:27 +0000187 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000188
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000189 int tryParseRegister();
David Blaikie960ea3f2014-06-08 16:18:35 +0000190 bool tryParseRegisterWithWriteBack(OperandVector &);
191 int tryParseShiftRegister(OperandVector &);
192 bool parseRegisterList(OperandVector &);
193 bool parseMemory(OperandVector &);
194 bool parseOperand(OperandVector &, StringRef Mnemonic);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000195 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000196 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
197 unsigned &ShiftAmount);
Saleem Abdulrasool38976512014-02-23 06:22:09 +0000198 bool parseLiteralValues(unsigned Size, SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000199 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000200 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000201 bool parseDirectiveThumbFunc(SMLoc L);
202 bool parseDirectiveCode(SMLoc L);
203 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000204 bool parseDirectiveReq(StringRef Name, SMLoc L);
205 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000206 bool parseDirectiveArch(SMLoc L);
207 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000208 bool parseDirectiveCPU(SMLoc L);
209 bool parseDirectiveFPU(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000210 bool parseDirectiveFnStart(SMLoc L);
211 bool parseDirectiveFnEnd(SMLoc L);
212 bool parseDirectiveCantUnwind(SMLoc L);
213 bool parseDirectivePersonality(SMLoc L);
214 bool parseDirectiveHandlerData(SMLoc L);
215 bool parseDirectiveSetFP(SMLoc L);
216 bool parseDirectivePad(SMLoc L);
217 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000218 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
David Peixotto80c083a2013-12-19 18:26:07 +0000219 bool parseDirectiveLtorg(SMLoc L);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +0000220 bool parseDirectiveEven(SMLoc L);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000221 bool parseDirectivePersonalityIndex(SMLoc L);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000222 bool parseDirectiveUnwindRaw(SMLoc L);
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000223 bool parseDirectiveTLSDescSeq(SMLoc L);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000224 bool parseDirectiveMovSP(SMLoc L);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000225 bool parseDirectiveObjectArch(SMLoc L);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +0000226 bool parseDirectiveArchExtension(SMLoc L);
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +0000227 bool parseDirectiveAlign(SMLoc L);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +0000228 bool parseDirectiveThumbSet(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000229
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000230 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000231 bool &CarrySetting, unsigned &ProcessorIMod,
232 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000233 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
234 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000235 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000236
Evan Cheng4d1ca962011-07-08 01:53:10 +0000237 bool isThumb() const {
238 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000239 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000240 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000241 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000242 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000243 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000244 bool isThumbTwo() const {
245 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
246 }
Tim Northovera2292d02013-06-10 23:20:58 +0000247 bool hasThumb() const {
248 return STI.getFeatureBits() & ARM::HasV4TOps;
249 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000250 bool hasV6Ops() const {
251 return STI.getFeatureBits() & ARM::HasV6Ops;
252 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000253 bool hasV6MOps() const {
254 return STI.getFeatureBits() & ARM::HasV6MOps;
255 }
James Molloy21efa7d2011-09-28 14:21:38 +0000256 bool hasV7Ops() const {
257 return STI.getFeatureBits() & ARM::HasV7Ops;
258 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000259 bool hasV8Ops() const {
260 return STI.getFeatureBits() & ARM::HasV8Ops;
261 }
Tim Northovera2292d02013-06-10 23:20:58 +0000262 bool hasARM() const {
263 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
264 }
Renato Golin92c816c2014-09-01 11:25:07 +0000265 bool hasThumb2DSP() const {
266 return STI.getFeatureBits() & ARM::FeatureDSPThumb2;
267 }
Oliver Stannard9e89d8c2014-11-05 12:06:39 +0000268 bool hasD16() const {
269 return STI.getFeatureBits() & ARM::FeatureD16;
270 }
Tim Northovera2292d02013-06-10 23:20:58 +0000271
Evan Cheng284b4672011-07-08 22:36:29 +0000272 void SwitchMode() {
Tim Northover26bb14e2014-08-18 11:49:42 +0000273 uint64_t FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
Evan Cheng91111d22011-07-09 05:47:46 +0000274 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000275 }
James Molloy21efa7d2011-09-28 14:21:38 +0000276 bool isMClass() const {
277 return STI.getFeatureBits() & ARM::FeatureMClass;
278 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000279
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000280 /// @name Auto-generated Match Functions
281 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000282
Chris Lattner3e4582a2010-09-06 19:11:01 +0000283#define GET_ASSEMBLER_HEADER
284#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000285
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000286 /// }
287
David Blaikie960ea3f2014-06-08 16:18:35 +0000288 OperandMatchResultTy parseITCondCode(OperandVector &);
289 OperandMatchResultTy parseCoprocNumOperand(OperandVector &);
290 OperandMatchResultTy parseCoprocRegOperand(OperandVector &);
291 OperandMatchResultTy parseCoprocOptionOperand(OperandVector &);
292 OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &);
293 OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &);
294 OperandMatchResultTy parseProcIFlagsOperand(OperandVector &);
295 OperandMatchResultTy parseMSRMaskOperand(OperandVector &);
Tim Northoveree843ef2014-08-15 10:47:12 +0000296 OperandMatchResultTy parseBankedRegOperand(OperandVector &);
David Blaikie960ea3f2014-06-08 16:18:35 +0000297 OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low,
298 int High);
299 OperandMatchResultTy parsePKHLSLImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000300 return parsePKHImm(O, "lsl", 0, 31);
301 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000302 OperandMatchResultTy parsePKHASRImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000303 return parsePKHImm(O, "asr", 1, 32);
304 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000305 OperandMatchResultTy parseSetEndImm(OperandVector &);
306 OperandMatchResultTy parseShifterImm(OperandVector &);
307 OperandMatchResultTy parseRotImm(OperandVector &);
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000308 OperandMatchResultTy parseModImm(OperandVector &);
David Blaikie960ea3f2014-06-08 16:18:35 +0000309 OperandMatchResultTy parseBitfield(OperandVector &);
310 OperandMatchResultTy parsePostIdxReg(OperandVector &);
311 OperandMatchResultTy parseAM3Offset(OperandVector &);
312 OperandMatchResultTy parseFPImm(OperandVector &);
313 OperandMatchResultTy parseVectorList(OperandVector &);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000314 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
315 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000316
317 // Asm Match Converter Methods
David Blaikie960ea3f2014-06-08 16:18:35 +0000318 void cvtThumbMultiply(MCInst &Inst, const OperandVector &);
319 void cvtThumbBranches(MCInst &Inst, const OperandVector &);
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +0000320
David Blaikie960ea3f2014-06-08 16:18:35 +0000321 bool validateInstruction(MCInst &Inst, const OperandVector &Ops);
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +0000322 bool processInstruction(MCInst &Inst, const OperandVector &Ops, MCStreamer &Out);
David Blaikie960ea3f2014-06-08 16:18:35 +0000323 bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands);
324 bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands);
325
Kevin Enderbyccab3172009-09-15 00:27:25 +0000326public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000327 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000328 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000329 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000330 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000331 Match_RequiresThumb2,
332#define GET_OPERAND_DIAGNOSTIC_TYPES
333#include "ARMGenAsmMatcher.inc"
334
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000335 };
336
Rafael Espindola961d4692014-11-11 05:18:41 +0000337 ARMAsmParser(MCSubtargetInfo & _STI, MCAsmParser & _Parser,
338 const MCInstrInfo &MII, const MCTargetOptions &Options)
339 : MCTargetAsmParser(), STI(_STI), MII(MII), UC(_Parser) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000340 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000341
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000342 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000343 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000344
Evan Cheng4d1ca962011-07-08 01:53:10 +0000345 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000346 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000347
348 // Not in an ITBlock to start with.
349 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000350
351 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000352 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000353
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000354 // Implementation of the MCTargetAsmParser interface:
Craig Topperca7e3e52014-03-10 03:19:03 +0000355 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
David Blaikie960ea3f2014-06-08 16:18:35 +0000356 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
357 SMLoc NameLoc, OperandVector &Operands) override;
Craig Topperca7e3e52014-03-10 03:19:03 +0000358 bool ParseDirective(AsmToken DirectiveID) override;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000359
David Blaikie960ea3f2014-06-08 16:18:35 +0000360 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
Craig Topperca7e3e52014-03-10 03:19:03 +0000361 unsigned Kind) override;
362 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000363
Chad Rosier49963552012-10-13 00:26:04 +0000364 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
David Blaikie960ea3f2014-06-08 16:18:35 +0000365 OperandVector &Operands, MCStreamer &Out,
Tim Northover26bb14e2014-08-18 11:49:42 +0000366 uint64_t &ErrorInfo,
Craig Topperca7e3e52014-03-10 03:19:03 +0000367 bool MatchingInlineAsm) override;
368 void onLabelParsed(MCSymbol *Symbol) override;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000369};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000370} // end anonymous namespace
371
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000372namespace {
373
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000374/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000375/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000376class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000377 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000378 k_CondCode,
379 k_CCOut,
380 k_ITCondMask,
381 k_CoprocNum,
382 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000383 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000384 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000385 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000386 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000387 k_Memory,
388 k_PostIndexRegister,
389 k_MSRMask,
Tim Northoveree843ef2014-08-15 10:47:12 +0000390 k_BankedReg,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000391 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000392 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000393 k_Register,
394 k_RegisterList,
395 k_DPRRegisterList,
396 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000397 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000398 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000399 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000400 k_ShiftedRegister,
401 k_ShiftedImmediate,
402 k_ShifterImmediate,
403 k_RotateImmediate,
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000404 k_ModifiedImmediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000405 k_BitfieldDescriptor,
406 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000407 } Kind;
408
Kevin Enderby488f20b2014-04-10 20:18:58 +0000409 SMLoc StartLoc, EndLoc, AlignmentLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000410 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000411
Eric Christopher8996c5d2013-03-15 00:42:55 +0000412 struct CCOp {
413 ARMCC::CondCodes Val;
414 };
415
416 struct CopOp {
417 unsigned Val;
418 };
419
420 struct CoprocOptionOp {
421 unsigned Val;
422 };
423
424 struct ITMaskOp {
425 unsigned Mask:4;
426 };
427
428 struct MBOptOp {
429 ARM_MB::MemBOpt Val;
430 };
431
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000432 struct ISBOptOp {
433 ARM_ISB::InstSyncBOpt Val;
434 };
435
Eric Christopher8996c5d2013-03-15 00:42:55 +0000436 struct IFlagsOp {
437 ARM_PROC::IFlags Val;
438 };
439
440 struct MMaskOp {
441 unsigned Val;
442 };
443
Tim Northoveree843ef2014-08-15 10:47:12 +0000444 struct BankedRegOp {
445 unsigned Val;
446 };
447
Eric Christopher8996c5d2013-03-15 00:42:55 +0000448 struct TokOp {
449 const char *Data;
450 unsigned Length;
451 };
452
453 struct RegOp {
454 unsigned RegNum;
455 };
456
457 // A vector register list is a sequential list of 1 to 4 registers.
458 struct VectorListOp {
459 unsigned RegNum;
460 unsigned Count;
461 unsigned LaneIndex;
462 bool isDoubleSpaced;
463 };
464
465 struct VectorIndexOp {
466 unsigned Val;
467 };
468
469 struct ImmOp {
470 const MCExpr *Val;
471 };
472
473 /// Combined record for all forms of ARM address expressions.
474 struct MemoryOp {
475 unsigned BaseRegNum;
476 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
477 // was specified.
478 const MCConstantExpr *OffsetImm; // Offset immediate value
479 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
480 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
481 unsigned ShiftImm; // shift for OffsetReg.
482 unsigned Alignment; // 0 = no alignment specified
483 // n = alignment in bytes (2, 4, 8, 16, or 32)
484 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
485 };
486
487 struct PostIdxRegOp {
488 unsigned RegNum;
489 bool isAdd;
490 ARM_AM::ShiftOpc ShiftTy;
491 unsigned ShiftImm;
492 };
493
494 struct ShifterImmOp {
495 bool isASR;
496 unsigned Imm;
497 };
498
499 struct RegShiftedRegOp {
500 ARM_AM::ShiftOpc ShiftTy;
501 unsigned SrcReg;
502 unsigned ShiftReg;
503 unsigned ShiftImm;
504 };
505
506 struct RegShiftedImmOp {
507 ARM_AM::ShiftOpc ShiftTy;
508 unsigned SrcReg;
509 unsigned ShiftImm;
510 };
511
512 struct RotImmOp {
513 unsigned Imm;
514 };
515
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000516 struct ModImmOp {
517 unsigned Bits;
518 unsigned Rot;
519 };
520
Eric Christopher8996c5d2013-03-15 00:42:55 +0000521 struct BitfieldOp {
522 unsigned LSB;
523 unsigned Width;
524 };
525
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000526 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000527 struct CCOp CC;
528 struct CopOp Cop;
529 struct CoprocOptionOp CoprocOption;
530 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000531 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000532 struct ITMaskOp ITMask;
533 struct IFlagsOp IFlags;
534 struct MMaskOp MMask;
Tim Northoveree843ef2014-08-15 10:47:12 +0000535 struct BankedRegOp BankedReg;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000536 struct TokOp Tok;
537 struct RegOp Reg;
538 struct VectorListOp VectorList;
539 struct VectorIndexOp VectorIndex;
540 struct ImmOp Imm;
541 struct MemoryOp Memory;
542 struct PostIdxRegOp PostIdxReg;
543 struct ShifterImmOp ShifterImm;
544 struct RegShiftedRegOp RegShiftedReg;
545 struct RegShiftedImmOp RegShiftedImm;
546 struct RotImmOp RotImm;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000547 struct ModImmOp ModImm;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000548 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000549 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000550
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000551public:
David Blaikie960ea3f2014-06-08 16:18:35 +0000552 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000553 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
554 Kind = o.Kind;
555 StartLoc = o.StartLoc;
556 EndLoc = o.EndLoc;
557 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000558 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000559 CC = o.CC;
560 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000561 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000562 ITMask = o.ITMask;
563 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000564 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000565 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000566 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000567 case k_CCOut:
568 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000569 Reg = o.Reg;
570 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000571 case k_RegisterList:
572 case k_DPRRegisterList:
573 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000574 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000575 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000576 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000577 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000578 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000579 VectorList = o.VectorList;
580 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000581 case k_CoprocNum:
582 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000583 Cop = o.Cop;
584 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000585 case k_CoprocOption:
586 CoprocOption = o.CoprocOption;
587 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000588 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000589 Imm = o.Imm;
590 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000591 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000592 MBOpt = o.MBOpt;
593 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000594 case k_InstSyncBarrierOpt:
595 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000596 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000597 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000598 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000599 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000600 PostIdxReg = o.PostIdxReg;
601 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000602 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000603 MMask = o.MMask;
604 break;
Tim Northoveree843ef2014-08-15 10:47:12 +0000605 case k_BankedReg:
606 BankedReg = o.BankedReg;
607 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000608 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000609 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000610 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000611 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000612 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000613 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000614 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000615 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000616 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000617 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000618 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000619 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000620 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000621 RotImm = o.RotImm;
622 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000623 case k_ModifiedImmediate:
624 ModImm = o.ModImm;
625 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000626 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000627 Bitfield = o.Bitfield;
628 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000629 case k_VectorIndex:
630 VectorIndex = o.VectorIndex;
631 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000632 }
633 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000634
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000635 /// getStartLoc - Get the location of the first token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000636 SMLoc getStartLoc() const override { return StartLoc; }
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000637 /// getEndLoc - Get the location of the last token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000638 SMLoc getEndLoc() const override { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000639 /// getLocRange - Get the range between the first and last token of this
640 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000641 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
642
Kevin Enderby488f20b2014-04-10 20:18:58 +0000643 /// getAlignmentLoc - Get the location of the Alignment token of this operand.
644 SMLoc getAlignmentLoc() const {
645 assert(Kind == k_Memory && "Invalid access!");
646 return AlignmentLoc;
647 }
648
Daniel Dunbard8042b72010-08-11 06:36:53 +0000649 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000650 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000651 return CC.Val;
652 }
653
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000654 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000655 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000656 return Cop.Val;
657 }
658
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000659 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000660 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000661 return StringRef(Tok.Data, Tok.Length);
662 }
663
Craig Topperca7e3e52014-03-10 03:19:03 +0000664 unsigned getReg() const override {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000665 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000666 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000667 }
668
Bill Wendlingbed94652010-11-09 23:28:44 +0000669 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000670 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
671 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000672 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000673 }
674
Kevin Enderbyf5079942009-10-13 22:19:02 +0000675 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000676 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000677 return Imm.Val;
678 }
679
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000680 unsigned getVectorIndex() const {
681 assert(Kind == k_VectorIndex && "Invalid access!");
682 return VectorIndex.Val;
683 }
684
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000685 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000686 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000687 return MBOpt.Val;
688 }
689
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000690 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
691 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
692 return ISBOpt.Val;
693 }
694
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000695 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000696 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000697 return IFlags.Val;
698 }
699
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000700 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000701 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000702 return MMask.Val;
703 }
704
Tim Northoveree843ef2014-08-15 10:47:12 +0000705 unsigned getBankedReg() const {
706 assert(Kind == k_BankedReg && "Invalid access!");
707 return BankedReg.Val;
708 }
709
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000710 bool isCoprocNum() const { return Kind == k_CoprocNum; }
711 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000712 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000713 bool isCondCode() const { return Kind == k_CondCode; }
714 bool isCCOut() const { return Kind == k_CCOut; }
715 bool isITMask() const { return Kind == k_ITCondMask; }
716 bool isITCondCode() const { return Kind == k_CondCode; }
Craig Topperca7e3e52014-03-10 03:19:03 +0000717 bool isImm() const override { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000718 // checks whether this operand is an unsigned offset which fits is a field
719 // of specified width and scaled by a specific number of bits
720 template<unsigned width, unsigned scale>
721 bool isUnsignedOffset() const {
722 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000723 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000724 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
725 int64_t Val = CE->getValue();
726 int64_t Align = 1LL << scale;
727 int64_t Max = Align * ((1LL << width) - 1);
728 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
729 }
730 return false;
731 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000732 // checks whether this operand is an signed offset which fits is a field
733 // of specified width and scaled by a specific number of bits
734 template<unsigned width, unsigned scale>
735 bool isSignedOffset() const {
736 if (!isImm()) return false;
737 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
738 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
739 int64_t Val = CE->getValue();
740 int64_t Align = 1LL << scale;
741 int64_t Max = Align * ((1LL << (width-1)) - 1);
742 int64_t Min = -Align * (1LL << (width-1));
743 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
744 }
745 return false;
746 }
747
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000748 // checks whether this operand is a memory operand computed as an offset
749 // applied to PC. the offset may have 8 bits of magnitude and is represented
750 // with two bits of shift. textually it may be either [pc, #imm], #imm or
751 // relocable expression...
752 bool isThumbMemPC() const {
753 int64_t Val = 0;
754 if (isImm()) {
755 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
757 if (!CE) return false;
758 Val = CE->getValue();
759 }
760 else if (isMem()) {
761 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
762 if(Memory.BaseRegNum != ARM::PC) return false;
763 Val = Memory.OffsetImm->getValue();
764 }
765 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000766 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000767 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000768 bool isFPImm() const {
769 if (!isImm()) return false;
770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
771 if (!CE) return false;
772 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
773 return Val != -1;
774 }
Jim Grosbachea231912011-12-22 22:19:05 +0000775 bool isFBits16() const {
776 if (!isImm()) return false;
777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
778 if (!CE) return false;
779 int64_t Value = CE->getValue();
780 return Value >= 0 && Value <= 16;
781 }
782 bool isFBits32() const {
783 if (!isImm()) return false;
784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
785 if (!CE) return false;
786 int64_t Value = CE->getValue();
787 return Value >= 1 && Value <= 32;
788 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000789 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000790 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000791 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
792 if (!CE) return false;
793 int64_t Value = CE->getValue();
794 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
795 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000796 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000797 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000798 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
799 if (!CE) return false;
800 int64_t Value = CE->getValue();
801 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
802 }
803 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000804 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000805 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
806 if (!CE) return false;
807 int64_t Value = CE->getValue();
808 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
809 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000810 bool isImm0_508s4Neg() const {
811 if (!isImm()) return false;
812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
813 if (!CE) return false;
814 int64_t Value = -CE->getValue();
815 // explicitly exclude zero. we want that to use the normal 0_508 version.
816 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
817 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000818 bool isImm0_239() 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 return Value >= 0 && Value < 240;
824 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000825 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000826 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
828 if (!CE) return false;
829 int64_t Value = CE->getValue();
830 return Value >= 0 && Value < 256;
831 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000832 bool isImm0_4095() const {
833 if (!isImm()) return false;
834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
835 if (!CE) return false;
836 int64_t Value = CE->getValue();
837 return Value >= 0 && Value < 4096;
838 }
839 bool isImm0_4095Neg() const {
840 if (!isImm()) return false;
841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
842 if (!CE) return false;
843 int64_t Value = -CE->getValue();
844 return Value > 0 && Value < 4096;
845 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000846 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000847 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
849 if (!CE) return false;
850 int64_t Value = CE->getValue();
851 return Value >= 0 && Value < 2;
852 }
853 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000854 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
856 if (!CE) return false;
857 int64_t Value = CE->getValue();
858 return Value >= 0 && Value < 4;
859 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000860 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000861 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
863 if (!CE) return false;
864 int64_t Value = CE->getValue();
865 return Value >= 0 && Value < 8;
866 }
867 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000868 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
870 if (!CE) return false;
871 int64_t Value = CE->getValue();
872 return Value >= 0 && Value < 16;
873 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000874 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000875 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
877 if (!CE) return false;
878 int64_t Value = CE->getValue();
879 return Value >= 0 && Value < 32;
880 }
Jim Grosbach00326402011-12-08 01:30:04 +0000881 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000882 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
884 if (!CE) return false;
885 int64_t Value = CE->getValue();
886 return Value >= 0 && Value < 64;
887 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000888 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000889 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000890 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
891 if (!CE) return false;
892 int64_t Value = CE->getValue();
893 return Value == 8;
894 }
895 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000896 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000897 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
898 if (!CE) return false;
899 int64_t Value = CE->getValue();
900 return Value == 16;
901 }
902 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000903 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000904 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
905 if (!CE) return false;
906 int64_t Value = CE->getValue();
907 return Value == 32;
908 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000909 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000910 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000911 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
912 if (!CE) return false;
913 int64_t Value = CE->getValue();
914 return Value > 0 && Value <= 8;
915 }
916 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000917 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
919 if (!CE) return false;
920 int64_t Value = CE->getValue();
921 return Value > 0 && Value <= 16;
922 }
923 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000924 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000925 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
926 if (!CE) return false;
927 int64_t Value = CE->getValue();
928 return Value > 0 && Value <= 32;
929 }
930 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000931 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000932 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
933 if (!CE) return false;
934 int64_t Value = CE->getValue();
935 return Value > 0 && Value <= 64;
936 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000937 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000938 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000939 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
940 if (!CE) return false;
941 int64_t Value = CE->getValue();
942 return Value > 0 && Value < 8;
943 }
944 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000945 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000946 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
947 if (!CE) return false;
948 int64_t Value = CE->getValue();
949 return Value > 0 && Value < 16;
950 }
951 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000952 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
954 if (!CE) return false;
955 int64_t Value = CE->getValue();
956 return Value > 0 && Value < 32;
957 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000958 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000959 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000960 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
961 if (!CE) return false;
962 int64_t Value = CE->getValue();
963 return Value > 0 && Value < 17;
964 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000965 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000966 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000967 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
968 if (!CE) return false;
969 int64_t Value = CE->getValue();
970 return Value > 0 && Value < 33;
971 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000972 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000973 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000974 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
975 if (!CE) return false;
976 int64_t Value = CE->getValue();
977 return Value >= 0 && Value < 33;
978 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000979 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000980 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000981 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
982 if (!CE) return false;
983 int64_t Value = CE->getValue();
984 return Value >= 0 && Value < 65536;
985 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000986 bool isImm256_65535Expr() const {
987 if (!isImm()) return false;
988 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
989 // If it's not a constant expression, it'll generate a fixup and be
990 // handled later.
991 if (!CE) return true;
992 int64_t Value = CE->getValue();
993 return Value >= 256 && Value < 65536;
994 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000995 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000996 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000997 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
998 // If it's not a constant expression, it'll generate a fixup and be
999 // handled later.
1000 if (!CE) return true;
1001 int64_t Value = CE->getValue();
1002 return Value >= 0 && Value < 65536;
1003 }
Jim Grosbachf1637842011-07-26 16:24:27 +00001004 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001005 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +00001006 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1007 if (!CE) return false;
1008 int64_t Value = CE->getValue();
1009 return Value >= 0 && Value <= 0xffffff;
1010 }
Jim Grosbach46dd4132011-08-17 21:51:27 +00001011 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001012 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +00001013 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1014 if (!CE) return false;
1015 int64_t Value = CE->getValue();
1016 return Value > 0 && Value < 33;
1017 }
Jim Grosbach27c1e252011-07-21 17:23:04 +00001018 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001019 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001020 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1021 if (!CE) return false;
1022 int64_t Value = CE->getValue();
1023 return Value >= 0 && Value < 32;
1024 }
1025 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001026 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001027 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1028 if (!CE) return false;
1029 int64_t Value = CE->getValue();
1030 return Value > 0 && Value <= 32;
1031 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001032 bool isAdrLabel() const {
1033 // If we have an immediate that's not a constant, treat it as a label
1034 // reference needing a fixup. If it is a constant, but it can't fit
1035 // into shift immediate encoding, we reject it.
1036 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1037 else return (isARMSOImm() || isARMSOImmNeg());
1038 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001039 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001040 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001041 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1042 if (!CE) return false;
1043 int64_t Value = CE->getValue();
1044 return ARM_AM::getSOImmVal(Value) != -1;
1045 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001046 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001047 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1049 if (!CE) return false;
1050 int64_t Value = CE->getValue();
1051 return ARM_AM::getSOImmVal(~Value) != -1;
1052 }
Jim Grosbach30506252011-12-08 00:31:07 +00001053 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001054 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001055 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1056 if (!CE) return false;
1057 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001058 // Only use this when not representable as a plain so_imm.
1059 return ARM_AM::getSOImmVal(Value) == -1 &&
1060 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001061 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001062 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001063 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001064 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1065 if (!CE) return false;
1066 int64_t Value = CE->getValue();
1067 return ARM_AM::getT2SOImmVal(Value) != -1;
1068 }
Jim Grosbachb009a872011-10-28 22:36:30 +00001069 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001070 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +00001071 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1072 if (!CE) return false;
1073 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +00001074 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1075 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +00001076 }
Jim Grosbach30506252011-12-08 00:31:07 +00001077 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001078 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001079 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1080 if (!CE) return false;
1081 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001082 // Only use this when not representable as a plain so_imm.
1083 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1084 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001085 }
Jim Grosbach0a547702011-07-22 17:44:50 +00001086 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001087 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +00001088 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1089 if (!CE) return false;
1090 int64_t Value = CE->getValue();
1091 return Value == 1 || Value == 0;
1092 }
Craig Topperca7e3e52014-03-10 03:19:03 +00001093 bool isReg() const override { return Kind == k_Register; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001094 bool isRegList() const { return Kind == k_RegisterList; }
1095 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1096 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001097 bool isToken() const override { return Kind == k_Token; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001098 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001099 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001100 bool isMem() const override { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001101 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1102 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1103 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1104 bool isRotImm() const { return Kind == k_RotateImmediate; }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001105 bool isModImm() const { return Kind == k_ModifiedImmediate; }
1106 bool isModImmNot() const {
1107 if (!isImm()) return false;
1108 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1109 if (!CE) return false;
1110 int64_t Value = CE->getValue();
1111 return ARM_AM::getSOImmVal(~Value) != -1;
1112 }
1113 bool isModImmNeg() const {
1114 if (!isImm()) return false;
1115 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1116 if (!CE) return false;
1117 int64_t Value = CE->getValue();
1118 return ARM_AM::getSOImmVal(Value) == -1 &&
1119 ARM_AM::getSOImmVal(-Value) != -1;
1120 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001121 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1122 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001123 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001124 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001125 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001126 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const {
Chad Rosier41099832012-09-11 23:02:35 +00001127 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001128 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001129 // No offset of any kind.
Craig Topper062a2ba2014-04-25 05:30:21 +00001130 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
Kevin Enderby488f20b2014-04-10 20:18:58 +00001131 (alignOK || Memory.Alignment == Alignment);
Jim Grosbacha95ec992011-10-11 17:29:55 +00001132 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001133 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001134 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001135 return false;
1136 // Base register must be PC.
1137 if (Memory.BaseRegNum != ARM::PC)
1138 return false;
1139 // Immediate offset in range [-4095, 4095].
1140 if (!Memory.OffsetImm) return true;
1141 int64_t Val = Memory.OffsetImm->getValue();
1142 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1143 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001144 bool isAlignedMemory() const {
1145 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001146 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001147 bool isAlignedMemoryNone() const {
1148 return isMemNoOffset(false, 0);
1149 }
1150 bool isDupAlignedMemoryNone() const {
1151 return isMemNoOffset(false, 0);
1152 }
1153 bool isAlignedMemory16() const {
1154 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1155 return true;
1156 return isMemNoOffset(false, 0);
1157 }
1158 bool isDupAlignedMemory16() const {
1159 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1160 return true;
1161 return isMemNoOffset(false, 0);
1162 }
1163 bool isAlignedMemory32() const {
1164 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1165 return true;
1166 return isMemNoOffset(false, 0);
1167 }
1168 bool isDupAlignedMemory32() const {
1169 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1170 return true;
1171 return isMemNoOffset(false, 0);
1172 }
1173 bool isAlignedMemory64() const {
1174 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1175 return true;
1176 return isMemNoOffset(false, 0);
1177 }
1178 bool isDupAlignedMemory64() const {
1179 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1180 return true;
1181 return isMemNoOffset(false, 0);
1182 }
1183 bool isAlignedMemory64or128() const {
1184 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1185 return true;
1186 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1187 return true;
1188 return isMemNoOffset(false, 0);
1189 }
1190 bool isDupAlignedMemory64or128() const {
1191 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1192 return true;
1193 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1194 return true;
1195 return isMemNoOffset(false, 0);
1196 }
1197 bool isAlignedMemory64or128or256() const {
1198 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1199 return true;
1200 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1201 return true;
1202 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
1203 return true;
1204 return isMemNoOffset(false, 0);
1205 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001206 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001207 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001208 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001209 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001210 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001211 if (!Memory.OffsetImm) return true;
1212 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001213 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001214 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001215 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001216 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001217 // Immediate offset in range [-4095, 4095].
1218 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1219 if (!CE) return false;
1220 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001221 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001222 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001223 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001224 // If we have an immediate that's not a constant, treat it as a label
1225 // reference needing a fixup. If it is a constant, it's something else
1226 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001227 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001228 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001229 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001230 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001231 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001232 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001233 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001234 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001235 if (!Memory.OffsetImm) return true;
1236 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001237 // The #-0 offset is encoded as INT32_MIN, and we have to check
1238 // for this too.
1239 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001240 }
1241 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001242 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001243 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001244 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001245 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1246 // Immediate offset in range [-255, 255].
1247 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1248 if (!CE) return false;
1249 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001250 // Special case, #-0 is INT32_MIN.
1251 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001252 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001253 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001254 // If we have an immediate that's not a constant, treat it as a label
1255 // reference needing a fixup. If it is a constant, it's something else
1256 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001257 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001258 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001259 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001260 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001261 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001262 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001263 if (!Memory.OffsetImm) return true;
1264 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001265 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001266 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001267 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001268 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001269 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001270 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001271 return false;
1272 return true;
1273 }
1274 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001275 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001276 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1277 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001278 return false;
1279 return true;
1280 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001281 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001282 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001283 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001284 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001285 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001286 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001287 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001288 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001289 return false;
1290 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001291 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001292 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001293 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001294 return false;
1295 return true;
1296 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001297 bool isMemThumbRR() const {
1298 // Thumb reg+reg addressing is simple. Just two registers, a base and
1299 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001300 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001301 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001302 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001303 return isARMLowRegister(Memory.BaseRegNum) &&
1304 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001305 }
1306 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001307 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001308 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001309 return false;
1310 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001311 if (!Memory.OffsetImm) return true;
1312 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001313 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1314 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001315 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001316 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001317 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001318 return false;
1319 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001320 if (!Memory.OffsetImm) return true;
1321 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001322 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1323 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001324 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001325 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001326 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001327 return false;
1328 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001329 if (!Memory.OffsetImm) return true;
1330 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001331 return Val >= 0 && Val <= 31;
1332 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001333 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001334 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001335 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001336 return false;
1337 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001338 if (!Memory.OffsetImm) return true;
1339 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001340 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001341 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001342 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001343 // If we have an immediate that's not a constant, treat it as a label
1344 // reference needing a fixup. If it is a constant, it's something else
1345 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001346 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001347 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001348 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001349 return false;
1350 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001351 if (!Memory.OffsetImm) return true;
1352 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001353 // Special case, #-0 is INT32_MIN.
1354 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001355 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001356 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001357 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001358 return false;
1359 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001360 if (!Memory.OffsetImm) return true;
1361 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001362 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1363 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001364 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001365 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001366 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001367 // Base reg of PC isn't allowed for these encodings.
1368 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001369 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001370 if (!Memory.OffsetImm) return true;
1371 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001372 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001373 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001374 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001375 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001376 return false;
1377 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001378 if (!Memory.OffsetImm) return true;
1379 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001380 return Val >= 0 && Val < 256;
1381 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001382 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001383 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001384 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001385 // Base reg of PC isn't allowed for these encodings.
1386 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001387 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001388 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001389 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001390 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001391 }
1392 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001393 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001394 return false;
1395 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001396 if (!Memory.OffsetImm) return true;
1397 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001398 return (Val >= 0 && Val < 4096);
1399 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001400 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001401 // If we have an immediate that's not a constant, treat it as a label
1402 // reference needing a fixup. If it is a constant, it's something else
1403 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001404 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001405 return true;
1406
Chad Rosier41099832012-09-11 23:02:35 +00001407 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001408 return false;
1409 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001410 if (!Memory.OffsetImm) return true;
1411 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001412 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001413 }
1414 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001415 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001416 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1417 if (!CE) return false;
1418 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001419 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001420 }
Jim Grosbach93981412011-10-11 21:55:36 +00001421 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001422 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001423 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1424 if (!CE) return false;
1425 int64_t Val = CE->getValue();
1426 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1427 (Val == INT32_MIN);
1428 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001429
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001430 bool isMSRMask() const { return Kind == k_MSRMask; }
Tim Northoveree843ef2014-08-15 10:47:12 +00001431 bool isBankedReg() const { return Kind == k_BankedReg; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001432 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001433
Jim Grosbach741cd732011-10-17 22:26:03 +00001434 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001435 bool isSingleSpacedVectorList() const {
1436 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1437 }
1438 bool isDoubleSpacedVectorList() const {
1439 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1440 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001441 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001442 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001443 return VectorList.Count == 1;
1444 }
1445
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001446 bool isVecListDPair() const {
1447 if (!isSingleSpacedVectorList()) return false;
1448 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1449 .contains(VectorList.RegNum));
1450 }
1451
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001452 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001453 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001454 return VectorList.Count == 3;
1455 }
1456
Jim Grosbach846bcff2011-10-21 20:35:01 +00001457 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001458 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001459 return VectorList.Count == 4;
1460 }
1461
Jim Grosbache5307f92012-03-05 21:43:40 +00001462 bool isVecListDPairSpaced() const {
Kevin Enderby56113982014-03-26 21:54:11 +00001463 if (Kind != k_VectorList) return false;
Kevin Enderby816ca272012-03-20 17:41:51 +00001464 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001465 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1466 .contains(VectorList.RegNum));
1467 }
1468
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001469 bool isVecListThreeQ() const {
1470 if (!isDoubleSpacedVectorList()) return false;
1471 return VectorList.Count == 3;
1472 }
1473
Jim Grosbach1e946a42012-01-24 00:43:12 +00001474 bool isVecListFourQ() const {
1475 if (!isDoubleSpacedVectorList()) return false;
1476 return VectorList.Count == 4;
1477 }
1478
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001479 bool isSingleSpacedVectorAllLanes() const {
1480 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1481 }
1482 bool isDoubleSpacedVectorAllLanes() const {
1483 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1484 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001485 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001486 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001487 return VectorList.Count == 1;
1488 }
1489
Jim Grosbach13a292c2012-03-06 22:01:44 +00001490 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001491 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001492 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1493 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001494 }
1495
Jim Grosbached428bc2012-03-06 23:10:38 +00001496 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001497 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001498 return VectorList.Count == 2;
1499 }
1500
Jim Grosbachb78403c2012-01-24 23:47:04 +00001501 bool isVecListThreeDAllLanes() const {
1502 if (!isSingleSpacedVectorAllLanes()) return false;
1503 return VectorList.Count == 3;
1504 }
1505
1506 bool isVecListThreeQAllLanes() const {
1507 if (!isDoubleSpacedVectorAllLanes()) return false;
1508 return VectorList.Count == 3;
1509 }
1510
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001511 bool isVecListFourDAllLanes() const {
1512 if (!isSingleSpacedVectorAllLanes()) return false;
1513 return VectorList.Count == 4;
1514 }
1515
1516 bool isVecListFourQAllLanes() const {
1517 if (!isDoubleSpacedVectorAllLanes()) return false;
1518 return VectorList.Count == 4;
1519 }
1520
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001521 bool isSingleSpacedVectorIndexed() const {
1522 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1523 }
1524 bool isDoubleSpacedVectorIndexed() const {
1525 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1526 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001527 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001528 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001529 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1530 }
1531
Jim Grosbachda511042011-12-14 23:35:06 +00001532 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001533 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001534 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1535 }
1536
1537 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001538 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001539 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1540 }
1541
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001542 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001543 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001544 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1545 }
1546
Jim Grosbachda511042011-12-14 23:35:06 +00001547 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001548 if (!isSingleSpacedVectorIndexed()) return false;
1549 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1550 }
1551
1552 bool isVecListTwoQWordIndexed() const {
1553 if (!isDoubleSpacedVectorIndexed()) return false;
1554 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1555 }
1556
1557 bool isVecListTwoQHWordIndexed() const {
1558 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001559 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1560 }
1561
1562 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001563 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001564 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1565 }
1566
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001567 bool isVecListThreeDByteIndexed() const {
1568 if (!isSingleSpacedVectorIndexed()) return false;
1569 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1570 }
1571
1572 bool isVecListThreeDHWordIndexed() const {
1573 if (!isSingleSpacedVectorIndexed()) return false;
1574 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1575 }
1576
1577 bool isVecListThreeQWordIndexed() const {
1578 if (!isDoubleSpacedVectorIndexed()) return false;
1579 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1580 }
1581
1582 bool isVecListThreeQHWordIndexed() const {
1583 if (!isDoubleSpacedVectorIndexed()) return false;
1584 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1585 }
1586
1587 bool isVecListThreeDWordIndexed() const {
1588 if (!isSingleSpacedVectorIndexed()) return false;
1589 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1590 }
1591
Jim Grosbach14952a02012-01-24 18:37:25 +00001592 bool isVecListFourDByteIndexed() const {
1593 if (!isSingleSpacedVectorIndexed()) return false;
1594 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1595 }
1596
1597 bool isVecListFourDHWordIndexed() const {
1598 if (!isSingleSpacedVectorIndexed()) return false;
1599 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1600 }
1601
1602 bool isVecListFourQWordIndexed() const {
1603 if (!isDoubleSpacedVectorIndexed()) return false;
1604 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1605 }
1606
1607 bool isVecListFourQHWordIndexed() const {
1608 if (!isDoubleSpacedVectorIndexed()) return false;
1609 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1610 }
1611
1612 bool isVecListFourDWordIndexed() const {
1613 if (!isSingleSpacedVectorIndexed()) return false;
1614 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1615 }
1616
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001617 bool isVectorIndex8() const {
1618 if (Kind != k_VectorIndex) return false;
1619 return VectorIndex.Val < 8;
1620 }
1621 bool isVectorIndex16() const {
1622 if (Kind != k_VectorIndex) return false;
1623 return VectorIndex.Val < 4;
1624 }
1625 bool isVectorIndex32() const {
1626 if (Kind != k_VectorIndex) return false;
1627 return VectorIndex.Val < 2;
1628 }
1629
Jim Grosbach741cd732011-10-17 22:26:03 +00001630 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001631 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001632 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1633 // Must be a constant.
1634 if (!CE) return false;
1635 int64_t Value = CE->getValue();
1636 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1637 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001638 return Value >= 0 && Value < 256;
1639 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001640
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001641 bool isNEONi16splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001642 if (isNEONByteReplicate(2))
1643 return false; // Leave that for bytes replication and forbid by default.
1644 if (!isImm())
1645 return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001646 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1647 // Must be a constant.
1648 if (!CE) return false;
Renato Golinf5dd1da2014-09-25 11:31:24 +00001649 unsigned Value = CE->getValue();
1650 return ARM_AM::isNEONi16splat(Value);
1651 }
1652
1653 bool isNEONi16splatNot() const {
1654 if (!isImm())
1655 return false;
1656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1657 // Must be a constant.
1658 if (!CE) return false;
1659 unsigned Value = CE->getValue();
1660 return ARM_AM::isNEONi16splat(~Value & 0xffff);
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001661 }
1662
Jim Grosbach8211c052011-10-18 00:22:00 +00001663 bool isNEONi32splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001664 if (isNEONByteReplicate(4))
1665 return false; // Leave that for bytes replication and forbid by default.
1666 if (!isImm())
1667 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1669 // Must be a constant.
1670 if (!CE) return false;
Renato Golinf5dd1da2014-09-25 11:31:24 +00001671 unsigned Value = CE->getValue();
1672 return ARM_AM::isNEONi32splat(Value);
1673 }
1674
1675 bool isNEONi32splatNot() const {
1676 if (!isImm())
1677 return false;
1678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1679 // Must be a constant.
1680 if (!CE) return false;
1681 unsigned Value = CE->getValue();
1682 return ARM_AM::isNEONi32splat(~Value);
Jim Grosbach8211c052011-10-18 00:22:00 +00001683 }
1684
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001685 bool isNEONByteReplicate(unsigned NumBytes) const {
1686 if (!isImm())
1687 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001688 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1689 // Must be a constant.
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001690 if (!CE)
1691 return false;
1692 int64_t Value = CE->getValue();
1693 if (!Value)
1694 return false; // Don't bother with zero.
1695
1696 unsigned char B = Value & 0xff;
1697 for (unsigned i = 1; i < NumBytes; ++i) {
1698 Value >>= 8;
1699 if ((Value & 0xff) != B)
1700 return false;
1701 }
1702 return true;
1703 }
1704 bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); }
1705 bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); }
1706 bool isNEONi32vmov() const {
1707 if (isNEONByteReplicate(4))
1708 return false; // Let it to be classified as byte-replicate case.
1709 if (!isImm())
1710 return false;
1711 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1712 // Must be a constant.
1713 if (!CE)
1714 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001715 int64_t Value = CE->getValue();
1716 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1717 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
Renato Golinf5dd1da2014-09-25 11:31:24 +00001718 // FIXME: This is probably wrong and a copy and paste from previous example
Jim Grosbach8211c052011-10-18 00:22:00 +00001719 return (Value >= 0 && Value < 256) ||
1720 (Value >= 0x0100 && Value <= 0xff00) ||
1721 (Value >= 0x010000 && Value <= 0xff0000) ||
1722 (Value >= 0x01000000 && Value <= 0xff000000) ||
1723 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1724 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1725 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001726 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001727 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1729 // Must be a constant.
1730 if (!CE) return false;
1731 int64_t Value = ~CE->getValue();
1732 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1733 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
Renato Golinf5dd1da2014-09-25 11:31:24 +00001734 // FIXME: This is probably wrong and a copy and paste from previous example
Jim Grosbach045b6c72011-12-19 23:51:07 +00001735 return (Value >= 0 && Value < 256) ||
1736 (Value >= 0x0100 && Value <= 0xff00) ||
1737 (Value >= 0x010000 && Value <= 0xff0000) ||
1738 (Value >= 0x01000000 && Value <= 0xff000000) ||
1739 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1740 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1741 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001742
Jim Grosbache4454e02011-10-18 16:18:11 +00001743 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001744 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001745 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1746 // Must be a constant.
1747 if (!CE) return false;
1748 uint64_t Value = CE->getValue();
1749 // i64 value with each byte being either 0 or 0xff.
1750 for (unsigned i = 0; i < 8; ++i)
1751 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1752 return true;
1753 }
1754
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001755 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001756 // Add as immediates when possible. Null MCExpr = 0.
Craig Topper062a2ba2014-04-25 05:30:21 +00001757 if (!Expr)
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001758 Inst.addOperand(MCOperand::CreateImm(0));
1759 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001760 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1761 else
1762 Inst.addOperand(MCOperand::CreateExpr(Expr));
1763 }
1764
Daniel Dunbard8042b72010-08-11 06:36:53 +00001765 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001766 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001767 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001768 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1769 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001770 }
1771
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001772 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1773 assert(N == 1 && "Invalid number of operands!");
1774 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1775 }
1776
Jim Grosbach48399582011-10-12 17:34:41 +00001777 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1778 assert(N == 1 && "Invalid number of operands!");
1779 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1780 }
1781
1782 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1783 assert(N == 1 && "Invalid number of operands!");
1784 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1785 }
1786
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001787 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1788 assert(N == 1 && "Invalid number of operands!");
1789 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1790 }
1791
1792 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1793 assert(N == 1 && "Invalid number of operands!");
1794 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1795 }
1796
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001797 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1798 assert(N == 1 && "Invalid number of operands!");
1799 Inst.addOperand(MCOperand::CreateReg(getReg()));
1800 }
1801
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001802 void addRegOperands(MCInst &Inst, unsigned N) const {
1803 assert(N == 1 && "Invalid number of operands!");
1804 Inst.addOperand(MCOperand::CreateReg(getReg()));
1805 }
1806
Jim Grosbachac798e12011-07-25 20:49:51 +00001807 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001808 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001809 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001810 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001811 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1812 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001813 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001814 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001815 }
1816
Jim Grosbachac798e12011-07-25 20:49:51 +00001817 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001818 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001819 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001820 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001821 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001822 // Shift of #32 is encoded as 0 where permitted
1823 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001824 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001825 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001826 }
1827
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001828 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001829 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001830 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1831 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001832 }
1833
Bill Wendling8d2aa032010-11-08 23:49:57 +00001834 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001835 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001836 const SmallVectorImpl<unsigned> &RegList = getRegList();
1837 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001838 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1839 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001840 }
1841
Bill Wendling9898ac92010-11-17 04:32:08 +00001842 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1843 addRegListOperands(Inst, N);
1844 }
1845
1846 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1847 addRegListOperands(Inst, N);
1848 }
1849
Jim Grosbach833b9d32011-07-27 20:15:40 +00001850 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1851 assert(N == 1 && "Invalid number of operands!");
1852 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1853 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1854 }
1855
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001856 void addModImmOperands(MCInst &Inst, unsigned N) const {
1857 assert(N == 1 && "Invalid number of operands!");
1858
1859 // Support for fixups (MCFixup)
1860 if (isImm())
1861 return addImmOperands(Inst, N);
1862
Asiri Rathnayake7835e9b2014-12-09 13:14:58 +00001863 Inst.addOperand(MCOperand::CreateImm(ModImm.Bits | (ModImm.Rot << 7)));
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001864 }
1865
1866 void addModImmNotOperands(MCInst &Inst, unsigned N) const {
1867 assert(N == 1 && "Invalid number of operands!");
1868 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1869 uint32_t Enc = ARM_AM::getSOImmVal(~CE->getValue());
1870 Inst.addOperand(MCOperand::CreateImm(Enc));
1871 }
1872
1873 void addModImmNegOperands(MCInst &Inst, unsigned N) const {
1874 assert(N == 1 && "Invalid number of operands!");
1875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1876 uint32_t Enc = ARM_AM::getSOImmVal(-CE->getValue());
1877 Inst.addOperand(MCOperand::CreateImm(Enc));
1878 }
1879
Jim Grosbach864b6092011-07-28 21:34:26 +00001880 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1881 assert(N == 1 && "Invalid number of operands!");
1882 // Munge the lsb/width into a bitfield mask.
1883 unsigned lsb = Bitfield.LSB;
1884 unsigned width = Bitfield.Width;
1885 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1886 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1887 (32 - (lsb + width)));
1888 Inst.addOperand(MCOperand::CreateImm(Mask));
1889 }
1890
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001891 void addImmOperands(MCInst &Inst, unsigned N) const {
1892 assert(N == 1 && "Invalid number of operands!");
1893 addExpr(Inst, getImm());
1894 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001895
Jim Grosbachea231912011-12-22 22:19:05 +00001896 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1897 assert(N == 1 && "Invalid number of operands!");
1898 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1899 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1900 }
1901
1902 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1903 assert(N == 1 && "Invalid number of operands!");
1904 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1905 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1906 }
1907
Jim Grosbache7fbce72011-10-03 23:38:36 +00001908 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1909 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001910 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1911 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1912 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001913 }
1914
Jim Grosbach7db8d692011-09-08 22:07:06 +00001915 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1916 assert(N == 1 && "Invalid number of operands!");
1917 // FIXME: We really want to scale the value here, but the LDRD/STRD
1918 // instruction don't encode operands that way yet.
1919 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1920 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1921 }
1922
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001923 void addImm0_1020s4Operands(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 Grosbach930f2f62012-04-05 20:57:13 +00001931 void addImm0_508s4NegOperands(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 Grosbach0a0b3072011-08-24 21:22:15 +00001939 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1940 assert(N == 1 && "Invalid number of operands!");
1941 // The immediate is scaled by four in the encoding and is stored
1942 // in the MCInst as such. Lop off the low two bits here.
1943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1944 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1945 }
1946
Jim Grosbach475c6db2011-07-25 23:09:14 +00001947 void addImm1_16Operands(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 Grosbach801e0a32011-07-22 23:16:18 +00001955 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1956 assert(N == 1 && "Invalid number of operands!");
1957 // The constant encodes as the immediate-1, and we store in the instruction
1958 // the bits as encoded, so subtract off one here.
1959 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1960 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1961 }
1962
Jim Grosbach46dd4132011-08-17 21:51:27 +00001963 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1964 assert(N == 1 && "Invalid number of operands!");
1965 // The constant encodes as the immediate, except for 32, which encodes as
1966 // zero.
1967 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1968 unsigned Imm = CE->getValue();
1969 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1970 }
1971
Jim Grosbach27c1e252011-07-21 17:23:04 +00001972 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1973 assert(N == 1 && "Invalid number of operands!");
1974 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1975 // the instruction as well.
1976 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1977 int Val = CE->getValue();
1978 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1979 }
1980
Jim Grosbachb009a872011-10-28 22:36:30 +00001981 void addT2SOImmNotOperands(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 bitwise
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 Grosbach30506252011-12-08 00:31:07 +00001989 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1990 assert(N == 1 && "Invalid number of operands!");
1991 // The operand is actually a t2_so_imm, 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
Jim Grosbach930f2f62012-04-05 20:57:13 +00001997 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1998 assert(N == 1 && "Invalid number of operands!");
1999 // The operand is actually an imm0_4095, but we have its
2000 // negation in the assembly source, so twiddle it here.
2001 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2002 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
2003 }
2004
Mihai Popad36cbaa2013-07-03 09:21:44 +00002005 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
2006 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
2007 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
2008 return;
2009 }
2010
2011 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
2012 assert(SR && "Unknown value type!");
2013 Inst.addOperand(MCOperand::CreateExpr(SR));
2014 }
2015
Mihai Popa8a9da5b2013-07-22 15:49:36 +00002016 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
2017 assert(N == 1 && "Invalid number of operands!");
2018 if (isImm()) {
2019 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2020 if (CE) {
2021 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
2022 return;
2023 }
2024
2025 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
2026 assert(SR && "Unknown value type!");
2027 Inst.addOperand(MCOperand::CreateExpr(SR));
2028 return;
2029 }
2030
2031 assert(isMem() && "Unknown value type!");
2032 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
2033 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
2034 }
2035
Jim Grosbach3d785ed2011-10-28 22:50:54 +00002036 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
2037 assert(N == 1 && "Invalid number of operands!");
2038 // The operand is actually a so_imm, but we have its bitwise
2039 // negation in the assembly source, so twiddle it here.
2040 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2041 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
2042 }
2043
Jim Grosbach30506252011-12-08 00:31:07 +00002044 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
2045 assert(N == 1 && "Invalid number of operands!");
2046 // The operand is actually a so_imm, but we have its
2047 // negation in the assembly source, so twiddle it here.
2048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2049 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
2050 }
2051
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002052 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
2053 assert(N == 1 && "Invalid number of operands!");
2054 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
2055 }
2056
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002057 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
2058 assert(N == 1 && "Invalid number of operands!");
2059 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
2060 }
2061
Jim Grosbachd3595712011-08-03 23:50:40 +00002062 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
2063 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002064 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00002065 }
2066
Jim Grosbach94298a92012-01-18 22:46:46 +00002067 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
2068 assert(N == 1 && "Invalid number of operands!");
2069 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00002070 Inst.addOperand(MCOperand::CreateImm(Imm));
2071 }
2072
Jiangning Liu10dd40e2012-08-02 08:13:13 +00002073 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
2074 assert(N == 1 && "Invalid number of operands!");
2075 assert(isImm() && "Not an immediate!");
2076
2077 // If we have an immediate that's not a constant, treat it as a label
2078 // reference needing a fixup.
2079 if (!isa<MCConstantExpr>(getImm())) {
2080 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2081 return;
2082 }
2083
2084 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2085 int Val = CE->getValue();
2086 Inst.addOperand(MCOperand::CreateImm(Val));
2087 }
2088
Jim Grosbacha95ec992011-10-11 17:29:55 +00002089 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
2090 assert(N == 2 && "Invalid number of operands!");
2091 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2092 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
2093 }
2094
Kevin Enderby488f20b2014-04-10 20:18:58 +00002095 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2096 addAlignedMemoryOperands(Inst, N);
2097 }
2098
2099 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2100 addAlignedMemoryOperands(Inst, N);
2101 }
2102
2103 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2104 addAlignedMemoryOperands(Inst, N);
2105 }
2106
2107 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2108 addAlignedMemoryOperands(Inst, N);
2109 }
2110
2111 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2112 addAlignedMemoryOperands(Inst, N);
2113 }
2114
2115 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2116 addAlignedMemoryOperands(Inst, N);
2117 }
2118
2119 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2120 addAlignedMemoryOperands(Inst, N);
2121 }
2122
2123 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2124 addAlignedMemoryOperands(Inst, N);
2125 }
2126
2127 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2128 addAlignedMemoryOperands(Inst, N);
2129 }
2130
2131 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2132 addAlignedMemoryOperands(Inst, N);
2133 }
2134
2135 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
2136 addAlignedMemoryOperands(Inst, N);
2137 }
2138
Jim Grosbachd3595712011-08-03 23:50:40 +00002139 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
2140 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002141 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2142 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00002143 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2144 // Special case for #-0
2145 if (Val == INT32_MIN) Val = 0;
2146 if (Val < 0) Val = -Val;
2147 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2148 } else {
2149 // For register offset, we encode the shift type and negation flag
2150 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002151 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2152 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002153 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002154 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2155 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002156 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002157 }
2158
Jim Grosbachcd17c122011-08-04 23:01:30 +00002159 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
2160 assert(N == 2 && "Invalid number of operands!");
2161 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2162 assert(CE && "non-constant AM2OffsetImm operand!");
2163 int32_t Val = CE->getValue();
2164 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2165 // Special case for #-0
2166 if (Val == INT32_MIN) Val = 0;
2167 if (Val < 0) Val = -Val;
2168 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2169 Inst.addOperand(MCOperand::CreateReg(0));
2170 Inst.addOperand(MCOperand::CreateImm(Val));
2171 }
2172
Jim Grosbach5b96b802011-08-10 20:29:19 +00002173 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
2174 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002175 // If we have an immediate that's not a constant, treat it as a label
2176 // reference needing a fixup. If it is a constant, it's something else
2177 // and we reject it.
2178 if (isImm()) {
2179 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2180 Inst.addOperand(MCOperand::CreateReg(0));
2181 Inst.addOperand(MCOperand::CreateImm(0));
2182 return;
2183 }
2184
Jim Grosbach871dff72011-10-11 15:59:20 +00002185 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2186 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002187 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2188 // Special case for #-0
2189 if (Val == INT32_MIN) Val = 0;
2190 if (Val < 0) Val = -Val;
2191 Val = ARM_AM::getAM3Opc(AddSub, Val);
2192 } else {
2193 // For register offset, we encode the shift type and negation flag
2194 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002195 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002196 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002197 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2198 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00002199 Inst.addOperand(MCOperand::CreateImm(Val));
2200 }
2201
2202 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
2203 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002204 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002205 int32_t Val =
2206 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
2207 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2208 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002209 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00002210 }
2211
2212 // Constant offset.
2213 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2214 int32_t Val = CE->getValue();
2215 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2216 // Special case for #-0
2217 if (Val == INT32_MIN) Val = 0;
2218 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002219 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002220 Inst.addOperand(MCOperand::CreateReg(0));
2221 Inst.addOperand(MCOperand::CreateImm(Val));
2222 }
2223
Jim Grosbachd3595712011-08-03 23:50:40 +00002224 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2225 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00002226 // If we have an immediate that's not a constant, treat it as a label
2227 // reference needing a fixup. If it is a constant, it's something else
2228 // and we reject it.
2229 if (isImm()) {
2230 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2231 Inst.addOperand(MCOperand::CreateImm(0));
2232 return;
2233 }
2234
Jim Grosbachd3595712011-08-03 23:50:40 +00002235 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002236 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002237 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2238 // Special case for #-0
2239 if (Val == INT32_MIN) Val = 0;
2240 if (Val < 0) Val = -Val;
2241 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002242 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002243 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002244 }
2245
Jim Grosbach7db8d692011-09-08 22:07:06 +00002246 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2247 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002248 // If we have an immediate that's not a constant, treat it as a label
2249 // reference needing a fixup. If it is a constant, it's something else
2250 // and we reject it.
2251 if (isImm()) {
2252 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2253 Inst.addOperand(MCOperand::CreateImm(0));
2254 return;
2255 }
2256
Jim Grosbach871dff72011-10-11 15:59:20 +00002257 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2258 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002259 Inst.addOperand(MCOperand::CreateImm(Val));
2260 }
2261
Jim Grosbacha05627e2011-09-09 18:37:27 +00002262 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2263 assert(N == 2 && "Invalid number of operands!");
2264 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002265 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2266 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002267 Inst.addOperand(MCOperand::CreateImm(Val));
2268 }
2269
Jim Grosbachd3595712011-08-03 23:50:40 +00002270 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2271 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002272 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2273 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002274 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002275 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002276
Jim Grosbach2392c532011-09-07 23:39:14 +00002277 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2278 addMemImm8OffsetOperands(Inst, N);
2279 }
2280
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002281 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002282 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002283 }
2284
2285 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2286 assert(N == 2 && "Invalid number of operands!");
2287 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002288 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002289 addExpr(Inst, getImm());
2290 Inst.addOperand(MCOperand::CreateImm(0));
2291 return;
2292 }
2293
2294 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002295 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2296 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002297 Inst.addOperand(MCOperand::CreateImm(Val));
2298 }
2299
Jim Grosbachd3595712011-08-03 23:50:40 +00002300 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2301 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002302 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002303 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002304 addExpr(Inst, getImm());
2305 Inst.addOperand(MCOperand::CreateImm(0));
2306 return;
2307 }
2308
2309 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002310 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2311 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002312 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002313 }
Bill Wendling811c9362010-11-30 07:44:32 +00002314
Jim Grosbach05541f42011-09-19 22:21:13 +00002315 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2316 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002317 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2318 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002319 }
2320
2321 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2322 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002323 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2324 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002325 }
2326
Jim Grosbachd3595712011-08-03 23:50:40 +00002327 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2328 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002329 unsigned Val =
2330 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2331 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002332 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2333 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002334 Inst.addOperand(MCOperand::CreateImm(Val));
2335 }
2336
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002337 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2338 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002339 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2340 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2341 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002342 }
2343
Jim Grosbachd3595712011-08-03 23:50:40 +00002344 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2345 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002346 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2347 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002348 }
2349
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002350 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2351 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002352 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2353 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002354 Inst.addOperand(MCOperand::CreateImm(Val));
2355 }
2356
Jim Grosbach26d35872011-08-19 18:55:51 +00002357 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2358 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002359 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2360 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002361 Inst.addOperand(MCOperand::CreateImm(Val));
2362 }
2363
Jim Grosbacha32c7532011-08-19 18:49:59 +00002364 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2365 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002366 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2367 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002368 Inst.addOperand(MCOperand::CreateImm(Val));
2369 }
2370
Jim Grosbach23983d62011-08-19 18:13:48 +00002371 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2372 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002373 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2374 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002375 Inst.addOperand(MCOperand::CreateImm(Val));
2376 }
2377
Jim Grosbachd3595712011-08-03 23:50:40 +00002378 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2379 assert(N == 1 && "Invalid number of operands!");
2380 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2381 assert(CE && "non-constant post-idx-imm8 operand!");
2382 int Imm = CE->getValue();
2383 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002384 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002385 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2386 Inst.addOperand(MCOperand::CreateImm(Imm));
2387 }
2388
Jim Grosbach93981412011-10-11 21:55:36 +00002389 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2390 assert(N == 1 && "Invalid number of operands!");
2391 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2392 assert(CE && "non-constant post-idx-imm8s4 operand!");
2393 int Imm = CE->getValue();
2394 bool isAdd = Imm >= 0;
2395 if (Imm == INT32_MIN) Imm = 0;
2396 // Immediate is scaled by 4.
2397 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2398 Inst.addOperand(MCOperand::CreateImm(Imm));
2399 }
2400
Jim Grosbachd3595712011-08-03 23:50:40 +00002401 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2402 assert(N == 2 && "Invalid number of operands!");
2403 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002404 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2405 }
2406
2407 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2408 assert(N == 2 && "Invalid number of operands!");
2409 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2410 // The sign, shift type, and shift amount are encoded in a single operand
2411 // using the AM2 encoding helpers.
2412 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2413 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2414 PostIdxReg.ShiftTy);
2415 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002416 }
2417
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002418 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2419 assert(N == 1 && "Invalid number of operands!");
2420 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2421 }
2422
Tim Northoveree843ef2014-08-15 10:47:12 +00002423 void addBankedRegOperands(MCInst &Inst, unsigned N) const {
2424 assert(N == 1 && "Invalid number of operands!");
2425 Inst.addOperand(MCOperand::CreateImm(unsigned(getBankedReg())));
2426 }
2427
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002428 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2429 assert(N == 1 && "Invalid number of operands!");
2430 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2431 }
2432
Jim Grosbach182b6a02011-11-29 23:51:09 +00002433 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002434 assert(N == 1 && "Invalid number of operands!");
2435 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2436 }
2437
Jim Grosbach04945c42011-12-02 00:35:16 +00002438 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2439 assert(N == 2 && "Invalid number of operands!");
2440 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2441 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2442 }
2443
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002444 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2445 assert(N == 1 && "Invalid number of operands!");
2446 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2447 }
2448
2449 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2450 assert(N == 1 && "Invalid number of operands!");
2451 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2452 }
2453
2454 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2455 assert(N == 1 && "Invalid number of operands!");
2456 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2457 }
2458
Jim Grosbach741cd732011-10-17 22:26:03 +00002459 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2460 assert(N == 1 && "Invalid number of operands!");
2461 // The immediate encodes the type of constant as well as the value.
2462 // Mask in that this is an i8 splat.
2463 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2464 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2465 }
2466
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002467 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2468 assert(N == 1 && "Invalid number of operands!");
2469 // The immediate encodes the type of constant as well as the value.
2470 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2471 unsigned Value = CE->getValue();
Renato Golinf5dd1da2014-09-25 11:31:24 +00002472 Value = ARM_AM::encodeNEONi16splat(Value);
2473 Inst.addOperand(MCOperand::CreateImm(Value));
2474 }
2475
2476 void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const {
2477 assert(N == 1 && "Invalid number of operands!");
2478 // The immediate encodes the type of constant as well as the value.
2479 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2480 unsigned Value = CE->getValue();
2481 Value = ARM_AM::encodeNEONi16splat(~Value & 0xffff);
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002482 Inst.addOperand(MCOperand::CreateImm(Value));
2483 }
2484
Jim Grosbach8211c052011-10-18 00:22:00 +00002485 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2486 assert(N == 1 && "Invalid number of operands!");
2487 // The immediate encodes the type of constant as well as the value.
2488 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2489 unsigned Value = CE->getValue();
Renato Golinf5dd1da2014-09-25 11:31:24 +00002490 Value = ARM_AM::encodeNEONi32splat(Value);
2491 Inst.addOperand(MCOperand::CreateImm(Value));
2492 }
2493
2494 void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const {
2495 assert(N == 1 && "Invalid number of operands!");
2496 // The immediate encodes the type of constant as well as the value.
2497 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2498 unsigned Value = CE->getValue();
2499 Value = ARM_AM::encodeNEONi32splat(~Value);
Jim Grosbach8211c052011-10-18 00:22:00 +00002500 Inst.addOperand(MCOperand::CreateImm(Value));
2501 }
2502
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002503 void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const {
2504 assert(N == 1 && "Invalid number of operands!");
2505 // The immediate encodes the type of constant as well as the value.
2506 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2507 unsigned Value = CE->getValue();
2508 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2509 Inst.getOpcode() == ARM::VMOVv16i8) &&
2510 "All vmvn instructions that wants to replicate non-zero byte "
2511 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2512 unsigned B = ((~Value) & 0xff);
2513 B |= 0xe00; // cmode = 0b1110
2514 Inst.addOperand(MCOperand::CreateImm(B));
2515 }
Jim Grosbach8211c052011-10-18 00:22:00 +00002516 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2517 assert(N == 1 && "Invalid number of operands!");
2518 // The immediate encodes the type of constant as well as the value.
2519 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2520 unsigned Value = CE->getValue();
2521 if (Value >= 256 && Value <= 0xffff)
2522 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2523 else if (Value > 0xffff && Value <= 0xffffff)
2524 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2525 else if (Value > 0xffffff)
2526 Value = (Value >> 24) | 0x600;
2527 Inst.addOperand(MCOperand::CreateImm(Value));
2528 }
2529
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002530 void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const {
2531 assert(N == 1 && "Invalid number of operands!");
2532 // The immediate encodes the type of constant as well as the value.
2533 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2534 unsigned Value = CE->getValue();
2535 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2536 Inst.getOpcode() == ARM::VMOVv16i8) &&
2537 "All instructions that wants to replicate non-zero byte "
2538 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2539 unsigned B = Value & 0xff;
2540 B |= 0xe00; // cmode = 0b1110
2541 Inst.addOperand(MCOperand::CreateImm(B));
2542 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00002543 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2544 assert(N == 1 && "Invalid number of operands!");
2545 // The immediate encodes the type of constant as well as the value.
2546 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2547 unsigned Value = ~CE->getValue();
2548 if (Value >= 256 && Value <= 0xffff)
2549 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2550 else if (Value > 0xffff && Value <= 0xffffff)
2551 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2552 else if (Value > 0xffffff)
2553 Value = (Value >> 24) | 0x600;
2554 Inst.addOperand(MCOperand::CreateImm(Value));
2555 }
2556
Jim Grosbache4454e02011-10-18 16:18:11 +00002557 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2558 assert(N == 1 && "Invalid number of operands!");
2559 // The immediate encodes the type of constant as well as the value.
2560 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2561 uint64_t Value = CE->getValue();
2562 unsigned Imm = 0;
2563 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2564 Imm |= (Value & 1) << i;
2565 }
2566 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2567 }
2568
Craig Topperca7e3e52014-03-10 03:19:03 +00002569 void print(raw_ostream &OS) const override;
Daniel Dunbarebace222010-08-11 06:37:04 +00002570
David Blaikie960ea3f2014-06-08 16:18:35 +00002571 static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) {
2572 auto Op = make_unique<ARMOperand>(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002573 Op->ITMask.Mask = Mask;
2574 Op->StartLoc = S;
2575 Op->EndLoc = S;
2576 return Op;
2577 }
2578
David Blaikie960ea3f2014-06-08 16:18:35 +00002579 static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC,
2580 SMLoc S) {
2581 auto Op = make_unique<ARMOperand>(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002582 Op->CC.Val = CC;
2583 Op->StartLoc = S;
2584 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002585 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002586 }
2587
David Blaikie960ea3f2014-06-08 16:18:35 +00002588 static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) {
2589 auto Op = make_unique<ARMOperand>(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002590 Op->Cop.Val = CopVal;
2591 Op->StartLoc = S;
2592 Op->EndLoc = S;
2593 return Op;
2594 }
2595
David Blaikie960ea3f2014-06-08 16:18:35 +00002596 static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) {
2597 auto Op = make_unique<ARMOperand>(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002598 Op->Cop.Val = CopVal;
2599 Op->StartLoc = S;
2600 Op->EndLoc = S;
2601 return Op;
2602 }
2603
David Blaikie960ea3f2014-06-08 16:18:35 +00002604 static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S,
2605 SMLoc E) {
2606 auto Op = make_unique<ARMOperand>(k_CoprocOption);
Jim Grosbach48399582011-10-12 17:34:41 +00002607 Op->Cop.Val = Val;
2608 Op->StartLoc = S;
2609 Op->EndLoc = E;
2610 return Op;
2611 }
2612
David Blaikie960ea3f2014-06-08 16:18:35 +00002613 static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) {
2614 auto Op = make_unique<ARMOperand>(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002615 Op->Reg.RegNum = RegNum;
2616 Op->StartLoc = S;
2617 Op->EndLoc = S;
2618 return Op;
2619 }
2620
David Blaikie960ea3f2014-06-08 16:18:35 +00002621 static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) {
2622 auto Op = make_unique<ARMOperand>(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002623 Op->Tok.Data = Str.data();
2624 Op->Tok.Length = Str.size();
2625 Op->StartLoc = S;
2626 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002627 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002628 }
2629
David Blaikie960ea3f2014-06-08 16:18:35 +00002630 static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S,
2631 SMLoc E) {
2632 auto Op = make_unique<ARMOperand>(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002633 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002634 Op->StartLoc = S;
2635 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002636 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002637 }
2638
David Blaikie960ea3f2014-06-08 16:18:35 +00002639 static std::unique_ptr<ARMOperand>
2640 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2641 unsigned ShiftReg, unsigned ShiftImm, SMLoc S,
2642 SMLoc E) {
2643 auto Op = make_unique<ARMOperand>(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002644 Op->RegShiftedReg.ShiftTy = ShTy;
2645 Op->RegShiftedReg.SrcReg = SrcReg;
2646 Op->RegShiftedReg.ShiftReg = ShiftReg;
2647 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002648 Op->StartLoc = S;
2649 Op->EndLoc = E;
2650 return Op;
2651 }
2652
David Blaikie960ea3f2014-06-08 16:18:35 +00002653 static std::unique_ptr<ARMOperand>
2654 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2655 unsigned ShiftImm, SMLoc S, SMLoc E) {
2656 auto Op = make_unique<ARMOperand>(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002657 Op->RegShiftedImm.ShiftTy = ShTy;
2658 Op->RegShiftedImm.SrcReg = SrcReg;
2659 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002660 Op->StartLoc = S;
2661 Op->EndLoc = E;
2662 return Op;
2663 }
2664
David Blaikie960ea3f2014-06-08 16:18:35 +00002665 static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm,
2666 SMLoc S, SMLoc E) {
2667 auto Op = make_unique<ARMOperand>(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002668 Op->ShifterImm.isASR = isASR;
2669 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002670 Op->StartLoc = S;
2671 Op->EndLoc = E;
2672 return Op;
2673 }
2674
David Blaikie960ea3f2014-06-08 16:18:35 +00002675 static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S,
2676 SMLoc E) {
2677 auto Op = make_unique<ARMOperand>(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002678 Op->RotImm.Imm = Imm;
2679 Op->StartLoc = S;
2680 Op->EndLoc = E;
2681 return Op;
2682 }
2683
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00002684 static std::unique_ptr<ARMOperand> CreateModImm(unsigned Bits, unsigned Rot,
2685 SMLoc S, SMLoc E) {
2686 auto Op = make_unique<ARMOperand>(k_ModifiedImmediate);
2687 Op->ModImm.Bits = Bits;
2688 Op->ModImm.Rot = Rot;
2689 Op->StartLoc = S;
2690 Op->EndLoc = E;
2691 return Op;
2692 }
2693
David Blaikie960ea3f2014-06-08 16:18:35 +00002694 static std::unique_ptr<ARMOperand>
2695 CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) {
2696 auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002697 Op->Bitfield.LSB = LSB;
2698 Op->Bitfield.Width = Width;
2699 Op->StartLoc = S;
2700 Op->EndLoc = E;
2701 return Op;
2702 }
2703
David Blaikie960ea3f2014-06-08 16:18:35 +00002704 static std::unique_ptr<ARMOperand>
2705 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002706 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002707 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002708 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002709
Chad Rosierfa705ee2013-07-01 20:49:23 +00002710 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002711 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002712 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002713 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002714 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002715
Chad Rosierfa705ee2013-07-01 20:49:23 +00002716 // Sort based on the register encoding values.
2717 array_pod_sort(Regs.begin(), Regs.end());
2718
David Blaikie960ea3f2014-06-08 16:18:35 +00002719 auto Op = make_unique<ARMOperand>(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002720 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002721 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002722 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002723 Op->StartLoc = StartLoc;
2724 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002725 return Op;
2726 }
2727
David Blaikie960ea3f2014-06-08 16:18:35 +00002728 static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum,
2729 unsigned Count,
2730 bool isDoubleSpaced,
2731 SMLoc S, SMLoc E) {
2732 auto Op = make_unique<ARMOperand>(k_VectorList);
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002733 Op->VectorList.RegNum = RegNum;
2734 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002735 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002736 Op->StartLoc = S;
2737 Op->EndLoc = E;
2738 return Op;
2739 }
2740
David Blaikie960ea3f2014-06-08 16:18:35 +00002741 static std::unique_ptr<ARMOperand>
2742 CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced,
2743 SMLoc S, SMLoc E) {
2744 auto Op = make_unique<ARMOperand>(k_VectorListAllLanes);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002745 Op->VectorList.RegNum = RegNum;
2746 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002747 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002748 Op->StartLoc = S;
2749 Op->EndLoc = E;
2750 return Op;
2751 }
2752
David Blaikie960ea3f2014-06-08 16:18:35 +00002753 static std::unique_ptr<ARMOperand>
2754 CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index,
2755 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2756 auto Op = make_unique<ARMOperand>(k_VectorListIndexed);
Jim Grosbach04945c42011-12-02 00:35:16 +00002757 Op->VectorList.RegNum = RegNum;
2758 Op->VectorList.Count = Count;
2759 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002760 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002761 Op->StartLoc = S;
2762 Op->EndLoc = E;
2763 return Op;
2764 }
2765
David Blaikie960ea3f2014-06-08 16:18:35 +00002766 static std::unique_ptr<ARMOperand>
2767 CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) {
2768 auto Op = make_unique<ARMOperand>(k_VectorIndex);
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002769 Op->VectorIndex.Val = Idx;
2770 Op->StartLoc = S;
2771 Op->EndLoc = E;
2772 return Op;
2773 }
2774
David Blaikie960ea3f2014-06-08 16:18:35 +00002775 static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S,
2776 SMLoc E) {
2777 auto Op = make_unique<ARMOperand>(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002778 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002779 Op->StartLoc = S;
2780 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002781 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002782 }
2783
David Blaikie960ea3f2014-06-08 16:18:35 +00002784 static std::unique_ptr<ARMOperand>
2785 CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm,
2786 unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType,
2787 unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S,
2788 SMLoc E, SMLoc AlignmentLoc = SMLoc()) {
2789 auto Op = make_unique<ARMOperand>(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002790 Op->Memory.BaseRegNum = BaseRegNum;
2791 Op->Memory.OffsetImm = OffsetImm;
2792 Op->Memory.OffsetRegNum = OffsetRegNum;
2793 Op->Memory.ShiftType = ShiftType;
2794 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002795 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002796 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002797 Op->StartLoc = S;
2798 Op->EndLoc = E;
Kevin Enderby488f20b2014-04-10 20:18:58 +00002799 Op->AlignmentLoc = AlignmentLoc;
Jim Grosbachd3595712011-08-03 23:50:40 +00002800 return Op;
2801 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002802
David Blaikie960ea3f2014-06-08 16:18:35 +00002803 static std::unique_ptr<ARMOperand>
2804 CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy,
2805 unsigned ShiftImm, SMLoc S, SMLoc E) {
2806 auto Op = make_unique<ARMOperand>(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002807 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002808 Op->PostIdxReg.isAdd = isAdd;
2809 Op->PostIdxReg.ShiftTy = ShiftTy;
2810 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002811 Op->StartLoc = S;
2812 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002813 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002814 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002815
David Blaikie960ea3f2014-06-08 16:18:35 +00002816 static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt,
2817 SMLoc S) {
2818 auto Op = make_unique<ARMOperand>(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002819 Op->MBOpt.Val = Opt;
2820 Op->StartLoc = S;
2821 Op->EndLoc = S;
2822 return Op;
2823 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002824
David Blaikie960ea3f2014-06-08 16:18:35 +00002825 static std::unique_ptr<ARMOperand>
2826 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) {
2827 auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002828 Op->ISBOpt.Val = Opt;
2829 Op->StartLoc = S;
2830 Op->EndLoc = S;
2831 return Op;
2832 }
2833
David Blaikie960ea3f2014-06-08 16:18:35 +00002834 static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags,
2835 SMLoc S) {
2836 auto Op = make_unique<ARMOperand>(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002837 Op->IFlags.Val = IFlags;
2838 Op->StartLoc = S;
2839 Op->EndLoc = S;
2840 return Op;
2841 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002842
David Blaikie960ea3f2014-06-08 16:18:35 +00002843 static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) {
2844 auto Op = make_unique<ARMOperand>(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002845 Op->MMask.Val = MMask;
2846 Op->StartLoc = S;
2847 Op->EndLoc = S;
2848 return Op;
2849 }
Tim Northoveree843ef2014-08-15 10:47:12 +00002850
2851 static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) {
2852 auto Op = make_unique<ARMOperand>(k_BankedReg);
2853 Op->BankedReg.Val = Reg;
2854 Op->StartLoc = S;
2855 Op->EndLoc = S;
2856 return Op;
2857 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002858};
2859
2860} // end anonymous namespace.
2861
Jim Grosbach602aa902011-07-13 15:34:57 +00002862void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002863 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002864 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002865 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002866 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002867 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002868 OS << "<ccout " << getReg() << ">";
2869 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002870 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002871 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002872 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2873 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2874 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002875 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2876 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2877 break;
2878 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002879 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002880 OS << "<coprocessor number: " << getCoproc() << ">";
2881 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002882 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002883 OS << "<coprocessor register: " << getCoproc() << ">";
2884 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002885 case k_CoprocOption:
2886 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2887 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002888 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002889 OS << "<mask: " << getMSRMask() << ">";
2890 break;
Tim Northoveree843ef2014-08-15 10:47:12 +00002891 case k_BankedReg:
2892 OS << "<banked reg: " << getBankedReg() << ">";
2893 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002894 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002895 getImm()->print(OS);
2896 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002897 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002898 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002899 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002900 case k_InstSyncBarrierOpt:
2901 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2902 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002903 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002904 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002905 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002906 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002907 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002908 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002909 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2910 << PostIdxReg.RegNum;
2911 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2912 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2913 << PostIdxReg.ShiftImm;
2914 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002915 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002916 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002917 OS << "<ARM_PROC::";
2918 unsigned IFlags = getProcIFlags();
2919 for (int i=2; i >= 0; --i)
2920 if (IFlags & (1 << i))
2921 OS << ARM_PROC::IFlagsToString(1 << i);
2922 OS << ">";
2923 break;
2924 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002925 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002926 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002927 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002928 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002929 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2930 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002931 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002932 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002933 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002934 << RegShiftedReg.SrcReg << " "
2935 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2936 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002937 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002938 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002939 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002940 << RegShiftedImm.SrcReg << " "
2941 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2942 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002943 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002944 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002945 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2946 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00002947 case k_ModifiedImmediate:
2948 OS << "<mod_imm #" << ModImm.Bits << ", #"
2949 << ModImm.Rot << ")>";
2950 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002951 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002952 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2953 << ", width: " << Bitfield.Width << ">";
2954 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002955 case k_RegisterList:
2956 case k_DPRRegisterList:
2957 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002958 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002959
Bill Wendlingbed94652010-11-09 23:28:44 +00002960 const SmallVectorImpl<unsigned> &RegList = getRegList();
2961 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002962 I = RegList.begin(), E = RegList.end(); I != E; ) {
2963 OS << *I;
2964 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002965 }
2966
2967 OS << ">";
2968 break;
2969 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002970 case k_VectorList:
2971 OS << "<vector_list " << VectorList.Count << " * "
2972 << VectorList.RegNum << ">";
2973 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002974 case k_VectorListAllLanes:
2975 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2976 << VectorList.RegNum << ">";
2977 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002978 case k_VectorListIndexed:
2979 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2980 << VectorList.Count << " * " << VectorList.RegNum << ">";
2981 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002982 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002983 OS << "'" << getToken() << "'";
2984 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002985 case k_VectorIndex:
2986 OS << "<vectorindex " << getVectorIndex() << ">";
2987 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002988 }
2989}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002990
2991/// @name Auto-generated Match Functions
2992/// {
2993
2994static unsigned MatchRegisterName(StringRef Name);
2995
2996/// }
2997
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002998bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2999 SMLoc &StartLoc, SMLoc &EndLoc) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003000 const AsmToken &Tok = getParser().getTok();
3001 StartLoc = Tok.getLoc();
3002 EndLoc = Tok.getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003003 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00003004
3005 return (RegNo == (unsigned)-1);
3006}
3007
Kevin Enderby8be42bd2009-10-30 22:55:57 +00003008/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00003009/// and if it is a register name the token is eaten and the register number is
3010/// returned. Otherwise return -1.
3011///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003012int ARMAsmParser::tryParseRegister() {
Rafael Espindola961d4692014-11-11 05:18:41 +00003013 MCAsmParser &Parser = getParser();
Chris Lattner44e5981c2010-10-30 04:09:10 +00003014 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00003015 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00003016
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003017 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00003018 unsigned RegNum = MatchRegisterName(lowerCase);
3019 if (!RegNum) {
3020 RegNum = StringSwitch<unsigned>(lowerCase)
3021 .Case("r13", ARM::SP)
3022 .Case("r14", ARM::LR)
3023 .Case("r15", ARM::PC)
3024 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00003025 // Additional register name aliases for 'gas' compatibility.
3026 .Case("a1", ARM::R0)
3027 .Case("a2", ARM::R1)
3028 .Case("a3", ARM::R2)
3029 .Case("a4", ARM::R3)
3030 .Case("v1", ARM::R4)
3031 .Case("v2", ARM::R5)
3032 .Case("v3", ARM::R6)
3033 .Case("v4", ARM::R7)
3034 .Case("v5", ARM::R8)
3035 .Case("v6", ARM::R9)
3036 .Case("v7", ARM::R10)
3037 .Case("v8", ARM::R11)
3038 .Case("sb", ARM::R9)
3039 .Case("sl", ARM::R10)
3040 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00003041 .Default(0);
3042 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00003043 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00003044 // Check for aliases registered via .req. Canonicalize to lower case.
3045 // That's more consistent since register names are case insensitive, and
3046 // it's how the original entry was passed in from MC/MCParser/AsmParser.
3047 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00003048 // If no match, return failure.
3049 if (Entry == RegisterReqs.end())
3050 return -1;
3051 Parser.Lex(); // Eat identifier token.
3052 return Entry->getValue();
3053 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00003054
Oliver Stannard9e89d8c2014-11-05 12:06:39 +00003055 // Some FPUs only have 16 D registers, so D16-D31 are invalid
3056 if (hasD16() && RegNum >= ARM::D16 && RegNum <= ARM::D31)
3057 return -1;
3058
Chris Lattner44e5981c2010-10-30 04:09:10 +00003059 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003060
Chris Lattner44e5981c2010-10-30 04:09:10 +00003061 return RegNum;
3062}
Jim Grosbach99710a82010-11-01 16:44:21 +00003063
Jim Grosbachbb24c592011-07-13 18:49:30 +00003064// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
3065// If a recoverable error occurs, return 1. If an irrecoverable error
3066// occurs, return -1. An irrecoverable error is one where tokens have been
3067// consumed in the process of trying to parse the shifter (i.e., when it is
3068// indeed a shifter operand, but malformed).
David Blaikie960ea3f2014-06-08 16:18:35 +00003069int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003070 MCAsmParser &Parser = getParser();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003071 SMLoc S = Parser.getTok().getLoc();
3072 const AsmToken &Tok = Parser.getTok();
Kevin Enderby62873712014-02-17 21:45:27 +00003073 if (Tok.isNot(AsmToken::Identifier))
3074 return -1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003075
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003076 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003077 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00003078 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003079 .Case("lsl", ARM_AM::lsl)
3080 .Case("lsr", ARM_AM::lsr)
3081 .Case("asr", ARM_AM::asr)
3082 .Case("ror", ARM_AM::ror)
3083 .Case("rrx", ARM_AM::rrx)
3084 .Default(ARM_AM::no_shift);
3085
3086 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00003087 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003088
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003089 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003090
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003091 // The source register for the shift has already been added to the
3092 // operand list, so we need to pop it off and combine it into the shifted
3093 // register operand instead.
David Blaikie960ea3f2014-06-08 16:18:35 +00003094 std::unique_ptr<ARMOperand> PrevOp(
3095 (ARMOperand *)Operands.pop_back_val().release());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003096 if (!PrevOp->isReg())
3097 return Error(PrevOp->getStartLoc(), "shift must be of a register");
3098 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003099
3100 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003101 int64_t Imm = 0;
3102 int ShiftReg = 0;
3103 if (ShiftTy == ARM_AM::rrx) {
3104 // RRX Doesn't have an explicit shift amount. The encoder expects
3105 // the shift register to be the same as the source register. Seems odd,
3106 // but OK.
3107 ShiftReg = SrcReg;
3108 } else {
3109 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003110 if (Parser.getTok().is(AsmToken::Hash) ||
3111 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003112 Parser.Lex(); // Eat hash.
3113 SMLoc ImmLoc = Parser.getTok().getLoc();
Craig Topper062a2ba2014-04-25 05:30:21 +00003114 const MCExpr *ShiftExpr = nullptr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003115 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003116 Error(ImmLoc, "invalid immediate shift value");
3117 return -1;
3118 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003119 // The expression must be evaluatable as an immediate.
3120 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00003121 if (!CE) {
3122 Error(ImmLoc, "invalid immediate shift value");
3123 return -1;
3124 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003125 // Range check the immediate.
3126 // lsl, ror: 0 <= imm <= 31
3127 // lsr, asr: 0 <= imm <= 32
3128 Imm = CE->getValue();
3129 if (Imm < 0 ||
3130 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
3131 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003132 Error(ImmLoc, "immediate shift value out of range");
3133 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003134 }
Jim Grosbach21488b82011-12-22 17:37:00 +00003135 // shift by zero is a nop. Always send it through as lsl.
3136 // ('as' compatibility)
3137 if (Imm == 0)
3138 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003139 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003140 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003141 EndLoc = Parser.getTok().getEndLoc();
3142 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00003143 if (ShiftReg == -1) {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003144 Error(L, "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003145 return -1;
3146 }
3147 } else {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003148 Error(Parser.getTok().getLoc(),
3149 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003150 return -1;
3151 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003152 }
3153
Owen Andersonb595ed02011-07-21 18:54:16 +00003154 if (ShiftReg && ShiftTy != ARM_AM::rrx)
3155 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00003156 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003157 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00003158 else
3159 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003160 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003161
Jim Grosbachbb24c592011-07-13 18:49:30 +00003162 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003163}
3164
3165
Bill Wendling2063b842010-11-18 23:43:05 +00003166/// Try to parse a register name. The token must be an Identifier when called.
3167/// If it's a register, an AsmOperand is created. Another AsmOperand is created
3168/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00003169///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00003170/// TODO this is likely to change to allow different register types and or to
3171/// parse for a specific register type.
David Blaikie960ea3f2014-06-08 16:18:35 +00003172bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003173 MCAsmParser &Parser = getParser();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003174 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003175 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00003176 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00003177 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00003178
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003179 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
3180 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003181
Chris Lattner44e5981c2010-10-30 04:09:10 +00003182 const AsmToken &ExclaimTok = Parser.getTok();
3183 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00003184 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
3185 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00003186 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003187 return false;
3188 }
3189
3190 // Also check for an index operand. This is only legal for vector registers,
3191 // but that'll get caught OK in operand matching, so we don't need to
3192 // explicitly filter everything else out here.
3193 if (Parser.getTok().is(AsmToken::LBrac)) {
3194 SMLoc SIdx = Parser.getTok().getLoc();
3195 Parser.Lex(); // Eat left bracket token.
3196
3197 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003198 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00003199 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003200 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003201 if (!MCE)
3202 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003203
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003204 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003205 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003206
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003207 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003208 Parser.Lex(); // Eat right bracket token.
3209
3210 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
3211 SIdx, E,
3212 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00003213 }
3214
Bill Wendling2063b842010-11-18 23:43:05 +00003215 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003216}
3217
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003218/// MatchCoprocessorOperandName - Try to parse an coprocessor related
Renato Golinac561c32014-06-26 13:10:53 +00003219/// instruction with a symbolic operand name.
3220/// We accept "crN" syntax for GAS compatibility.
3221/// <operand-name> ::= <prefix><number>
3222/// If CoprocOp is 'c', then:
3223/// <prefix> ::= c | cr
3224/// If CoprocOp is 'p', then :
3225/// <prefix> ::= p
3226/// <number> ::= integer in range [0, 15]
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003227static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003228 // Use the same layout as the tablegen'erated register name matcher. Ugly,
3229 // but efficient.
Renato Golinac561c32014-06-26 13:10:53 +00003230 if (Name.size() < 2 || Name[0] != CoprocOp)
3231 return -1;
3232 Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front();
3233
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003234 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00003235 default: return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003236 case 1:
3237 switch (Name[0]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003238 default: return -1;
3239 case '0': return 0;
3240 case '1': return 1;
3241 case '2': return 2;
3242 case '3': return 3;
3243 case '4': return 4;
3244 case '5': return 5;
3245 case '6': return 6;
3246 case '7': return 7;
3247 case '8': return 8;
3248 case '9': return 9;
3249 }
Renato Golinac561c32014-06-26 13:10:53 +00003250 case 2:
3251 if (Name[0] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003252 return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003253 switch (Name[1]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003254 default: return -1;
Renato Golinbc0b0372014-08-04 23:21:56 +00003255 // CP10 and CP11 are VFP/NEON and so vector instructions should be used.
3256 // However, old cores (v5/v6) did use them in that way.
3257 case '0': return 10;
3258 case '1': return 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003259 case '2': return 12;
3260 case '3': return 13;
3261 case '4': return 14;
3262 case '5': return 15;
3263 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003264 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003265}
3266
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003267/// parseITCondCode - Try to parse a condition code for an IT instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003268ARMAsmParser::OperandMatchResultTy
3269ARMAsmParser::parseITCondCode(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003270 MCAsmParser &Parser = getParser();
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003271 SMLoc S = Parser.getTok().getLoc();
3272 const AsmToken &Tok = Parser.getTok();
3273 if (!Tok.is(AsmToken::Identifier))
3274 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00003275 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003276 .Case("eq", ARMCC::EQ)
3277 .Case("ne", ARMCC::NE)
3278 .Case("hs", ARMCC::HS)
3279 .Case("cs", ARMCC::HS)
3280 .Case("lo", ARMCC::LO)
3281 .Case("cc", ARMCC::LO)
3282 .Case("mi", ARMCC::MI)
3283 .Case("pl", ARMCC::PL)
3284 .Case("vs", ARMCC::VS)
3285 .Case("vc", ARMCC::VC)
3286 .Case("hi", ARMCC::HI)
3287 .Case("ls", ARMCC::LS)
3288 .Case("ge", ARMCC::GE)
3289 .Case("lt", ARMCC::LT)
3290 .Case("gt", ARMCC::GT)
3291 .Case("le", ARMCC::LE)
3292 .Case("al", ARMCC::AL)
3293 .Default(~0U);
3294 if (CC == ~0U)
3295 return MatchOperand_NoMatch;
3296 Parser.Lex(); // Eat the token.
3297
3298 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3299
3300 return MatchOperand_Success;
3301}
3302
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003303/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003304/// token must be an Identifier when called, and if it is a coprocessor
3305/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003306ARMAsmParser::OperandMatchResultTy
3307ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003308 MCAsmParser &Parser = getParser();
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003309 SMLoc S = Parser.getTok().getLoc();
3310 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003311 if (Tok.isNot(AsmToken::Identifier))
3312 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003313
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003314 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003315 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003316 return MatchOperand_NoMatch;
Renato Golinbc0b0372014-08-04 23:21:56 +00003317 // ARMv7 and v8 don't allow cp10/cp11 due to VFP/NEON specific instructions
3318 if ((hasV7Ops() || hasV8Ops()) && (Num == 10 || Num == 11))
3319 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003320
3321 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003322 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003323 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003324}
3325
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003326/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003327/// token must be an Identifier when called, and if it is a coprocessor
3328/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003329ARMAsmParser::OperandMatchResultTy
3330ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003331 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003332 SMLoc S = Parser.getTok().getLoc();
3333 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003334 if (Tok.isNot(AsmToken::Identifier))
3335 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003336
3337 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3338 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003339 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003340
3341 Parser.Lex(); // Eat identifier token.
3342 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003343 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003344}
3345
Jim Grosbach48399582011-10-12 17:34:41 +00003346/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3347/// coproc_option : '{' imm0_255 '}'
David Blaikie960ea3f2014-06-08 16:18:35 +00003348ARMAsmParser::OperandMatchResultTy
3349ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003350 MCAsmParser &Parser = getParser();
Jim Grosbach48399582011-10-12 17:34:41 +00003351 SMLoc S = Parser.getTok().getLoc();
3352
3353 // If this isn't a '{', this isn't a coprocessor immediate operand.
3354 if (Parser.getTok().isNot(AsmToken::LCurly))
3355 return MatchOperand_NoMatch;
3356 Parser.Lex(); // Eat the '{'
3357
3358 const MCExpr *Expr;
3359 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003360 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003361 Error(Loc, "illegal expression");
3362 return MatchOperand_ParseFail;
3363 }
3364 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3365 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3366 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3367 return MatchOperand_ParseFail;
3368 }
3369 int Val = CE->getValue();
3370
3371 // Check for and consume the closing '}'
3372 if (Parser.getTok().isNot(AsmToken::RCurly))
3373 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003374 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003375 Parser.Lex(); // Eat the '}'
3376
3377 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3378 return MatchOperand_Success;
3379}
3380
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003381// For register list parsing, we need to map from raw GPR register numbering
3382// to the enumeration values. The enumeration values aren't sorted by
3383// register number due to our using "sp", "lr" and "pc" as canonical names.
3384static unsigned getNextRegister(unsigned Reg) {
3385 // If this is a GPR, we need to do it manually, otherwise we can rely
3386 // on the sort ordering of the enumeration since the other reg-classes
3387 // are sane.
3388 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3389 return Reg + 1;
3390 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003391 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003392 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3393 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3394 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3395 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3396 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3397 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3398 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3399 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3400 }
3401}
3402
Jim Grosbach85a23432011-11-11 21:27:40 +00003403// Return the low-subreg of a given Q register.
3404static unsigned getDRegFromQReg(unsigned QReg) {
3405 switch (QReg) {
3406 default: llvm_unreachable("expected a Q register!");
3407 case ARM::Q0: return ARM::D0;
3408 case ARM::Q1: return ARM::D2;
3409 case ARM::Q2: return ARM::D4;
3410 case ARM::Q3: return ARM::D6;
3411 case ARM::Q4: return ARM::D8;
3412 case ARM::Q5: return ARM::D10;
3413 case ARM::Q6: return ARM::D12;
3414 case ARM::Q7: return ARM::D14;
3415 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003416 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003417 case ARM::Q10: return ARM::D20;
3418 case ARM::Q11: return ARM::D22;
3419 case ARM::Q12: return ARM::D24;
3420 case ARM::Q13: return ARM::D26;
3421 case ARM::Q14: return ARM::D28;
3422 case ARM::Q15: return ARM::D30;
3423 }
3424}
3425
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003426/// Parse a register list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003427bool ARMAsmParser::parseRegisterList(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003428 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00003429 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003430 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003431 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003432 Parser.Lex(); // Eat '{' token.
3433 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003434
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003435 // Check the first register in the list to see what register class
3436 // this is a list of.
3437 int Reg = tryParseRegister();
3438 if (Reg == -1)
3439 return Error(RegLoc, "register expected");
3440
Jim Grosbach85a23432011-11-11 21:27:40 +00003441 // The reglist instructions have at most 16 registers, so reserve
3442 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003443 int EReg = 0;
3444 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003445
3446 // Allow Q regs and just interpret them as the two D sub-registers.
3447 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3448 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003449 EReg = MRI->getEncodingValue(Reg);
3450 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003451 ++Reg;
3452 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003453 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003454 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3455 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3456 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3457 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3458 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3459 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3460 else
3461 return Error(RegLoc, "invalid register in register list");
3462
Jim Grosbach85a23432011-11-11 21:27:40 +00003463 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003464 EReg = MRI->getEncodingValue(Reg);
3465 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003466
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003467 // This starts immediately after the first register token in the list,
3468 // so we can see either a comma or a minus (range separator) as a legal
3469 // next token.
3470 while (Parser.getTok().is(AsmToken::Comma) ||
3471 Parser.getTok().is(AsmToken::Minus)) {
3472 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003473 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003474 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003475 int EndReg = tryParseRegister();
3476 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003477 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003478 // Allow Q regs and just interpret them as the two D sub-registers.
3479 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3480 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003481 // If the register is the same as the start reg, there's nothing
3482 // more to do.
3483 if (Reg == EndReg)
3484 continue;
3485 // The register must be in the same register class as the first.
3486 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003487 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003488 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003489 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003490 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003491
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003492 // Add all the registers in the range to the register list.
3493 while (Reg != EndReg) {
3494 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003495 EReg = MRI->getEncodingValue(Reg);
3496 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003497 }
3498 continue;
3499 }
3500 Parser.Lex(); // Eat the comma.
3501 RegLoc = Parser.getTok().getLoc();
3502 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003503 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003504 Reg = tryParseRegister();
3505 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003506 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003507 // Allow Q regs and just interpret them as the two D sub-registers.
3508 bool isQReg = false;
3509 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3510 Reg = getDRegFromQReg(Reg);
3511 isQReg = true;
3512 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003513 // The register must be in the same register class as the first.
3514 if (!RC->contains(Reg))
3515 return Error(RegLoc, "invalid register in register list");
3516 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003517 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003518 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3519 Warning(RegLoc, "register list not in ascending order");
3520 else
3521 return Error(RegLoc, "register list not in ascending order");
3522 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003523 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003524 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3525 ") in register list");
3526 continue;
3527 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003528 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003529 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3530 Reg != OldReg + 1)
3531 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003532 EReg = MRI->getEncodingValue(Reg);
3533 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3534 if (isQReg) {
3535 EReg = MRI->getEncodingValue(++Reg);
3536 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3537 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003538 }
3539
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003540 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003541 return Error(Parser.getTok().getLoc(), "'}' expected");
3542 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003543 Parser.Lex(); // Eat '}' token.
3544
Jim Grosbach18bf3632011-12-13 21:48:29 +00003545 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003546 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003547
3548 // The ARM system instruction variants for LDM/STM have a '^' token here.
3549 if (Parser.getTok().is(AsmToken::Caret)) {
3550 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3551 Parser.Lex(); // Eat '^' token.
3552 }
3553
Bill Wendling2063b842010-11-18 23:43:05 +00003554 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003555}
3556
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003557// Helper function to parse the lane index for vector lists.
3558ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003559parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003560 MCAsmParser &Parser = getParser();
Jim Grosbach04945c42011-12-02 00:35:16 +00003561 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003562 if (Parser.getTok().is(AsmToken::LBrac)) {
3563 Parser.Lex(); // Eat the '['.
3564 if (Parser.getTok().is(AsmToken::RBrac)) {
3565 // "Dn[]" is the 'all lanes' syntax.
3566 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003567 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003568 Parser.Lex(); // Eat the ']'.
3569 return MatchOperand_Success;
3570 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003571
3572 // There's an optional '#' token here. Normally there wouldn't be, but
3573 // inline assemble puts one in, and it's friendly to accept that.
3574 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003575 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003576
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003577 const MCExpr *LaneIndex;
3578 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003579 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003580 Error(Loc, "illegal expression");
3581 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003582 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003583 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3584 if (!CE) {
3585 Error(Loc, "lane index must be empty or an integer");
3586 return MatchOperand_ParseFail;
3587 }
3588 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3589 Error(Parser.getTok().getLoc(), "']' expected");
3590 return MatchOperand_ParseFail;
3591 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003592 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003593 Parser.Lex(); // Eat the ']'.
3594 int64_t Val = CE->getValue();
3595
3596 // FIXME: Make this range check context sensitive for .8, .16, .32.
3597 if (Val < 0 || Val > 7) {
3598 Error(Parser.getTok().getLoc(), "lane index out of range");
3599 return MatchOperand_ParseFail;
3600 }
3601 Index = Val;
3602 LaneKind = IndexedLane;
3603 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003604 }
3605 LaneKind = NoLanes;
3606 return MatchOperand_Success;
3607}
3608
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003609// parse a vector register list
David Blaikie960ea3f2014-06-08 16:18:35 +00003610ARMAsmParser::OperandMatchResultTy
3611ARMAsmParser::parseVectorList(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003612 MCAsmParser &Parser = getParser();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003613 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003614 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003615 SMLoc S = Parser.getTok().getLoc();
3616 // As an extension (to match gas), support a plain D register or Q register
3617 // (without encosing curly braces) as a single or double entry list,
3618 // respectively.
3619 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003620 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003621 int Reg = tryParseRegister();
3622 if (Reg == -1)
3623 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003624 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003625 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003626 if (Res != MatchOperand_Success)
3627 return Res;
3628 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003629 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003630 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003631 break;
3632 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003633 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3634 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003635 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003636 case IndexedLane:
3637 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003638 LaneIndex,
3639 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003640 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003641 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003642 return MatchOperand_Success;
3643 }
3644 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3645 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003646 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003647 if (Res != MatchOperand_Success)
3648 return Res;
3649 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003650 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003651 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003652 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003653 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003654 break;
3655 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003656 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3657 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003658 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3659 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003660 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003661 case IndexedLane:
3662 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003663 LaneIndex,
3664 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003665 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003666 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003667 return MatchOperand_Success;
3668 }
3669 Error(S, "vector register expected");
3670 return MatchOperand_ParseFail;
3671 }
3672
3673 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003674 return MatchOperand_NoMatch;
3675
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003676 Parser.Lex(); // Eat '{' token.
3677 SMLoc RegLoc = Parser.getTok().getLoc();
3678
3679 int Reg = tryParseRegister();
3680 if (Reg == -1) {
3681 Error(RegLoc, "register expected");
3682 return MatchOperand_ParseFail;
3683 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003684 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003685 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003686 unsigned FirstReg = Reg;
3687 // The list is of D registers, but we also allow Q regs and just interpret
3688 // them as the two D sub-registers.
3689 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3690 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003691 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3692 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003693 ++Reg;
3694 ++Count;
3695 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003696
3697 SMLoc E;
3698 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003699 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003700
Jim Grosbache891fe82011-11-15 23:19:15 +00003701 while (Parser.getTok().is(AsmToken::Comma) ||
3702 Parser.getTok().is(AsmToken::Minus)) {
3703 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003704 if (!Spacing)
3705 Spacing = 1; // Register range implies a single spaced list.
3706 else if (Spacing == 2) {
3707 Error(Parser.getTok().getLoc(),
3708 "sequential registers in double spaced list");
3709 return MatchOperand_ParseFail;
3710 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003711 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003712 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003713 int EndReg = tryParseRegister();
3714 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003715 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003716 return MatchOperand_ParseFail;
3717 }
3718 // Allow Q regs and just interpret them as the two D sub-registers.
3719 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3720 EndReg = getDRegFromQReg(EndReg) + 1;
3721 // If the register is the same as the start reg, there's nothing
3722 // more to do.
3723 if (Reg == EndReg)
3724 continue;
3725 // The register must be in the same register class as the first.
3726 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003727 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003728 return MatchOperand_ParseFail;
3729 }
3730 // Ranges must go from low to high.
3731 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003732 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003733 return MatchOperand_ParseFail;
3734 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003735 // Parse the lane specifier if present.
3736 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003737 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003738 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3739 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003740 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003741 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003742 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003743 return MatchOperand_ParseFail;
3744 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003745
3746 // Add all the registers in the range to the register list.
3747 Count += EndReg - Reg;
3748 Reg = EndReg;
3749 continue;
3750 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003751 Parser.Lex(); // Eat the comma.
3752 RegLoc = Parser.getTok().getLoc();
3753 int OldReg = Reg;
3754 Reg = tryParseRegister();
3755 if (Reg == -1) {
3756 Error(RegLoc, "register expected");
3757 return MatchOperand_ParseFail;
3758 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003759 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003760 // It's OK to use the enumeration values directly here rather, as the
3761 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003762 //
3763 // The list is of D registers, but we also allow Q regs and just interpret
3764 // them as the two D sub-registers.
3765 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003766 if (!Spacing)
3767 Spacing = 1; // Register range implies a single spaced list.
3768 else if (Spacing == 2) {
3769 Error(RegLoc,
3770 "invalid register in double-spaced list (must be 'D' register')");
3771 return MatchOperand_ParseFail;
3772 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003773 Reg = getDRegFromQReg(Reg);
3774 if (Reg != OldReg + 1) {
3775 Error(RegLoc, "non-contiguous register range");
3776 return MatchOperand_ParseFail;
3777 }
3778 ++Reg;
3779 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003780 // Parse the lane specifier if present.
3781 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003782 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003783 SMLoc LaneLoc = Parser.getTok().getLoc();
3784 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3785 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) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003788 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003789 return MatchOperand_ParseFail;
3790 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003791 continue;
3792 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003793 // Normal D register.
3794 // Figure out the register spacing (single or double) of the list if
3795 // we don't know it already.
3796 if (!Spacing)
3797 Spacing = 1 + (Reg == OldReg + 2);
3798
3799 // Just check that it's contiguous and keep going.
3800 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003801 Error(RegLoc, "non-contiguous register range");
3802 return MatchOperand_ParseFail;
3803 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003804 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003805 // Parse the lane specifier if present.
3806 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003807 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003808 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003809 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003810 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003811 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003812 Error(EndLoc, "mismatched lane index in register list");
3813 return MatchOperand_ParseFail;
3814 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003815 }
3816
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003817 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003818 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003819 return MatchOperand_ParseFail;
3820 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003821 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003822 Parser.Lex(); // Eat '}' token.
3823
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003824 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003825 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003826 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003827 // composite register classes.
3828 if (Count == 2) {
3829 const MCRegisterClass *RC = (Spacing == 1) ?
3830 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3831 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3832 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3833 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003834
Jim Grosbach2f50e922011-12-15 21:44:33 +00003835 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3836 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003837 break;
3838 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003839 // Two-register operands have been converted to the
3840 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003841 if (Count == 2) {
3842 const MCRegisterClass *RC = (Spacing == 1) ?
3843 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3844 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003845 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3846 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003847 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003848 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003849 S, E));
3850 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003851 case IndexedLane:
3852 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003853 LaneIndex,
3854 (Spacing == 2),
3855 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003856 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003857 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003858 return MatchOperand_Success;
3859}
3860
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003861/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003862ARMAsmParser::OperandMatchResultTy
3863ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003864 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003865 SMLoc S = Parser.getTok().getLoc();
3866 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003867 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003868
Jiangning Liu288e1af2012-08-02 08:21:27 +00003869 if (Tok.is(AsmToken::Identifier)) {
3870 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003871
Jiangning Liu288e1af2012-08-02 08:21:27 +00003872 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3873 .Case("sy", ARM_MB::SY)
3874 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003875 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003876 .Case("sh", ARM_MB::ISH)
3877 .Case("ish", ARM_MB::ISH)
3878 .Case("shst", ARM_MB::ISHST)
3879 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003880 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003881 .Case("nsh", ARM_MB::NSH)
3882 .Case("un", ARM_MB::NSH)
3883 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003884 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003885 .Case("unst", ARM_MB::NSHST)
3886 .Case("osh", ARM_MB::OSH)
3887 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003888 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003889 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003890
Joey Gouly926d3f52013-09-05 15:35:24 +00003891 // ishld, oshld, nshld and ld are only available from ARMv8.
3892 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3893 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3894 Opt = ~0U;
3895
Jiangning Liu288e1af2012-08-02 08:21:27 +00003896 if (Opt == ~0U)
3897 return MatchOperand_NoMatch;
3898
3899 Parser.Lex(); // Eat identifier token.
3900 } else if (Tok.is(AsmToken::Hash) ||
3901 Tok.is(AsmToken::Dollar) ||
3902 Tok.is(AsmToken::Integer)) {
3903 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003904 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003905 SMLoc Loc = Parser.getTok().getLoc();
3906
3907 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003908 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003909 Error(Loc, "illegal expression");
3910 return MatchOperand_ParseFail;
3911 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00003912
Jiangning Liu288e1af2012-08-02 08:21:27 +00003913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3914 if (!CE) {
3915 Error(Loc, "constant expression expected");
3916 return MatchOperand_ParseFail;
3917 }
3918
3919 int Val = CE->getValue();
3920 if (Val & ~0xf) {
3921 Error(Loc, "immediate value out of range");
3922 return MatchOperand_ParseFail;
3923 }
3924
3925 Opt = ARM_MB::RESERVED_0 + Val;
3926 } else
3927 return MatchOperand_ParseFail;
3928
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003929 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003930 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003931}
3932
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003933/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003934ARMAsmParser::OperandMatchResultTy
3935ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003936 MCAsmParser &Parser = getParser();
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003937 SMLoc S = Parser.getTok().getLoc();
3938 const AsmToken &Tok = Parser.getTok();
3939 unsigned Opt;
3940
3941 if (Tok.is(AsmToken::Identifier)) {
3942 StringRef OptStr = Tok.getString();
3943
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003944 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003945 Opt = ARM_ISB::SY;
3946 else
3947 return MatchOperand_NoMatch;
3948
3949 Parser.Lex(); // Eat identifier token.
3950 } else if (Tok.is(AsmToken::Hash) ||
3951 Tok.is(AsmToken::Dollar) ||
3952 Tok.is(AsmToken::Integer)) {
3953 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003954 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003955 SMLoc Loc = Parser.getTok().getLoc();
3956
3957 const MCExpr *ISBarrierID;
3958 if (getParser().parseExpression(ISBarrierID)) {
3959 Error(Loc, "illegal expression");
3960 return MatchOperand_ParseFail;
3961 }
3962
3963 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3964 if (!CE) {
3965 Error(Loc, "constant expression expected");
3966 return MatchOperand_ParseFail;
3967 }
3968
3969 int Val = CE->getValue();
3970 if (Val & ~0xf) {
3971 Error(Loc, "immediate value out of range");
3972 return MatchOperand_ParseFail;
3973 }
3974
3975 Opt = ARM_ISB::RESERVED_0 + Val;
3976 } else
3977 return MatchOperand_ParseFail;
3978
3979 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3980 (ARM_ISB::InstSyncBOpt)Opt, S));
3981 return MatchOperand_Success;
3982}
3983
3984
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003985/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003986ARMAsmParser::OperandMatchResultTy
3987ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003988 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003989 SMLoc S = Parser.getTok().getLoc();
3990 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003991 if (!Tok.is(AsmToken::Identifier))
3992 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003993 StringRef IFlagsStr = Tok.getString();
3994
Owen Anderson10c5b122011-10-05 17:16:40 +00003995 // An iflags string of "none" is interpreted to mean that none of the AIF
3996 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003997 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003998 if (IFlagsStr != "none") {
3999 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
4000 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
4001 .Case("a", ARM_PROC::A)
4002 .Case("i", ARM_PROC::I)
4003 .Case("f", ARM_PROC::F)
4004 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004005
Owen Anderson10c5b122011-10-05 17:16:40 +00004006 // If some specific iflag is already set, it means that some letter is
4007 // present more than once, this is not acceptable.
4008 if (Flag == ~0U || (IFlags & Flag))
4009 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004010
Owen Anderson10c5b122011-10-05 17:16:40 +00004011 IFlags |= Flag;
4012 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004013 }
4014
4015 Parser.Lex(); // Eat identifier token.
4016 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
4017 return MatchOperand_Success;
4018}
4019
Jim Grosbach2d6ef442011-07-25 20:14:50 +00004020/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00004021ARMAsmParser::OperandMatchResultTy
4022ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004023 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004024 SMLoc S = Parser.getTok().getLoc();
4025 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00004026 if (!Tok.is(AsmToken::Identifier))
4027 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004028 StringRef Mask = Tok.getString();
4029
James Molloy21efa7d2011-09-28 14:21:38 +00004030 if (isMClass()) {
4031 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00004032 std::string Name = Mask.lower();
4033 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00004034 // Note: in the documentation:
4035 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
4036 // for MSR APSR_nzcvq.
4037 // but we do make it an alias here. This is so to get the "mask encoding"
4038 // bits correct on MSR APSR writes.
4039 //
4040 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
4041 // should really only be allowed when writing a special register. Note
4042 // they get dropped in the MRS instruction reading a special register as
4043 // the SYSm field is only 8 bits.
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00004044 .Case("apsr", 0x800)
4045 .Case("apsr_nzcvq", 0x800)
4046 .Case("apsr_g", 0x400)
4047 .Case("apsr_nzcvqg", 0xc00)
4048 .Case("iapsr", 0x801)
4049 .Case("iapsr_nzcvq", 0x801)
4050 .Case("iapsr_g", 0x401)
4051 .Case("iapsr_nzcvqg", 0xc01)
4052 .Case("eapsr", 0x802)
4053 .Case("eapsr_nzcvq", 0x802)
4054 .Case("eapsr_g", 0x402)
4055 .Case("eapsr_nzcvqg", 0xc02)
4056 .Case("xpsr", 0x803)
4057 .Case("xpsr_nzcvq", 0x803)
4058 .Case("xpsr_g", 0x403)
4059 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00004060 .Case("ipsr", 0x805)
4061 .Case("epsr", 0x806)
4062 .Case("iepsr", 0x807)
4063 .Case("msp", 0x808)
4064 .Case("psp", 0x809)
4065 .Case("primask", 0x810)
4066 .Case("basepri", 0x811)
4067 .Case("basepri_max", 0x812)
4068 .Case("faultmask", 0x813)
4069 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00004070 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00004071
James Molloy21efa7d2011-09-28 14:21:38 +00004072 if (FlagsVal == ~0U)
4073 return MatchOperand_NoMatch;
4074
Renato Golin92c816c2014-09-01 11:25:07 +00004075 if (!hasThumb2DSP() && (FlagsVal & 0x400))
4076 // The _g and _nzcvqg versions are only valid if the DSP extension is
4077 // available.
4078 return MatchOperand_NoMatch;
4079
Kevin Enderby6c7279e2012-06-15 22:14:44 +00004080 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00004081 // basepri, basepri_max and faultmask only valid for V7m.
4082 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00004083
James Molloy21efa7d2011-09-28 14:21:38 +00004084 Parser.Lex(); // Eat identifier token.
4085 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4086 return MatchOperand_Success;
4087 }
4088
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004089 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
4090 size_t Start = 0, Next = Mask.find('_');
4091 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004092 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004093 if (Next != StringRef::npos)
4094 Flags = Mask.slice(Next+1, Mask.size());
4095
4096 // FlagsVal contains the complete mask:
4097 // 3-0: Mask
4098 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4099 unsigned FlagsVal = 0;
4100
4101 if (SpecReg == "apsr") {
4102 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00004103 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004104 .Case("g", 0x4) // same as CPSR_s
4105 .Case("nzcvqg", 0xc) // same as CPSR_fs
4106 .Default(~0U);
4107
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00004108 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004109 if (!Flags.empty())
4110 return MatchOperand_NoMatch;
4111 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00004112 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00004113 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004114 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00004115 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
4116 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00004117 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004118 for (int i = 0, e = Flags.size(); i != e; ++i) {
4119 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
4120 .Case("c", 1)
4121 .Case("x", 2)
4122 .Case("s", 4)
4123 .Case("f", 8)
4124 .Default(~0U);
4125
4126 // If some specific flag is already set, it means that some letter is
4127 // present more than once, this is not acceptable.
4128 if (FlagsVal == ~0U || (FlagsVal & Flag))
4129 return MatchOperand_NoMatch;
4130 FlagsVal |= Flag;
4131 }
4132 } else // No match for special register.
4133 return MatchOperand_NoMatch;
4134
Owen Anderson03a173e2011-10-21 18:43:28 +00004135 // Special register without flags is NOT equivalent to "fc" flags.
4136 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
4137 // two lines would enable gas compatibility at the expense of breaking
4138 // round-tripping.
4139 //
4140 // if (!FlagsVal)
4141 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004142
4143 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4144 if (SpecReg == "spsr")
4145 FlagsVal |= 16;
4146
4147 Parser.Lex(); // Eat identifier token.
4148 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4149 return MatchOperand_Success;
4150}
4151
Tim Northoveree843ef2014-08-15 10:47:12 +00004152/// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for
4153/// use in the MRS/MSR instructions added to support virtualization.
4154ARMAsmParser::OperandMatchResultTy
4155ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004156 MCAsmParser &Parser = getParser();
Tim Northoveree843ef2014-08-15 10:47:12 +00004157 SMLoc S = Parser.getTok().getLoc();
4158 const AsmToken &Tok = Parser.getTok();
4159 if (!Tok.is(AsmToken::Identifier))
4160 return MatchOperand_NoMatch;
4161 StringRef RegName = Tok.getString();
4162
4163 // The values here come from B9.2.3 of the ARM ARM, where bits 4-0 are SysM
4164 // and bit 5 is R.
4165 unsigned Encoding = StringSwitch<unsigned>(RegName.lower())
4166 .Case("r8_usr", 0x00)
4167 .Case("r9_usr", 0x01)
4168 .Case("r10_usr", 0x02)
4169 .Case("r11_usr", 0x03)
4170 .Case("r12_usr", 0x04)
4171 .Case("sp_usr", 0x05)
4172 .Case("lr_usr", 0x06)
4173 .Case("r8_fiq", 0x08)
4174 .Case("r9_fiq", 0x09)
4175 .Case("r10_fiq", 0x0a)
4176 .Case("r11_fiq", 0x0b)
4177 .Case("r12_fiq", 0x0c)
4178 .Case("sp_fiq", 0x0d)
4179 .Case("lr_fiq", 0x0e)
4180 .Case("lr_irq", 0x10)
4181 .Case("sp_irq", 0x11)
4182 .Case("lr_svc", 0x12)
4183 .Case("sp_svc", 0x13)
4184 .Case("lr_abt", 0x14)
4185 .Case("sp_abt", 0x15)
4186 .Case("lr_und", 0x16)
4187 .Case("sp_und", 0x17)
4188 .Case("lr_mon", 0x1c)
4189 .Case("sp_mon", 0x1d)
4190 .Case("elr_hyp", 0x1e)
4191 .Case("sp_hyp", 0x1f)
4192 .Case("spsr_fiq", 0x2e)
4193 .Case("spsr_irq", 0x30)
4194 .Case("spsr_svc", 0x32)
4195 .Case("spsr_abt", 0x34)
4196 .Case("spsr_und", 0x36)
4197 .Case("spsr_mon", 0x3c)
4198 .Case("spsr_hyp", 0x3e)
4199 .Default(~0U);
4200
4201 if (Encoding == ~0U)
4202 return MatchOperand_NoMatch;
4203
4204 Parser.Lex(); // Eat identifier token.
4205 Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S));
4206 return MatchOperand_Success;
4207}
4208
David Blaikie960ea3f2014-06-08 16:18:35 +00004209ARMAsmParser::OperandMatchResultTy
4210ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low,
4211 int High) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004212 MCAsmParser &Parser = getParser();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004213 const AsmToken &Tok = Parser.getTok();
4214 if (Tok.isNot(AsmToken::Identifier)) {
4215 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4216 return MatchOperand_ParseFail;
4217 }
4218 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004219 std::string LowerOp = Op.lower();
4220 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004221 if (ShiftName != LowerOp && ShiftName != UpperOp) {
4222 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4223 return MatchOperand_ParseFail;
4224 }
4225 Parser.Lex(); // Eat shift type token.
4226
4227 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004228 if (Parser.getTok().isNot(AsmToken::Hash) &&
4229 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004230 Error(Parser.getTok().getLoc(), "'#' expected");
4231 return MatchOperand_ParseFail;
4232 }
4233 Parser.Lex(); // Eat hash token.
4234
4235 const MCExpr *ShiftAmount;
4236 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004237 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004238 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004239 Error(Loc, "illegal expression");
4240 return MatchOperand_ParseFail;
4241 }
4242 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4243 if (!CE) {
4244 Error(Loc, "constant expression expected");
4245 return MatchOperand_ParseFail;
4246 }
4247 int Val = CE->getValue();
4248 if (Val < Low || Val > High) {
4249 Error(Loc, "immediate value out of range");
4250 return MatchOperand_ParseFail;
4251 }
4252
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004253 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00004254
4255 return MatchOperand_Success;
4256}
4257
David Blaikie960ea3f2014-06-08 16:18:35 +00004258ARMAsmParser::OperandMatchResultTy
4259ARMAsmParser::parseSetEndImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004260 MCAsmParser &Parser = getParser();
Jim Grosbach0a547702011-07-22 17:44:50 +00004261 const AsmToken &Tok = Parser.getTok();
4262 SMLoc S = Tok.getLoc();
4263 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004264 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004265 return MatchOperand_ParseFail;
4266 }
Tim Northover4d141442013-05-31 15:58:45 +00004267 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00004268 .Case("be", 1)
4269 .Case("le", 0)
4270 .Default(-1);
4271 Parser.Lex(); // Eat the token.
4272
4273 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004274 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004275 return MatchOperand_ParseFail;
4276 }
4277 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4278 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004279 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00004280 return MatchOperand_Success;
4281}
4282
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004283/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
4284/// instructions. Legal values are:
4285/// lsl #n 'n' in [0,31]
4286/// asr #n 'n' in [1,32]
4287/// n == 32 encoded as n == 0.
David Blaikie960ea3f2014-06-08 16:18:35 +00004288ARMAsmParser::OperandMatchResultTy
4289ARMAsmParser::parseShifterImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004290 MCAsmParser &Parser = getParser();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004291 const AsmToken &Tok = Parser.getTok();
4292 SMLoc S = Tok.getLoc();
4293 if (Tok.isNot(AsmToken::Identifier)) {
4294 Error(S, "shift operator 'asr' or 'lsl' expected");
4295 return MatchOperand_ParseFail;
4296 }
4297 StringRef ShiftName = Tok.getString();
4298 bool isASR;
4299 if (ShiftName == "lsl" || ShiftName == "LSL")
4300 isASR = false;
4301 else if (ShiftName == "asr" || ShiftName == "ASR")
4302 isASR = true;
4303 else {
4304 Error(S, "shift operator 'asr' or 'lsl' expected");
4305 return MatchOperand_ParseFail;
4306 }
4307 Parser.Lex(); // Eat the operator.
4308
4309 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004310 if (Parser.getTok().isNot(AsmToken::Hash) &&
4311 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004312 Error(Parser.getTok().getLoc(), "'#' expected");
4313 return MatchOperand_ParseFail;
4314 }
4315 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004316 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004317
4318 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004319 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004320 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004321 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004322 return MatchOperand_ParseFail;
4323 }
4324 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4325 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004326 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004327 return MatchOperand_ParseFail;
4328 }
4329
4330 int64_t Val = CE->getValue();
4331 if (isASR) {
4332 // Shift amount must be in [1,32]
4333 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004334 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004335 return MatchOperand_ParseFail;
4336 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00004337 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4338 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004339 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00004340 return MatchOperand_ParseFail;
4341 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004342 if (Val == 32) Val = 0;
4343 } else {
4344 // Shift amount must be in [1,32]
4345 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004346 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004347 return MatchOperand_ParseFail;
4348 }
4349 }
4350
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004351 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004352
4353 return MatchOperand_Success;
4354}
4355
Jim Grosbach833b9d32011-07-27 20:15:40 +00004356/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4357/// of instructions. Legal values are:
4358/// ror #n 'n' in {0, 8, 16, 24}
David Blaikie960ea3f2014-06-08 16:18:35 +00004359ARMAsmParser::OperandMatchResultTy
4360ARMAsmParser::parseRotImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004361 MCAsmParser &Parser = getParser();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004362 const AsmToken &Tok = Parser.getTok();
4363 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00004364 if (Tok.isNot(AsmToken::Identifier))
4365 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004366 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00004367 if (ShiftName != "ror" && ShiftName != "ROR")
4368 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004369 Parser.Lex(); // Eat the operator.
4370
4371 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004372 if (Parser.getTok().isNot(AsmToken::Hash) &&
4373 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004374 Error(Parser.getTok().getLoc(), "'#' expected");
4375 return MatchOperand_ParseFail;
4376 }
4377 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004378 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004379
4380 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004381 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004382 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004383 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004384 return MatchOperand_ParseFail;
4385 }
4386 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4387 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004388 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004389 return MatchOperand_ParseFail;
4390 }
4391
4392 int64_t Val = CE->getValue();
4393 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4394 // normally, zero is represented in asm by omitting the rotate operand
4395 // entirely.
4396 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004397 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004398 return MatchOperand_ParseFail;
4399 }
4400
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004401 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004402
4403 return MatchOperand_Success;
4404}
4405
David Blaikie960ea3f2014-06-08 16:18:35 +00004406ARMAsmParser::OperandMatchResultTy
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004407ARMAsmParser::parseModImm(OperandVector &Operands) {
4408 MCAsmParser &Parser = getParser();
4409 MCAsmLexer &Lexer = getLexer();
4410 int64_t Imm1, Imm2;
4411
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004412 SMLoc S = Parser.getTok().getLoc();
4413
Asiri Rathnayake13cef352014-12-04 19:34:59 +00004414 // 1) A mod_imm operand can appear in the place of a register name:
4415 // add r0, #mod_imm
4416 // add r0, r0, #mod_imm
4417 // to correctly handle the latter, we bail out as soon as we see an
4418 // identifier.
4419 //
4420 // 2) Similarly, we do not want to parse into complex operands:
4421 // mov r0, #mod_imm
4422 // mov r0, :lower16:(_foo)
4423 if (Parser.getTok().is(AsmToken::Identifier) ||
4424 Parser.getTok().is(AsmToken::Colon))
4425 return MatchOperand_NoMatch;
4426
4427 // Hash (dollar) is optional as per the ARMARM
4428 if (Parser.getTok().is(AsmToken::Hash) ||
4429 Parser.getTok().is(AsmToken::Dollar)) {
4430 // Avoid parsing into complex operands (#:)
4431 if (Lexer.peekTok().is(AsmToken::Colon))
4432 return MatchOperand_NoMatch;
4433
4434 // Eat the hash (dollar)
4435 Parser.Lex();
4436 }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004437
4438 SMLoc Sx1, Ex1;
4439 Sx1 = Parser.getTok().getLoc();
4440 const MCExpr *Imm1Exp;
4441 if (getParser().parseExpression(Imm1Exp, Ex1)) {
4442 Error(Sx1, "malformed expression");
4443 return MatchOperand_ParseFail;
4444 }
4445
4446 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm1Exp);
4447
4448 if (CE) {
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004449 // Immediate must fit within 32-bits
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004450 Imm1 = CE->getValue();
4451 if (Imm1 < INT32_MIN || Imm1 > UINT32_MAX) {
4452 Error(Sx1, "immediate operand must be representable with 32 bits");
4453 return MatchOperand_ParseFail;
4454 }
4455
4456 int Enc = ARM_AM::getSOImmVal(Imm1);
4457 if (Enc != -1 && Parser.getTok().is(AsmToken::EndOfStatement)) {
4458 // We have a match!
4459 Operands.push_back(ARMOperand::CreateModImm((Enc & 0xFF),
4460 (Enc & 0xF00) >> 7,
4461 Sx1, Ex1));
4462 return MatchOperand_Success;
4463 }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004464
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004465 // We have parsed an immediate which is not for us, fallback to a plain
4466 // immediate. This can happen for instruction aliases. For an example,
4467 // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform
4468 // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite
4469 // instruction with a mod_imm operand. The alias is defined such that the
4470 // parser method is shared, that's why we have to do this here.
4471 if (Parser.getTok().is(AsmToken::EndOfStatement)) {
4472 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4473 return MatchOperand_Success;
4474 }
4475 } else {
4476 // Operands like #(l1 - l2) can only be evaluated at a later stage (via an
4477 // MCFixup). Fallback to a plain immediate.
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004478 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4479 return MatchOperand_Success;
4480 }
4481
4482 // From this point onward, we expect the input to be a (#bits, #rot) pair
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004483 if (Parser.getTok().isNot(AsmToken::Comma)) {
4484 Error(Sx1, "expected modified immediate operand: #[0, 255], #even[0-30]");
4485 return MatchOperand_ParseFail;
4486 }
4487
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004488 if (Imm1 & ~0xFF) {
4489 Error(Sx1, "immediate operand must a number in the range [0, 255]");
4490 return MatchOperand_ParseFail;
4491 }
4492
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004493 // Eat the comma
4494 Parser.Lex();
4495
4496 // Repeat for #rot
4497 SMLoc Sx2, Ex2;
4498 Sx2 = Parser.getTok().getLoc();
4499
Asiri Rathnayake13cef352014-12-04 19:34:59 +00004500 // Eat the optional hash (dollar)
4501 if (Parser.getTok().is(AsmToken::Hash) ||
4502 Parser.getTok().is(AsmToken::Dollar))
4503 Parser.Lex();
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004504
4505 const MCExpr *Imm2Exp;
4506 if (getParser().parseExpression(Imm2Exp, Ex2)) {
4507 Error(Sx2, "malformed expression");
4508 return MatchOperand_ParseFail;
4509 }
4510
4511 CE = dyn_cast<MCConstantExpr>(Imm2Exp);
4512
4513 if (CE) {
4514 Imm2 = CE->getValue();
4515 if (!(Imm2 & ~0x1E)) {
4516 // We have a match!
4517 Operands.push_back(ARMOperand::CreateModImm(Imm1, Imm2, S, Ex2));
4518 return MatchOperand_Success;
4519 }
4520 Error(Sx2, "immediate operand must an even number in the range [0, 30]");
4521 return MatchOperand_ParseFail;
4522 } else {
4523 Error(Sx2, "constant expression expected");
4524 return MatchOperand_ParseFail;
4525 }
4526}
4527
4528ARMAsmParser::OperandMatchResultTy
David Blaikie960ea3f2014-06-08 16:18:35 +00004529ARMAsmParser::parseBitfield(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004530 MCAsmParser &Parser = getParser();
Jim Grosbach864b6092011-07-28 21:34:26 +00004531 SMLoc S = Parser.getTok().getLoc();
4532 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004533 if (Parser.getTok().isNot(AsmToken::Hash) &&
4534 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004535 Error(Parser.getTok().getLoc(), "'#' expected");
4536 return MatchOperand_ParseFail;
4537 }
4538 Parser.Lex(); // Eat hash token.
4539
4540 const MCExpr *LSBExpr;
4541 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004542 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004543 Error(E, "malformed immediate expression");
4544 return MatchOperand_ParseFail;
4545 }
4546 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4547 if (!CE) {
4548 Error(E, "'lsb' operand must be an immediate");
4549 return MatchOperand_ParseFail;
4550 }
4551
4552 int64_t LSB = CE->getValue();
4553 // The LSB must be in the range [0,31]
4554 if (LSB < 0 || LSB > 31) {
4555 Error(E, "'lsb' operand must be in the range [0,31]");
4556 return MatchOperand_ParseFail;
4557 }
4558 E = Parser.getTok().getLoc();
4559
4560 // Expect another immediate operand.
4561 if (Parser.getTok().isNot(AsmToken::Comma)) {
4562 Error(Parser.getTok().getLoc(), "too few operands");
4563 return MatchOperand_ParseFail;
4564 }
4565 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004566 if (Parser.getTok().isNot(AsmToken::Hash) &&
4567 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004568 Error(Parser.getTok().getLoc(), "'#' expected");
4569 return MatchOperand_ParseFail;
4570 }
4571 Parser.Lex(); // Eat hash token.
4572
4573 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004574 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004575 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004576 Error(E, "malformed immediate expression");
4577 return MatchOperand_ParseFail;
4578 }
4579 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4580 if (!CE) {
4581 Error(E, "'width' operand must be an immediate");
4582 return MatchOperand_ParseFail;
4583 }
4584
4585 int64_t Width = CE->getValue();
4586 // The LSB must be in the range [1,32-lsb]
4587 if (Width < 1 || Width > 32 - LSB) {
4588 Error(E, "'width' operand must be in the range [1,32-lsb]");
4589 return MatchOperand_ParseFail;
4590 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004591
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004592 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004593
4594 return MatchOperand_Success;
4595}
4596
David Blaikie960ea3f2014-06-08 16:18:35 +00004597ARMAsmParser::OperandMatchResultTy
4598ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
Jim Grosbachd3595712011-08-03 23:50:40 +00004599 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004600 // postidx_reg := '+' register {, shift}
4601 // | '-' register {, shift}
4602 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004603
4604 // This method must return MatchOperand_NoMatch without consuming any tokens
4605 // in the case where there is no match, as other alternatives take other
4606 // parse methods.
Rafael Espindola961d4692014-11-11 05:18:41 +00004607 MCAsmParser &Parser = getParser();
Jim Grosbachd3595712011-08-03 23:50:40 +00004608 AsmToken Tok = Parser.getTok();
4609 SMLoc S = Tok.getLoc();
4610 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004611 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004612 if (Tok.is(AsmToken::Plus)) {
4613 Parser.Lex(); // Eat the '+' token.
4614 haveEaten = true;
4615 } else if (Tok.is(AsmToken::Minus)) {
4616 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004617 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004618 haveEaten = true;
4619 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004620
4621 SMLoc E = Parser.getTok().getEndLoc();
4622 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004623 if (Reg == -1) {
4624 if (!haveEaten)
4625 return MatchOperand_NoMatch;
4626 Error(Parser.getTok().getLoc(), "register expected");
4627 return MatchOperand_ParseFail;
4628 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004629
Jim Grosbachc320c852011-08-05 21:28:30 +00004630 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4631 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004632 if (Parser.getTok().is(AsmToken::Comma)) {
4633 Parser.Lex(); // Eat the ','.
4634 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4635 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004636
4637 // FIXME: Only approximates end...may include intervening whitespace.
4638 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004639 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004640
4641 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4642 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004643
4644 return MatchOperand_Success;
4645}
4646
David Blaikie960ea3f2014-06-08 16:18:35 +00004647ARMAsmParser::OperandMatchResultTy
4648ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004649 // Check for a post-index addressing register operand. Specifically:
4650 // am3offset := '+' register
4651 // | '-' register
4652 // | register
4653 // | # imm
4654 // | # + imm
4655 // | # - imm
4656
4657 // This method must return MatchOperand_NoMatch without consuming any tokens
4658 // in the case where there is no match, as other alternatives take other
4659 // parse methods.
Rafael Espindola961d4692014-11-11 05:18:41 +00004660 MCAsmParser &Parser = getParser();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004661 AsmToken Tok = Parser.getTok();
4662 SMLoc S = Tok.getLoc();
4663
4664 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004665 if (Parser.getTok().is(AsmToken::Hash) ||
4666 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004667 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004668 // Explicitly look for a '-', as we need to encode negative zero
4669 // differently.
4670 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4671 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004672 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004673 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004674 return MatchOperand_ParseFail;
4675 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4676 if (!CE) {
4677 Error(S, "constant expression expected");
4678 return MatchOperand_ParseFail;
4679 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004680 // Negative zero is encoded as the flag value INT32_MIN.
4681 int32_t Val = CE->getValue();
4682 if (isNegative && Val == 0)
4683 Val = INT32_MIN;
4684
4685 Operands.push_back(
4686 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4687
4688 return MatchOperand_Success;
4689 }
4690
4691
4692 bool haveEaten = false;
4693 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004694 if (Tok.is(AsmToken::Plus)) {
4695 Parser.Lex(); // Eat the '+' token.
4696 haveEaten = true;
4697 } else if (Tok.is(AsmToken::Minus)) {
4698 Parser.Lex(); // Eat the '-' token.
4699 isAdd = false;
4700 haveEaten = true;
4701 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004702
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004703 Tok = Parser.getTok();
4704 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004705 if (Reg == -1) {
4706 if (!haveEaten)
4707 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004708 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004709 return MatchOperand_ParseFail;
4710 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004711
4712 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004713 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004714
4715 return MatchOperand_Success;
4716}
4717
Tim Northovereb5e4d52013-07-22 09:06:12 +00004718/// Convert parsed operands to MCInst. Needed here because this instruction
4719/// only has two register operands, but multiplication is commutative so
4720/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
David Blaikie960ea3f2014-06-08 16:18:35 +00004721void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
4722 const OperandVector &Operands) {
4723 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1);
4724 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004725 // If we have a three-operand form, make sure to set Rn to be the operand
4726 // that isn't the same as Rd.
4727 unsigned RegOp = 4;
4728 if (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00004729 ((ARMOperand &)*Operands[4]).getReg() ==
4730 ((ARMOperand &)*Operands[3]).getReg())
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004731 RegOp = 5;
David Blaikie960ea3f2014-06-08 16:18:35 +00004732 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004733 Inst.addOperand(Inst.getOperand(0));
David Blaikie960ea3f2014-06-08 16:18:35 +00004734 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004735}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004736
David Blaikie960ea3f2014-06-08 16:18:35 +00004737void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
4738 const OperandVector &Operands) {
Mihai Popaad18d3c2013-08-09 10:38:32 +00004739 int CondOp = -1, ImmOp = -1;
4740 switch(Inst.getOpcode()) {
4741 case ARM::tB:
4742 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4743
4744 case ARM::t2B:
4745 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4746
4747 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4748 }
4749 // first decide whether or not the branch should be conditional
4750 // by looking at it's location relative to an IT block
4751 if(inITBlock()) {
4752 // inside an IT block we cannot have any conditional branches. any
4753 // such instructions needs to be converted to unconditional form
4754 switch(Inst.getOpcode()) {
4755 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4756 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4757 }
4758 } else {
4759 // outside IT blocks we can only have unconditional branches with AL
4760 // condition code or conditional branches with non-AL condition code
David Blaikie960ea3f2014-06-08 16:18:35 +00004761 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode();
Mihai Popaad18d3c2013-08-09 10:38:32 +00004762 switch(Inst.getOpcode()) {
4763 case ARM::tB:
4764 case ARM::tBcc:
4765 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4766 break;
4767 case ARM::t2B:
4768 case ARM::t2Bcc:
4769 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4770 break;
4771 }
4772 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004773
Mihai Popaad18d3c2013-08-09 10:38:32 +00004774 // now decide on encoding size based on branch target range
4775 switch(Inst.getOpcode()) {
4776 // classify tB as either t2B or t1B based on range of immediate operand
4777 case ARM::tB: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004778 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4779 if (!op.isSignedOffset<11, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004780 Inst.setOpcode(ARM::t2B);
4781 break;
4782 }
4783 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4784 case ARM::tBcc: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004785 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4786 if (!op.isSignedOffset<8, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004787 Inst.setOpcode(ARM::t2Bcc);
4788 break;
4789 }
4790 }
David Blaikie960ea3f2014-06-08 16:18:35 +00004791 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1);
4792 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2);
Mihai Popaad18d3c2013-08-09 10:38:32 +00004793}
4794
Bill Wendlinge18980a2010-11-06 22:36:58 +00004795/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004796/// or an error. The first token must be a '[' when called.
David Blaikie960ea3f2014-06-08 16:18:35 +00004797bool ARMAsmParser::parseMemory(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004798 MCAsmParser &Parser = getParser();
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004799 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004800 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004801 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004802 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004803 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004804
Sean Callanan936b0d32010-01-19 21:44:56 +00004805 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004806 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004807 if (BaseRegNum == -1)
4808 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004809
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004810 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004811 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004812 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4813 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004814 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004815
Jim Grosbachd3595712011-08-03 23:50:40 +00004816 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004817 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004818 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004819
Craig Topper062a2ba2014-04-25 05:30:21 +00004820 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4821 ARM_AM::no_shift, 0, 0, false,
4822 S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004823
Jim Grosbach40700e02011-09-19 18:42:21 +00004824 // If there's a pre-indexing writeback marker, '!', just add it as a token
4825 // operand. It's rather odd, but syntactically valid.
4826 if (Parser.getTok().is(AsmToken::Exclaim)) {
4827 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4828 Parser.Lex(); // Eat the '!'.
4829 }
4830
Jim Grosbachd3595712011-08-03 23:50:40 +00004831 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004832 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004833
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004834 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4835 "Lost colon or comma in memory operand?!");
4836 if (Tok.is(AsmToken::Comma)) {
4837 Parser.Lex(); // Eat the comma.
4838 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004839
Jim Grosbacha95ec992011-10-11 17:29:55 +00004840 // If we have a ':', it's an alignment specifier.
4841 if (Parser.getTok().is(AsmToken::Colon)) {
4842 Parser.Lex(); // Eat the ':'.
4843 E = Parser.getTok().getLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00004844 SMLoc AlignmentLoc = Tok.getLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004845
4846 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004847 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004848 return true;
4849
4850 // The expression has to be a constant. Memory references with relocations
4851 // don't come through here, as they use the <label> forms of the relevant
4852 // instructions.
4853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4854 if (!CE)
4855 return Error (E, "constant expression expected");
4856
4857 unsigned Align = 0;
4858 switch (CE->getValue()) {
4859 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004860 return Error(E,
4861 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4862 case 16: Align = 2; break;
4863 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004864 case 64: Align = 8; break;
4865 case 128: Align = 16; break;
4866 case 256: Align = 32; break;
4867 }
4868
4869 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004870 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004871 return Error(Parser.getTok().getLoc(), "']' expected");
4872 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004873 Parser.Lex(); // Eat right bracket token.
4874
4875 // Don't worry about range checking the value here. That's handled by
4876 // the is*() predicates.
Craig Topper062a2ba2014-04-25 05:30:21 +00004877 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004878 ARM_AM::no_shift, 0, Align,
Kevin Enderby488f20b2014-04-10 20:18:58 +00004879 false, S, E, AlignmentLoc));
Jim Grosbacha95ec992011-10-11 17:29:55 +00004880
4881 // If there's a pre-indexing writeback marker, '!', just add it as a token
4882 // operand.
4883 if (Parser.getTok().is(AsmToken::Exclaim)) {
4884 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4885 Parser.Lex(); // Eat the '!'.
4886 }
4887
4888 return false;
4889 }
4890
4891 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004892 // offset. Be friendly and also accept a plain integer (without a leading
4893 // hash) for gas compatibility.
4894 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004895 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004896 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004897 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004898 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004899 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004900
Owen Anderson967674d2011-08-29 19:36:44 +00004901 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004902 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004903 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004904 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004905
4906 // The expression has to be a constant. Memory references with relocations
4907 // don't come through here, as they use the <label> forms of the relevant
4908 // instructions.
4909 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4910 if (!CE)
4911 return Error (E, "constant expression expected");
4912
Owen Anderson967674d2011-08-29 19:36:44 +00004913 // If the constant was #-0, represent it as INT32_MIN.
4914 int32_t Val = CE->getValue();
4915 if (isNegative && Val == 0)
4916 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4917
Jim Grosbachd3595712011-08-03 23:50:40 +00004918 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004919 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004920 return Error(Parser.getTok().getLoc(), "']' expected");
4921 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004922 Parser.Lex(); // Eat right bracket token.
4923
4924 // Don't worry about range checking the value here. That's handled by
4925 // the is*() predicates.
4926 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004927 ARM_AM::no_shift, 0, 0,
4928 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004929
4930 // If there's a pre-indexing writeback marker, '!', just add it as a token
4931 // operand.
4932 if (Parser.getTok().is(AsmToken::Exclaim)) {
4933 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4934 Parser.Lex(); // Eat the '!'.
4935 }
4936
4937 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004938 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004939
4940 // The register offset is optionally preceded by a '+' or '-'
4941 bool isNegative = false;
4942 if (Parser.getTok().is(AsmToken::Minus)) {
4943 isNegative = true;
4944 Parser.Lex(); // Eat the '-'.
4945 } else if (Parser.getTok().is(AsmToken::Plus)) {
4946 // Nothing to do.
4947 Parser.Lex(); // Eat the '+'.
4948 }
4949
4950 E = Parser.getTok().getLoc();
4951 int OffsetRegNum = tryParseRegister();
4952 if (OffsetRegNum == -1)
4953 return Error(E, "register expected");
4954
4955 // If there's a shift operator, handle it.
4956 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004957 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004958 if (Parser.getTok().is(AsmToken::Comma)) {
4959 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004960 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004961 return true;
4962 }
4963
4964 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004965 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004966 return Error(Parser.getTok().getLoc(), "']' expected");
4967 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004968 Parser.Lex(); // Eat right bracket token.
4969
Craig Topper062a2ba2014-04-25 05:30:21 +00004970 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004971 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004972 S, E));
4973
Jim Grosbachc320c852011-08-05 21:28:30 +00004974 // If there's a pre-indexing writeback marker, '!', just add it as a token
4975 // operand.
4976 if (Parser.getTok().is(AsmToken::Exclaim)) {
4977 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4978 Parser.Lex(); // Eat the '!'.
4979 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004980
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004981 return false;
4982}
4983
Jim Grosbachd3595712011-08-03 23:50:40 +00004984/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004985/// ( lsl | lsr | asr | ror ) , # shift_amount
4986/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004987/// return true if it parses a shift otherwise it returns false.
4988bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4989 unsigned &Amount) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004990 MCAsmParser &Parser = getParser();
Jim Grosbachd3595712011-08-03 23:50:40 +00004991 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004992 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004993 if (Tok.isNot(AsmToken::Identifier))
4994 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004995 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004996 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4997 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004998 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004999 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00005000 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005001 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00005002 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005003 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00005004 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005005 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00005006 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005007 else
Jim Grosbachd3595712011-08-03 23:50:40 +00005008 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00005009 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005010
Jim Grosbachd3595712011-08-03 23:50:40 +00005011 // rrx stands alone.
5012 Amount = 0;
5013 if (St != ARM_AM::rrx) {
5014 Loc = Parser.getTok().getLoc();
5015 // A '#' and a shift amount.
5016 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005017 if (HashTok.isNot(AsmToken::Hash) &&
5018 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00005019 return Error(HashTok.getLoc(), "'#' expected");
5020 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005021
Jim Grosbachd3595712011-08-03 23:50:40 +00005022 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005023 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00005024 return true;
5025 // Range check the immediate.
5026 // lsl, ror: 0 <= imm <= 31
5027 // lsr, asr: 0 <= imm <= 32
5028 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
5029 if (!CE)
5030 return Error(Loc, "shift amount must be an immediate");
5031 int64_t Imm = CE->getValue();
5032 if (Imm < 0 ||
5033 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
5034 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
5035 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00005036 // If <ShiftTy> #0, turn it into a no_shift.
5037 if (Imm == 0)
5038 St = ARM_AM::lsl;
5039 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
5040 if (Imm == 32)
5041 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00005042 Amount = Imm;
5043 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005044
5045 return false;
5046}
5047
Jim Grosbache7fbce72011-10-03 23:38:36 +00005048/// parseFPImm - A floating point immediate expression operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005049ARMAsmParser::OperandMatchResultTy
5050ARMAsmParser::parseFPImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005051 MCAsmParser &Parser = getParser();
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005052 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005053 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005054 // integer only.
5055 //
5056 // This routine still creates a generic Immediate operand, containing
5057 // a bitcast of the 64-bit floating point value. The various operands
5058 // that accept floats can check whether the value is valid for them
5059 // via the standard is*() predicates.
5060
Jim Grosbache7fbce72011-10-03 23:38:36 +00005061 SMLoc S = Parser.getTok().getLoc();
5062
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005063 if (Parser.getTok().isNot(AsmToken::Hash) &&
5064 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00005065 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00005066
5067 // Disambiguate the VMOV forms that can accept an FP immediate.
5068 // vmov.f32 <sreg>, #imm
5069 // vmov.f64 <dreg>, #imm
5070 // vmov.f32 <dreg>, #imm @ vector f32x2
5071 // vmov.f32 <qreg>, #imm @ vector f32x4
5072 //
5073 // There are also the NEON VMOV instructions which expect an
5074 // integer constant. Make sure we don't try to parse an FPImm
5075 // for these:
5076 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
David Blaikie960ea3f2014-06-08 16:18:35 +00005077 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]);
5078 bool isVmovf = TyOp.isToken() &&
5079 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64");
5080 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
5081 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
5082 Mnemonic.getToken() == "fconsts");
David Peixottoa872e0e2014-01-07 18:19:23 +00005083 if (!(isVmovf || isFconst))
Jim Grosbach741cd732011-10-17 22:26:03 +00005084 return MatchOperand_NoMatch;
5085
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00005086 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00005087
5088 // Handle negation, as that still comes through as a separate token.
5089 bool isNegative = false;
5090 if (Parser.getTok().is(AsmToken::Minus)) {
5091 isNegative = true;
5092 Parser.Lex();
5093 }
5094 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00005095 SMLoc Loc = Tok.getLoc();
David Peixottoa872e0e2014-01-07 18:19:23 +00005096 if (Tok.is(AsmToken::Real) && isVmovf) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005097 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00005098 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
5099 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005100 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00005101 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005102 Operands.push_back(ARMOperand::CreateImm(
5103 MCConstantExpr::Create(IntVal, getContext()),
5104 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00005105 return MatchOperand_Success;
5106 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005107 // Also handle plain integers. Instructions which allow floating point
5108 // immediates also allow a raw encoded 8-bit value.
David Peixottoa872e0e2014-01-07 18:19:23 +00005109 if (Tok.is(AsmToken::Integer) && isFconst) {
Jim Grosbache7fbce72011-10-03 23:38:36 +00005110 int64_t Val = Tok.getIntVal();
5111 Parser.Lex(); // Eat the token.
5112 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00005113 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00005114 return MatchOperand_ParseFail;
5115 }
David Peixottoa872e0e2014-01-07 18:19:23 +00005116 float RealVal = ARM_AM::getFPImmFloat(Val);
5117 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
5118
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005119 Operands.push_back(ARMOperand::CreateImm(
5120 MCConstantExpr::Create(Val, getContext()), S,
5121 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00005122 return MatchOperand_Success;
5123 }
5124
Jim Grosbach235c8d22012-01-19 02:47:30 +00005125 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00005126 return MatchOperand_ParseFail;
5127}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005128
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005129/// Parse a arm instruction operand. For now this parses the operand regardless
5130/// of the mnemonic.
David Blaikie960ea3f2014-06-08 16:18:35 +00005131bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005132 MCAsmParser &Parser = getParser();
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005133 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005134
5135 // Check if the current operand has a custom associated parser, if so, try to
5136 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00005137 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
5138 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005139 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00005140 // If there wasn't a custom match, try the generic matcher below. Otherwise,
5141 // there was a match, but an error occurred, in which case, just return that
5142 // the operand parsing failed.
5143 if (ResTy == MatchOperand_ParseFail)
5144 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005145
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005146 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005147 default:
5148 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00005149 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00005150 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00005151 // If we've seen a branch mnemonic, the next operand must be a label. This
5152 // is true even if the label is a register name. So "br r1" means branch to
5153 // label "r1".
5154 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
5155 if (!ExpectLabel) {
5156 if (!tryParseRegisterWithWriteBack(Operands))
5157 return false;
5158 int Res = tryParseShiftRegister(Operands);
5159 if (Res == 0) // success
5160 return false;
5161 else if (Res == -1) // irrecoverable error
5162 return true;
5163 // If this is VMRS, check for the apsr_nzcv operand.
5164 if (Mnemonic == "vmrs" &&
5165 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
5166 S = Parser.getTok().getLoc();
5167 Parser.Lex();
5168 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
5169 return false;
5170 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00005171 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00005172
5173 // Fall though for the Identifier case that is not a register or a
5174 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00005175 }
Jim Grosbach4e380352011-10-26 21:14:08 +00005176 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00005177 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00005178 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00005179 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00005180 // This was not a register so parse other operands that start with an
5181 // identifier (like labels) as expressions and create them as immediates.
5182 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005183 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005184 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00005185 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005186 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00005187 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
5188 return false;
5189 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005190 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005191 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00005192 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005193 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005194 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00005195 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00005196 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005197 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00005198 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00005199
5200 if (Parser.getTok().isNot(AsmToken::Colon)) {
5201 bool isNegative = Parser.getTok().is(AsmToken::Minus);
5202 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005203 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00005204 return true;
5205 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
5206 if (CE) {
5207 int32_t Val = CE->getValue();
5208 if (isNegative && Val == 0)
5209 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
5210 }
5211 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5212 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00005213
5214 // There can be a trailing '!' on operands that we want as a separate
Saleem Abdulrasool83e37702013-12-28 03:07:12 +00005215 // '!' Token operand. Handle that here. For example, the compatibility
Jim Grosbach9be2d712013-02-23 00:52:09 +00005216 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
5217 if (Parser.getTok().is(AsmToken::Exclaim)) {
5218 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
5219 Parser.getTok().getLoc()));
5220 Parser.Lex(); // Eat exclaim token
5221 }
Jim Grosbach003607f2012-04-16 21:18:46 +00005222 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00005223 }
Jim Grosbach003607f2012-04-16 21:18:46 +00005224 // w/ a ':' after the '#', it's just like a plain ':'.
5225 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00005226 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005227 case AsmToken::Colon: {
5228 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00005229 // FIXME: Check it's an expression prefix,
5230 // e.g. (FOO - :lower16:BAR) isn't legal.
5231 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005232 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00005233 return true;
5234
Evan Cheng965b3c72011-01-13 07:58:56 +00005235 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005236 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00005237 return true;
5238
Evan Cheng965b3c72011-01-13 07:58:56 +00005239 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00005240 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00005241 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00005242 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00005243 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005244 }
David Peixottoe407d092013-12-19 18:12:36 +00005245 case AsmToken::Equal: {
5246 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
5247 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
5248
David Peixottoe407d092013-12-19 18:12:36 +00005249 Parser.Lex(); // Eat '='
5250 const MCExpr *SubExprVal;
5251 if (getParser().parseExpression(SubExprVal))
5252 return true;
5253 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5254
David Peixottob9b73622014-02-04 17:22:40 +00005255 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
David Peixottoe407d092013-12-19 18:12:36 +00005256 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
5257 return false;
5258 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005259 }
5260}
5261
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005262// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00005263// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005264bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005265 MCAsmParser &Parser = getParser();
Evan Cheng965b3c72011-01-13 07:58:56 +00005266 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005267
Saleem Abdulrasool435f4562014-01-10 04:38:40 +00005268 // consume an optional '#' (GNU compatibility)
5269 if (getLexer().is(AsmToken::Hash))
5270 Parser.Lex();
5271
Jason W Kim1f7bc072011-01-11 23:53:41 +00005272 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00005273 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00005274 Parser.Lex(); // Eat ':'
5275
5276 if (getLexer().isNot(AsmToken::Identifier)) {
5277 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
5278 return true;
5279 }
5280
5281 StringRef IDVal = Parser.getTok().getIdentifier();
5282 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00005283 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005284 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00005285 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005286 } else {
5287 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
5288 return true;
5289 }
5290 Parser.Lex();
5291
5292 if (getLexer().isNot(AsmToken::Colon)) {
5293 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
5294 return true;
5295 }
5296 Parser.Lex(); // Eat the last ':'
5297 return false;
5298}
5299
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005300/// \brief Given a mnemonic, split out possible predication code and carry
5301/// setting letters to form a canonical mnemonic and flags.
5302//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005303// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005304// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005305StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005306 unsigned &PredicationCode,
5307 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005308 unsigned &ProcessorIMod,
5309 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005310 PredicationCode = ARMCC::AL;
5311 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005312 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005313
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005314 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005315 //
5316 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005317 if ((Mnemonic == "movs" && isThumb()) ||
5318 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
5319 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
5320 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
5321 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00005322 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005323 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
5324 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00005325 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00005326 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005327 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
5328 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
Charlie Turner4d88ae22014-12-01 08:33:28 +00005329 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic == "hvc" ||
5330 Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005331 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005332
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005333 // First, split out any predication code. Ignore mnemonics we know aren't
5334 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00005335 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00005336 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00005337 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00005338 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005339 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
5340 .Case("eq", ARMCC::EQ)
5341 .Case("ne", ARMCC::NE)
5342 .Case("hs", ARMCC::HS)
5343 .Case("cs", ARMCC::HS)
5344 .Case("lo", ARMCC::LO)
5345 .Case("cc", ARMCC::LO)
5346 .Case("mi", ARMCC::MI)
5347 .Case("pl", ARMCC::PL)
5348 .Case("vs", ARMCC::VS)
5349 .Case("vc", ARMCC::VC)
5350 .Case("hi", ARMCC::HI)
5351 .Case("ls", ARMCC::LS)
5352 .Case("ge", ARMCC::GE)
5353 .Case("lt", ARMCC::LT)
5354 .Case("gt", ARMCC::GT)
5355 .Case("le", ARMCC::LE)
5356 .Case("al", ARMCC::AL)
5357 .Default(~0U);
5358 if (CC != ~0U) {
5359 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
5360 PredicationCode = CC;
5361 }
Bill Wendling193961b2010-10-29 23:50:21 +00005362 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005363
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005364 // Next, determine if we have a carry setting bit. We explicitly ignore all
5365 // the instructions we know end in 's'.
5366 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00005367 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005368 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
5369 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
5370 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00005371 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00005372 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00005373 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00005374 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
David Peixottoa872e0e2014-01-07 18:19:23 +00005375 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00005376 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005377 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
5378 CarrySetting = true;
5379 }
5380
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005381 // The "cps" instruction can have a interrupt mode operand which is glued into
5382 // the mnemonic. Check if this is the case, split it and parse the imod op
5383 if (Mnemonic.startswith("cps")) {
5384 // Split out any imod code.
5385 unsigned IMod =
5386 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
5387 .Case("ie", ARM_PROC::IE)
5388 .Case("id", ARM_PROC::ID)
5389 .Default(~0U);
5390 if (IMod != ~0U) {
5391 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5392 ProcessorIMod = IMod;
5393 }
5394 }
5395
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005396 // The "it" instruction has the condition mask on the end of the mnemonic.
5397 if (Mnemonic.startswith("it")) {
5398 ITMask = Mnemonic.slice(2, Mnemonic.size());
5399 Mnemonic = Mnemonic.slice(0, 2);
5400 }
5401
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005402 return Mnemonic;
5403}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005404
5405/// \brief Given a canonical mnemonic, determine if the instruction ever allows
5406/// inclusion of carry set or predication code operands.
5407//
5408// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00005409void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00005410getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5411 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005412 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5413 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005414 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005415 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005416 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005417 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005418 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00005419 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005420 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005421 Mnemonic == "mla" || Mnemonic == "smlal" ||
5422 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005423 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00005424 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00005425 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005426
Tim Northover2c45a382013-06-26 16:52:40 +00005427 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5428 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00005429 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
5430 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
5431 Mnemonic.startswith("vsel") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00005432 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005433 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
5434 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Charlie Turner4d88ae22014-12-01 08:33:28 +00005435 Mnemonic == "vrintm" || Mnemonic.startswith("aes") || Mnemonic == "hvc" ||
Amara Emerson33089092013-09-19 11:59:01 +00005436 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5437 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00005438 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005439 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005440 } else if (!isThumb()) {
5441 // Some instructions are only predicable in Thumb mode
5442 CanAcceptPredicationCode
5443 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5444 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5445 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5446 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5447 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5448 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5449 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5450 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00005451 if (hasV6MOps())
5452 CanAcceptPredicationCode = Mnemonic != "movs";
5453 else
5454 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005455 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005456 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005457}
5458
Jim Grosbach7283da92011-08-16 21:12:37 +00005459bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
David Blaikie960ea3f2014-06-08 16:18:35 +00005460 OperandVector &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005461 // FIXME: This is all horribly hacky. We really need a better way to deal
5462 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005463
5464 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5465 // another does not. Specifically, the MOVW instruction does not. So we
5466 // special case it here and remove the defaulted (non-setting) cc_out
5467 // operand if that's the instruction we're trying to match.
5468 //
5469 // We do this as post-processing of the explicit operands rather than just
5470 // conditionally adding the cc_out in the first place because we need
5471 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005472 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005473 !static_cast<ARMOperand &>(*Operands[4]).isARMSOImm() &&
5474 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
5475 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach7283da92011-08-16 21:12:37 +00005476 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005477
5478 // Register-register 'add' for thumb does not have a cc_out operand
5479 // when there are only two register operands.
5480 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005481 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5482 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5483 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005484 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005485 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005486 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5487 // have to check the immediate range here since Thumb2 has a variant
5488 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005489 if (((isThumb() && Mnemonic == "add") ||
5490 (isThumbTwo() && Mnemonic == "sub")) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005491 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5492 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5493 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
5494 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5495 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
5496 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005497 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005498 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5499 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005500 // selecting via the generic "add" mnemonic, so to know that we
5501 // should remove the cc_out operand, we have to explicitly check that
5502 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005503 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005504 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5505 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5506 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005507 // Nest conditions rather than one big 'if' statement for readability.
5508 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005509 // If both registers are low, we're in an IT block, and the immediate is
5510 // in range, we should use encoding T1 instead, which has a cc_out.
5511 if (inITBlock() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005512 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
5513 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
5514 static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005515 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005516 // Check against T3. If the second register is the PC, this is an
5517 // alternate form of ADR, which uses encoding T4, so check for that too.
David Blaikie960ea3f2014-06-08 16:18:35 +00005518 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
5519 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm())
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005520 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005521
5522 // Otherwise, we use encoding T4, which does not have a cc_out
5523 // operand.
5524 return true;
5525 }
5526
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005527 // The thumb2 multiply instruction doesn't have a CCOut register, so
5528 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5529 // use the 16-bit encoding or not.
5530 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005531 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5532 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5533 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5534 static_cast<ARMOperand &>(*Operands[5]).isReg() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005535 // If the registers aren't low regs, the destination reg isn't the
5536 // same as one of the source regs, or the cc_out operand is zero
5537 // outside of an IT block, we have to use the 32-bit encoding, so
5538 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005539 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5540 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5541 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
5542 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5543 static_cast<ARMOperand &>(*Operands[5]).getReg() &&
5544 static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5545 static_cast<ARMOperand &>(*Operands[4]).getReg())))
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005546 return true;
5547
Jim Grosbachefa7e952011-11-15 19:55:16 +00005548 // Also check the 'mul' syntax variant that doesn't specify an explicit
5549 // destination register.
5550 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005551 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5552 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5553 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
Jim Grosbachefa7e952011-11-15 19:55:16 +00005554 // If the registers aren't low regs or the cc_out operand is zero
5555 // outside of an IT block, we have to use the 32-bit encoding, so
5556 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005557 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5558 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
Jim Grosbachefa7e952011-11-15 19:55:16 +00005559 !inITBlock()))
5560 return true;
5561
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005562
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005563
Jim Grosbach4b701af2011-08-24 21:42:27 +00005564 // Register-register 'add/sub' for thumb does not have a cc_out operand
5565 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5566 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5567 // right, this will result in better diagnostics (which operand is off)
5568 // anyway.
5569 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5570 (Operands.size() == 5 || Operands.size() == 6) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005571 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5572 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
5573 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5574 (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005575 (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005576 static_cast<ARMOperand &>(*Operands[5]).isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005577 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005578
Jim Grosbach7283da92011-08-16 21:12:37 +00005579 return false;
5580}
5581
David Blaikie960ea3f2014-06-08 16:18:35 +00005582bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
5583 OperandVector &Operands) {
Joey Goulye8602552013-07-19 16:34:16 +00005584 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5585 unsigned RegIdx = 3;
5586 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005587 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") {
5588 if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5589 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32")
Joey Goulye8602552013-07-19 16:34:16 +00005590 RegIdx = 4;
5591
David Blaikie960ea3f2014-06-08 16:18:35 +00005592 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
5593 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
5594 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
5595 ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
5596 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
Joey Goulye8602552013-07-19 16:34:16 +00005597 return true;
5598 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005599 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005600}
5601
Jim Grosbach12952fe2011-11-11 23:08:10 +00005602static bool isDataTypeToken(StringRef Tok) {
5603 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5604 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5605 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5606 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5607 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5608 Tok == ".f" || Tok == ".d";
5609}
5610
5611// FIXME: This bit should probably be handled via an explicit match class
5612// in the .td files that matches the suffix instead of having it be
5613// a literal string token the way it is now.
5614static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5615 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5616}
Tim Northover26bb14e2014-08-18 11:49:42 +00005617static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features,
Chad Rosier9f7a2212013-04-18 22:35:36 +00005618 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005619
5620static bool RequiresVFPRegListValidation(StringRef Inst,
5621 bool &AcceptSinglePrecisionOnly,
5622 bool &AcceptDoublePrecisionOnly) {
5623 if (Inst.size() < 7)
5624 return false;
5625
5626 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5627 StringRef AddressingMode = Inst.substr(4, 2);
5628 if (AddressingMode == "ia" || AddressingMode == "db" ||
5629 AddressingMode == "ea" || AddressingMode == "fd") {
5630 AcceptSinglePrecisionOnly = Inst[6] == 's';
5631 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5632 return true;
5633 }
5634 }
5635
5636 return false;
5637}
5638
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005639/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005640bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
David Blaikie960ea3f2014-06-08 16:18:35 +00005641 SMLoc NameLoc, OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005642 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005643 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005644 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005645 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005646 bool AcceptDoublePrecisionOnly;
5647 RequireVFPRegisterListCheck =
5648 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5649 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005650
Jim Grosbach8be2f652011-12-09 23:34:09 +00005651 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005652 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005653 // The generic tblgen'erated code does this later, at the start of
5654 // MatchInstructionImpl(), but that's too late for aliases that include
5655 // any sort of suffix.
Tim Northover26bb14e2014-08-18 11:49:42 +00005656 uint64_t AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005657 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5658 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005659
Jim Grosbachab5830e2011-12-14 02:16:11 +00005660 // First check for the ARM-specific .req directive.
5661 if (Parser.getTok().is(AsmToken::Identifier) &&
5662 Parser.getTok().getIdentifier() == ".req") {
5663 parseDirectiveReq(Name, NameLoc);
5664 // We always return 'error' for this, as we're done with this
5665 // statement and don't need to match the 'instruction."
5666 return true;
5667 }
5668
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005669 // Create the leading tokens for the mnemonic, split by '.' characters.
5670 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005671 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005672
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005673 // Split out the predication code and carry setting flag from the mnemonic.
5674 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005675 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005676 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005677 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005678 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005679 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005680
Jim Grosbach1c171b12011-08-25 17:23:55 +00005681 // In Thumb1, only the branch (B) instruction can be predicated.
5682 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005683 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005684 return Error(NameLoc, "conditional execution not supported in Thumb1");
5685 }
5686
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005687 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5688
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005689 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5690 // is the mask as it will be for the IT encoding if the conditional
5691 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5692 // where the conditional bit0 is zero, the instruction post-processing
5693 // will adjust the mask accordingly.
5694 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005695 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5696 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005697 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005698 return Error(Loc, "too many conditions on IT instruction");
5699 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005700 unsigned Mask = 8;
5701 for (unsigned i = ITMask.size(); i != 0; --i) {
5702 char pos = ITMask[i - 1];
5703 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005704 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005705 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005706 }
5707 Mask >>= 1;
5708 if (ITMask[i - 1] == 't')
5709 Mask |= 8;
5710 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005711 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005712 }
5713
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005714 // FIXME: This is all a pretty gross hack. We should automatically handle
5715 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005716
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005717 // Next, add the CCOut and ConditionCode operands, if needed.
5718 //
5719 // For mnemonics which can ever incorporate a carry setting bit or predication
5720 // code, our matching model involves us always generating CCOut and
5721 // ConditionCode operands to match the mnemonic "as written" and then we let
5722 // the matcher deal with finding the right instruction or generating an
5723 // appropriate error.
5724 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005725 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005726
Jim Grosbach03a8a162011-07-14 22:04:21 +00005727 // If we had a carry-set on an instruction that can't do that, issue an
5728 // error.
5729 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005730 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005731 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005732 "' can not set flags, but 's' suffix specified");
5733 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005734 // If we had a predication code on an instruction that can't do that, issue an
5735 // error.
5736 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005737 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005738 return Error(NameLoc, "instruction '" + Mnemonic +
5739 "' is not predicable, but condition code specified");
5740 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005741
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005742 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005743 if (CanAcceptCarrySet) {
5744 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005745 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005746 Loc));
5747 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005748
5749 // Add the predication code operand, if necessary.
5750 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005751 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5752 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005753 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005754 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005755 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005756
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005757 // Add the processor imod operand, if necessary.
5758 if (ProcessorIMod) {
5759 Operands.push_back(ARMOperand::CreateImm(
5760 MCConstantExpr::Create(ProcessorIMod, getContext()),
5761 NameLoc, NameLoc));
Oliver Stannard1ae8b472014-09-24 14:20:01 +00005762 } else if (Mnemonic == "cps" && isMClass()) {
5763 return Error(NameLoc, "instruction 'cps' requires effect for M-class");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005764 }
5765
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005766 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005767 while (Next != StringRef::npos) {
5768 Start = Next;
5769 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005770 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005771
Jim Grosbach12952fe2011-11-11 23:08:10 +00005772 // Some NEON instructions have an optional datatype suffix that is
5773 // completely ignored. Check for that.
5774 if (isDataTypeToken(ExtraToken) &&
5775 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5776 continue;
5777
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005778 // For for ARM mode generate an error if the .n qualifier is used.
5779 if (ExtraToken == ".n" && !isThumb()) {
5780 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005781 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005782 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5783 "arm mode");
5784 }
5785
5786 // The .n qualifier is always discarded as that is what the tables
5787 // and matcher expect. In ARM mode the .w qualifier has no effect,
5788 // so discard it to avoid errors that can be caused by the matcher.
5789 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005790 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5791 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5792 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005793 }
5794
5795 // Read the remaining operands.
5796 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005797 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005798 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005799 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005800 return true;
5801 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005802
5803 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005804 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005805
5806 // Parse and remember the 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 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005813
Chris Lattnera2a9d162010-09-11 16:18:25 +00005814 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005815 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005816 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005817 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005818 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005819
Chris Lattner91689c12010-09-08 05:10:46 +00005820 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005821
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005822 if (RequireVFPRegisterListCheck) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005823 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back());
5824 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList())
5825 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005826 "VFP/Neon single precision register expected");
David Blaikie960ea3f2014-06-08 16:18:35 +00005827 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList())
5828 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005829 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005830 }
5831
Jim Grosbach7283da92011-08-16 21:12:37 +00005832 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5833 // do and don't have a cc_out optional-def operand. With some spot-checks
5834 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005835 // parse and adjust accordingly before actually matching. We shouldn't ever
5836 // try to remove a cc_out operand that was explicitly set on the the
5837 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5838 // table driven matcher doesn't fit well with the ARM instruction set.
David Blaikie960ea3f2014-06-08 16:18:35 +00005839 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005840 Operands.erase(Operands.begin() + 1);
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005841
Joey Goulye8602552013-07-19 16:34:16 +00005842 // Some instructions have the same mnemonic, but don't always
5843 // have a predicate. Distinguish them here and delete the
5844 // predicate if needed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005845 if (shouldOmitPredicateOperand(Mnemonic, Operands))
Joey Goulye8602552013-07-19 16:34:16 +00005846 Operands.erase(Operands.begin() + 1);
Joey Goulye8602552013-07-19 16:34:16 +00005847
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005848 // ARM mode 'blx' need special handling, as the register operand version
5849 // is predicable, but the label operand version is not. So, we can't rely
5850 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005851 // a k_CondCode operand in the list. If we're trying to match the label
5852 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005853 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005854 static_cast<ARMOperand &>(*Operands[2]).isImm())
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005855 Operands.erase(Operands.begin() + 1);
Jim Grosbach8cffa282011-08-11 23:51:13 +00005856
Weiming Zhao8f56f882012-11-16 21:55:34 +00005857 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5858 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5859 // a single GPRPair reg operand is used in the .td file to replace the two
5860 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5861 // expressed as a GPRPair, so we have to manually merge them.
5862 // FIXME: We would really like to be able to tablegen'erate this.
5863 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005864 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5865 Mnemonic == "stlexd")) {
5866 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005867 unsigned Idx = isLoad ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005868 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
5869 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005870
5871 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5872 // Adjust only if Op1 and Op2 are GPRs.
David Blaikie960ea3f2014-06-08 16:18:35 +00005873 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
5874 MRC.contains(Op2.getReg())) {
5875 unsigned Reg1 = Op1.getReg();
5876 unsigned Reg2 = Op2.getReg();
Weiming Zhao8f56f882012-11-16 21:55:34 +00005877 unsigned Rt = MRI->getEncodingValue(Reg1);
5878 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5879
5880 // Rt2 must be Rt + 1 and Rt must be even.
5881 if (Rt + 1 != Rt2 || (Rt & 1)) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005882 Error(Op2.getStartLoc(), isLoad
5883 ? "destination operands must be sequential"
5884 : "source operands must be sequential");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005885 return true;
5886 }
5887 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5888 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
David Blaikie960ea3f2014-06-08 16:18:35 +00005889 Operands[Idx] =
5890 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
5891 Operands.erase(Operands.begin() + Idx + 1);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005892 }
5893 }
5894
Renato Golin36c626e2014-09-26 16:14:29 +00005895 // If first 2 operands of a 3 operand instruction are the same
5896 // then transform to 2 operand version of the same instruction
5897 // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1'
5898 // FIXME: We would really like to be able to tablegen'erate this.
5899 if (isThumbOne() && Operands.size() == 6 &&
5900 (Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" ||
5901 Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5902 Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" ||
5903 Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic")) {
5904 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5905 ARMOperand &Op4 = static_cast<ARMOperand &>(*Operands[4]);
5906 ARMOperand &Op5 = static_cast<ARMOperand &>(*Operands[5]);
5907
5908 // If both registers are the same then remove one of them from
5909 // the operand list.
5910 if (Op3.isReg() && Op4.isReg() && Op3.getReg() == Op4.getReg()) {
5911 // If 3rd operand (variable Op5) is a register and the instruction is adds/sub
5912 // then do not transform as the backend already handles this instruction
5913 // correctly.
5914 if (!Op5.isReg() || !((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub")) {
5915 Operands.erase(Operands.begin() + 3);
5916 if (Mnemonic == "add" && !CarrySetting) {
5917 // Special case for 'add' (not 'adds') instruction must
5918 // remove the CCOut operand as well.
5919 Operands.erase(Operands.begin() + 1);
5920 }
5921 }
5922 }
5923 }
5924
5925 // If instruction is 'add' and first two register operands
5926 // use SP register, then remove one of the SP registers from
5927 // the instruction.
5928 // FIXME: We would really like to be able to tablegen'erate this.
5929 if (isThumbOne() && Operands.size() == 5 && Mnemonic == "add" && !CarrySetting) {
5930 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5931 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5932 if (Op2.isReg() && Op3.isReg() && Op2.getReg() == ARM::SP && Op3.getReg() == ARM::SP) {
5933 Operands.erase(Operands.begin() + 2);
5934 }
5935 }
5936
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005937 // GNU Assembler extension (compatibility)
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005938 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005939 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5940 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5941 if (Op3.isMem()) {
5942 assert(Op2.isReg() && "expected register argument");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005943
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005944 unsigned SuperReg = MRI->getMatchingSuperReg(
David Blaikie960ea3f2014-06-08 16:18:35 +00005945 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005946
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005947 assert(SuperReg && "expected register pair");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005948
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005949 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005950
David Blaikie960ea3f2014-06-08 16:18:35 +00005951 Operands.insert(
5952 Operands.begin() + 3,
5953 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005954 }
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005955 }
5956
Kevin Enderby78f95722013-07-31 21:05:30 +00005957 // FIXME: As said above, this is all a pretty gross hack. This instruction
5958 // does not fit with other "subs" and tblgen.
5959 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5960 // so the Mnemonic is the original name "subs" and delete the predicate
5961 // operand so it will match the table entry.
5962 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005963 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5964 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
5965 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5966 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
5967 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5968 Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
Kevin Enderby78f95722013-07-31 21:05:30 +00005969 Operands.erase(Operands.begin() + 1);
Kevin Enderby78f95722013-07-31 21:05:30 +00005970 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005971 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005972}
5973
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005974// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005975
5976// return 'true' if register list contains non-low GPR registers,
5977// 'false' otherwise. If Reg is in the register list or is HiReg, set
5978// 'containsReg' to true.
5979static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5980 unsigned HiReg, bool &containsReg) {
5981 containsReg = false;
5982 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5983 unsigned OpReg = Inst.getOperand(i).getReg();
5984 if (OpReg == Reg)
5985 containsReg = true;
5986 // Anything other than a low register isn't legal here.
5987 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5988 return true;
5989 }
5990 return false;
5991}
5992
Rafael Espindola5403da42014-12-04 14:10:20 +00005993// Check if the specified regisgter is in the register list of the inst,
Jim Grosbacha31f2232011-09-07 18:05:34 +00005994// starting at the indicated operand number.
Rafael Espindola5403da42014-12-04 14:10:20 +00005995static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005996 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5997 unsigned OpReg = Inst.getOperand(i).getReg();
Rafael Espindola5403da42014-12-04 14:10:20 +00005998 if (OpReg == Reg)
5999 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00006000 }
6001 return false;
6002}
6003
Richard Barton8d519fe2013-09-05 14:14:19 +00006004// Return true if instruction has the interesting property of being
6005// allowed in IT blocks, but not being predicable.
6006static bool instIsBreakpoint(const MCInst &Inst) {
6007 return Inst.getOpcode() == ARM::tBKPT ||
6008 Inst.getOpcode() == ARM::BKPT ||
6009 Inst.getOpcode() == ARM::tHLT ||
6010 Inst.getOpcode() == ARM::HLT;
6011
6012}
6013
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006014// FIXME: We would really like to be able to tablegen'erate this.
David Blaikie960ea3f2014-06-08 16:18:35 +00006015bool ARMAsmParser::validateInstruction(MCInst &Inst,
6016 const OperandVector &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00006017 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00006018 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00006019
Jim Grosbached16ec42011-08-29 22:24:09 +00006020 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00006021 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00006022 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00006023 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006024 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006025 if (ITState.FirstCond)
6026 ITState.FirstCond = false;
6027 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00006028 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006029 // The instruction must be predicable.
6030 if (!MCID.isPredicable())
6031 return Error(Loc, "instructions in IT block must be predicable");
6032 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00006033 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00006034 ARMCC::getOppositeCondition(ITState.Cond);
6035 if (Cond != ITCond) {
6036 // Find the condition code Operand to get its SMLoc information.
6037 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00006038 for (unsigned I = 1; I < Operands.size(); ++I)
David Blaikie960ea3f2014-06-08 16:18:35 +00006039 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006040 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00006041 return Error(CondLoc, "incorrect condition in IT block; got '" +
6042 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
6043 "', but expected '" +
6044 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
6045 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00006046 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00006047 } else if (isThumbTwo() && MCID.isPredicable() &&
6048 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00006049 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
6050 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00006051 return Error(Loc, "predicated instructions must be in IT block");
6052
Tilmann Scheller255722b2013-09-30 16:11:48 +00006053 const unsigned Opcode = Inst.getOpcode();
6054 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00006055 case ARM::LDRD:
6056 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006057 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00006058 const unsigned RtReg = Inst.getOperand(0).getReg();
6059
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006060 // Rt can't be R14.
6061 if (RtReg == ARM::LR)
6062 return Error(Operands[3]->getStartLoc(),
6063 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006064
6065 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006066 // Rt must be even-numbered.
6067 if ((Rt & 1) == 1)
6068 return Error(Operands[3]->getStartLoc(),
6069 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006070
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006071 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00006072 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006073 if (Rt2 != Rt + 1)
6074 return Error(Operands[3]->getStartLoc(),
6075 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006076
6077 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
6078 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
6079 // For addressing modes with writeback, the base register needs to be
6080 // different from the destination registers.
6081 if (Rn == Rt || Rn == Rt2)
6082 return Error(Operands[3]->getStartLoc(),
6083 "base register needs to be different from destination "
6084 "registers");
6085 }
6086
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006087 return false;
6088 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006089 case ARM::t2LDRDi8:
6090 case ARM::t2LDRD_PRE:
6091 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00006092 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006093 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6094 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6095 if (Rt2 == Rt)
6096 return Error(Operands[3]->getStartLoc(),
6097 "destination operands can't be identical");
6098 return false;
6099 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00006100 case ARM::STRD: {
6101 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006102 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6103 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00006104 if (Rt2 != Rt + 1)
6105 return Error(Operands[3]->getStartLoc(),
6106 "source operands must be sequential");
6107 return false;
6108 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00006109 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006110 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006111 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006112 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6113 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006114 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00006115 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006116 "source operands must be sequential");
6117 return false;
6118 }
Tilmann Scheller3352a582014-07-23 12:38:17 +00006119 case ARM::STR_PRE_IMM:
6120 case ARM::STR_PRE_REG:
6121 case ARM::STR_POST_IMM:
Tilmann Scheller27272792014-07-23 13:03:47 +00006122 case ARM::STR_POST_REG:
Tilmann Scheller96ef72e2014-07-24 09:55:46 +00006123 case ARM::STRH_PRE:
6124 case ARM::STRH_POST:
Tilmann Scheller27272792014-07-23 13:03:47 +00006125 case ARM::STRB_PRE_IMM:
6126 case ARM::STRB_PRE_REG:
6127 case ARM::STRB_POST_IMM:
6128 case ARM::STRB_POST_REG: {
Tilmann Scheller3352a582014-07-23 12:38:17 +00006129 // Rt must be different from Rn.
6130 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6131 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6132
6133 if (Rt == Rn)
6134 return Error(Operands[3]->getStartLoc(),
6135 "source register and base register can't be identical");
6136 return false;
6137 }
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006138 case ARM::LDR_PRE_IMM:
6139 case ARM::LDR_PRE_REG:
6140 case ARM::LDR_POST_IMM:
Tilmann Scheller8ff079c2014-08-01 11:33:47 +00006141 case ARM::LDR_POST_REG:
6142 case ARM::LDRH_PRE:
6143 case ARM::LDRH_POST:
6144 case ARM::LDRSH_PRE:
Tilmann Scheller7cc0ed42014-08-01 12:08:04 +00006145 case ARM::LDRSH_POST:
6146 case ARM::LDRB_PRE_IMM:
6147 case ARM::LDRB_PRE_REG:
6148 case ARM::LDRB_POST_IMM:
6149 case ARM::LDRB_POST_REG:
6150 case ARM::LDRSB_PRE:
6151 case ARM::LDRSB_POST: {
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006152 // Rt must be different from Rn.
6153 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6154 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6155
6156 if (Rt == Rn)
6157 return Error(Operands[3]->getStartLoc(),
6158 "destination register and base register can't be identical");
6159 return false;
6160 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00006161 case ARM::SBFX:
6162 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006163 // Width must be in range [1, 32-lsb].
6164 unsigned LSB = Inst.getOperand(2).getImm();
6165 unsigned Widthm1 = Inst.getOperand(3).getImm();
6166 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00006167 return Error(Operands[5]->getStartLoc(),
6168 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00006169 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00006170 }
Rafael Espindola5403da42014-12-04 14:10:20 +00006171 // Notionally handles ARM::tLDMIA_UPD too.
6172 case ARM::tLDMIA: {
6173 // If we're parsing Thumb2, the .w variant is available and handles
6174 // most cases that are normally illegal for a Thumb1 LDM instruction.
6175 // We'll make the transformation in processInstruction() if necessary.
6176 //
6177 // Thumb LDM instructions are writeback iff the base register is not
6178 // in the register list.
6179 unsigned Rn = Inst.getOperand(0).getReg();
6180 bool HasWritebackToken =
6181 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
6182 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
6183 bool ListContainsBase;
6184 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
6185 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
6186 "registers must be in range r0-r7");
6187 // If we should have writeback, then there should be a '!' token.
6188 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
6189 return Error(Operands[2]->getStartLoc(),
6190 "writeback operator '!' expected");
6191 // If we should not have writeback, there must not be a '!'. This is
6192 // true even for the 32-bit wide encodings.
6193 if (ListContainsBase && HasWritebackToken)
6194 return Error(Operands[3]->getStartLoc(),
6195 "writeback operator '!' not allowed when base register "
6196 "in register list");
6197 if (listContainsReg(Inst, 3 + HasWritebackToken, ARM::SP))
6198 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
6199 "SP not allowed in register list");
6200 break;
6201 }
Tim Northover08a86602013-10-22 19:00:39 +00006202 case ARM::LDMIA_UPD:
6203 case ARM::LDMDB_UPD:
6204 case ARM::LDMIB_UPD:
6205 case ARM::LDMDA_UPD:
6206 // ARM variants loading and updating the same register are only officially
6207 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
6208 if (!hasV7Ops())
6209 break;
Rafael Espindola5403da42014-12-04 14:10:20 +00006210 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6211 return Error(Operands.back()->getStartLoc(),
6212 "writeback register not allowed in register list");
6213 break;
Jyoti Allur3b686072014-10-22 10:41:14 +00006214 case ARM::t2LDMIA:
6215 case ARM::t2LDMDB:
6216 case ARM::t2STMIA:
Rafael Espindola5403da42014-12-04 14:10:20 +00006217 case ARM::t2STMDB: {
6218 if (listContainsReg(Inst, 3, ARM::SP))
6219 return Error(Operands.back()->getStartLoc(),
6220 "SP not allowed in register list");
6221 break;
6222 }
Tim Northover08a86602013-10-22 19:00:39 +00006223 case ARM::t2LDMIA_UPD:
6224 case ARM::t2LDMDB_UPD:
6225 case ARM::t2STMIA_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006226 case ARM::t2STMDB_UPD: {
6227 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6228 return Error(Operands.back()->getStartLoc(),
6229 "writeback register not allowed in register list");
6230
6231 if (listContainsReg(Inst, 4, ARM::SP))
6232 return Error(Operands.back()->getStartLoc(),
6233 "SP not allowed in register list");
6234 break;
6235 }
Tim Northover8eaf1542013-11-12 21:32:41 +00006236 case ARM::sysLDMIA_UPD:
6237 case ARM::sysLDMDA_UPD:
6238 case ARM::sysLDMDB_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006239 case ARM::sysLDMIB_UPD:
6240 if (!listContainsReg(Inst, 3, ARM::PC))
6241 return Error(Operands[4]->getStartLoc(),
6242 "writeback register only allowed on system LDM "
6243 "if PC in register-list");
Tim Northover8eaf1542013-11-12 21:32:41 +00006244 break;
6245 case ARM::sysSTMIA_UPD:
6246 case ARM::sysSTMDA_UPD:
6247 case ARM::sysSTMDB_UPD:
6248 case ARM::sysSTMIB_UPD:
6249 return Error(Operands[2]->getStartLoc(),
6250 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006251 case ARM::tMUL: {
6252 // The second source operand must be the same register as the destination
6253 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00006254 //
6255 // In this case, we must directly check the parsed operands because the
6256 // cvtThumbMultiply() function is written in such a way that it guarantees
6257 // this first statement is always true for the new Inst. Essentially, the
6258 // destination is unconditionally copied into the second source operand
6259 // without checking to see if it matches what we actually parsed.
David Blaikie960ea3f2014-06-08 16:18:35 +00006260 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
6261 ((ARMOperand &)*Operands[5]).getReg()) &&
6262 (((ARMOperand &)*Operands[3]).getReg() !=
6263 ((ARMOperand &)*Operands[4]).getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00006264 return Error(Operands[3]->getStartLoc(),
6265 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006266 }
6267 break;
6268 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00006269 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
6270 // so only issue a diagnostic for thumb1. The instructions will be
6271 // switched to the t2 encodings in processInstruction() if necessary.
Rafael Espindola5403da42014-12-04 14:10:20 +00006272 case ARM::tPOP: {
6273 bool ListContainsBase;
6274 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
6275 !isThumbTwo())
6276 return Error(Operands[2]->getStartLoc(),
6277 "registers must be in range r0-r7 or pc");
6278 break;
6279 }
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006280 case ARM::tPUSH: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006281 bool ListContainsBase;
6282 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
6283 !isThumbTwo())
6284 return Error(Operands[2]->getStartLoc(),
6285 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006286 break;
6287 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00006288 case ARM::tSTMIA_UPD: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006289 bool ListContainsBase, InvalidLowList;
6290 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
6291 0, ListContainsBase);
6292 if (InvalidLowList && !isThumbTwo())
6293 return Error(Operands[4]->getStartLoc(),
6294 "registers must be in range r0-r7");
6295
6296 // This would be converted to a 32-bit stm, but that's not valid if the
6297 // writeback register is in the list.
6298 if (InvalidLowList && ListContainsBase)
6299 return Error(Operands[4]->getStartLoc(),
6300 "writeback operator '!' not allowed when base register "
6301 "in register list");
6302 if (listContainsReg(Inst, 4, ARM::SP) && !inITBlock())
6303 return Error(Operands.back()->getStartLoc(),
6304 "SP not allowed in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00006305 break;
6306 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00006307 case ARM::tADDrSP: {
6308 // If the non-SP source operand and the destination operand are not the
6309 // same, we need thumb2 (for the wide encoding), or we have an error.
6310 if (!isThumbTwo() &&
6311 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
6312 return Error(Operands[4]->getStartLoc(),
6313 "source register must be the same as destination");
6314 }
6315 break;
6316 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006317 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006318 case ARM::tB:
David Blaikie960ea3f2014-06-08 16:18:35 +00006319 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006320 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006321 break;
6322 case ARM::t2B: {
6323 int op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006324 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006325 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006326 break;
6327 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006328 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006329 case ARM::tBcc:
David Blaikie960ea3f2014-06-08 16:18:35 +00006330 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006331 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006332 break;
6333 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006334 int Op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006335 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006336 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006337 break;
6338 }
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006339 case ARM::MOVi16:
6340 case ARM::t2MOVi16:
6341 case ARM::t2MOVTi16:
6342 {
6343 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
6344 // especially when we turn it into a movw and the expression <symbol> does
6345 // not have a :lower16: or :upper16 as part of the expression. We don't
6346 // want the behavior of silently truncating, which can be unexpected and
6347 // lead to bugs that are difficult to find since this is an easy mistake
6348 // to make.
6349 int i = (Operands[3]->isImm()) ? 3 : 4;
David Blaikie960ea3f2014-06-08 16:18:35 +00006350 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
6351 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006352 if (CE) break;
David Blaikie960ea3f2014-06-08 16:18:35 +00006353 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006354 if (!E) break;
6355 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
6356 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006357 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
6358 return Error(
6359 Op.getStartLoc(),
6360 "immediate expression for mov requires :lower16: or :upper16");
6361 break;
6362 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006363 }
6364
6365 return false;
6366}
6367
Jim Grosbach1a747242012-01-23 23:45:44 +00006368static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00006369 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006370 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006371 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006372 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6373 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6374 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6375 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6376 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6377 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6378 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
6379 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
6380 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006381
6382 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006383 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6384 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6385 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6386 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6387 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006388
Jim Grosbach1e946a42012-01-24 00:43:12 +00006389 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6390 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6391 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6392 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6393 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006394
Jim Grosbach1e946a42012-01-24 00:43:12 +00006395 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
6396 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
6397 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
6398 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
6399 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00006400
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006401 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006402 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6403 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6404 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6405 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
6406 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6407 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6408 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6409 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6410 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
6411 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6412 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
6413 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
6414 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
6415 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
6416 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006417
Jim Grosbach1a747242012-01-23 23:45:44 +00006418 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006419 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6420 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6421 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6422 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6423 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6424 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6425 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6426 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6427 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6428 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6429 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6430 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6431 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
6432 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
6433 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
6434 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
6435 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
6436 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00006437
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006438 // VST4LN
6439 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6440 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6441 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6442 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
6443 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6444 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6445 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6446 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6447 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
6448 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6449 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
6450 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
6451 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
6452 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
6453 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
6454
Jim Grosbachda70eac2012-01-24 00:58:13 +00006455 // VST4
6456 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6457 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6458 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6459 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6460 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6461 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6462 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6463 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6464 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6465 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6466 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6467 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6468 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6469 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6470 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6471 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6472 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6473 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00006474 }
6475}
6476
Jim Grosbach1a747242012-01-23 23:45:44 +00006477static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00006478 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006479 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006480 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006481 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6482 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6483 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6484 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6485 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6486 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6487 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6488 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6489 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006490
6491 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006492 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6493 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6494 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6495 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6496 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6497 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6498 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6499 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6500 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6501 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6502 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6503 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6504 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6505 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6506 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006507
Jim Grosbachb78403c2012-01-24 23:47:04 +00006508 // VLD3DUP
6509 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6510 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6511 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6512 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
Kevin Enderbyd88fec32014-04-08 18:00:52 +00006513 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
Jim Grosbachb78403c2012-01-24 23:47:04 +00006514 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6515 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6516 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6517 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6518 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6519 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6520 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6521 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6522 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6523 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6524 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6525 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6526 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6527
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006528 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006529 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6530 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6531 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6532 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6533 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6534 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6535 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6536 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6537 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6538 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6539 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6540 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6541 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6542 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6543 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006544
6545 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006546 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6547 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6548 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6549 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6550 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6551 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6552 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6553 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6554 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6555 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6556 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6557 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6558 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6559 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6560 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6561 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6562 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6563 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00006564
Jim Grosbach14952a02012-01-24 18:37:25 +00006565 // VLD4LN
6566 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6567 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6568 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00006569 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00006570 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6571 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6572 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6573 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6574 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6575 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6576 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6577 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6578 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6579 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6580 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6581
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006582 // VLD4DUP
6583 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6584 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6585 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6586 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6587 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6588 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6589 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6590 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6591 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6592 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6593 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6594 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6595 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6596 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6597 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6598 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6599 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6600 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6601
Jim Grosbached561fc2012-01-24 00:43:17 +00006602 // VLD4
6603 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6604 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6605 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6606 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6607 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6608 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6609 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6610 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6611 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6612 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6613 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6614 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6615 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6616 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6617 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6618 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6619 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6620 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006621 }
6622}
6623
David Blaikie960ea3f2014-06-08 16:18:35 +00006624bool ARMAsmParser::processInstruction(MCInst &Inst,
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006625 const OperandVector &Operands,
6626 MCStreamer &Out) {
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006627 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006628 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6629 case ARM::LDRT_POST:
6630 case ARM::LDRBT_POST: {
6631 const unsigned Opcode =
6632 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6633 : ARM::LDRBT_POST_IMM;
6634 MCInst TmpInst;
6635 TmpInst.setOpcode(Opcode);
6636 TmpInst.addOperand(Inst.getOperand(0));
6637 TmpInst.addOperand(Inst.getOperand(1));
6638 TmpInst.addOperand(Inst.getOperand(1));
6639 TmpInst.addOperand(MCOperand::CreateReg(0));
6640 TmpInst.addOperand(MCOperand::CreateImm(0));
6641 TmpInst.addOperand(Inst.getOperand(2));
6642 TmpInst.addOperand(Inst.getOperand(3));
6643 Inst = TmpInst;
6644 return true;
6645 }
6646 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6647 case ARM::STRT_POST:
6648 case ARM::STRBT_POST: {
6649 const unsigned Opcode =
6650 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6651 : ARM::STRBT_POST_IMM;
6652 MCInst TmpInst;
6653 TmpInst.setOpcode(Opcode);
6654 TmpInst.addOperand(Inst.getOperand(1));
6655 TmpInst.addOperand(Inst.getOperand(0));
6656 TmpInst.addOperand(Inst.getOperand(1));
6657 TmpInst.addOperand(MCOperand::CreateReg(0));
6658 TmpInst.addOperand(MCOperand::CreateImm(0));
6659 TmpInst.addOperand(Inst.getOperand(2));
6660 TmpInst.addOperand(Inst.getOperand(3));
6661 Inst = TmpInst;
6662 return true;
6663 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006664 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6665 case ARM::ADDri: {
6666 if (Inst.getOperand(1).getReg() != ARM::PC ||
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006667 Inst.getOperand(5).getReg() != 0 ||
6668 !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm()))
Jim Grosbache974a6a2012-09-25 00:08:13 +00006669 return false;
6670 MCInst TmpInst;
6671 TmpInst.setOpcode(ARM::ADR);
6672 TmpInst.addOperand(Inst.getOperand(0));
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006673 if (Inst.getOperand(2).isImm()) {
Asiri Rathnayake7835e9b2014-12-09 13:14:58 +00006674 // Immediate (mod_imm) will be in its encoded form, we must unencode it
6675 // before passing it to the ADR instruction.
6676 unsigned Enc = Inst.getOperand(2).getImm();
6677 TmpInst.addOperand(MCOperand::CreateImm(
6678 ARM_AM::rotr32(Enc & 0xFF, (Enc & 0xF00) >> 7)));
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006679 } else {
6680 // Turn PC-relative expression into absolute expression.
6681 // Reading PC provides the start of the current instruction + 8 and
6682 // the transform to adr is biased by that.
6683 MCSymbol *Dot = getContext().CreateTempSymbol();
6684 Out.EmitLabel(Dot);
6685 const MCExpr *OpExpr = Inst.getOperand(2).getExpr();
6686 const MCExpr *InstPC = MCSymbolRefExpr::Create(Dot,
6687 MCSymbolRefExpr::VK_None,
6688 getContext());
6689 const MCExpr *Const8 = MCConstantExpr::Create(8, getContext());
6690 const MCExpr *ReadPC = MCBinaryExpr::CreateAdd(InstPC, Const8,
6691 getContext());
6692 const MCExpr *FixupAddr = MCBinaryExpr::CreateAdd(ReadPC, OpExpr,
6693 getContext());
6694 TmpInst.addOperand(MCOperand::CreateExpr(FixupAddr));
6695 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006696 TmpInst.addOperand(Inst.getOperand(3));
6697 TmpInst.addOperand(Inst.getOperand(4));
6698 Inst = TmpInst;
6699 return true;
6700 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006701 // Aliases for alternate PC+imm syntax of LDR instructions.
6702 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006703 // Select the narrow version if the immediate will fit.
6704 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006705 Inst.getOperand(1).getImm() <= 0xff &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006706 !(static_cast<ARMOperand &>(*Operands[2]).isToken() &&
6707 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006708 Inst.setOpcode(ARM::tLDRpci);
6709 else
6710 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006711 return true;
6712 case ARM::t2LDRBpcrel:
6713 Inst.setOpcode(ARM::t2LDRBpci);
6714 return true;
6715 case ARM::t2LDRHpcrel:
6716 Inst.setOpcode(ARM::t2LDRHpci);
6717 return true;
6718 case ARM::t2LDRSBpcrel:
6719 Inst.setOpcode(ARM::t2LDRSBpci);
6720 return true;
6721 case ARM::t2LDRSHpcrel:
6722 Inst.setOpcode(ARM::t2LDRSHpci);
6723 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006724 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006725 case ARM::VST1LNdWB_register_Asm_8:
6726 case ARM::VST1LNdWB_register_Asm_16:
6727 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006728 MCInst TmpInst;
6729 // Shuffle the operands around so the lane index operand is in the
6730 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006731 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006732 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006733 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6734 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6735 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6736 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6737 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6738 TmpInst.addOperand(Inst.getOperand(1)); // lane
6739 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6740 TmpInst.addOperand(Inst.getOperand(6));
6741 Inst = TmpInst;
6742 return true;
6743 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006744
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006745 case ARM::VST2LNdWB_register_Asm_8:
6746 case ARM::VST2LNdWB_register_Asm_16:
6747 case ARM::VST2LNdWB_register_Asm_32:
6748 case ARM::VST2LNqWB_register_Asm_16:
6749 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006750 MCInst TmpInst;
6751 // Shuffle the operands around so the lane index operand is in the
6752 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006753 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006754 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006755 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6756 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6757 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6758 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6759 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006760 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6761 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006762 TmpInst.addOperand(Inst.getOperand(1)); // lane
6763 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6764 TmpInst.addOperand(Inst.getOperand(6));
6765 Inst = TmpInst;
6766 return true;
6767 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006768
6769 case ARM::VST3LNdWB_register_Asm_8:
6770 case ARM::VST3LNdWB_register_Asm_16:
6771 case ARM::VST3LNdWB_register_Asm_32:
6772 case ARM::VST3LNqWB_register_Asm_16:
6773 case ARM::VST3LNqWB_register_Asm_32: {
6774 MCInst TmpInst;
6775 // Shuffle the operands around so the lane index operand is in the
6776 // right place.
6777 unsigned Spacing;
6778 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6779 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6780 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6781 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6782 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6783 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6784 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6785 Spacing));
6786 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6787 Spacing * 2));
6788 TmpInst.addOperand(Inst.getOperand(1)); // lane
6789 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6790 TmpInst.addOperand(Inst.getOperand(6));
6791 Inst = TmpInst;
6792 return true;
6793 }
6794
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006795 case ARM::VST4LNdWB_register_Asm_8:
6796 case ARM::VST4LNdWB_register_Asm_16:
6797 case ARM::VST4LNdWB_register_Asm_32:
6798 case ARM::VST4LNqWB_register_Asm_16:
6799 case ARM::VST4LNqWB_register_Asm_32: {
6800 MCInst TmpInst;
6801 // Shuffle the operands around so the lane index operand is in the
6802 // right place.
6803 unsigned Spacing;
6804 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6805 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6806 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6807 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6808 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6809 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6810 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6811 Spacing));
6812 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6813 Spacing * 2));
6814 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6815 Spacing * 3));
6816 TmpInst.addOperand(Inst.getOperand(1)); // lane
6817 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6818 TmpInst.addOperand(Inst.getOperand(6));
6819 Inst = TmpInst;
6820 return true;
6821 }
6822
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006823 case ARM::VST1LNdWB_fixed_Asm_8:
6824 case ARM::VST1LNdWB_fixed_Asm_16:
6825 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006826 MCInst TmpInst;
6827 // Shuffle the operands around so the lane index operand is in the
6828 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006829 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006830 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006831 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6832 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6833 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6834 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6835 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6836 TmpInst.addOperand(Inst.getOperand(1)); // lane
6837 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6838 TmpInst.addOperand(Inst.getOperand(5));
6839 Inst = TmpInst;
6840 return true;
6841 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006842
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006843 case ARM::VST2LNdWB_fixed_Asm_8:
6844 case ARM::VST2LNdWB_fixed_Asm_16:
6845 case ARM::VST2LNdWB_fixed_Asm_32:
6846 case ARM::VST2LNqWB_fixed_Asm_16:
6847 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006848 MCInst TmpInst;
6849 // Shuffle the operands around so the lane index operand is in the
6850 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006851 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006852 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006853 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6854 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6855 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6856 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6857 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6859 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006860 TmpInst.addOperand(Inst.getOperand(1)); // lane
6861 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6862 TmpInst.addOperand(Inst.getOperand(5));
6863 Inst = TmpInst;
6864 return true;
6865 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006866
6867 case ARM::VST3LNdWB_fixed_Asm_8:
6868 case ARM::VST3LNdWB_fixed_Asm_16:
6869 case ARM::VST3LNdWB_fixed_Asm_32:
6870 case ARM::VST3LNqWB_fixed_Asm_16:
6871 case ARM::VST3LNqWB_fixed_Asm_32: {
6872 MCInst TmpInst;
6873 // Shuffle the operands around so the lane index operand is in the
6874 // right place.
6875 unsigned Spacing;
6876 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6877 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6878 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6879 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6880 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6881 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6882 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6883 Spacing));
6884 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6885 Spacing * 2));
6886 TmpInst.addOperand(Inst.getOperand(1)); // lane
6887 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6888 TmpInst.addOperand(Inst.getOperand(5));
6889 Inst = TmpInst;
6890 return true;
6891 }
6892
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006893 case ARM::VST4LNdWB_fixed_Asm_8:
6894 case ARM::VST4LNdWB_fixed_Asm_16:
6895 case ARM::VST4LNdWB_fixed_Asm_32:
6896 case ARM::VST4LNqWB_fixed_Asm_16:
6897 case ARM::VST4LNqWB_fixed_Asm_32: {
6898 MCInst TmpInst;
6899 // Shuffle the operands around so the lane index operand is in the
6900 // right place.
6901 unsigned Spacing;
6902 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6903 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6904 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6905 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6906 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6907 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6908 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6909 Spacing));
6910 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6911 Spacing * 2));
6912 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6913 Spacing * 3));
6914 TmpInst.addOperand(Inst.getOperand(1)); // lane
6915 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6916 TmpInst.addOperand(Inst.getOperand(5));
6917 Inst = TmpInst;
6918 return true;
6919 }
6920
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006921 case ARM::VST1LNdAsm_8:
6922 case ARM::VST1LNdAsm_16:
6923 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006924 MCInst TmpInst;
6925 // Shuffle the operands around so the lane index operand is in the
6926 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006927 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006928 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006929 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6930 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6931 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6932 TmpInst.addOperand(Inst.getOperand(1)); // lane
6933 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6934 TmpInst.addOperand(Inst.getOperand(5));
6935 Inst = TmpInst;
6936 return true;
6937 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006938
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006939 case ARM::VST2LNdAsm_8:
6940 case ARM::VST2LNdAsm_16:
6941 case ARM::VST2LNdAsm_32:
6942 case ARM::VST2LNqAsm_16:
6943 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006944 MCInst TmpInst;
6945 // Shuffle the operands around so the lane index operand is in the
6946 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006947 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006948 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006949 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6950 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6951 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006952 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6953 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006954 TmpInst.addOperand(Inst.getOperand(1)); // lane
6955 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6956 TmpInst.addOperand(Inst.getOperand(5));
6957 Inst = TmpInst;
6958 return true;
6959 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006960
6961 case ARM::VST3LNdAsm_8:
6962 case ARM::VST3LNdAsm_16:
6963 case ARM::VST3LNdAsm_32:
6964 case ARM::VST3LNqAsm_16:
6965 case ARM::VST3LNqAsm_32: {
6966 MCInst TmpInst;
6967 // Shuffle the operands around so the lane index operand is in the
6968 // right place.
6969 unsigned Spacing;
6970 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6971 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6972 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6973 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6974 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6975 Spacing));
6976 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6977 Spacing * 2));
6978 TmpInst.addOperand(Inst.getOperand(1)); // lane
6979 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6980 TmpInst.addOperand(Inst.getOperand(5));
6981 Inst = TmpInst;
6982 return true;
6983 }
6984
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006985 case ARM::VST4LNdAsm_8:
6986 case ARM::VST4LNdAsm_16:
6987 case ARM::VST4LNdAsm_32:
6988 case ARM::VST4LNqAsm_16:
6989 case ARM::VST4LNqAsm_32: {
6990 MCInst TmpInst;
6991 // Shuffle the operands around so the lane index operand is in the
6992 // right place.
6993 unsigned Spacing;
6994 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6995 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6996 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6997 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6998 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6999 Spacing));
7000 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7001 Spacing * 2));
7002 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7003 Spacing * 3));
7004 TmpInst.addOperand(Inst.getOperand(1)); // lane
7005 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7006 TmpInst.addOperand(Inst.getOperand(5));
7007 Inst = TmpInst;
7008 return true;
7009 }
7010
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007011 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007012 case ARM::VLD1LNdWB_register_Asm_8:
7013 case ARM::VLD1LNdWB_register_Asm_16:
7014 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007015 MCInst TmpInst;
7016 // Shuffle the operands around so the lane index operand is in the
7017 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007018 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007019 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007020 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7021 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7022 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7023 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7024 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7025 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7026 TmpInst.addOperand(Inst.getOperand(1)); // lane
7027 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7028 TmpInst.addOperand(Inst.getOperand(6));
7029 Inst = TmpInst;
7030 return true;
7031 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007032
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007033 case ARM::VLD2LNdWB_register_Asm_8:
7034 case ARM::VLD2LNdWB_register_Asm_16:
7035 case ARM::VLD2LNdWB_register_Asm_32:
7036 case ARM::VLD2LNqWB_register_Asm_16:
7037 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007038 MCInst TmpInst;
7039 // Shuffle the operands around so the lane index operand is in the
7040 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007041 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007042 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007043 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007044 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7045 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007046 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7047 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7048 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7049 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7050 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007051 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7052 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007053 TmpInst.addOperand(Inst.getOperand(1)); // lane
7054 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7055 TmpInst.addOperand(Inst.getOperand(6));
7056 Inst = TmpInst;
7057 return true;
7058 }
7059
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007060 case ARM::VLD3LNdWB_register_Asm_8:
7061 case ARM::VLD3LNdWB_register_Asm_16:
7062 case ARM::VLD3LNdWB_register_Asm_32:
7063 case ARM::VLD3LNqWB_register_Asm_16:
7064 case ARM::VLD3LNqWB_register_Asm_32: {
7065 MCInst TmpInst;
7066 // Shuffle the operands around so the lane index operand is in the
7067 // right place.
7068 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007069 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007070 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7071 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7072 Spacing));
7073 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007074 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007075 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7076 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7077 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7078 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7079 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7081 Spacing));
7082 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007083 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007084 TmpInst.addOperand(Inst.getOperand(1)); // lane
7085 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7086 TmpInst.addOperand(Inst.getOperand(6));
7087 Inst = TmpInst;
7088 return true;
7089 }
7090
Jim Grosbach14952a02012-01-24 18:37:25 +00007091 case ARM::VLD4LNdWB_register_Asm_8:
7092 case ARM::VLD4LNdWB_register_Asm_16:
7093 case ARM::VLD4LNdWB_register_Asm_32:
7094 case ARM::VLD4LNqWB_register_Asm_16:
7095 case ARM::VLD4LNqWB_register_Asm_32: {
7096 MCInst TmpInst;
7097 // Shuffle the operands around so the lane index operand is in the
7098 // right place.
7099 unsigned Spacing;
7100 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7101 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7102 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7103 Spacing));
7104 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7105 Spacing * 2));
7106 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7107 Spacing * 3));
7108 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)
7113 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7114 Spacing));
7115 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7116 Spacing * 2));
7117 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7118 Spacing * 3));
7119 TmpInst.addOperand(Inst.getOperand(1)); // lane
7120 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7121 TmpInst.addOperand(Inst.getOperand(6));
7122 Inst = TmpInst;
7123 return true;
7124 }
7125
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007126 case ARM::VLD1LNdWB_fixed_Asm_8:
7127 case ARM::VLD1LNdWB_fixed_Asm_16:
7128 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007129 MCInst TmpInst;
7130 // Shuffle the operands around so the lane index operand is in the
7131 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007132 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007133 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007134 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7135 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7136 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7137 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7138 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7139 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7140 TmpInst.addOperand(Inst.getOperand(1)); // lane
7141 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7142 TmpInst.addOperand(Inst.getOperand(5));
7143 Inst = TmpInst;
7144 return true;
7145 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007146
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007147 case ARM::VLD2LNdWB_fixed_Asm_8:
7148 case ARM::VLD2LNdWB_fixed_Asm_16:
7149 case ARM::VLD2LNdWB_fixed_Asm_32:
7150 case ARM::VLD2LNqWB_fixed_Asm_16:
7151 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007152 MCInst TmpInst;
7153 // Shuffle the operands around so the lane index operand is in the
7154 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007155 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007156 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007157 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007158 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7159 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007160 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7161 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7162 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7163 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7164 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007165 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7166 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007167 TmpInst.addOperand(Inst.getOperand(1)); // lane
7168 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7169 TmpInst.addOperand(Inst.getOperand(5));
7170 Inst = TmpInst;
7171 return true;
7172 }
7173
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007174 case ARM::VLD3LNdWB_fixed_Asm_8:
7175 case ARM::VLD3LNdWB_fixed_Asm_16:
7176 case ARM::VLD3LNdWB_fixed_Asm_32:
7177 case ARM::VLD3LNqWB_fixed_Asm_16:
7178 case ARM::VLD3LNqWB_fixed_Asm_32: {
7179 MCInst TmpInst;
7180 // Shuffle the operands around so the lane index operand is in the
7181 // right place.
7182 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007183 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007184 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7185 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7186 Spacing));
7187 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007188 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007189 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7190 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7191 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7192 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7193 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7194 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7195 Spacing));
7196 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007197 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007198 TmpInst.addOperand(Inst.getOperand(1)); // lane
7199 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7200 TmpInst.addOperand(Inst.getOperand(5));
7201 Inst = TmpInst;
7202 return true;
7203 }
7204
Jim Grosbach14952a02012-01-24 18:37:25 +00007205 case ARM::VLD4LNdWB_fixed_Asm_8:
7206 case ARM::VLD4LNdWB_fixed_Asm_16:
7207 case ARM::VLD4LNdWB_fixed_Asm_32:
7208 case ARM::VLD4LNqWB_fixed_Asm_16:
7209 case ARM::VLD4LNqWB_fixed_Asm_32: {
7210 MCInst TmpInst;
7211 // Shuffle the operands around so the lane index operand is in the
7212 // right place.
7213 unsigned Spacing;
7214 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7215 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7216 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7217 Spacing));
7218 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7219 Spacing * 2));
7220 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7221 Spacing * 3));
7222 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)
7227 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7228 Spacing));
7229 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7230 Spacing * 2));
7231 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7232 Spacing * 3));
7233 TmpInst.addOperand(Inst.getOperand(1)); // lane
7234 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7235 TmpInst.addOperand(Inst.getOperand(5));
7236 Inst = TmpInst;
7237 return true;
7238 }
7239
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007240 case ARM::VLD1LNdAsm_8:
7241 case ARM::VLD1LNdAsm_16:
7242 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00007243 MCInst TmpInst;
7244 // Shuffle the operands around so the lane index operand is in the
7245 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007246 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007247 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00007248 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7249 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7250 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7251 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7252 TmpInst.addOperand(Inst.getOperand(1)); // lane
7253 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7254 TmpInst.addOperand(Inst.getOperand(5));
7255 Inst = TmpInst;
7256 return true;
7257 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007258
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007259 case ARM::VLD2LNdAsm_8:
7260 case ARM::VLD2LNdAsm_16:
7261 case ARM::VLD2LNdAsm_32:
7262 case ARM::VLD2LNqAsm_16:
7263 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007264 MCInst TmpInst;
7265 // Shuffle the operands around so the lane index operand is in the
7266 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007267 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007268 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007269 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007270 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7271 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007272 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7273 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7274 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007275 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7276 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007277 TmpInst.addOperand(Inst.getOperand(1)); // lane
7278 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7279 TmpInst.addOperand(Inst.getOperand(5));
7280 Inst = TmpInst;
7281 return true;
7282 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007283
7284 case ARM::VLD3LNdAsm_8:
7285 case ARM::VLD3LNdAsm_16:
7286 case ARM::VLD3LNdAsm_32:
7287 case ARM::VLD3LNqAsm_16:
7288 case ARM::VLD3LNqAsm_32: {
7289 MCInst TmpInst;
7290 // Shuffle the operands around so the lane index operand is in the
7291 // right place.
7292 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007293 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007294 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7295 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7296 Spacing));
7297 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007298 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007299 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7300 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7301 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7302 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7303 Spacing));
7304 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007305 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007306 TmpInst.addOperand(Inst.getOperand(1)); // lane
7307 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7308 TmpInst.addOperand(Inst.getOperand(5));
7309 Inst = TmpInst;
7310 return true;
7311 }
7312
Jim Grosbach14952a02012-01-24 18:37:25 +00007313 case ARM::VLD4LNdAsm_8:
7314 case ARM::VLD4LNdAsm_16:
7315 case ARM::VLD4LNdAsm_32:
7316 case ARM::VLD4LNqAsm_16:
7317 case ARM::VLD4LNqAsm_32: {
7318 MCInst TmpInst;
7319 // Shuffle the operands around so the lane index operand is in the
7320 // right place.
7321 unsigned Spacing;
7322 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7323 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7324 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7325 Spacing));
7326 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7327 Spacing * 2));
7328 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7329 Spacing * 3));
7330 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7331 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7332 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7333 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7334 Spacing));
7335 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7336 Spacing * 2));
7337 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7338 Spacing * 3));
7339 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 }
7345
Jim Grosbachb78403c2012-01-24 23:47:04 +00007346 // VLD3DUP single 3-element structure to all lanes instructions.
7347 case ARM::VLD3DUPdAsm_8:
7348 case ARM::VLD3DUPdAsm_16:
7349 case ARM::VLD3DUPdAsm_32:
7350 case ARM::VLD3DUPqAsm_8:
7351 case ARM::VLD3DUPqAsm_16:
7352 case ARM::VLD3DUPqAsm_32: {
7353 MCInst TmpInst;
7354 unsigned Spacing;
7355 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7356 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() +
7360 Spacing * 2));
7361 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7362 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7363 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7364 TmpInst.addOperand(Inst.getOperand(4));
7365 Inst = TmpInst;
7366 return true;
7367 }
7368
7369 case ARM::VLD3DUPdWB_fixed_Asm_8:
7370 case ARM::VLD3DUPdWB_fixed_Asm_16:
7371 case ARM::VLD3DUPdWB_fixed_Asm_32:
7372 case ARM::VLD3DUPqWB_fixed_Asm_8:
7373 case ARM::VLD3DUPqWB_fixed_Asm_16:
7374 case ARM::VLD3DUPqWB_fixed_Asm_32: {
7375 MCInst TmpInst;
7376 unsigned Spacing;
7377 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7378 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7379 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7380 Spacing));
7381 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7382 Spacing * 2));
7383 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7384 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7385 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7386 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7387 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7388 TmpInst.addOperand(Inst.getOperand(4));
7389 Inst = TmpInst;
7390 return true;
7391 }
7392
7393 case ARM::VLD3DUPdWB_register_Asm_8:
7394 case ARM::VLD3DUPdWB_register_Asm_16:
7395 case ARM::VLD3DUPdWB_register_Asm_32:
7396 case ARM::VLD3DUPqWB_register_Asm_8:
7397 case ARM::VLD3DUPqWB_register_Asm_16:
7398 case ARM::VLD3DUPqWB_register_Asm_32: {
7399 MCInst TmpInst;
7400 unsigned Spacing;
7401 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7402 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7403 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7404 Spacing));
7405 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7406 Spacing * 2));
7407 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7408 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7409 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7410 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7411 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7412 TmpInst.addOperand(Inst.getOperand(5));
7413 Inst = TmpInst;
7414 return true;
7415 }
7416
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007417 // VLD3 multiple 3-element structure instructions.
7418 case ARM::VLD3dAsm_8:
7419 case ARM::VLD3dAsm_16:
7420 case ARM::VLD3dAsm_32:
7421 case ARM::VLD3qAsm_8:
7422 case ARM::VLD3qAsm_16:
7423 case ARM::VLD3qAsm_32: {
7424 MCInst TmpInst;
7425 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007426 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007427 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7428 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7429 Spacing));
7430 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7431 Spacing * 2));
7432 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7433 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7434 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7435 TmpInst.addOperand(Inst.getOperand(4));
7436 Inst = TmpInst;
7437 return true;
7438 }
7439
7440 case ARM::VLD3dWB_fixed_Asm_8:
7441 case ARM::VLD3dWB_fixed_Asm_16:
7442 case ARM::VLD3dWB_fixed_Asm_32:
7443 case ARM::VLD3qWB_fixed_Asm_8:
7444 case ARM::VLD3qWB_fixed_Asm_16:
7445 case ARM::VLD3qWB_fixed_Asm_32: {
7446 MCInst TmpInst;
7447 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007448 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007449 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7450 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7451 Spacing));
7452 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7453 Spacing * 2));
7454 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7455 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7456 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7457 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7458 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7459 TmpInst.addOperand(Inst.getOperand(4));
7460 Inst = TmpInst;
7461 return true;
7462 }
7463
7464 case ARM::VLD3dWB_register_Asm_8:
7465 case ARM::VLD3dWB_register_Asm_16:
7466 case ARM::VLD3dWB_register_Asm_32:
7467 case ARM::VLD3qWB_register_Asm_8:
7468 case ARM::VLD3qWB_register_Asm_16:
7469 case ARM::VLD3qWB_register_Asm_32: {
7470 MCInst TmpInst;
7471 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007472 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007473 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7474 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7475 Spacing));
7476 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7477 Spacing * 2));
7478 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7479 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7480 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7481 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7482 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7483 TmpInst.addOperand(Inst.getOperand(5));
7484 Inst = TmpInst;
7485 return true;
7486 }
7487
Jim Grosbach086cbfa2012-01-25 00:01:08 +00007488 // VLD4DUP single 3-element structure to all lanes instructions.
7489 case ARM::VLD4DUPdAsm_8:
7490 case ARM::VLD4DUPdAsm_16:
7491 case ARM::VLD4DUPdAsm_32:
7492 case ARM::VLD4DUPqAsm_8:
7493 case ARM::VLD4DUPqAsm_16:
7494 case ARM::VLD4DUPqAsm_32: {
7495 MCInst TmpInst;
7496 unsigned Spacing;
7497 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7498 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7500 Spacing));
7501 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7502 Spacing * 2));
7503 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7504 Spacing * 3));
7505 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7506 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7507 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7508 TmpInst.addOperand(Inst.getOperand(4));
7509 Inst = TmpInst;
7510 return true;
7511 }
7512
7513 case ARM::VLD4DUPdWB_fixed_Asm_8:
7514 case ARM::VLD4DUPdWB_fixed_Asm_16:
7515 case ARM::VLD4DUPdWB_fixed_Asm_32:
7516 case ARM::VLD4DUPqWB_fixed_Asm_8:
7517 case ARM::VLD4DUPqWB_fixed_Asm_16:
7518 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7519 MCInst TmpInst;
7520 unsigned Spacing;
7521 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7522 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7523 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7524 Spacing));
7525 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7526 Spacing * 2));
7527 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7528 Spacing * 3));
7529 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7530 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7531 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7532 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7533 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7534 TmpInst.addOperand(Inst.getOperand(4));
7535 Inst = TmpInst;
7536 return true;
7537 }
7538
7539 case ARM::VLD4DUPdWB_register_Asm_8:
7540 case ARM::VLD4DUPdWB_register_Asm_16:
7541 case ARM::VLD4DUPdWB_register_Asm_32:
7542 case ARM::VLD4DUPqWB_register_Asm_8:
7543 case ARM::VLD4DUPqWB_register_Asm_16:
7544 case ARM::VLD4DUPqWB_register_Asm_32: {
7545 MCInst TmpInst;
7546 unsigned Spacing;
7547 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7548 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7549 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7550 Spacing));
7551 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7552 Spacing * 2));
7553 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7554 Spacing * 3));
7555 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7556 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7557 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7558 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7559 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7560 TmpInst.addOperand(Inst.getOperand(5));
7561 Inst = TmpInst;
7562 return true;
7563 }
7564
7565 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00007566 case ARM::VLD4dAsm_8:
7567 case ARM::VLD4dAsm_16:
7568 case ARM::VLD4dAsm_32:
7569 case ARM::VLD4qAsm_8:
7570 case ARM::VLD4qAsm_16:
7571 case ARM::VLD4qAsm_32: {
7572 MCInst TmpInst;
7573 unsigned Spacing;
7574 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7575 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7577 Spacing));
7578 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7579 Spacing * 2));
7580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7581 Spacing * 3));
7582 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7583 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7584 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7585 TmpInst.addOperand(Inst.getOperand(4));
7586 Inst = TmpInst;
7587 return true;
7588 }
7589
7590 case ARM::VLD4dWB_fixed_Asm_8:
7591 case ARM::VLD4dWB_fixed_Asm_16:
7592 case ARM::VLD4dWB_fixed_Asm_32:
7593 case ARM::VLD4qWB_fixed_Asm_8:
7594 case ARM::VLD4qWB_fixed_Asm_16:
7595 case ARM::VLD4qWB_fixed_Asm_32: {
7596 MCInst TmpInst;
7597 unsigned Spacing;
7598 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7599 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7600 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7601 Spacing));
7602 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7603 Spacing * 2));
7604 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7605 Spacing * 3));
7606 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7607 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7608 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7609 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7610 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7611 TmpInst.addOperand(Inst.getOperand(4));
7612 Inst = TmpInst;
7613 return true;
7614 }
7615
7616 case ARM::VLD4dWB_register_Asm_8:
7617 case ARM::VLD4dWB_register_Asm_16:
7618 case ARM::VLD4dWB_register_Asm_32:
7619 case ARM::VLD4qWB_register_Asm_8:
7620 case ARM::VLD4qWB_register_Asm_16:
7621 case ARM::VLD4qWB_register_Asm_32: {
7622 MCInst TmpInst;
7623 unsigned Spacing;
7624 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7625 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7626 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7627 Spacing));
7628 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7629 Spacing * 2));
7630 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7631 Spacing * 3));
7632 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7633 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7634 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7635 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7636 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7637 TmpInst.addOperand(Inst.getOperand(5));
7638 Inst = TmpInst;
7639 return true;
7640 }
7641
Jim Grosbach1a747242012-01-23 23:45:44 +00007642 // VST3 multiple 3-element structure instructions.
7643 case ARM::VST3dAsm_8:
7644 case ARM::VST3dAsm_16:
7645 case ARM::VST3dAsm_32:
7646 case ARM::VST3qAsm_8:
7647 case ARM::VST3qAsm_16:
7648 case ARM::VST3qAsm_32: {
7649 MCInst TmpInst;
7650 unsigned Spacing;
7651 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7652 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7653 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7654 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7655 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7656 Spacing));
7657 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7658 Spacing * 2));
7659 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7660 TmpInst.addOperand(Inst.getOperand(4));
7661 Inst = TmpInst;
7662 return true;
7663 }
7664
7665 case ARM::VST3dWB_fixed_Asm_8:
7666 case ARM::VST3dWB_fixed_Asm_16:
7667 case ARM::VST3dWB_fixed_Asm_32:
7668 case ARM::VST3qWB_fixed_Asm_8:
7669 case ARM::VST3qWB_fixed_Asm_16:
7670 case ARM::VST3qWB_fixed_Asm_32: {
7671 MCInst TmpInst;
7672 unsigned Spacing;
7673 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7674 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7675 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7676 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7677 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7678 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7679 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7680 Spacing));
7681 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7682 Spacing * 2));
7683 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7684 TmpInst.addOperand(Inst.getOperand(4));
7685 Inst = TmpInst;
7686 return true;
7687 }
7688
7689 case ARM::VST3dWB_register_Asm_8:
7690 case ARM::VST3dWB_register_Asm_16:
7691 case ARM::VST3dWB_register_Asm_32:
7692 case ARM::VST3qWB_register_Asm_8:
7693 case ARM::VST3qWB_register_Asm_16:
7694 case ARM::VST3qWB_register_Asm_32: {
7695 MCInst TmpInst;
7696 unsigned Spacing;
7697 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7698 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7699 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7700 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7701 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7702 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7703 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7704 Spacing));
7705 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7706 Spacing * 2));
7707 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7708 TmpInst.addOperand(Inst.getOperand(5));
7709 Inst = TmpInst;
7710 return true;
7711 }
7712
Jim Grosbachda70eac2012-01-24 00:58:13 +00007713 // VST4 multiple 3-element structure instructions.
7714 case ARM::VST4dAsm_8:
7715 case ARM::VST4dAsm_16:
7716 case ARM::VST4dAsm_32:
7717 case ARM::VST4qAsm_8:
7718 case ARM::VST4qAsm_16:
7719 case ARM::VST4qAsm_32: {
7720 MCInst TmpInst;
7721 unsigned Spacing;
7722 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7723 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7724 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7725 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7726 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7727 Spacing));
7728 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7729 Spacing * 2));
7730 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7731 Spacing * 3));
7732 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7733 TmpInst.addOperand(Inst.getOperand(4));
7734 Inst = TmpInst;
7735 return true;
7736 }
7737
7738 case ARM::VST4dWB_fixed_Asm_8:
7739 case ARM::VST4dWB_fixed_Asm_16:
7740 case ARM::VST4dWB_fixed_Asm_32:
7741 case ARM::VST4qWB_fixed_Asm_8:
7742 case ARM::VST4qWB_fixed_Asm_16:
7743 case ARM::VST4qWB_fixed_Asm_32: {
7744 MCInst TmpInst;
7745 unsigned Spacing;
7746 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7747 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7748 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7749 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7750 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7751 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7752 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7753 Spacing));
7754 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7755 Spacing * 2));
7756 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7757 Spacing * 3));
7758 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7759 TmpInst.addOperand(Inst.getOperand(4));
7760 Inst = TmpInst;
7761 return true;
7762 }
7763
7764 case ARM::VST4dWB_register_Asm_8:
7765 case ARM::VST4dWB_register_Asm_16:
7766 case ARM::VST4dWB_register_Asm_32:
7767 case ARM::VST4qWB_register_Asm_8:
7768 case ARM::VST4qWB_register_Asm_16:
7769 case ARM::VST4qWB_register_Asm_32: {
7770 MCInst TmpInst;
7771 unsigned Spacing;
7772 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7773 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7774 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7775 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7776 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7777 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7778 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7779 Spacing));
7780 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7781 Spacing * 2));
7782 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7783 Spacing * 3));
7784 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7785 TmpInst.addOperand(Inst.getOperand(5));
7786 Inst = TmpInst;
7787 return true;
7788 }
7789
Jim Grosbachad66de12012-04-11 00:15:16 +00007790 // Handle encoding choice for the shift-immediate instructions.
7791 case ARM::t2LSLri:
7792 case ARM::t2LSRri:
7793 case ARM::t2ASRri: {
7794 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7795 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7796 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007797 !(static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7798 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) {
Jim Grosbachad66de12012-04-11 00:15:16 +00007799 unsigned NewOpc;
7800 switch (Inst.getOpcode()) {
7801 default: llvm_unreachable("unexpected opcode");
7802 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7803 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7804 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7805 }
7806 // The Thumb1 operands aren't in the same order. Awesome, eh?
7807 MCInst TmpInst;
7808 TmpInst.setOpcode(NewOpc);
7809 TmpInst.addOperand(Inst.getOperand(0));
7810 TmpInst.addOperand(Inst.getOperand(5));
7811 TmpInst.addOperand(Inst.getOperand(1));
7812 TmpInst.addOperand(Inst.getOperand(2));
7813 TmpInst.addOperand(Inst.getOperand(3));
7814 TmpInst.addOperand(Inst.getOperand(4));
7815 Inst = TmpInst;
7816 return true;
7817 }
7818 return false;
7819 }
7820
Jim Grosbach485e5622011-12-13 22:45:11 +00007821 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007822 case ARM::t2MOVsr:
7823 case ARM::t2MOVSsr: {
7824 // Which instruction to expand to depends on the CCOut operand and
7825 // whether we're in an IT block if the register operands are low
7826 // registers.
7827 bool isNarrow = false;
7828 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7829 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7830 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7831 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7832 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7833 isNarrow = true;
7834 MCInst TmpInst;
7835 unsigned newOpc;
7836 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7837 default: llvm_unreachable("unexpected opcode!");
7838 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7839 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7840 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7841 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7842 }
7843 TmpInst.setOpcode(newOpc);
7844 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7845 if (isNarrow)
7846 TmpInst.addOperand(MCOperand::CreateReg(
7847 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7848 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7849 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7850 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7851 TmpInst.addOperand(Inst.getOperand(5));
7852 if (!isNarrow)
7853 TmpInst.addOperand(MCOperand::CreateReg(
7854 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7855 Inst = TmpInst;
7856 return true;
7857 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007858 case ARM::t2MOVsi:
7859 case ARM::t2MOVSsi: {
7860 // Which instruction to expand to depends on the CCOut operand and
7861 // whether we're in an IT block if the register operands are low
7862 // registers.
7863 bool isNarrow = false;
7864 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7865 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7866 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7867 isNarrow = true;
7868 MCInst TmpInst;
7869 unsigned newOpc;
7870 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7871 default: llvm_unreachable("unexpected opcode!");
7872 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7873 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7874 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7875 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007876 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007877 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007878 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7879 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007880 TmpInst.setOpcode(newOpc);
7881 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7882 if (isNarrow)
7883 TmpInst.addOperand(MCOperand::CreateReg(
7884 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7885 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007886 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007887 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007888 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7889 TmpInst.addOperand(Inst.getOperand(4));
7890 if (!isNarrow)
7891 TmpInst.addOperand(MCOperand::CreateReg(
7892 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7893 Inst = TmpInst;
7894 return true;
7895 }
7896 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007897 case ARM::ASRr:
7898 case ARM::LSRr:
7899 case ARM::LSLr:
7900 case ARM::RORr: {
7901 ARM_AM::ShiftOpc ShiftTy;
7902 switch(Inst.getOpcode()) {
7903 default: llvm_unreachable("unexpected opcode!");
7904 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7905 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7906 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7907 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7908 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007909 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7910 MCInst TmpInst;
7911 TmpInst.setOpcode(ARM::MOVsr);
7912 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7913 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7914 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7915 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7916 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7917 TmpInst.addOperand(Inst.getOperand(4));
7918 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7919 Inst = TmpInst;
7920 return true;
7921 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007922 case ARM::ASRi:
7923 case ARM::LSRi:
7924 case ARM::LSLi:
7925 case ARM::RORi: {
7926 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007927 switch(Inst.getOpcode()) {
7928 default: llvm_unreachable("unexpected opcode!");
7929 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7930 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7931 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7932 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7933 }
7934 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007935 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007936 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007937 // A shift by 32 should be encoded as 0 when permitted
7938 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7939 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007940 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007941 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007942 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007943 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7944 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007945 if (Opc == ARM::MOVsi)
7946 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007947 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7948 TmpInst.addOperand(Inst.getOperand(4));
7949 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7950 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007951 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007952 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007953 case ARM::RRXi: {
7954 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7955 MCInst TmpInst;
7956 TmpInst.setOpcode(ARM::MOVsi);
7957 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7958 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7959 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7960 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7961 TmpInst.addOperand(Inst.getOperand(3));
7962 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7963 Inst = TmpInst;
7964 return true;
7965 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007966 case ARM::t2LDMIA_UPD: {
7967 // If this is a load of a single register, then we should use
7968 // a post-indexed LDR instruction instead, per the ARM ARM.
7969 if (Inst.getNumOperands() != 5)
7970 return false;
7971 MCInst TmpInst;
7972 TmpInst.setOpcode(ARM::t2LDR_POST);
7973 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7974 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7975 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7976 TmpInst.addOperand(MCOperand::CreateImm(4));
7977 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7978 TmpInst.addOperand(Inst.getOperand(3));
7979 Inst = TmpInst;
7980 return true;
7981 }
7982 case ARM::t2STMDB_UPD: {
7983 // If this is a store of a single register, then we should use
7984 // a pre-indexed STR instruction instead, per the ARM ARM.
7985 if (Inst.getNumOperands() != 5)
7986 return false;
7987 MCInst TmpInst;
7988 TmpInst.setOpcode(ARM::t2STR_PRE);
7989 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7990 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7991 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7992 TmpInst.addOperand(MCOperand::CreateImm(-4));
7993 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7994 TmpInst.addOperand(Inst.getOperand(3));
7995 Inst = TmpInst;
7996 return true;
7997 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007998 case ARM::LDMIA_UPD:
7999 // If this is a load of a single register via a 'pop', then we should use
8000 // a post-indexed LDR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008001 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008002 Inst.getNumOperands() == 5) {
8003 MCInst TmpInst;
8004 TmpInst.setOpcode(ARM::LDR_POST_IMM);
8005 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8006 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8007 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8008 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
8009 TmpInst.addOperand(MCOperand::CreateImm(4));
8010 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8011 TmpInst.addOperand(Inst.getOperand(3));
8012 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008013 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008014 }
8015 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008016 case ARM::STMDB_UPD:
8017 // If this is a store of a single register via a 'push', then we should use
8018 // a pre-indexed STR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008019 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008020 Inst.getNumOperands() == 5) {
8021 MCInst TmpInst;
8022 TmpInst.setOpcode(ARM::STR_PRE_IMM);
8023 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8024 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8025 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
8026 TmpInst.addOperand(MCOperand::CreateImm(-4));
8027 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8028 TmpInst.addOperand(Inst.getOperand(3));
8029 Inst = TmpInst;
8030 }
8031 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00008032 case ARM::t2ADDri12:
8033 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
8034 // mnemonic was used (not "addw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008035 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008036 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8037 break;
8038 Inst.setOpcode(ARM::t2ADDri);
8039 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8040 break;
8041 case ARM::t2SUBri12:
8042 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
8043 // mnemonic was used (not "subw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008044 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008045 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8046 break;
8047 Inst.setOpcode(ARM::t2SUBri);
8048 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8049 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008050 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008051 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00008052 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8053 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8054 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008055 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008056 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008057 return true;
8058 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008059 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008060 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008061 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008062 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8063 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8064 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008065 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008066 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008067 return true;
8068 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008069 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00008070 case ARM::t2ADDri:
8071 case ARM::t2SUBri: {
8072 // If the destination and first source operand are the same, and
8073 // the flags are compatible with the current IT status, use encoding T2
8074 // instead of T3. For compatibility with the system 'as'. Make sure the
8075 // wide encoding wasn't explicit.
8076 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00008077 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00008078 (unsigned)Inst.getOperand(2).getImm() > 255 ||
8079 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008080 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
8081 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8082 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbachdef5e342012-03-30 17:20:40 +00008083 break;
8084 MCInst TmpInst;
8085 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
8086 ARM::tADDi8 : ARM::tSUBi8);
8087 TmpInst.addOperand(Inst.getOperand(0));
8088 TmpInst.addOperand(Inst.getOperand(5));
8089 TmpInst.addOperand(Inst.getOperand(0));
8090 TmpInst.addOperand(Inst.getOperand(2));
8091 TmpInst.addOperand(Inst.getOperand(3));
8092 TmpInst.addOperand(Inst.getOperand(4));
8093 Inst = TmpInst;
8094 return true;
8095 }
Jim Grosbache489bab2011-12-05 22:16:39 +00008096 case ARM::t2ADDrr: {
8097 // If the destination and first source operand are the same, and
8098 // there's no setting of the flags, use encoding T2 instead of T3.
8099 // Note that this is only for ADD, not SUB. This mirrors the system
8100 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
8101 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
8102 Inst.getOperand(5).getReg() != 0 ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008103 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8104 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00008105 break;
8106 MCInst TmpInst;
8107 TmpInst.setOpcode(ARM::tADDhirr);
8108 TmpInst.addOperand(Inst.getOperand(0));
8109 TmpInst.addOperand(Inst.getOperand(0));
8110 TmpInst.addOperand(Inst.getOperand(2));
8111 TmpInst.addOperand(Inst.getOperand(3));
8112 TmpInst.addOperand(Inst.getOperand(4));
8113 Inst = TmpInst;
8114 return true;
8115 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00008116 case ARM::tADDrSP: {
8117 // If the non-SP source operand and the destination operand are not the
8118 // same, we need to use the 32-bit encoding if it's available.
8119 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
8120 Inst.setOpcode(ARM::t2ADDrr);
8121 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8122 return true;
8123 }
8124 break;
8125 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008126 case ARM::tB:
8127 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008128 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008129 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008130 return true;
8131 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008132 break;
8133 case ARM::t2B:
8134 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008135 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008136 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008137 return true;
8138 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008139 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00008140 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008141 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00008142 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00008143 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00008144 return true;
8145 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00008146 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008147 case ARM::tBcc:
8148 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00008149 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008150 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00008151 return true;
8152 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00008153 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008154 case ARM::tLDMIA: {
8155 // If the register list contains any high registers, or if the writeback
8156 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
8157 // instead if we're in Thumb2. Otherwise, this should have generated
8158 // an error in validateInstruction().
8159 unsigned Rn = Inst.getOperand(0).getReg();
8160 bool hasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00008161 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8162 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Jim Grosbacha31f2232011-09-07 18:05:34 +00008163 bool listContainsBase;
8164 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
8165 (!listContainsBase && !hasWritebackToken) ||
8166 (listContainsBase && hasWritebackToken)) {
8167 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8168 assert (isThumbTwo());
8169 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
8170 // If we're switching to the updating version, we need to insert
8171 // the writeback tied operand.
8172 if (hasWritebackToken)
8173 Inst.insert(Inst.begin(),
8174 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00008175 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008176 }
8177 break;
8178 }
Jim Grosbach099c9762011-09-16 20:50:13 +00008179 case ARM::tSTMIA_UPD: {
8180 // If the register list contains any high registers, we need to use
8181 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8182 // should have generated an error in validateInstruction().
8183 unsigned Rn = Inst.getOperand(0).getReg();
8184 bool listContainsBase;
8185 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
8186 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8187 assert (isThumbTwo());
8188 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00008189 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00008190 }
8191 break;
8192 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008193 case ARM::tPOP: {
8194 bool listContainsBase;
8195 // If the register list contains any high registers, we need to use
8196 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8197 // should have generated an error in validateInstruction().
8198 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008199 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008200 assert (isThumbTwo());
8201 Inst.setOpcode(ARM::t2LDMIA_UPD);
8202 // Add the base register and writeback operands.
8203 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8204 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008205 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008206 }
8207 case ARM::tPUSH: {
8208 bool listContainsBase;
8209 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008210 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008211 assert (isThumbTwo());
8212 Inst.setOpcode(ARM::t2STMDB_UPD);
8213 // Add the base register and writeback operands.
8214 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8215 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008216 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008217 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008218 case ARM::t2MOVi: {
8219 // If we can use the 16-bit encoding and the user didn't explicitly
8220 // request the 32-bit variant, transform it here.
8221 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00008222 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00008223 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008224 Inst.getOperand(4).getReg() == ARM::CPSR) ||
8225 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
8226 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8227 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008228 // The operands aren't in the same order for tMOVi8...
8229 MCInst TmpInst;
8230 TmpInst.setOpcode(ARM::tMOVi8);
8231 TmpInst.addOperand(Inst.getOperand(0));
8232 TmpInst.addOperand(Inst.getOperand(4));
8233 TmpInst.addOperand(Inst.getOperand(1));
8234 TmpInst.addOperand(Inst.getOperand(2));
8235 TmpInst.addOperand(Inst.getOperand(3));
8236 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008237 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008238 }
8239 break;
8240 }
8241 case ARM::t2MOVr: {
8242 // If we can use the 16-bit encoding and the user didn't explicitly
8243 // request the 32-bit variant, transform it here.
8244 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8245 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8246 Inst.getOperand(2).getImm() == ARMCC::AL &&
8247 Inst.getOperand(4).getReg() == ARM::CPSR &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008248 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8249 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008250 // The operands aren't the same for tMOV[S]r... (no cc_out)
8251 MCInst TmpInst;
8252 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
8253 TmpInst.addOperand(Inst.getOperand(0));
8254 TmpInst.addOperand(Inst.getOperand(1));
8255 TmpInst.addOperand(Inst.getOperand(2));
8256 TmpInst.addOperand(Inst.getOperand(3));
8257 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008258 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008259 }
8260 break;
8261 }
Jim Grosbach82213192011-09-19 20:29:33 +00008262 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00008263 case ARM::t2SXTB:
8264 case ARM::t2UXTH:
8265 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00008266 // If we can use the 16-bit encoding and the user didn't explicitly
8267 // request the 32-bit variant, transform it here.
8268 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8269 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8270 Inst.getOperand(2).getImm() == 0 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008271 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8272 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00008273 unsigned NewOpc;
8274 switch (Inst.getOpcode()) {
8275 default: llvm_unreachable("Illegal opcode!");
8276 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
8277 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
8278 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
8279 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
8280 }
Jim Grosbach82213192011-09-19 20:29:33 +00008281 // The operands aren't the same for thumb1 (no rotate operand).
8282 MCInst TmpInst;
8283 TmpInst.setOpcode(NewOpc);
8284 TmpInst.addOperand(Inst.getOperand(0));
8285 TmpInst.addOperand(Inst.getOperand(1));
8286 TmpInst.addOperand(Inst.getOperand(3));
8287 TmpInst.addOperand(Inst.getOperand(4));
8288 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008289 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00008290 }
8291 break;
8292 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008293 case ARM::MOVsi: {
8294 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00008295 // rrx shifts and asr/lsr of #32 is encoded as 0
8296 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
8297 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008298 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
8299 // Shifting by zero is accepted as a vanilla 'MOVr'
8300 MCInst TmpInst;
8301 TmpInst.setOpcode(ARM::MOVr);
8302 TmpInst.addOperand(Inst.getOperand(0));
8303 TmpInst.addOperand(Inst.getOperand(1));
8304 TmpInst.addOperand(Inst.getOperand(3));
8305 TmpInst.addOperand(Inst.getOperand(4));
8306 TmpInst.addOperand(Inst.getOperand(5));
8307 Inst = TmpInst;
8308 return true;
8309 }
8310 return false;
8311 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00008312 case ARM::ANDrsi:
8313 case ARM::ORRrsi:
8314 case ARM::EORrsi:
8315 case ARM::BICrsi:
8316 case ARM::SUBrsi:
8317 case ARM::ADDrsi: {
8318 unsigned newOpc;
8319 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
8320 if (SOpc == ARM_AM::rrx) return false;
8321 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00008322 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00008323 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
8324 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
8325 case ARM::EORrsi: newOpc = ARM::EORrr; break;
8326 case ARM::BICrsi: newOpc = ARM::BICrr; break;
8327 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
8328 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
8329 }
8330 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00008331 // The exception is for right shifts, where 0 == 32
8332 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
8333 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00008334 MCInst TmpInst;
8335 TmpInst.setOpcode(newOpc);
8336 TmpInst.addOperand(Inst.getOperand(0));
8337 TmpInst.addOperand(Inst.getOperand(1));
8338 TmpInst.addOperand(Inst.getOperand(2));
8339 TmpInst.addOperand(Inst.getOperand(4));
8340 TmpInst.addOperand(Inst.getOperand(5));
8341 TmpInst.addOperand(Inst.getOperand(6));
8342 Inst = TmpInst;
8343 return true;
8344 }
8345 return false;
8346 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00008347 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008348 case ARM::t2IT: {
8349 // The mask bits for all but the first condition are represented as
8350 // the low bit of the condition code value implies 't'. We currently
8351 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00008352 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008353 MCOperand &MO = Inst.getOperand(1);
8354 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00008355 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00008356 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008357 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008358 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00008359 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00008360 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008361 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00008362
8363 // Set up the IT block state according to the IT instruction we just
8364 // matched.
8365 assert(!inITBlock() && "nested IT blocks?!");
8366 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
8367 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
8368 ITState.CurPosition = 0;
8369 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008370 break;
8371 }
Richard Bartona39625e2012-07-09 16:12:24 +00008372 case ARM::t2LSLrr:
8373 case ARM::t2LSRrr:
8374 case ARM::t2ASRrr:
8375 case ARM::t2SBCrr:
8376 case ARM::t2RORrr:
8377 case ARM::t2BICrr:
8378 {
Richard Bartond5660372012-07-09 16:14:28 +00008379 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008380 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8381 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8382 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008383 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008384 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8385 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8386 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8387 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008388 unsigned NewOpc;
8389 switch (Inst.getOpcode()) {
8390 default: llvm_unreachable("unexpected opcode");
8391 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
8392 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
8393 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
8394 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
8395 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
8396 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
8397 }
8398 MCInst TmpInst;
8399 TmpInst.setOpcode(NewOpc);
8400 TmpInst.addOperand(Inst.getOperand(0));
8401 TmpInst.addOperand(Inst.getOperand(5));
8402 TmpInst.addOperand(Inst.getOperand(1));
8403 TmpInst.addOperand(Inst.getOperand(2));
8404 TmpInst.addOperand(Inst.getOperand(3));
8405 TmpInst.addOperand(Inst.getOperand(4));
8406 Inst = TmpInst;
8407 return true;
8408 }
8409 return false;
8410 }
8411 case ARM::t2ANDrr:
8412 case ARM::t2EORrr:
8413 case ARM::t2ADCrr:
8414 case ARM::t2ORRrr:
8415 {
Richard Bartond5660372012-07-09 16:14:28 +00008416 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008417 // These instructions are special in that they are commutable, so shorter encodings
8418 // are available more often.
8419 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8420 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8421 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
8422 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008423 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008424 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8425 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8426 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8427 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008428 unsigned NewOpc;
8429 switch (Inst.getOpcode()) {
8430 default: llvm_unreachable("unexpected opcode");
8431 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
8432 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
8433 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
8434 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
8435 }
8436 MCInst TmpInst;
8437 TmpInst.setOpcode(NewOpc);
8438 TmpInst.addOperand(Inst.getOperand(0));
8439 TmpInst.addOperand(Inst.getOperand(5));
8440 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
8441 TmpInst.addOperand(Inst.getOperand(1));
8442 TmpInst.addOperand(Inst.getOperand(2));
8443 } else {
8444 TmpInst.addOperand(Inst.getOperand(2));
8445 TmpInst.addOperand(Inst.getOperand(1));
8446 }
8447 TmpInst.addOperand(Inst.getOperand(3));
8448 TmpInst.addOperand(Inst.getOperand(4));
8449 Inst = TmpInst;
8450 return true;
8451 }
8452 return false;
8453 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008454 }
Jim Grosbachafad0532011-11-10 23:42:14 +00008455 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008456}
8457
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008458unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
8459 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
8460 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008461 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00008462 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008463 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
8464 assert(MCID.hasOptionalDef() &&
8465 "optionally flag setting instruction missing optional def operand");
8466 assert(MCID.NumOperands == Inst.getNumOperands() &&
8467 "operand count mismatch!");
8468 // Find the optional-def operand (cc_out).
8469 unsigned OpNo;
8470 for (OpNo = 0;
8471 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
8472 ++OpNo)
8473 ;
8474 // If we're parsing Thumb1, reject it completely.
8475 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
8476 return Match_MnemonicFail;
8477 // If we're parsing Thumb2, which form is legal depends on whether we're
8478 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00008479 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
8480 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008481 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00008482 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8483 inITBlock())
8484 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008485 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008486 // Some high-register supporting Thumb1 encodings only allow both registers
8487 // to be from r0-r7 when in Thumb2.
Renato Golin36c626e2014-09-26 16:14:29 +00008488 else if (Opc == ARM::tADDhirr && isThumbOne() && !hasV6MOps() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008489 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8490 isARMLowRegister(Inst.getOperand(2).getReg()))
8491 return Match_RequiresThumb2;
8492 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00008493 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008494 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8495 isARMLowRegister(Inst.getOperand(1).getReg()))
8496 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008497 return Match_Success;
8498}
8499
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008500namespace llvm {
8501template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008502 return true; // In an assembly source, no need to second-guess
8503}
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008504}
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008505
Tim Northover26bb14e2014-08-18 11:49:42 +00008506static const char *getSubtargetFeatureName(uint64_t Val);
David Blaikie960ea3f2014-06-08 16:18:35 +00008507bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
8508 OperandVector &Operands,
Tim Northover26bb14e2014-08-18 11:49:42 +00008509 MCStreamer &Out, uint64_t &ErrorInfo,
David Blaikie960ea3f2014-06-08 16:18:35 +00008510 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00008511 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00008512 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00008513
Chad Rosier2f480a82012-10-12 22:53:36 +00008514 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00008515 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00008516 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00008517 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008518 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008519 // Context sensitive operand constraints aren't handled by the matcher,
8520 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008521 if (validateInstruction(Inst, Operands)) {
8522 // Still progress the IT block, otherwise one wrong condition causes
8523 // nasty cascading errors.
8524 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008525 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008526 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008527
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008528 { // processInstruction() updates inITBlock state, we need to save it away
8529 bool wasInITBlock = inITBlock();
8530
8531 // Some instructions need post-processing to, for example, tweak which
8532 // encoding is selected. Loop on it while changes happen so the
8533 // individual transformations can chain off each other. E.g.,
8534 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00008535 while (processInstruction(Inst, Operands, Out))
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008536 ;
8537
8538 // Only after the instruction is fully processed, we can validate it
8539 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00008540 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008541 Warning(IDLoc, "deprecated instruction in IT block");
8542 }
8543 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008544
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008545 // Only move forward at the very end so that everything in validate
8546 // and process gets a consistent answer about whether we're in an IT
8547 // block.
8548 forwardITPosition();
8549
Jim Grosbach82f76d12012-01-25 19:52:01 +00008550 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8551 // doesn't actually encode.
8552 if (Inst.getOpcode() == ARM::ITasm)
8553 return false;
8554
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00008555 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00008556 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00008557 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008558 case Match_MissingFeature: {
8559 assert(ErrorInfo && "Unknown missing feature!");
8560 // Special case the error message for the very common case where only
8561 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8562 std::string Msg = "instruction requires:";
Tim Northover26bb14e2014-08-18 11:49:42 +00008563 uint64_t Mask = 1;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008564 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8565 if (ErrorInfo & Mask) {
8566 Msg += " ";
8567 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8568 }
8569 Mask <<= 1;
8570 }
8571 return Error(IDLoc, Msg);
8572 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008573 case Match_InvalidOperand: {
8574 SMLoc ErrorLoc = IDLoc;
Tim Northover26bb14e2014-08-18 11:49:42 +00008575 if (ErrorInfo != ~0ULL) {
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008576 if (ErrorInfo >= Operands.size())
8577 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00008578
David Blaikie960ea3f2014-06-08 16:18:35 +00008579 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008580 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8581 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008582
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008583 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00008584 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008585 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00008586 return Error(IDLoc, "invalid instruction",
David Blaikie960ea3f2014-06-08 16:18:35 +00008587 ((ARMOperand &)*Operands[0]).getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00008588 case Match_RequiresNotITBlock:
8589 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008590 case Match_RequiresITBlock:
8591 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008592 case Match_RequiresV6:
8593 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8594 case Match_RequiresThumb2:
8595 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00008596 case Match_ImmRange0_15: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008597 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Jim Grosbach087affe2012-06-22 23:56:48 +00008598 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8599 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8600 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008601 case Match_ImmRange0_239: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008602 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008603 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8604 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8605 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00008606 case Match_AlignedMemoryRequiresNone:
8607 case Match_DupAlignedMemoryRequiresNone:
8608 case Match_AlignedMemoryRequires16:
8609 case Match_DupAlignedMemoryRequires16:
8610 case Match_AlignedMemoryRequires32:
8611 case Match_DupAlignedMemoryRequires32:
8612 case Match_AlignedMemoryRequires64:
8613 case Match_DupAlignedMemoryRequires64:
8614 case Match_AlignedMemoryRequires64or128:
8615 case Match_DupAlignedMemoryRequires64or128:
8616 case Match_AlignedMemoryRequires64or128or256:
8617 {
David Blaikie960ea3f2014-06-08 16:18:35 +00008618 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00008619 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8620 switch (MatchResult) {
8621 default:
8622 llvm_unreachable("Missing Match_Aligned type");
8623 case Match_AlignedMemoryRequiresNone:
8624 case Match_DupAlignedMemoryRequiresNone:
8625 return Error(ErrorLoc, "alignment must be omitted");
8626 case Match_AlignedMemoryRequires16:
8627 case Match_DupAlignedMemoryRequires16:
8628 return Error(ErrorLoc, "alignment must be 16 or omitted");
8629 case Match_AlignedMemoryRequires32:
8630 case Match_DupAlignedMemoryRequires32:
8631 return Error(ErrorLoc, "alignment must be 32 or omitted");
8632 case Match_AlignedMemoryRequires64:
8633 case Match_DupAlignedMemoryRequires64:
8634 return Error(ErrorLoc, "alignment must be 64 or omitted");
8635 case Match_AlignedMemoryRequires64or128:
8636 case Match_DupAlignedMemoryRequires64or128:
8637 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8638 case Match_AlignedMemoryRequires64or128or256:
8639 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8640 }
8641 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008642 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008643
Eric Christopher91d7b902010-10-29 09:26:59 +00008644 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00008645}
8646
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008647/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00008648bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008649 const MCObjectFileInfo::Environment Format =
8650 getContext().getObjectFileInfo()->getObjectFileType();
8651 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008652 bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008653
Kevin Enderbyccab3172009-09-15 00:27:25 +00008654 StringRef IDVal = DirectiveID.getIdentifier();
8655 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008656 return parseLiteralValues(4, DirectiveID.getLoc());
8657 else if (IDVal == ".short" || IDVal == ".hword")
8658 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008659 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008660 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00008661 else if (IDVal == ".arm")
8662 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008663 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008664 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008665 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008666 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008667 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008668 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008669 else if (IDVal == ".unreq")
8670 return parseDirectiveUnreq(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00008671 else if (IDVal == ".fnend")
8672 return parseDirectiveFnEnd(DirectiveID.getLoc());
8673 else if (IDVal == ".cantunwind")
8674 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8675 else if (IDVal == ".personality")
8676 return parseDirectivePersonality(DirectiveID.getLoc());
8677 else if (IDVal == ".handlerdata")
8678 return parseDirectiveHandlerData(DirectiveID.getLoc());
8679 else if (IDVal == ".setfp")
8680 return parseDirectiveSetFP(DirectiveID.getLoc());
8681 else if (IDVal == ".pad")
8682 return parseDirectivePad(DirectiveID.getLoc());
8683 else if (IDVal == ".save")
8684 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8685 else if (IDVal == ".vsave")
8686 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008687 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008688 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008689 else if (IDVal == ".even")
8690 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008691 else if (IDVal == ".personalityindex")
8692 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008693 else if (IDVal == ".unwind_raw")
8694 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008695 else if (IDVal == ".movsp")
8696 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008697 else if (IDVal == ".arch_extension")
8698 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008699 else if (IDVal == ".align")
8700 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008701 else if (IDVal == ".thumb_set")
8702 return parseDirectiveThumbSet(DirectiveID.getLoc());
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008703
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008704 if (!IsMachO && !IsCOFF) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008705 if (IDVal == ".arch")
8706 return parseDirectiveArch(DirectiveID.getLoc());
8707 else if (IDVal == ".cpu")
8708 return parseDirectiveCPU(DirectiveID.getLoc());
8709 else if (IDVal == ".eabi_attribute")
8710 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8711 else if (IDVal == ".fpu")
8712 return parseDirectiveFPU(DirectiveID.getLoc());
8713 else if (IDVal == ".fnstart")
8714 return parseDirectiveFnStart(DirectiveID.getLoc());
8715 else if (IDVal == ".inst")
8716 return parseDirectiveInst(DirectiveID.getLoc());
8717 else if (IDVal == ".inst.n")
8718 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8719 else if (IDVal == ".inst.w")
8720 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8721 else if (IDVal == ".object_arch")
8722 return parseDirectiveObjectArch(DirectiveID.getLoc());
8723 else if (IDVal == ".tlsdescseq")
8724 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8725 }
8726
Kevin Enderbyccab3172009-09-15 00:27:25 +00008727 return true;
8728}
8729
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008730/// parseLiteralValues
8731/// ::= .hword expression [, expression]*
8732/// ::= .short expression [, expression]*
8733/// ::= .word expression [, expression]*
8734bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008735 MCAsmParser &Parser = getParser();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008736 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8737 for (;;) {
8738 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008739 if (getParser().parseExpression(Value)) {
8740 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008741 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008742 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008743
Eric Christopherbf7bc492013-01-09 03:52:05 +00008744 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008745
8746 if (getLexer().is(AsmToken::EndOfStatement))
8747 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008748
Kevin Enderbyccab3172009-09-15 00:27:25 +00008749 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008750 if (getLexer().isNot(AsmToken::Comma)) {
8751 Error(L, "unexpected token in directive");
8752 return false;
8753 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008754 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008755 }
8756 }
8757
Sean Callanana83fd7d2010-01-19 20:27:46 +00008758 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008759 return false;
8760}
8761
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008762/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008763/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008764bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008765 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008766 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8767 Error(L, "unexpected token in directive");
8768 return false;
8769 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008770 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008771
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008772 if (!hasThumb()) {
8773 Error(L, "target does not support Thumb mode");
8774 return false;
8775 }
Tim Northovera2292d02013-06-10 23:20:58 +00008776
Jim Grosbach7f882392011-12-07 18:04:19 +00008777 if (!isThumb())
8778 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008779
Jim Grosbach7f882392011-12-07 18:04:19 +00008780 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8781 return false;
8782}
8783
8784/// parseDirectiveARM
8785/// ::= .arm
8786bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008787 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008788 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8789 Error(L, "unexpected token in directive");
8790 return false;
8791 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008792 Parser.Lex();
8793
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008794 if (!hasARM()) {
8795 Error(L, "target does not support ARM mode");
8796 return false;
8797 }
Tim Northovera2292d02013-06-10 23:20:58 +00008798
Jim Grosbach7f882392011-12-07 18:04:19 +00008799 if (isThumb())
8800 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008801
Jim Grosbach7f882392011-12-07 18:04:19 +00008802 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008803 return false;
8804}
8805
Tim Northover1744d0a2013-10-25 12:49:50 +00008806void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8807 if (NextSymbolIsThumb) {
8808 getParser().getStreamer().EmitThumbFunc(Symbol);
8809 NextSymbolIsThumb = false;
8810 }
8811}
8812
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008813/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008814/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008815bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008816 MCAsmParser &Parser = getParser();
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008817 const auto Format = getContext().getObjectFileInfo()->getObjectFileType();
8818 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008819
Jim Grosbach1152cc02011-12-21 22:30:16 +00008820 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008821 // ELF doesn't
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008822 if (IsMachO) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008823 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008824 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008825 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8826 Error(L, "unexpected token in .thumb_func directive");
8827 return false;
8828 }
8829
Tim Northover1744d0a2013-10-25 12:49:50 +00008830 MCSymbol *Func =
8831 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8832 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008833 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008834 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008835 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008836 }
8837
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008838 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008839 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8840 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008841 return false;
8842 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008843
Tim Northover1744d0a2013-10-25 12:49:50 +00008844 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008845 return false;
8846}
8847
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008848/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008849/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008850bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008851 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008852 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008853 if (Tok.isNot(AsmToken::Identifier)) {
8854 Error(L, "unexpected token in .syntax directive");
8855 return false;
8856 }
8857
Benjamin Kramer92d89982010-07-14 22:38:02 +00008858 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008859 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008860 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008861 } else if (Mode == "divided" || Mode == "DIVIDED") {
8862 Error(L, "'.syntax divided' arm asssembly not supported");
8863 return false;
8864 } else {
8865 Error(L, "unrecognized syntax mode in .syntax directive");
8866 return false;
8867 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008868
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008869 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8870 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8871 return false;
8872 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008873 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008874
8875 // TODO tell the MC streamer the mode
8876 // getParser().getStreamer().Emit???();
8877 return false;
8878}
8879
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008880/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008881/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008882bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008883 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008884 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008885 if (Tok.isNot(AsmToken::Integer)) {
8886 Error(L, "unexpected token in .code directive");
8887 return false;
8888 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008889 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008890 if (Val != 16 && Val != 32) {
8891 Error(L, "invalid operand to .code directive");
8892 return false;
8893 }
8894 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008895
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008896 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8897 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8898 return false;
8899 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008900 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008901
Evan Cheng284b4672011-07-08 22:36:29 +00008902 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008903 if (!hasThumb()) {
8904 Error(L, "target does not support Thumb mode");
8905 return false;
8906 }
Tim Northovera2292d02013-06-10 23:20:58 +00008907
Jim Grosbachf471ac32011-09-06 18:46:23 +00008908 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008909 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008910 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008911 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008912 if (!hasARM()) {
8913 Error(L, "target does not support ARM mode");
8914 return false;
8915 }
Tim Northovera2292d02013-06-10 23:20:58 +00008916
Jim Grosbachf471ac32011-09-06 18:46:23 +00008917 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008918 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008919 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008920 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008921
Kevin Enderby146dcf22009-10-15 20:48:48 +00008922 return false;
8923}
8924
Jim Grosbachab5830e2011-12-14 02:16:11 +00008925/// parseDirectiveReq
8926/// ::= name .req registername
8927bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008928 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008929 Parser.Lex(); // Eat the '.req' token.
8930 unsigned Reg;
8931 SMLoc SRegLoc, ERegLoc;
8932 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008933 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008934 Error(SRegLoc, "register name expected");
8935 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008936 }
8937
8938 // Shouldn't be anything else.
8939 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008940 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008941 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8942 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008943 }
8944
8945 Parser.Lex(); // Consume the EndOfStatement
8946
David Blaikie5106ce72014-11-19 05:49:42 +00008947 if (!RegisterReqs.insert(std::make_pair(Name, Reg)).second) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008948 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8949 return false;
8950 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00008951
8952 return false;
8953}
8954
8955/// parseDirectiveUneq
8956/// ::= .unreq registername
8957bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008958 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008959 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008960 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008961 Error(L, "unexpected input in .unreq directive.");
8962 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008963 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00008964 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008965 Parser.Lex(); // Eat the identifier.
8966 return false;
8967}
8968
Jason W Kim135d2442011-12-20 17:38:12 +00008969/// parseDirectiveArch
8970/// ::= .arch token
8971bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00008972 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8973
8974 unsigned ID = StringSwitch<unsigned>(Arch)
8975#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8976 .Case(NAME, ARM::ID)
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +00008977#define ARM_ARCH_ALIAS(NAME, ID) \
8978 .Case(NAME, ARM::ID)
Logan Chien439e8f92013-12-11 17:16:25 +00008979#include "MCTargetDesc/ARMArchName.def"
8980 .Default(ARM::INVALID_ARCH);
8981
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008982 if (ID == ARM::INVALID_ARCH) {
8983 Error(L, "Unknown arch name");
8984 return false;
8985 }
Logan Chien439e8f92013-12-11 17:16:25 +00008986
8987 getTargetStreamer().emitArch(ID);
8988 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008989}
8990
8991/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008992/// ::= .eabi_attribute int, int [, "str"]
8993/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00008994bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008995 MCAsmParser &Parser = getParser();
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008996 int64_t Tag;
8997 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008998 TagLoc = Parser.getTok().getLoc();
8999 if (Parser.getTok().is(AsmToken::Identifier)) {
9000 StringRef Name = Parser.getTok().getIdentifier();
9001 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
9002 if (Tag == -1) {
9003 Error(TagLoc, "attribute name not recognised: " + Name);
9004 Parser.eatToEndOfStatement();
9005 return false;
9006 }
9007 Parser.Lex();
9008 } else {
9009 const MCExpr *AttrExpr;
9010
9011 TagLoc = Parser.getTok().getLoc();
9012 if (Parser.parseExpression(AttrExpr)) {
9013 Parser.eatToEndOfStatement();
9014 return false;
9015 }
9016
9017 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
9018 if (!CE) {
9019 Error(TagLoc, "expected numeric constant");
9020 Parser.eatToEndOfStatement();
9021 return false;
9022 }
9023
9024 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009025 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009026
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009027 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009028 Error(Parser.getTok().getLoc(), "comma expected");
9029 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009030 return false;
9031 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009032 Parser.Lex(); // skip comma
9033
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009034 StringRef StringValue = "";
9035 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00009036
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009037 int64_t IntegerValue = 0;
9038 bool IsIntegerValue = false;
9039
9040 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
9041 IsStringValue = true;
9042 else if (Tag == ARMBuildAttrs::compatibility) {
9043 IsStringValue = true;
9044 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00009045 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009046 IsIntegerValue = true;
9047 else if (Tag % 2 == 1)
9048 IsStringValue = true;
9049 else
9050 llvm_unreachable("invalid tag type");
9051
9052 if (IsIntegerValue) {
9053 const MCExpr *ValueExpr;
9054 SMLoc ValueExprLoc = Parser.getTok().getLoc();
9055 if (Parser.parseExpression(ValueExpr)) {
9056 Parser.eatToEndOfStatement();
9057 return false;
9058 }
9059
9060 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
9061 if (!CE) {
9062 Error(ValueExprLoc, "expected numeric constant");
9063 Parser.eatToEndOfStatement();
9064 return false;
9065 }
9066
9067 IntegerValue = CE->getValue();
9068 }
9069
9070 if (Tag == ARMBuildAttrs::compatibility) {
9071 if (Parser.getTok().isNot(AsmToken::Comma))
9072 IsStringValue = false;
9073 else
9074 Parser.Lex();
9075 }
9076
9077 if (IsStringValue) {
9078 if (Parser.getTok().isNot(AsmToken::String)) {
9079 Error(Parser.getTok().getLoc(), "bad string constant");
9080 Parser.eatToEndOfStatement();
9081 return false;
9082 }
9083
9084 StringValue = Parser.getTok().getStringContents();
9085 Parser.Lex();
9086 }
9087
9088 if (IsIntegerValue && IsStringValue) {
9089 assert(Tag == ARMBuildAttrs::compatibility);
9090 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
9091 } else if (IsIntegerValue)
9092 getTargetStreamer().emitAttribute(Tag, IntegerValue);
9093 else if (IsStringValue)
9094 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00009095 return false;
9096}
9097
9098/// parseDirectiveCPU
9099/// ::= .cpu str
9100bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
9101 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
9102 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
Roman Divacky7e6b5952014-12-02 20:03:22 +00009103
Roman Divackyfdf05602014-12-03 18:39:44 +00009104 if (!STI.isCPUStringValid(CPU)) {
Roman Divacky7e6b5952014-12-02 20:03:22 +00009105 Error(L, "Unknown CPU name");
9106 return false;
9107 }
9108
Roman Divacky6fd64ff2014-12-04 21:39:24 +00009109 // FIXME: This switches the CPU features globally, therefore it might
9110 // happen that code you would not expect to assemble will. For details
9111 // see: http://llvm.org/bugs/show_bug.cgi?id=20757
Roman Divacky7e6b5952014-12-02 20:03:22 +00009112 STI.InitMCProcessorInfo(CPU, "");
9113 STI.InitCPUSchedModel(CPU);
9114 unsigned FB = ComputeAvailableFeatures(STI.getFeatureBits());
9115 setAvailableFeatures(FB);
9116
Logan Chien8cbb80d2013-10-28 17:51:12 +00009117 return false;
9118}
9119
Nico Weberae050bb2014-08-16 05:37:51 +00009120// FIXME: This is duplicated in getARMFPUFeatures() in
9121// tools/clang/lib/Driver/Tools.cpp
9122static const struct {
9123 const unsigned Fpu;
9124 const uint64_t Enabled;
9125 const uint64_t Disabled;
9126} Fpus[] = {
9127 {ARM::VFP, ARM::FeatureVFP2, ARM::FeatureNEON},
9128 {ARM::VFPV2, ARM::FeatureVFP2, ARM::FeatureNEON},
9129 {ARM::VFPV3, ARM::FeatureVFP3, ARM::FeatureNEON},
9130 {ARM::VFPV3_D16, ARM::FeatureVFP3 | ARM::FeatureD16, ARM::FeatureNEON},
9131 {ARM::VFPV4, ARM::FeatureVFP4, ARM::FeatureNEON},
9132 {ARM::VFPV4_D16, ARM::FeatureVFP4 | ARM::FeatureD16, ARM::FeatureNEON},
Oliver Stannard37e4daa2014-10-01 09:02:17 +00009133 {ARM::FPV5_D16, ARM::FeatureFPARMv8 | ARM::FeatureD16,
9134 ARM::FeatureNEON | ARM::FeatureCrypto},
Nico Weberae050bb2014-08-16 05:37:51 +00009135 {ARM::FP_ARMV8, ARM::FeatureFPARMv8,
9136 ARM::FeatureNEON | ARM::FeatureCrypto},
9137 {ARM::NEON, ARM::FeatureNEON, 0},
9138 {ARM::NEON_VFPV4, ARM::FeatureVFP4 | ARM::FeatureNEON, 0},
9139 {ARM::NEON_FP_ARMV8, ARM::FeatureFPARMv8 | ARM::FeatureNEON,
9140 ARM::FeatureCrypto},
9141 {ARM::CRYPTO_NEON_FP_ARMV8,
9142 ARM::FeatureFPARMv8 | ARM::FeatureNEON | ARM::FeatureCrypto, 0},
9143 {ARM::SOFTVFP, 0, 0},
9144};
9145
Logan Chien8cbb80d2013-10-28 17:51:12 +00009146/// parseDirectiveFPU
9147/// ::= .fpu str
9148bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
9149 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
9150
9151 unsigned ID = StringSwitch<unsigned>(FPU)
9152#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
9153#include "ARMFPUName.def"
9154 .Default(ARM::INVALID_FPU);
9155
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009156 if (ID == ARM::INVALID_FPU) {
9157 Error(L, "Unknown FPU name");
9158 return false;
9159 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009160
Nico Weberae050bb2014-08-16 05:37:51 +00009161 for (const auto &Fpu : Fpus) {
9162 if (Fpu.Fpu != ID)
9163 continue;
9164
9165 // Need to toggle features that should be on but are off and that
9166 // should off but are on.
Tim Northover26bb14e2014-08-18 11:49:42 +00009167 uint64_t Toggle = (Fpu.Enabled & ~STI.getFeatureBits()) |
Nico Weberae050bb2014-08-16 05:37:51 +00009168 (Fpu.Disabled & STI.getFeatureBits());
9169 setAvailableFeatures(ComputeAvailableFeatures(STI.ToggleFeature(Toggle)));
9170 break;
9171 }
9172
Logan Chien8cbb80d2013-10-28 17:51:12 +00009173 getTargetStreamer().emitFPU(ID);
9174 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00009175}
9176
Logan Chien4ea23b52013-05-10 16:17:24 +00009177/// parseDirectiveFnStart
9178/// ::= .fnstart
9179bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009180 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009181 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009182 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009183 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009184 }
9185
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009186 // Reset the unwind directives parser state
9187 UC.reset();
9188
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009189 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009190
9191 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00009192 return false;
9193}
9194
9195/// parseDirectiveFnEnd
9196/// ::= .fnend
9197bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
9198 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009199 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009200 Error(L, ".fnstart must precede .fnend directive");
9201 return false;
9202 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009203
9204 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009205 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009206
9207 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00009208 return false;
9209}
9210
9211/// parseDirectiveCantUnwind
9212/// ::= .cantunwind
9213bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009214 UC.recordCantUnwind(L);
9215
Logan Chien4ea23b52013-05-10 16:17:24 +00009216 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009217 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009218 Error(L, ".fnstart must precede .cantunwind directive");
9219 return false;
9220 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009221 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009222 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009223 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009224 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009225 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009226 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009227 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009228 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009229 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009230 }
9231
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009232 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00009233 return false;
9234}
9235
9236/// parseDirectivePersonality
9237/// ::= .personality name
9238bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009239 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009240 bool HasExistingPersonality = UC.hasPersonality();
9241
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009242 UC.recordPersonality(L);
9243
Logan Chien4ea23b52013-05-10 16:17:24 +00009244 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009245 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009246 Error(L, ".fnstart must precede .personality directive");
9247 return false;
9248 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009249 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009250 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009251 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009252 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009253 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009254 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009255 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009256 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009257 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009258 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009259 if (HasExistingPersonality) {
9260 Parser.eatToEndOfStatement();
9261 Error(L, "multiple personality directives");
9262 UC.emitPersonalityLocNotes();
9263 return false;
9264 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009265
9266 // Parse the name of the personality routine
9267 if (Parser.getTok().isNot(AsmToken::Identifier)) {
9268 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009269 Error(L, "unexpected input in .personality directive.");
9270 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009271 }
9272 StringRef Name(Parser.getTok().getIdentifier());
9273 Parser.Lex();
9274
9275 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009276 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00009277 return false;
9278}
9279
9280/// parseDirectiveHandlerData
9281/// ::= .handlerdata
9282bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009283 UC.recordHandlerData(L);
9284
Logan Chien4ea23b52013-05-10 16:17:24 +00009285 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009286 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009287 Error(L, ".fnstart must precede .personality directive");
9288 return false;
9289 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009290 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009291 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009292 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009293 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009294 }
9295
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009296 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00009297 return false;
9298}
9299
9300/// parseDirectiveSetFP
9301/// ::= .setfp fpreg, spreg [, offset]
9302bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009303 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009304 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009305 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009306 Error(L, ".fnstart must precede .setfp directive");
9307 return false;
9308 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009309 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009310 Error(L, ".setfp must precede .handlerdata directive");
9311 return false;
9312 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009313
9314 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009315 SMLoc FPRegLoc = Parser.getTok().getLoc();
9316 int FPReg = tryParseRegister();
9317 if (FPReg == -1) {
9318 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009319 return false;
9320 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009321
9322 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009323 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009324 Error(Parser.getTok().getLoc(), "comma expected");
9325 return false;
9326 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009327 Parser.Lex(); // skip comma
9328
9329 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009330 SMLoc SPRegLoc = Parser.getTok().getLoc();
9331 int SPReg = tryParseRegister();
9332 if (SPReg == -1) {
9333 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009334 return false;
9335 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009336
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009337 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
9338 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009339 return false;
9340 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009341
9342 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009343 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00009344
9345 // Parse offset
9346 int64_t Offset = 0;
9347 if (Parser.getTok().is(AsmToken::Comma)) {
9348 Parser.Lex(); // skip comma
9349
9350 if (Parser.getTok().isNot(AsmToken::Hash) &&
9351 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009352 Error(Parser.getTok().getLoc(), "'#' expected");
9353 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009354 }
9355 Parser.Lex(); // skip hash token.
9356
9357 const MCExpr *OffsetExpr;
9358 SMLoc ExLoc = Parser.getTok().getLoc();
9359 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009360 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9361 Error(ExLoc, "malformed setfp offset");
9362 return false;
9363 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009364 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009365 if (!CE) {
9366 Error(ExLoc, "setfp offset must be an immediate");
9367 return false;
9368 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009369
9370 Offset = CE->getValue();
9371 }
9372
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009373 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
9374 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00009375 return false;
9376}
9377
9378/// parseDirective
9379/// ::= .pad offset
9380bool ARMAsmParser::parseDirectivePad(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009381 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009382 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009383 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009384 Error(L, ".fnstart must precede .pad directive");
9385 return false;
9386 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009387 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009388 Error(L, ".pad must precede .handlerdata directive");
9389 return false;
9390 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009391
9392 // Parse the offset
9393 if (Parser.getTok().isNot(AsmToken::Hash) &&
9394 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009395 Error(Parser.getTok().getLoc(), "'#' expected");
9396 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009397 }
9398 Parser.Lex(); // skip hash token.
9399
9400 const MCExpr *OffsetExpr;
9401 SMLoc ExLoc = Parser.getTok().getLoc();
9402 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009403 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9404 Error(ExLoc, "malformed pad offset");
9405 return false;
9406 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009407 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009408 if (!CE) {
9409 Error(ExLoc, "pad offset must be an immediate");
9410 return false;
9411 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009412
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009413 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00009414 return false;
9415}
9416
9417/// parseDirectiveRegSave
9418/// ::= .save { registers }
9419/// ::= .vsave { registers }
9420bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
9421 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009422 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009423 Error(L, ".fnstart must precede .save or .vsave directives");
9424 return false;
9425 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009426 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009427 Error(L, ".save or .vsave must precede .handlerdata directive");
9428 return false;
9429 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009430
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009431 // RAII object to make sure parsed operands are deleted.
David Blaikie960ea3f2014-06-08 16:18:35 +00009432 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009433
Logan Chien4ea23b52013-05-10 16:17:24 +00009434 // Parse the register list
David Blaikie960ea3f2014-06-08 16:18:35 +00009435 if (parseRegisterList(Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00009436 return false;
David Blaikie960ea3f2014-06-08 16:18:35 +00009437 ARMOperand &Op = (ARMOperand &)*Operands[0];
9438 if (!IsVector && !Op.isRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009439 Error(L, ".save expects GPR registers");
9440 return false;
9441 }
David Blaikie960ea3f2014-06-08 16:18:35 +00009442 if (IsVector && !Op.isDPRRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009443 Error(L, ".vsave expects DPR registers");
9444 return false;
9445 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009446
David Blaikie960ea3f2014-06-08 16:18:35 +00009447 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00009448 return false;
9449}
9450
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009451/// parseDirectiveInst
9452/// ::= .inst opcode [, ...]
9453/// ::= .inst.n opcode [, ...]
9454/// ::= .inst.w opcode [, ...]
9455bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009456 MCAsmParser &Parser = getParser();
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009457 int Width;
9458
9459 if (isThumb()) {
9460 switch (Suffix) {
9461 case 'n':
9462 Width = 2;
9463 break;
9464 case 'w':
9465 Width = 4;
9466 break;
9467 default:
9468 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009469 Error(Loc, "cannot determine Thumb instruction size, "
9470 "use inst.n/inst.w instead");
9471 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009472 }
9473 } else {
9474 if (Suffix) {
9475 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009476 Error(Loc, "width suffixes are invalid in ARM mode");
9477 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009478 }
9479 Width = 4;
9480 }
9481
9482 if (getLexer().is(AsmToken::EndOfStatement)) {
9483 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009484 Error(Loc, "expected expression following directive");
9485 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009486 }
9487
9488 for (;;) {
9489 const MCExpr *Expr;
9490
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009491 if (getParser().parseExpression(Expr)) {
9492 Error(Loc, "expected expression");
9493 return false;
9494 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009495
9496 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009497 if (!Value) {
9498 Error(Loc, "expected constant expression");
9499 return false;
9500 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009501
9502 switch (Width) {
9503 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009504 if (Value->getValue() > 0xffff) {
9505 Error(Loc, "inst.n operand is too big, use inst.w instead");
9506 return false;
9507 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009508 break;
9509 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009510 if (Value->getValue() > 0xffffffff) {
9511 Error(Loc,
9512 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
9513 return false;
9514 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009515 break;
9516 default:
9517 llvm_unreachable("only supported widths are 2 and 4");
9518 }
9519
9520 getTargetStreamer().emitInst(Value->getValue(), Suffix);
9521
9522 if (getLexer().is(AsmToken::EndOfStatement))
9523 break;
9524
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009525 if (getLexer().isNot(AsmToken::Comma)) {
9526 Error(Loc, "unexpected token in directive");
9527 return false;
9528 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009529
9530 Parser.Lex();
9531 }
9532
9533 Parser.Lex();
9534 return false;
9535}
9536
David Peixotto80c083a2013-12-19 18:26:07 +00009537/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00009538/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00009539bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00009540 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00009541 return false;
9542}
9543
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009544bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9545 const MCSection *Section = getStreamer().getCurrentSection().first;
9546
9547 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9548 TokError("unexpected token in directive");
9549 return false;
9550 }
9551
9552 if (!Section) {
Rafael Espindola7b61ddf2014-10-15 16:12:52 +00009553 getStreamer().InitSections(false);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009554 Section = getStreamer().getCurrentSection().first;
9555 }
9556
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00009557 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009558 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00009559 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009560 else
Rafael Espindola7b514962014-02-04 18:34:04 +00009561 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009562
9563 return false;
9564}
9565
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009566/// parseDirectivePersonalityIndex
9567/// ::= .personalityindex index
9568bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009569 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009570 bool HasExistingPersonality = UC.hasPersonality();
9571
9572 UC.recordPersonalityIndex(L);
9573
9574 if (!UC.hasFnStart()) {
9575 Parser.eatToEndOfStatement();
9576 Error(L, ".fnstart must precede .personalityindex directive");
9577 return false;
9578 }
9579 if (UC.cantUnwind()) {
9580 Parser.eatToEndOfStatement();
9581 Error(L, ".personalityindex cannot be used with .cantunwind");
9582 UC.emitCantUnwindLocNotes();
9583 return false;
9584 }
9585 if (UC.hasHandlerData()) {
9586 Parser.eatToEndOfStatement();
9587 Error(L, ".personalityindex must precede .handlerdata directive");
9588 UC.emitHandlerDataLocNotes();
9589 return false;
9590 }
9591 if (HasExistingPersonality) {
9592 Parser.eatToEndOfStatement();
9593 Error(L, "multiple personality directives");
9594 UC.emitPersonalityLocNotes();
9595 return false;
9596 }
9597
9598 const MCExpr *IndexExpression;
9599 SMLoc IndexLoc = Parser.getTok().getLoc();
9600 if (Parser.parseExpression(IndexExpression)) {
9601 Parser.eatToEndOfStatement();
9602 return false;
9603 }
9604
9605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9606 if (!CE) {
9607 Parser.eatToEndOfStatement();
9608 Error(IndexLoc, "index must be a constant number");
9609 return false;
9610 }
9611 if (CE->getValue() < 0 ||
9612 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9613 Parser.eatToEndOfStatement();
9614 Error(IndexLoc, "personality routine index should be in range [0-3]");
9615 return false;
9616 }
9617
9618 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9619 return false;
9620}
9621
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009622/// parseDirectiveUnwindRaw
9623/// ::= .unwind_raw offset, opcode [, opcode...]
9624bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009625 MCAsmParser &Parser = getParser();
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009626 if (!UC.hasFnStart()) {
9627 Parser.eatToEndOfStatement();
9628 Error(L, ".fnstart must precede .unwind_raw directives");
9629 return false;
9630 }
9631
9632 int64_t StackOffset;
9633
9634 const MCExpr *OffsetExpr;
9635 SMLoc OffsetLoc = getLexer().getLoc();
9636 if (getLexer().is(AsmToken::EndOfStatement) ||
9637 getParser().parseExpression(OffsetExpr)) {
9638 Error(OffsetLoc, "expected expression");
9639 Parser.eatToEndOfStatement();
9640 return false;
9641 }
9642
9643 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9644 if (!CE) {
9645 Error(OffsetLoc, "offset must be a constant");
9646 Parser.eatToEndOfStatement();
9647 return false;
9648 }
9649
9650 StackOffset = CE->getValue();
9651
9652 if (getLexer().isNot(AsmToken::Comma)) {
9653 Error(getLexer().getLoc(), "expected comma");
9654 Parser.eatToEndOfStatement();
9655 return false;
9656 }
9657 Parser.Lex();
9658
9659 SmallVector<uint8_t, 16> Opcodes;
9660 for (;;) {
9661 const MCExpr *OE;
9662
9663 SMLoc OpcodeLoc = getLexer().getLoc();
9664 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9665 Error(OpcodeLoc, "expected opcode expression");
9666 Parser.eatToEndOfStatement();
9667 return false;
9668 }
9669
9670 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9671 if (!OC) {
9672 Error(OpcodeLoc, "opcode value must be a constant");
9673 Parser.eatToEndOfStatement();
9674 return false;
9675 }
9676
9677 const int64_t Opcode = OC->getValue();
9678 if (Opcode & ~0xff) {
9679 Error(OpcodeLoc, "invalid opcode");
9680 Parser.eatToEndOfStatement();
9681 return false;
9682 }
9683
9684 Opcodes.push_back(uint8_t(Opcode));
9685
9686 if (getLexer().is(AsmToken::EndOfStatement))
9687 break;
9688
9689 if (getLexer().isNot(AsmToken::Comma)) {
9690 Error(getLexer().getLoc(), "unexpected token in directive");
9691 Parser.eatToEndOfStatement();
9692 return false;
9693 }
9694
9695 Parser.Lex();
9696 }
9697
9698 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9699
9700 Parser.Lex();
9701 return false;
9702}
9703
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009704/// parseDirectiveTLSDescSeq
9705/// ::= .tlsdescseq tls-variable
9706bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009707 MCAsmParser &Parser = getParser();
9708
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009709 if (getLexer().isNot(AsmToken::Identifier)) {
9710 TokError("expected variable after '.tlsdescseq' directive");
9711 Parser.eatToEndOfStatement();
9712 return false;
9713 }
9714
9715 const MCSymbolRefExpr *SRE =
9716 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9717 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9718 Lex();
9719
9720 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9721 Error(Parser.getTok().getLoc(), "unexpected token");
9722 Parser.eatToEndOfStatement();
9723 return false;
9724 }
9725
9726 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9727 return false;
9728}
9729
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009730/// parseDirectiveMovSP
9731/// ::= .movsp reg [, #offset]
9732bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009733 MCAsmParser &Parser = getParser();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009734 if (!UC.hasFnStart()) {
9735 Parser.eatToEndOfStatement();
9736 Error(L, ".fnstart must precede .movsp directives");
9737 return false;
9738 }
9739 if (UC.getFPReg() != ARM::SP) {
9740 Parser.eatToEndOfStatement();
9741 Error(L, "unexpected .movsp directive");
9742 return false;
9743 }
9744
9745 SMLoc SPRegLoc = Parser.getTok().getLoc();
9746 int SPReg = tryParseRegister();
9747 if (SPReg == -1) {
9748 Parser.eatToEndOfStatement();
9749 Error(SPRegLoc, "register expected");
9750 return false;
9751 }
9752
9753 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9754 Parser.eatToEndOfStatement();
9755 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9756 return false;
9757 }
9758
9759 int64_t Offset = 0;
9760 if (Parser.getTok().is(AsmToken::Comma)) {
9761 Parser.Lex();
9762
9763 if (Parser.getTok().isNot(AsmToken::Hash)) {
9764 Error(Parser.getTok().getLoc(), "expected #constant");
9765 Parser.eatToEndOfStatement();
9766 return false;
9767 }
9768 Parser.Lex();
9769
9770 const MCExpr *OffsetExpr;
9771 SMLoc OffsetLoc = Parser.getTok().getLoc();
9772 if (Parser.parseExpression(OffsetExpr)) {
9773 Parser.eatToEndOfStatement();
9774 Error(OffsetLoc, "malformed offset expression");
9775 return false;
9776 }
9777
9778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9779 if (!CE) {
9780 Parser.eatToEndOfStatement();
9781 Error(OffsetLoc, "offset must be an immediate constant");
9782 return false;
9783 }
9784
9785 Offset = CE->getValue();
9786 }
9787
9788 getTargetStreamer().emitMovSP(SPReg, Offset);
9789 UC.saveFPReg(SPReg);
9790
9791 return false;
9792}
9793
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009794/// parseDirectiveObjectArch
9795/// ::= .object_arch name
9796bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009797 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009798 if (getLexer().isNot(AsmToken::Identifier)) {
9799 Error(getLexer().getLoc(), "unexpected token");
9800 Parser.eatToEndOfStatement();
9801 return false;
9802 }
9803
9804 StringRef Arch = Parser.getTok().getString();
9805 SMLoc ArchLoc = Parser.getTok().getLoc();
9806 getLexer().Lex();
9807
9808 unsigned ID = StringSwitch<unsigned>(Arch)
9809#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9810 .Case(NAME, ARM::ID)
9811#define ARM_ARCH_ALIAS(NAME, ID) \
9812 .Case(NAME, ARM::ID)
9813#include "MCTargetDesc/ARMArchName.def"
9814#undef ARM_ARCH_NAME
9815#undef ARM_ARCH_ALIAS
9816 .Default(ARM::INVALID_ARCH);
9817
9818 if (ID == ARM::INVALID_ARCH) {
9819 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9820 Parser.eatToEndOfStatement();
9821 return false;
9822 }
9823
9824 getTargetStreamer().emitObjectArch(ID);
9825
9826 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9827 Error(getLexer().getLoc(), "unexpected token");
9828 Parser.eatToEndOfStatement();
9829 }
9830
9831 return false;
9832}
9833
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009834/// parseDirectiveAlign
9835/// ::= .align
9836bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9837 // NOTE: if this is not the end of the statement, fall back to the target
9838 // agnostic handling for this directive which will correctly handle this.
9839 if (getLexer().isNot(AsmToken::EndOfStatement))
9840 return true;
9841
9842 // '.align' is target specifically handled to mean 2**2 byte alignment.
9843 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9844 getStreamer().EmitCodeAlignment(4, 0);
9845 else
9846 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9847
9848 return false;
9849}
9850
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009851/// parseDirectiveThumbSet
9852/// ::= .thumb_set name, value
9853bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009854 MCAsmParser &Parser = getParser();
9855
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009856 StringRef Name;
9857 if (Parser.parseIdentifier(Name)) {
9858 TokError("expected identifier after '.thumb_set'");
9859 Parser.eatToEndOfStatement();
9860 return false;
9861 }
9862
9863 if (getLexer().isNot(AsmToken::Comma)) {
9864 TokError("expected comma after name '" + Name + "'");
9865 Parser.eatToEndOfStatement();
9866 return false;
9867 }
9868 Lex();
9869
9870 const MCExpr *Value;
9871 if (Parser.parseExpression(Value)) {
9872 TokError("missing expression");
9873 Parser.eatToEndOfStatement();
9874 return false;
9875 }
9876
9877 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9878 TokError("unexpected token");
9879 Parser.eatToEndOfStatement();
9880 return false;
9881 }
9882 Lex();
9883
9884 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
Rafael Espindola466d6632014-04-27 20:23:58 +00009885 getTargetStreamer().emitThumbSet(Alias, Value);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009886 return false;
9887}
9888
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009889/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009890extern "C" void LLVMInitializeARMAsmParser() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00009891 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9892 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9893 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9894 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009895}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009896
Chris Lattner3e4582a2010-09-06 19:11:01 +00009897#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009898#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009899#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009900#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009901
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009902static const struct {
9903 const char *Name;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009904 const unsigned ArchCheck;
9905 const uint64_t Features;
9906} Extensions[] = {
9907 { "crc", Feature_HasV8, ARM::FeatureCRC },
9908 { "crypto", Feature_HasV8,
9909 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9910 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
9911 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
9912 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
9913 // FIXME: iWMMXT not supported
9914 { "iwmmxt", Feature_None, 0 },
9915 // FIXME: iWMMXT2 not supported
9916 { "iwmmxt2", Feature_None, 0 },
9917 // FIXME: Maverick not supported
9918 { "maverick", Feature_None, 0 },
9919 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
9920 // FIXME: ARMv6-m OS Extensions feature not checked
9921 { "os", Feature_None, 0 },
9922 // FIXME: Also available in ARMv6-K
9923 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
9924 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9925 // FIXME: Only available in A-class, isel not predicated
9926 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
9927 // FIXME: xscale not supported
9928 { "xscale", Feature_None, 0 },
9929};
9930
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009931/// parseDirectiveArchExtension
9932/// ::= .arch_extension [no]feature
9933bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009934 MCAsmParser &Parser = getParser();
9935
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009936 if (getLexer().isNot(AsmToken::Identifier)) {
9937 Error(getLexer().getLoc(), "unexpected token");
9938 Parser.eatToEndOfStatement();
9939 return false;
9940 }
9941
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009942 StringRef Name = Parser.getTok().getString();
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009943 SMLoc ExtLoc = Parser.getTok().getLoc();
9944 getLexer().Lex();
9945
9946 bool EnableFeature = true;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009947 if (Name.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009948 EnableFeature = false;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009949 Name = Name.substr(2);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009950 }
9951
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009952 for (const auto &Extension : Extensions) {
9953 if (Extension.Name != Name)
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009954 continue;
9955
Saleem Abdulrasool8988c2a2014-07-27 19:07:09 +00009956 if (!Extension.Features)
9957 report_fatal_error("unsupported architectural extension: " + Name);
9958
9959 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) {
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009960 Error(ExtLoc, "architectural extension '" + Name + "' is not "
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009961 "allowed for the current base architecture");
9962 return false;
9963 }
9964
Tim Northover26bb14e2014-08-18 11:49:42 +00009965 uint64_t ToggleFeatures = EnableFeature
Saleem Abdulrasool78c44722014-08-17 19:20:38 +00009966 ? (~STI.getFeatureBits() & Extension.Features)
9967 : ( STI.getFeatureBits() & Extension.Features);
Tim Northover26bb14e2014-08-18 11:49:42 +00009968 uint64_t Features =
Saleem Abdulrasool78c44722014-08-17 19:20:38 +00009969 ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
9970 setAvailableFeatures(Features);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009971 return false;
9972 }
9973
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009974 Error(ExtLoc, "unknown architectural extension: " + Name);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009975 Parser.eatToEndOfStatement();
9976 return false;
9977}
9978
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009979// Define this matcher function after the auto-generated include so we
9980// have the match class enum definitions.
David Blaikie960ea3f2014-06-08 16:18:35 +00009981unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009982 unsigned Kind) {
David Blaikie960ea3f2014-06-08 16:18:35 +00009983 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009984 // If the kind is a token for a literal immediate, check if our asm
9985 // operand matches. This is for InstAliases which have a fixed-value
9986 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009987 switch (Kind) {
9988 default: break;
9989 case MCK__35_0:
David Blaikie960ea3f2014-06-08 16:18:35 +00009990 if (Op.isImm())
9991 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009992 if (CE->getValue() == 0)
9993 return Match_Success;
9994 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00009995 case MCK_ModImm:
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009996 case MCK_ARMSOImm:
David Blaikie960ea3f2014-06-08 16:18:35 +00009997 if (Op.isImm()) {
9998 const MCExpr *SOExpr = Op.getImm();
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009999 int64_t Value;
10000 if (!SOExpr->EvaluateAsAbsolute(Value))
Stepan Dyatkovskiydf657cc2014-03-29 13:12:40 +000010001 return Match_Success;
Richard Barton3db1d582014-05-01 11:37:44 +000010002 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
10003 "expression value must be representable in 32 bits");
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010004 }
10005 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +000010006 case MCK_GPRPair:
David Blaikie960ea3f2014-06-08 16:18:35 +000010007 if (Op.isReg() &&
10008 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +000010009 return Match_Success;
10010 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010011 }
10012 return Match_InvalidOperand;
10013}