blob: 6bb41e4bbe69b4a27af12bf38e443453ffa602dc [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;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000132 MCAsmParser &Parser;
Joey Gouly0e76fa72013-09-12 10:28:05 +0000133 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000134 const MCRegisterInfo *MRI;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000135 UnwindContext UC;
David Peixottoe407d092013-12-19 18:12:36 +0000136
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000137 ARMTargetStreamer &getTargetStreamer() {
Rafael Espindola4a1a3602014-01-14 01:21:46 +0000138 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000139 return static_cast<ARMTargetStreamer &>(TS);
140 }
141
Jim Grosbachab5830e2011-12-14 02:16:11 +0000142 // Map of register aliases registers via the .req directive.
143 StringMap<unsigned> RegisterReqs;
144
Tim Northover1744d0a2013-10-25 12:49:50 +0000145 bool NextSymbolIsThumb;
146
Jim Grosbached16ec42011-08-29 22:24:09 +0000147 struct {
148 ARMCC::CondCodes Cond; // Condition for IT block.
149 unsigned Mask:4; // Condition mask for instructions.
150 // Starting at first 1 (from lsb).
151 // '1' condition as indicated in IT.
152 // '0' inverse of condition (else).
153 // Count of instructions in IT block is
154 // 4 - trailingzeroes(mask)
155
156 bool FirstCond; // Explicit flag for when we're parsing the
157 // First instruction in the IT block. It's
158 // implied in the mask, so needs special
159 // handling.
160
161 unsigned CurPosition; // Current position in parsing of IT
162 // block. In range [0,3]. Initialized
163 // according to count of instructions in block.
164 // ~0U if no active IT block.
165 } ITState;
166 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000167 void forwardITPosition() {
168 if (!inITBlock()) return;
169 // Move to the next instruction in the IT block, if there is one. If not,
170 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000171 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000172 if (++ITState.CurPosition == 5 - TZ)
173 ITState.CurPosition = ~0U; // Done with the IT block after this.
174 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000175
176
Kevin Enderbyccab3172009-09-15 00:27:25 +0000177 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000178 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
179
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000180 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) {
181 return Parser.Note(L, Msg, Ranges);
182 }
Benjamin Kramer673824b2012-04-15 17:04:27 +0000183 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000184 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000185 return Parser.Warning(L, Msg, Ranges);
186 }
187 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000188 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000189 return Parser.Error(L, Msg, Ranges);
190 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000191
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000192 int tryParseRegister();
David Blaikie960ea3f2014-06-08 16:18:35 +0000193 bool tryParseRegisterWithWriteBack(OperandVector &);
194 int tryParseShiftRegister(OperandVector &);
195 bool parseRegisterList(OperandVector &);
196 bool parseMemory(OperandVector &);
197 bool parseOperand(OperandVector &, StringRef Mnemonic);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000198 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000199 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
200 unsigned &ShiftAmount);
Saleem Abdulrasool38976512014-02-23 06:22:09 +0000201 bool parseLiteralValues(unsigned Size, SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000202 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000203 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000204 bool parseDirectiveThumbFunc(SMLoc L);
205 bool parseDirectiveCode(SMLoc L);
206 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000207 bool parseDirectiveReq(StringRef Name, SMLoc L);
208 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000209 bool parseDirectiveArch(SMLoc L);
210 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000211 bool parseDirectiveCPU(SMLoc L);
212 bool parseDirectiveFPU(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000213 bool parseDirectiveFnStart(SMLoc L);
214 bool parseDirectiveFnEnd(SMLoc L);
215 bool parseDirectiveCantUnwind(SMLoc L);
216 bool parseDirectivePersonality(SMLoc L);
217 bool parseDirectiveHandlerData(SMLoc L);
218 bool parseDirectiveSetFP(SMLoc L);
219 bool parseDirectivePad(SMLoc L);
220 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000221 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
David Peixotto80c083a2013-12-19 18:26:07 +0000222 bool parseDirectiveLtorg(SMLoc L);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +0000223 bool parseDirectiveEven(SMLoc L);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000224 bool parseDirectivePersonalityIndex(SMLoc L);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000225 bool parseDirectiveUnwindRaw(SMLoc L);
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000226 bool parseDirectiveTLSDescSeq(SMLoc L);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000227 bool parseDirectiveMovSP(SMLoc L);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000228 bool parseDirectiveObjectArch(SMLoc L);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +0000229 bool parseDirectiveArchExtension(SMLoc L);
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +0000230 bool parseDirectiveAlign(SMLoc L);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +0000231 bool parseDirectiveThumbSet(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000232
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000233 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000234 bool &CarrySetting, unsigned &ProcessorIMod,
235 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000236 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
237 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000238 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000239
Evan Cheng4d1ca962011-07-08 01:53:10 +0000240 bool isThumb() const {
241 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000242 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000243 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000244 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000245 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000246 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000247 bool isThumbTwo() const {
248 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
249 }
Tim Northovera2292d02013-06-10 23:20:58 +0000250 bool hasThumb() const {
251 return STI.getFeatureBits() & ARM::HasV4TOps;
252 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000253 bool hasV6Ops() const {
254 return STI.getFeatureBits() & ARM::HasV6Ops;
255 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000256 bool hasV6MOps() const {
257 return STI.getFeatureBits() & ARM::HasV6MOps;
258 }
James Molloy21efa7d2011-09-28 14:21:38 +0000259 bool hasV7Ops() const {
260 return STI.getFeatureBits() & ARM::HasV7Ops;
261 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000262 bool hasV8Ops() const {
263 return STI.getFeatureBits() & ARM::HasV8Ops;
264 }
Tim Northovera2292d02013-06-10 23:20:58 +0000265 bool hasARM() const {
266 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
267 }
268
Evan Cheng284b4672011-07-08 22:36:29 +0000269 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000270 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
271 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000272 }
James Molloy21efa7d2011-09-28 14:21:38 +0000273 bool isMClass() const {
274 return STI.getFeatureBits() & ARM::FeatureMClass;
275 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000276
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000277 /// @name Auto-generated Match Functions
278 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000279
Chris Lattner3e4582a2010-09-06 19:11:01 +0000280#define GET_ASSEMBLER_HEADER
281#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000282
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000283 /// }
284
David Blaikie960ea3f2014-06-08 16:18:35 +0000285 OperandMatchResultTy parseITCondCode(OperandVector &);
286 OperandMatchResultTy parseCoprocNumOperand(OperandVector &);
287 OperandMatchResultTy parseCoprocRegOperand(OperandVector &);
288 OperandMatchResultTy parseCoprocOptionOperand(OperandVector &);
289 OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &);
290 OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &);
291 OperandMatchResultTy parseProcIFlagsOperand(OperandVector &);
292 OperandMatchResultTy parseMSRMaskOperand(OperandVector &);
293 OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low,
294 int High);
295 OperandMatchResultTy parsePKHLSLImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000296 return parsePKHImm(O, "lsl", 0, 31);
297 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000298 OperandMatchResultTy parsePKHASRImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000299 return parsePKHImm(O, "asr", 1, 32);
300 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000301 OperandMatchResultTy parseSetEndImm(OperandVector &);
302 OperandMatchResultTy parseShifterImm(OperandVector &);
303 OperandMatchResultTy parseRotImm(OperandVector &);
304 OperandMatchResultTy parseBitfield(OperandVector &);
305 OperandMatchResultTy parsePostIdxReg(OperandVector &);
306 OperandMatchResultTy parseAM3Offset(OperandVector &);
307 OperandMatchResultTy parseFPImm(OperandVector &);
308 OperandMatchResultTy parseVectorList(OperandVector &);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000309 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
310 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000311
312 // Asm Match Converter Methods
David Blaikie960ea3f2014-06-08 16:18:35 +0000313 void cvtThumbMultiply(MCInst &Inst, const OperandVector &);
314 void cvtThumbBranches(MCInst &Inst, const OperandVector &);
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +0000315
David Blaikie960ea3f2014-06-08 16:18:35 +0000316 bool validateInstruction(MCInst &Inst, const OperandVector &Ops);
317 bool processInstruction(MCInst &Inst, const OperandVector &Ops);
318 bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands);
319 bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands);
320
Kevin Enderbyccab3172009-09-15 00:27:25 +0000321public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000322 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000323 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000324 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000325 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000326 Match_RequiresThumb2,
327#define GET_OPERAND_DIAGNOSTIC_TYPES
328#include "ARMGenAsmMatcher.inc"
329
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000330 };
331
Joey Gouly0e76fa72013-09-12 10:28:05 +0000332 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
Evgeniy Stepanov0a951b72014-04-23 11:16:03 +0000333 const MCInstrInfo &MII,
334 const MCTargetOptions &Options)
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000335 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), UC(_Parser) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000336 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000337
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000338 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000339 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000340
Evan Cheng4d1ca962011-07-08 01:53:10 +0000341 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000342 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000343
344 // Not in an ITBlock to start with.
345 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000346
347 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000348 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000349
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000350 // Implementation of the MCTargetAsmParser interface:
Craig Topperca7e3e52014-03-10 03:19:03 +0000351 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
David Blaikie960ea3f2014-06-08 16:18:35 +0000352 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
353 SMLoc NameLoc, OperandVector &Operands) override;
Craig Topperca7e3e52014-03-10 03:19:03 +0000354 bool ParseDirective(AsmToken DirectiveID) override;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000355
David Blaikie960ea3f2014-06-08 16:18:35 +0000356 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
Craig Topperca7e3e52014-03-10 03:19:03 +0000357 unsigned Kind) override;
358 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000359
Chad Rosier49963552012-10-13 00:26:04 +0000360 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
David Blaikie960ea3f2014-06-08 16:18:35 +0000361 OperandVector &Operands, MCStreamer &Out,
362 unsigned &ErrorInfo,
Craig Topperca7e3e52014-03-10 03:19:03 +0000363 bool MatchingInlineAsm) override;
364 void onLabelParsed(MCSymbol *Symbol) override;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000365};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000366} // end anonymous namespace
367
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000368namespace {
369
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000370/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000371/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000372class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000373 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000374 k_CondCode,
375 k_CCOut,
376 k_ITCondMask,
377 k_CoprocNum,
378 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000379 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000380 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000381 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000382 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000383 k_Memory,
384 k_PostIndexRegister,
385 k_MSRMask,
386 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000387 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000388 k_Register,
389 k_RegisterList,
390 k_DPRRegisterList,
391 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000392 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000393 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000394 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000395 k_ShiftedRegister,
396 k_ShiftedImmediate,
397 k_ShifterImmediate,
398 k_RotateImmediate,
399 k_BitfieldDescriptor,
400 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000401 } Kind;
402
Kevin Enderby488f20b2014-04-10 20:18:58 +0000403 SMLoc StartLoc, EndLoc, AlignmentLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000404 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000405
Eric Christopher8996c5d2013-03-15 00:42:55 +0000406 struct CCOp {
407 ARMCC::CondCodes Val;
408 };
409
410 struct CopOp {
411 unsigned Val;
412 };
413
414 struct CoprocOptionOp {
415 unsigned Val;
416 };
417
418 struct ITMaskOp {
419 unsigned Mask:4;
420 };
421
422 struct MBOptOp {
423 ARM_MB::MemBOpt Val;
424 };
425
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000426 struct ISBOptOp {
427 ARM_ISB::InstSyncBOpt Val;
428 };
429
Eric Christopher8996c5d2013-03-15 00:42:55 +0000430 struct IFlagsOp {
431 ARM_PROC::IFlags Val;
432 };
433
434 struct MMaskOp {
435 unsigned Val;
436 };
437
438 struct TokOp {
439 const char *Data;
440 unsigned Length;
441 };
442
443 struct RegOp {
444 unsigned RegNum;
445 };
446
447 // A vector register list is a sequential list of 1 to 4 registers.
448 struct VectorListOp {
449 unsigned RegNum;
450 unsigned Count;
451 unsigned LaneIndex;
452 bool isDoubleSpaced;
453 };
454
455 struct VectorIndexOp {
456 unsigned Val;
457 };
458
459 struct ImmOp {
460 const MCExpr *Val;
461 };
462
463 /// Combined record for all forms of ARM address expressions.
464 struct MemoryOp {
465 unsigned BaseRegNum;
466 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
467 // was specified.
468 const MCConstantExpr *OffsetImm; // Offset immediate value
469 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
470 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
471 unsigned ShiftImm; // shift for OffsetReg.
472 unsigned Alignment; // 0 = no alignment specified
473 // n = alignment in bytes (2, 4, 8, 16, or 32)
474 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
475 };
476
477 struct PostIdxRegOp {
478 unsigned RegNum;
479 bool isAdd;
480 ARM_AM::ShiftOpc ShiftTy;
481 unsigned ShiftImm;
482 };
483
484 struct ShifterImmOp {
485 bool isASR;
486 unsigned Imm;
487 };
488
489 struct RegShiftedRegOp {
490 ARM_AM::ShiftOpc ShiftTy;
491 unsigned SrcReg;
492 unsigned ShiftReg;
493 unsigned ShiftImm;
494 };
495
496 struct RegShiftedImmOp {
497 ARM_AM::ShiftOpc ShiftTy;
498 unsigned SrcReg;
499 unsigned ShiftImm;
500 };
501
502 struct RotImmOp {
503 unsigned Imm;
504 };
505
506 struct BitfieldOp {
507 unsigned LSB;
508 unsigned Width;
509 };
510
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000511 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000512 struct CCOp CC;
513 struct CopOp Cop;
514 struct CoprocOptionOp CoprocOption;
515 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000516 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000517 struct ITMaskOp ITMask;
518 struct IFlagsOp IFlags;
519 struct MMaskOp MMask;
520 struct TokOp Tok;
521 struct RegOp Reg;
522 struct VectorListOp VectorList;
523 struct VectorIndexOp VectorIndex;
524 struct ImmOp Imm;
525 struct MemoryOp Memory;
526 struct PostIdxRegOp PostIdxReg;
527 struct ShifterImmOp ShifterImm;
528 struct RegShiftedRegOp RegShiftedReg;
529 struct RegShiftedImmOp RegShiftedImm;
530 struct RotImmOp RotImm;
531 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000532 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000533
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000534public:
David Blaikie960ea3f2014-06-08 16:18:35 +0000535 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000536 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
537 Kind = o.Kind;
538 StartLoc = o.StartLoc;
539 EndLoc = o.EndLoc;
540 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000541 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000542 CC = o.CC;
543 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000544 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000545 ITMask = o.ITMask;
546 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000547 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000548 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000549 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000550 case k_CCOut:
551 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000552 Reg = o.Reg;
553 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000554 case k_RegisterList:
555 case k_DPRRegisterList:
556 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000557 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000558 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000559 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000560 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000561 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000562 VectorList = o.VectorList;
563 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000564 case k_CoprocNum:
565 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000566 Cop = o.Cop;
567 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000568 case k_CoprocOption:
569 CoprocOption = o.CoprocOption;
570 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000571 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000572 Imm = o.Imm;
573 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000574 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000575 MBOpt = o.MBOpt;
576 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000577 case k_InstSyncBarrierOpt:
578 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000579 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000580 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000581 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000582 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000583 PostIdxReg = o.PostIdxReg;
584 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000585 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000586 MMask = o.MMask;
587 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000588 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000589 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000590 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000591 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000592 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000593 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000594 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000595 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000596 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000597 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000598 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000599 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000600 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000601 RotImm = o.RotImm;
602 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000603 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000604 Bitfield = o.Bitfield;
605 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000606 case k_VectorIndex:
607 VectorIndex = o.VectorIndex;
608 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000609 }
610 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000611
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000612 /// getStartLoc - Get the location of the first token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000613 SMLoc getStartLoc() const override { return StartLoc; }
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000614 /// getEndLoc - Get the location of the last token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000615 SMLoc getEndLoc() const override { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000616 /// getLocRange - Get the range between the first and last token of this
617 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000618 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
619
Kevin Enderby488f20b2014-04-10 20:18:58 +0000620 /// getAlignmentLoc - Get the location of the Alignment token of this operand.
621 SMLoc getAlignmentLoc() const {
622 assert(Kind == k_Memory && "Invalid access!");
623 return AlignmentLoc;
624 }
625
Daniel Dunbard8042b72010-08-11 06:36:53 +0000626 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000627 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000628 return CC.Val;
629 }
630
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000631 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000632 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000633 return Cop.Val;
634 }
635
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000636 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000637 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000638 return StringRef(Tok.Data, Tok.Length);
639 }
640
Craig Topperca7e3e52014-03-10 03:19:03 +0000641 unsigned getReg() const override {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000642 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000643 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000644 }
645
Bill Wendlingbed94652010-11-09 23:28:44 +0000646 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000647 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
648 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000649 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000650 }
651
Kevin Enderbyf5079942009-10-13 22:19:02 +0000652 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000653 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000654 return Imm.Val;
655 }
656
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000657 unsigned getVectorIndex() const {
658 assert(Kind == k_VectorIndex && "Invalid access!");
659 return VectorIndex.Val;
660 }
661
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000662 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000663 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000664 return MBOpt.Val;
665 }
666
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000667 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
668 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
669 return ISBOpt.Val;
670 }
671
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000672 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000673 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000674 return IFlags.Val;
675 }
676
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000677 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000678 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000679 return MMask.Val;
680 }
681
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000682 bool isCoprocNum() const { return Kind == k_CoprocNum; }
683 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000684 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000685 bool isCondCode() const { return Kind == k_CondCode; }
686 bool isCCOut() const { return Kind == k_CCOut; }
687 bool isITMask() const { return Kind == k_ITCondMask; }
688 bool isITCondCode() const { return Kind == k_CondCode; }
Craig Topperca7e3e52014-03-10 03:19:03 +0000689 bool isImm() const override { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000690 // checks whether this operand is an unsigned offset which fits is a field
691 // of specified width and scaled by a specific number of bits
692 template<unsigned width, unsigned scale>
693 bool isUnsignedOffset() const {
694 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000695 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000696 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
697 int64_t Val = CE->getValue();
698 int64_t Align = 1LL << scale;
699 int64_t Max = Align * ((1LL << width) - 1);
700 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
701 }
702 return false;
703 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000704 // checks whether this operand is an signed offset which fits is a field
705 // of specified width and scaled by a specific number of bits
706 template<unsigned width, unsigned scale>
707 bool isSignedOffset() const {
708 if (!isImm()) return false;
709 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
710 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
711 int64_t Val = CE->getValue();
712 int64_t Align = 1LL << scale;
713 int64_t Max = Align * ((1LL << (width-1)) - 1);
714 int64_t Min = -Align * (1LL << (width-1));
715 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
716 }
717 return false;
718 }
719
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000720 // checks whether this operand is a memory operand computed as an offset
721 // applied to PC. the offset may have 8 bits of magnitude and is represented
722 // with two bits of shift. textually it may be either [pc, #imm], #imm or
723 // relocable expression...
724 bool isThumbMemPC() const {
725 int64_t Val = 0;
726 if (isImm()) {
727 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
729 if (!CE) return false;
730 Val = CE->getValue();
731 }
732 else if (isMem()) {
733 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
734 if(Memory.BaseRegNum != ARM::PC) return false;
735 Val = Memory.OffsetImm->getValue();
736 }
737 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000738 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000739 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000740 bool isFPImm() const {
741 if (!isImm()) return false;
742 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
743 if (!CE) return false;
744 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
745 return Val != -1;
746 }
Jim Grosbachea231912011-12-22 22:19:05 +0000747 bool isFBits16() const {
748 if (!isImm()) return false;
749 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
750 if (!CE) return false;
751 int64_t Value = CE->getValue();
752 return Value >= 0 && Value <= 16;
753 }
754 bool isFBits32() const {
755 if (!isImm()) return false;
756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
757 if (!CE) return false;
758 int64_t Value = CE->getValue();
759 return Value >= 1 && Value <= 32;
760 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000761 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000762 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000763 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
764 if (!CE) return false;
765 int64_t Value = CE->getValue();
766 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
767 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000768 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000769 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
771 if (!CE) return false;
772 int64_t Value = CE->getValue();
773 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
774 }
775 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000776 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
778 if (!CE) return false;
779 int64_t Value = CE->getValue();
780 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
781 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000782 bool isImm0_508s4Neg() 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 // explicitly exclude zero. we want that to use the normal 0_508 version.
788 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
789 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000790 bool isImm0_239() const {
791 if (!isImm()) return false;
792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
793 if (!CE) return false;
794 int64_t Value = CE->getValue();
795 return Value >= 0 && Value < 240;
796 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000797 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000798 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000799 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
800 if (!CE) return false;
801 int64_t Value = CE->getValue();
802 return Value >= 0 && Value < 256;
803 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000804 bool isImm0_4095() const {
805 if (!isImm()) return false;
806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
807 if (!CE) return false;
808 int64_t Value = CE->getValue();
809 return Value >= 0 && Value < 4096;
810 }
811 bool isImm0_4095Neg() const {
812 if (!isImm()) return false;
813 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
814 if (!CE) return false;
815 int64_t Value = -CE->getValue();
816 return Value > 0 && Value < 4096;
817 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000818 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000819 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
821 if (!CE) return false;
822 int64_t Value = CE->getValue();
823 return Value >= 0 && Value < 2;
824 }
825 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000826 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
828 if (!CE) return false;
829 int64_t Value = CE->getValue();
830 return Value >= 0 && Value < 4;
831 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000832 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000833 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
835 if (!CE) return false;
836 int64_t Value = CE->getValue();
837 return Value >= 0 && Value < 8;
838 }
839 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000840 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
842 if (!CE) return false;
843 int64_t Value = CE->getValue();
844 return Value >= 0 && Value < 16;
845 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000846 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000847 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
849 if (!CE) return false;
850 int64_t Value = CE->getValue();
851 return Value >= 0 && Value < 32;
852 }
Jim Grosbach00326402011-12-08 01:30:04 +0000853 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000854 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
856 if (!CE) return false;
857 int64_t Value = CE->getValue();
858 return Value >= 0 && Value < 64;
859 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000860 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000861 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
863 if (!CE) return false;
864 int64_t Value = CE->getValue();
865 return Value == 8;
866 }
867 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000868 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
870 if (!CE) return false;
871 int64_t Value = CE->getValue();
872 return Value == 16;
873 }
874 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000875 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
877 if (!CE) return false;
878 int64_t Value = CE->getValue();
879 return Value == 32;
880 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000881 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000882 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
884 if (!CE) return false;
885 int64_t Value = CE->getValue();
886 return Value > 0 && Value <= 8;
887 }
888 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000889 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000890 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
891 if (!CE) return false;
892 int64_t Value = CE->getValue();
893 return Value > 0 && Value <= 16;
894 }
895 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000896 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000897 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
898 if (!CE) return false;
899 int64_t Value = CE->getValue();
900 return Value > 0 && Value <= 32;
901 }
902 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000903 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000904 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
905 if (!CE) return false;
906 int64_t Value = CE->getValue();
907 return Value > 0 && Value <= 64;
908 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000909 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000910 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +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 isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000917 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +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 isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000924 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +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 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000930 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000931 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000932 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
933 if (!CE) return false;
934 int64_t Value = CE->getValue();
935 return Value > 0 && Value < 17;
936 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000937 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000938 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000939 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
940 if (!CE) return false;
941 int64_t Value = CE->getValue();
942 return Value > 0 && Value < 33;
943 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000944 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000945 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000946 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
947 if (!CE) return false;
948 int64_t Value = CE->getValue();
949 return Value >= 0 && Value < 33;
950 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000951 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000952 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
954 if (!CE) return false;
955 int64_t Value = CE->getValue();
956 return Value >= 0 && Value < 65536;
957 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000958 bool isImm256_65535Expr() const {
959 if (!isImm()) return false;
960 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
961 // If it's not a constant expression, it'll generate a fixup and be
962 // handled later.
963 if (!CE) return true;
964 int64_t Value = CE->getValue();
965 return Value >= 256 && Value < 65536;
966 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000967 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000968 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000969 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
970 // If it's not a constant expression, it'll generate a fixup and be
971 // handled later.
972 if (!CE) return true;
973 int64_t Value = CE->getValue();
974 return Value >= 0 && Value < 65536;
975 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000976 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000977 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000978 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
979 if (!CE) return false;
980 int64_t Value = CE->getValue();
981 return Value >= 0 && Value <= 0xffffff;
982 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000983 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000984 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000985 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
986 if (!CE) return false;
987 int64_t Value = CE->getValue();
988 return Value > 0 && Value < 33;
989 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000990 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000991 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000992 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
993 if (!CE) return false;
994 int64_t Value = CE->getValue();
995 return Value >= 0 && Value < 32;
996 }
997 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000998 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000999 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1000 if (!CE) return false;
1001 int64_t Value = CE->getValue();
1002 return Value > 0 && Value <= 32;
1003 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001004 bool isAdrLabel() const {
1005 // If we have an immediate that's not a constant, treat it as a label
1006 // reference needing a fixup. If it is a constant, but it can't fit
1007 // into shift immediate encoding, we reject it.
1008 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1009 else return (isARMSOImm() || isARMSOImmNeg());
1010 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001011 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001012 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001013 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1014 if (!CE) return false;
1015 int64_t Value = CE->getValue();
1016 return ARM_AM::getSOImmVal(Value) != -1;
1017 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001018 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001019 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001020 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1021 if (!CE) return false;
1022 int64_t Value = CE->getValue();
1023 return ARM_AM::getSOImmVal(~Value) != -1;
1024 }
Jim Grosbach30506252011-12-08 00:31:07 +00001025 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001026 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001027 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1028 if (!CE) return false;
1029 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001030 // Only use this when not representable as a plain so_imm.
1031 return ARM_AM::getSOImmVal(Value) == -1 &&
1032 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001033 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001034 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001035 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001036 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1037 if (!CE) return false;
1038 int64_t Value = CE->getValue();
1039 return ARM_AM::getT2SOImmVal(Value) != -1;
1040 }
Jim Grosbachb009a872011-10-28 22:36:30 +00001041 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001042 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +00001043 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1044 if (!CE) return false;
1045 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +00001046 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1047 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +00001048 }
Jim Grosbach30506252011-12-08 00:31:07 +00001049 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001050 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001051 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1052 if (!CE) return false;
1053 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001054 // Only use this when not representable as a plain so_imm.
1055 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1056 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001057 }
Jim Grosbach0a547702011-07-22 17:44:50 +00001058 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001059 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +00001060 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1061 if (!CE) return false;
1062 int64_t Value = CE->getValue();
1063 return Value == 1 || Value == 0;
1064 }
Craig Topperca7e3e52014-03-10 03:19:03 +00001065 bool isReg() const override { return Kind == k_Register; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001066 bool isRegList() const { return Kind == k_RegisterList; }
1067 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1068 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001069 bool isToken() const override { return Kind == k_Token; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001070 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001071 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001072 bool isMem() const override { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001073 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1074 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1075 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1076 bool isRotImm() const { return Kind == k_RotateImmediate; }
1077 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1078 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001079 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001080 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001081 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001082 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const {
Chad Rosier41099832012-09-11 23:02:35 +00001083 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001084 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001085 // No offset of any kind.
Craig Topper062a2ba2014-04-25 05:30:21 +00001086 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
Kevin Enderby488f20b2014-04-10 20:18:58 +00001087 (alignOK || Memory.Alignment == Alignment);
Jim Grosbacha95ec992011-10-11 17:29:55 +00001088 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001089 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001090 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001091 return false;
1092 // Base register must be PC.
1093 if (Memory.BaseRegNum != ARM::PC)
1094 return false;
1095 // Immediate offset in range [-4095, 4095].
1096 if (!Memory.OffsetImm) return true;
1097 int64_t Val = Memory.OffsetImm->getValue();
1098 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1099 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001100 bool isAlignedMemory() const {
1101 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001102 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001103 bool isAlignedMemoryNone() const {
1104 return isMemNoOffset(false, 0);
1105 }
1106 bool isDupAlignedMemoryNone() const {
1107 return isMemNoOffset(false, 0);
1108 }
1109 bool isAlignedMemory16() const {
1110 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1111 return true;
1112 return isMemNoOffset(false, 0);
1113 }
1114 bool isDupAlignedMemory16() const {
1115 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1116 return true;
1117 return isMemNoOffset(false, 0);
1118 }
1119 bool isAlignedMemory32() const {
1120 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1121 return true;
1122 return isMemNoOffset(false, 0);
1123 }
1124 bool isDupAlignedMemory32() const {
1125 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1126 return true;
1127 return isMemNoOffset(false, 0);
1128 }
1129 bool isAlignedMemory64() const {
1130 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1131 return true;
1132 return isMemNoOffset(false, 0);
1133 }
1134 bool isDupAlignedMemory64() const {
1135 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1136 return true;
1137 return isMemNoOffset(false, 0);
1138 }
1139 bool isAlignedMemory64or128() const {
1140 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1141 return true;
1142 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1143 return true;
1144 return isMemNoOffset(false, 0);
1145 }
1146 bool isDupAlignedMemory64or128() const {
1147 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1148 return true;
1149 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1150 return true;
1151 return isMemNoOffset(false, 0);
1152 }
1153 bool isAlignedMemory64or128or256() const {
1154 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1155 return true;
1156 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1157 return true;
1158 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
1159 return true;
1160 return isMemNoOffset(false, 0);
1161 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001162 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001163 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001164 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001165 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001166 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001167 if (!Memory.OffsetImm) return true;
1168 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001169 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001170 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001171 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001172 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001173 // Immediate offset in range [-4095, 4095].
1174 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1175 if (!CE) return false;
1176 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001177 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001178 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001179 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001180 // If we have an immediate that's not a constant, treat it as a label
1181 // reference needing a fixup. If it is a constant, it's something else
1182 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001183 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001184 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001185 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001186 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001187 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001188 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001189 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001190 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001191 if (!Memory.OffsetImm) return true;
1192 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001193 // The #-0 offset is encoded as INT32_MIN, and we have to check
1194 // for this too.
1195 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001196 }
1197 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001198 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001199 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001200 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001201 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1202 // Immediate offset in range [-255, 255].
1203 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1204 if (!CE) return false;
1205 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001206 // Special case, #-0 is INT32_MIN.
1207 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001208 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001209 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001210 // If we have an immediate that's not a constant, treat it as a label
1211 // reference needing a fixup. If it is a constant, it's something else
1212 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001213 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001214 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001215 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001216 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001217 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001218 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001219 if (!Memory.OffsetImm) return true;
1220 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001221 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001222 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001223 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001224 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001225 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001226 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001227 return false;
1228 return true;
1229 }
1230 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001231 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001232 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1233 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001234 return false;
1235 return true;
1236 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001237 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001238 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001239 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001240 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001241 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001242 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001243 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001244 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001245 return false;
1246 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001247 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001248 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001249 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001250 return false;
1251 return true;
1252 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001253 bool isMemThumbRR() const {
1254 // Thumb reg+reg addressing is simple. Just two registers, a base and
1255 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001256 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001257 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001258 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001259 return isARMLowRegister(Memory.BaseRegNum) &&
1260 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001261 }
1262 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001263 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001264 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001265 return false;
1266 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001267 if (!Memory.OffsetImm) return true;
1268 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001269 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1270 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001271 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001272 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001273 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001274 return false;
1275 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001276 if (!Memory.OffsetImm) return true;
1277 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001278 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1279 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001280 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001281 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001282 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001283 return false;
1284 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001285 if (!Memory.OffsetImm) return true;
1286 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001287 return Val >= 0 && Val <= 31;
1288 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001289 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001290 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001291 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001292 return false;
1293 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001294 if (!Memory.OffsetImm) return true;
1295 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001296 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001297 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001298 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001299 // If we have an immediate that's not a constant, treat it as a label
1300 // reference needing a fixup. If it is a constant, it's something else
1301 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001302 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001303 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001304 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001305 return false;
1306 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001307 if (!Memory.OffsetImm) return true;
1308 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001309 // Special case, #-0 is INT32_MIN.
1310 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001311 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001312 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001313 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001314 return false;
1315 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001316 if (!Memory.OffsetImm) return true;
1317 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001318 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1319 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001320 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001321 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001322 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001323 // Base reg of PC isn't allowed for these encodings.
1324 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001325 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001326 if (!Memory.OffsetImm) return true;
1327 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001328 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001329 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001330 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001331 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001332 return false;
1333 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001334 if (!Memory.OffsetImm) return true;
1335 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001336 return Val >= 0 && Val < 256;
1337 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001338 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001339 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001340 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001341 // Base reg of PC isn't allowed for these encodings.
1342 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001343 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001344 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001345 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001346 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001347 }
1348 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001349 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001350 return false;
1351 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001352 if (!Memory.OffsetImm) return true;
1353 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001354 return (Val >= 0 && Val < 4096);
1355 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001356 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001357 // If we have an immediate that's not a constant, treat it as a label
1358 // reference needing a fixup. If it is a constant, it's something else
1359 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001360 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001361 return true;
1362
Chad Rosier41099832012-09-11 23:02:35 +00001363 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001364 return false;
1365 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001366 if (!Memory.OffsetImm) return true;
1367 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001368 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001369 }
1370 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001371 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001372 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1373 if (!CE) return false;
1374 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001375 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001376 }
Jim Grosbach93981412011-10-11 21:55:36 +00001377 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001378 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001379 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1380 if (!CE) return false;
1381 int64_t Val = CE->getValue();
1382 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1383 (Val == INT32_MIN);
1384 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001385
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001386 bool isMSRMask() const { return Kind == k_MSRMask; }
1387 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001388
Jim Grosbach741cd732011-10-17 22:26:03 +00001389 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001390 bool isSingleSpacedVectorList() const {
1391 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1392 }
1393 bool isDoubleSpacedVectorList() const {
1394 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1395 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001396 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001397 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001398 return VectorList.Count == 1;
1399 }
1400
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001401 bool isVecListDPair() const {
1402 if (!isSingleSpacedVectorList()) return false;
1403 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1404 .contains(VectorList.RegNum));
1405 }
1406
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001407 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001408 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001409 return VectorList.Count == 3;
1410 }
1411
Jim Grosbach846bcff2011-10-21 20:35:01 +00001412 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001413 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001414 return VectorList.Count == 4;
1415 }
1416
Jim Grosbache5307f92012-03-05 21:43:40 +00001417 bool isVecListDPairSpaced() const {
Kevin Enderby56113982014-03-26 21:54:11 +00001418 if (Kind != k_VectorList) return false;
Kevin Enderby816ca272012-03-20 17:41:51 +00001419 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001420 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1421 .contains(VectorList.RegNum));
1422 }
1423
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001424 bool isVecListThreeQ() const {
1425 if (!isDoubleSpacedVectorList()) return false;
1426 return VectorList.Count == 3;
1427 }
1428
Jim Grosbach1e946a42012-01-24 00:43:12 +00001429 bool isVecListFourQ() const {
1430 if (!isDoubleSpacedVectorList()) return false;
1431 return VectorList.Count == 4;
1432 }
1433
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001434 bool isSingleSpacedVectorAllLanes() const {
1435 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1436 }
1437 bool isDoubleSpacedVectorAllLanes() const {
1438 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1439 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001440 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001441 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001442 return VectorList.Count == 1;
1443 }
1444
Jim Grosbach13a292c2012-03-06 22:01:44 +00001445 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001446 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001447 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1448 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001449 }
1450
Jim Grosbached428bc2012-03-06 23:10:38 +00001451 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001452 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001453 return VectorList.Count == 2;
1454 }
1455
Jim Grosbachb78403c2012-01-24 23:47:04 +00001456 bool isVecListThreeDAllLanes() const {
1457 if (!isSingleSpacedVectorAllLanes()) return false;
1458 return VectorList.Count == 3;
1459 }
1460
1461 bool isVecListThreeQAllLanes() const {
1462 if (!isDoubleSpacedVectorAllLanes()) return false;
1463 return VectorList.Count == 3;
1464 }
1465
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001466 bool isVecListFourDAllLanes() const {
1467 if (!isSingleSpacedVectorAllLanes()) return false;
1468 return VectorList.Count == 4;
1469 }
1470
1471 bool isVecListFourQAllLanes() const {
1472 if (!isDoubleSpacedVectorAllLanes()) return false;
1473 return VectorList.Count == 4;
1474 }
1475
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001476 bool isSingleSpacedVectorIndexed() const {
1477 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1478 }
1479 bool isDoubleSpacedVectorIndexed() const {
1480 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1481 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001482 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001483 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001484 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1485 }
1486
Jim Grosbachda511042011-12-14 23:35:06 +00001487 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001488 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001489 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1490 }
1491
1492 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001493 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001494 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1495 }
1496
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001497 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001498 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001499 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1500 }
1501
Jim Grosbachda511042011-12-14 23:35:06 +00001502 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001503 if (!isSingleSpacedVectorIndexed()) return false;
1504 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1505 }
1506
1507 bool isVecListTwoQWordIndexed() const {
1508 if (!isDoubleSpacedVectorIndexed()) return false;
1509 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1510 }
1511
1512 bool isVecListTwoQHWordIndexed() const {
1513 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001514 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1515 }
1516
1517 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001518 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001519 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1520 }
1521
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001522 bool isVecListThreeDByteIndexed() const {
1523 if (!isSingleSpacedVectorIndexed()) return false;
1524 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1525 }
1526
1527 bool isVecListThreeDHWordIndexed() const {
1528 if (!isSingleSpacedVectorIndexed()) return false;
1529 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1530 }
1531
1532 bool isVecListThreeQWordIndexed() const {
1533 if (!isDoubleSpacedVectorIndexed()) return false;
1534 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1535 }
1536
1537 bool isVecListThreeQHWordIndexed() const {
1538 if (!isDoubleSpacedVectorIndexed()) return false;
1539 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1540 }
1541
1542 bool isVecListThreeDWordIndexed() const {
1543 if (!isSingleSpacedVectorIndexed()) return false;
1544 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1545 }
1546
Jim Grosbach14952a02012-01-24 18:37:25 +00001547 bool isVecListFourDByteIndexed() const {
1548 if (!isSingleSpacedVectorIndexed()) return false;
1549 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1550 }
1551
1552 bool isVecListFourDHWordIndexed() const {
1553 if (!isSingleSpacedVectorIndexed()) return false;
1554 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1555 }
1556
1557 bool isVecListFourQWordIndexed() const {
1558 if (!isDoubleSpacedVectorIndexed()) return false;
1559 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1560 }
1561
1562 bool isVecListFourQHWordIndexed() const {
1563 if (!isDoubleSpacedVectorIndexed()) return false;
1564 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1565 }
1566
1567 bool isVecListFourDWordIndexed() const {
1568 if (!isSingleSpacedVectorIndexed()) return false;
1569 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1570 }
1571
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001572 bool isVectorIndex8() const {
1573 if (Kind != k_VectorIndex) return false;
1574 return VectorIndex.Val < 8;
1575 }
1576 bool isVectorIndex16() const {
1577 if (Kind != k_VectorIndex) return false;
1578 return VectorIndex.Val < 4;
1579 }
1580 bool isVectorIndex32() const {
1581 if (Kind != k_VectorIndex) return false;
1582 return VectorIndex.Val < 2;
1583 }
1584
Jim Grosbach741cd732011-10-17 22:26:03 +00001585 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001586 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1588 // Must be a constant.
1589 if (!CE) return false;
1590 int64_t Value = CE->getValue();
1591 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1592 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001593 return Value >= 0 && Value < 256;
1594 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001595
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001596 bool isNEONi16splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001597 if (isNEONByteReplicate(2))
1598 return false; // Leave that for bytes replication and forbid by default.
1599 if (!isImm())
1600 return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001601 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1602 // Must be a constant.
1603 if (!CE) return false;
1604 int64_t Value = CE->getValue();
1605 // i16 value in the range [0,255] or [0x0100, 0xff00]
1606 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1607 }
1608
Jim Grosbach8211c052011-10-18 00:22:00 +00001609 bool isNEONi32splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001610 if (isNEONByteReplicate(4))
1611 return false; // Leave that for bytes replication and forbid by default.
1612 if (!isImm())
1613 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1615 // Must be a constant.
1616 if (!CE) return false;
1617 int64_t Value = CE->getValue();
1618 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1619 return (Value >= 0 && Value < 256) ||
1620 (Value >= 0x0100 && Value <= 0xff00) ||
1621 (Value >= 0x010000 && Value <= 0xff0000) ||
1622 (Value >= 0x01000000 && Value <= 0xff000000);
1623 }
1624
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001625 bool isNEONByteReplicate(unsigned NumBytes) const {
1626 if (!isImm())
1627 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001628 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1629 // Must be a constant.
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001630 if (!CE)
1631 return false;
1632 int64_t Value = CE->getValue();
1633 if (!Value)
1634 return false; // Don't bother with zero.
1635
1636 unsigned char B = Value & 0xff;
1637 for (unsigned i = 1; i < NumBytes; ++i) {
1638 Value >>= 8;
1639 if ((Value & 0xff) != B)
1640 return false;
1641 }
1642 return true;
1643 }
1644 bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); }
1645 bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); }
1646 bool isNEONi32vmov() const {
1647 if (isNEONByteReplicate(4))
1648 return false; // Let it to be classified as byte-replicate case.
1649 if (!isImm())
1650 return false;
1651 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1652 // Must be a constant.
1653 if (!CE)
1654 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001655 int64_t Value = CE->getValue();
1656 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1657 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1658 return (Value >= 0 && Value < 256) ||
1659 (Value >= 0x0100 && Value <= 0xff00) ||
1660 (Value >= 0x010000 && Value <= 0xff0000) ||
1661 (Value >= 0x01000000 && Value <= 0xff000000) ||
1662 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1663 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1664 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001665 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001666 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001667 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1668 // Must be a constant.
1669 if (!CE) return false;
1670 int64_t Value = ~CE->getValue();
1671 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1672 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1673 return (Value >= 0 && Value < 256) ||
1674 (Value >= 0x0100 && Value <= 0xff00) ||
1675 (Value >= 0x010000 && Value <= 0xff0000) ||
1676 (Value >= 0x01000000 && Value <= 0xff000000) ||
1677 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1678 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1679 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001680
Jim Grosbache4454e02011-10-18 16:18:11 +00001681 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001682 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1684 // Must be a constant.
1685 if (!CE) return false;
1686 uint64_t Value = CE->getValue();
1687 // i64 value with each byte being either 0 or 0xff.
1688 for (unsigned i = 0; i < 8; ++i)
1689 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1690 return true;
1691 }
1692
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001693 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001694 // Add as immediates when possible. Null MCExpr = 0.
Craig Topper062a2ba2014-04-25 05:30:21 +00001695 if (!Expr)
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001696 Inst.addOperand(MCOperand::CreateImm(0));
1697 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001698 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1699 else
1700 Inst.addOperand(MCOperand::CreateExpr(Expr));
1701 }
1702
Daniel Dunbard8042b72010-08-11 06:36:53 +00001703 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001704 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001705 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001706 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1707 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001708 }
1709
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001710 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1711 assert(N == 1 && "Invalid number of operands!");
1712 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1713 }
1714
Jim Grosbach48399582011-10-12 17:34:41 +00001715 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1716 assert(N == 1 && "Invalid number of operands!");
1717 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1718 }
1719
1720 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1721 assert(N == 1 && "Invalid number of operands!");
1722 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1723 }
1724
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001725 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1726 assert(N == 1 && "Invalid number of operands!");
1727 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1728 }
1729
1730 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1731 assert(N == 1 && "Invalid number of operands!");
1732 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1733 }
1734
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001735 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1736 assert(N == 1 && "Invalid number of operands!");
1737 Inst.addOperand(MCOperand::CreateReg(getReg()));
1738 }
1739
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001740 void addRegOperands(MCInst &Inst, unsigned N) const {
1741 assert(N == 1 && "Invalid number of operands!");
1742 Inst.addOperand(MCOperand::CreateReg(getReg()));
1743 }
1744
Jim Grosbachac798e12011-07-25 20:49:51 +00001745 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001746 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001747 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001748 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001749 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1750 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001751 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001752 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001753 }
1754
Jim Grosbachac798e12011-07-25 20:49:51 +00001755 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001756 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001757 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001758 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001759 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001760 // Shift of #32 is encoded as 0 where permitted
1761 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001762 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001763 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001764 }
1765
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001766 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001767 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001768 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1769 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001770 }
1771
Bill Wendling8d2aa032010-11-08 23:49:57 +00001772 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001773 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001774 const SmallVectorImpl<unsigned> &RegList = getRegList();
1775 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001776 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1777 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001778 }
1779
Bill Wendling9898ac92010-11-17 04:32:08 +00001780 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1781 addRegListOperands(Inst, N);
1782 }
1783
1784 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1785 addRegListOperands(Inst, N);
1786 }
1787
Jim Grosbach833b9d32011-07-27 20:15:40 +00001788 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1789 assert(N == 1 && "Invalid number of operands!");
1790 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1791 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1792 }
1793
Jim Grosbach864b6092011-07-28 21:34:26 +00001794 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1795 assert(N == 1 && "Invalid number of operands!");
1796 // Munge the lsb/width into a bitfield mask.
1797 unsigned lsb = Bitfield.LSB;
1798 unsigned width = Bitfield.Width;
1799 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1800 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1801 (32 - (lsb + width)));
1802 Inst.addOperand(MCOperand::CreateImm(Mask));
1803 }
1804
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001805 void addImmOperands(MCInst &Inst, unsigned N) const {
1806 assert(N == 1 && "Invalid number of operands!");
1807 addExpr(Inst, getImm());
1808 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001809
Jim Grosbachea231912011-12-22 22:19:05 +00001810 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1811 assert(N == 1 && "Invalid number of operands!");
1812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1813 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1814 }
1815
1816 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1817 assert(N == 1 && "Invalid number of operands!");
1818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1819 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1820 }
1821
Jim Grosbache7fbce72011-10-03 23:38:36 +00001822 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1823 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1825 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1826 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001827 }
1828
Jim Grosbach7db8d692011-09-08 22:07:06 +00001829 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1830 assert(N == 1 && "Invalid number of operands!");
1831 // FIXME: We really want to scale the value here, but the LDRD/STRD
1832 // instruction don't encode operands that way yet.
1833 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1834 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1835 }
1836
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001837 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1838 assert(N == 1 && "Invalid number of operands!");
1839 // The immediate is scaled by four in the encoding and is stored
1840 // in the MCInst as such. Lop off the low two bits here.
1841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1842 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1843 }
1844
Jim Grosbach930f2f62012-04-05 20:57:13 +00001845 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1846 assert(N == 1 && "Invalid number of operands!");
1847 // The immediate is scaled by four in the encoding and is stored
1848 // in the MCInst as such. Lop off the low two bits here.
1849 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1850 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1851 }
1852
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001853 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1854 assert(N == 1 && "Invalid number of operands!");
1855 // The immediate is scaled by four in the encoding and is stored
1856 // in the MCInst as such. Lop off the low two bits here.
1857 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1858 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1859 }
1860
Jim Grosbach475c6db2011-07-25 23:09:14 +00001861 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1862 assert(N == 1 && "Invalid number of operands!");
1863 // The constant encodes as the immediate-1, and we store in the instruction
1864 // the bits as encoded, so subtract off one here.
1865 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1866 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1867 }
1868
Jim Grosbach801e0a32011-07-22 23:16:18 +00001869 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1870 assert(N == 1 && "Invalid number of operands!");
1871 // The constant encodes as the immediate-1, and we store in the instruction
1872 // the bits as encoded, so subtract off one here.
1873 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1874 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1875 }
1876
Jim Grosbach46dd4132011-08-17 21:51:27 +00001877 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1878 assert(N == 1 && "Invalid number of operands!");
1879 // The constant encodes as the immediate, except for 32, which encodes as
1880 // zero.
1881 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1882 unsigned Imm = CE->getValue();
1883 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1884 }
1885
Jim Grosbach27c1e252011-07-21 17:23:04 +00001886 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1887 assert(N == 1 && "Invalid number of operands!");
1888 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1889 // the instruction as well.
1890 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1891 int Val = CE->getValue();
1892 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1893 }
1894
Jim Grosbachb009a872011-10-28 22:36:30 +00001895 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1896 assert(N == 1 && "Invalid number of operands!");
1897 // The operand is actually a t2_so_imm, but we have its bitwise
1898 // negation in the assembly source, so twiddle it here.
1899 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1900 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1901 }
1902
Jim Grosbach30506252011-12-08 00:31:07 +00001903 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1904 assert(N == 1 && "Invalid number of operands!");
1905 // The operand is actually a t2_so_imm, but we have its
1906 // negation in the assembly source, so twiddle it here.
1907 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1908 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1909 }
1910
Jim Grosbach930f2f62012-04-05 20:57:13 +00001911 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1912 assert(N == 1 && "Invalid number of operands!");
1913 // The operand is actually an imm0_4095, but we have its
1914 // negation in the assembly source, so twiddle it here.
1915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1916 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1917 }
1918
Mihai Popad36cbaa2013-07-03 09:21:44 +00001919 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1920 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1921 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1922 return;
1923 }
1924
1925 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1926 assert(SR && "Unknown value type!");
1927 Inst.addOperand(MCOperand::CreateExpr(SR));
1928 }
1929
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001930 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1931 assert(N == 1 && "Invalid number of operands!");
1932 if (isImm()) {
1933 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1934 if (CE) {
1935 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1936 return;
1937 }
1938
1939 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1940 assert(SR && "Unknown value type!");
1941 Inst.addOperand(MCOperand::CreateExpr(SR));
1942 return;
1943 }
1944
1945 assert(isMem() && "Unknown value type!");
1946 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1947 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1948 }
1949
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001950 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1951 assert(N == 1 && "Invalid number of operands!");
1952 // The operand is actually a so_imm, but we have its bitwise
1953 // negation in the assembly source, so twiddle it here.
1954 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1955 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1956 }
1957
Jim Grosbach30506252011-12-08 00:31:07 +00001958 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1959 assert(N == 1 && "Invalid number of operands!");
1960 // The operand is actually a so_imm, but we have its
1961 // negation in the assembly source, so twiddle it here.
1962 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1963 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1964 }
1965
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001966 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1967 assert(N == 1 && "Invalid number of operands!");
1968 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1969 }
1970
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001971 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1972 assert(N == 1 && "Invalid number of operands!");
1973 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1974 }
1975
Jim Grosbachd3595712011-08-03 23:50:40 +00001976 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1977 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001978 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001979 }
1980
Jim Grosbach94298a92012-01-18 22:46:46 +00001981 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1982 assert(N == 1 && "Invalid number of operands!");
1983 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001984 Inst.addOperand(MCOperand::CreateImm(Imm));
1985 }
1986
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001987 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1988 assert(N == 1 && "Invalid number of operands!");
1989 assert(isImm() && "Not an immediate!");
1990
1991 // If we have an immediate that's not a constant, treat it as a label
1992 // reference needing a fixup.
1993 if (!isa<MCConstantExpr>(getImm())) {
1994 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1995 return;
1996 }
1997
1998 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1999 int Val = CE->getValue();
2000 Inst.addOperand(MCOperand::CreateImm(Val));
2001 }
2002
Jim Grosbacha95ec992011-10-11 17:29:55 +00002003 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
2004 assert(N == 2 && "Invalid number of operands!");
2005 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2006 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
2007 }
2008
Kevin Enderby488f20b2014-04-10 20:18:58 +00002009 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2010 addAlignedMemoryOperands(Inst, N);
2011 }
2012
2013 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2014 addAlignedMemoryOperands(Inst, N);
2015 }
2016
2017 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2018 addAlignedMemoryOperands(Inst, N);
2019 }
2020
2021 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2022 addAlignedMemoryOperands(Inst, N);
2023 }
2024
2025 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2026 addAlignedMemoryOperands(Inst, N);
2027 }
2028
2029 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2030 addAlignedMemoryOperands(Inst, N);
2031 }
2032
2033 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2034 addAlignedMemoryOperands(Inst, N);
2035 }
2036
2037 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2038 addAlignedMemoryOperands(Inst, N);
2039 }
2040
2041 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2042 addAlignedMemoryOperands(Inst, N);
2043 }
2044
2045 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2046 addAlignedMemoryOperands(Inst, N);
2047 }
2048
2049 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
2050 addAlignedMemoryOperands(Inst, N);
2051 }
2052
Jim Grosbachd3595712011-08-03 23:50:40 +00002053 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
2054 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002055 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2056 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00002057 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2058 // Special case for #-0
2059 if (Val == INT32_MIN) Val = 0;
2060 if (Val < 0) Val = -Val;
2061 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2062 } else {
2063 // For register offset, we encode the shift type and negation flag
2064 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002065 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2066 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002067 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002068 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2069 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002070 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002071 }
2072
Jim Grosbachcd17c122011-08-04 23:01:30 +00002073 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
2074 assert(N == 2 && "Invalid number of operands!");
2075 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2076 assert(CE && "non-constant AM2OffsetImm operand!");
2077 int32_t Val = CE->getValue();
2078 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2079 // Special case for #-0
2080 if (Val == INT32_MIN) Val = 0;
2081 if (Val < 0) Val = -Val;
2082 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2083 Inst.addOperand(MCOperand::CreateReg(0));
2084 Inst.addOperand(MCOperand::CreateImm(Val));
2085 }
2086
Jim Grosbach5b96b802011-08-10 20:29:19 +00002087 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
2088 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002089 // If we have an immediate that's not a constant, treat it as a label
2090 // reference needing a fixup. If it is a constant, it's something else
2091 // and we reject it.
2092 if (isImm()) {
2093 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2094 Inst.addOperand(MCOperand::CreateReg(0));
2095 Inst.addOperand(MCOperand::CreateImm(0));
2096 return;
2097 }
2098
Jim Grosbach871dff72011-10-11 15:59:20 +00002099 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2100 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002101 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2102 // Special case for #-0
2103 if (Val == INT32_MIN) Val = 0;
2104 if (Val < 0) Val = -Val;
2105 Val = ARM_AM::getAM3Opc(AddSub, Val);
2106 } else {
2107 // For register offset, we encode the shift type and negation flag
2108 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002109 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002110 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002111 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2112 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00002113 Inst.addOperand(MCOperand::CreateImm(Val));
2114 }
2115
2116 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
2117 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002118 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002119 int32_t Val =
2120 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
2121 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2122 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002123 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00002124 }
2125
2126 // Constant offset.
2127 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2128 int32_t Val = CE->getValue();
2129 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2130 // Special case for #-0
2131 if (Val == INT32_MIN) Val = 0;
2132 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002133 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002134 Inst.addOperand(MCOperand::CreateReg(0));
2135 Inst.addOperand(MCOperand::CreateImm(Val));
2136 }
2137
Jim Grosbachd3595712011-08-03 23:50:40 +00002138 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2139 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00002140 // If we have an immediate that's not a constant, treat it as a label
2141 // reference needing a fixup. If it is a constant, it's something else
2142 // and we reject it.
2143 if (isImm()) {
2144 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2145 Inst.addOperand(MCOperand::CreateImm(0));
2146 return;
2147 }
2148
Jim Grosbachd3595712011-08-03 23:50:40 +00002149 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002150 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002151 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2152 // Special case for #-0
2153 if (Val == INT32_MIN) Val = 0;
2154 if (Val < 0) Val = -Val;
2155 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002156 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002157 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002158 }
2159
Jim Grosbach7db8d692011-09-08 22:07:06 +00002160 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2161 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002162 // If we have an immediate that's not a constant, treat it as a label
2163 // reference needing a fixup. If it is a constant, it's something else
2164 // and we reject it.
2165 if (isImm()) {
2166 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2167 Inst.addOperand(MCOperand::CreateImm(0));
2168 return;
2169 }
2170
Jim Grosbach871dff72011-10-11 15:59:20 +00002171 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2172 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002173 Inst.addOperand(MCOperand::CreateImm(Val));
2174 }
2175
Jim Grosbacha05627e2011-09-09 18:37:27 +00002176 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2177 assert(N == 2 && "Invalid number of operands!");
2178 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002179 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2180 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002181 Inst.addOperand(MCOperand::CreateImm(Val));
2182 }
2183
Jim Grosbachd3595712011-08-03 23:50:40 +00002184 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2185 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002186 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2187 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002188 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002189 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002190
Jim Grosbach2392c532011-09-07 23:39:14 +00002191 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2192 addMemImm8OffsetOperands(Inst, N);
2193 }
2194
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002195 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002196 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002197 }
2198
2199 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2200 assert(N == 2 && "Invalid number of operands!");
2201 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002202 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002203 addExpr(Inst, getImm());
2204 Inst.addOperand(MCOperand::CreateImm(0));
2205 return;
2206 }
2207
2208 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002209 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2210 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002211 Inst.addOperand(MCOperand::CreateImm(Val));
2212 }
2213
Jim Grosbachd3595712011-08-03 23:50:40 +00002214 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2215 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002216 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002217 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002218 addExpr(Inst, getImm());
2219 Inst.addOperand(MCOperand::CreateImm(0));
2220 return;
2221 }
2222
2223 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002224 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2225 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002226 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002227 }
Bill Wendling811c9362010-11-30 07:44:32 +00002228
Jim Grosbach05541f42011-09-19 22:21:13 +00002229 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2230 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002231 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2232 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002233 }
2234
2235 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2236 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002237 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2238 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002239 }
2240
Jim Grosbachd3595712011-08-03 23:50:40 +00002241 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2242 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002243 unsigned Val =
2244 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2245 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002246 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2247 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002248 Inst.addOperand(MCOperand::CreateImm(Val));
2249 }
2250
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002251 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2252 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002253 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2254 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2255 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002256 }
2257
Jim Grosbachd3595712011-08-03 23:50:40 +00002258 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2259 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002260 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2261 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002262 }
2263
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002264 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2265 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002266 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2267 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002268 Inst.addOperand(MCOperand::CreateImm(Val));
2269 }
2270
Jim Grosbach26d35872011-08-19 18:55:51 +00002271 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2272 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002273 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2274 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002275 Inst.addOperand(MCOperand::CreateImm(Val));
2276 }
2277
Jim Grosbacha32c7532011-08-19 18:49:59 +00002278 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2279 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002280 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2281 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002282 Inst.addOperand(MCOperand::CreateImm(Val));
2283 }
2284
Jim Grosbach23983d62011-08-19 18:13:48 +00002285 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2286 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002287 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2288 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002289 Inst.addOperand(MCOperand::CreateImm(Val));
2290 }
2291
Jim Grosbachd3595712011-08-03 23:50:40 +00002292 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2293 assert(N == 1 && "Invalid number of operands!");
2294 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2295 assert(CE && "non-constant post-idx-imm8 operand!");
2296 int Imm = CE->getValue();
2297 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002298 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002299 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2300 Inst.addOperand(MCOperand::CreateImm(Imm));
2301 }
2302
Jim Grosbach93981412011-10-11 21:55:36 +00002303 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2304 assert(N == 1 && "Invalid number of operands!");
2305 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2306 assert(CE && "non-constant post-idx-imm8s4 operand!");
2307 int Imm = CE->getValue();
2308 bool isAdd = Imm >= 0;
2309 if (Imm == INT32_MIN) Imm = 0;
2310 // Immediate is scaled by 4.
2311 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2312 Inst.addOperand(MCOperand::CreateImm(Imm));
2313 }
2314
Jim Grosbachd3595712011-08-03 23:50:40 +00002315 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2316 assert(N == 2 && "Invalid number of operands!");
2317 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002318 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2319 }
2320
2321 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2322 assert(N == 2 && "Invalid number of operands!");
2323 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2324 // The sign, shift type, and shift amount are encoded in a single operand
2325 // using the AM2 encoding helpers.
2326 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2327 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2328 PostIdxReg.ShiftTy);
2329 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002330 }
2331
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002332 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2333 assert(N == 1 && "Invalid number of operands!");
2334 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2335 }
2336
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002337 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2338 assert(N == 1 && "Invalid number of operands!");
2339 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2340 }
2341
Jim Grosbach182b6a02011-11-29 23:51:09 +00002342 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002343 assert(N == 1 && "Invalid number of operands!");
2344 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2345 }
2346
Jim Grosbach04945c42011-12-02 00:35:16 +00002347 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2348 assert(N == 2 && "Invalid number of operands!");
2349 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2350 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2351 }
2352
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002353 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2354 assert(N == 1 && "Invalid number of operands!");
2355 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2356 }
2357
2358 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2359 assert(N == 1 && "Invalid number of operands!");
2360 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2361 }
2362
2363 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2364 assert(N == 1 && "Invalid number of operands!");
2365 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2366 }
2367
Jim Grosbach741cd732011-10-17 22:26:03 +00002368 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2369 assert(N == 1 && "Invalid number of operands!");
2370 // The immediate encodes the type of constant as well as the value.
2371 // Mask in that this is an i8 splat.
2372 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2373 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2374 }
2375
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002376 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2377 assert(N == 1 && "Invalid number of operands!");
2378 // The immediate encodes the type of constant as well as the value.
2379 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2380 unsigned Value = CE->getValue();
2381 if (Value >= 256)
2382 Value = (Value >> 8) | 0xa00;
2383 else
2384 Value |= 0x800;
2385 Inst.addOperand(MCOperand::CreateImm(Value));
2386 }
2387
Jim Grosbach8211c052011-10-18 00:22:00 +00002388 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2389 assert(N == 1 && "Invalid number of operands!");
2390 // The immediate encodes the type of constant as well as the value.
2391 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2392 unsigned Value = CE->getValue();
2393 if (Value >= 256 && Value <= 0xff00)
2394 Value = (Value >> 8) | 0x200;
2395 else if (Value > 0xffff && Value <= 0xff0000)
2396 Value = (Value >> 16) | 0x400;
2397 else if (Value > 0xffffff)
2398 Value = (Value >> 24) | 0x600;
2399 Inst.addOperand(MCOperand::CreateImm(Value));
2400 }
2401
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002402 void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const {
2403 assert(N == 1 && "Invalid number of operands!");
2404 // The immediate encodes the type of constant as well as the value.
2405 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2406 unsigned Value = CE->getValue();
2407 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2408 Inst.getOpcode() == ARM::VMOVv16i8) &&
2409 "All vmvn instructions that wants to replicate non-zero byte "
2410 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2411 unsigned B = ((~Value) & 0xff);
2412 B |= 0xe00; // cmode = 0b1110
2413 Inst.addOperand(MCOperand::CreateImm(B));
2414 }
Jim Grosbach8211c052011-10-18 00:22:00 +00002415 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2416 assert(N == 1 && "Invalid number of operands!");
2417 // The immediate encodes the type of constant as well as the value.
2418 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2419 unsigned Value = CE->getValue();
2420 if (Value >= 256 && Value <= 0xffff)
2421 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2422 else if (Value > 0xffff && Value <= 0xffffff)
2423 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2424 else if (Value > 0xffffff)
2425 Value = (Value >> 24) | 0x600;
2426 Inst.addOperand(MCOperand::CreateImm(Value));
2427 }
2428
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002429 void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const {
2430 assert(N == 1 && "Invalid number of operands!");
2431 // The immediate encodes the type of constant as well as the value.
2432 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2433 unsigned Value = CE->getValue();
2434 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2435 Inst.getOpcode() == ARM::VMOVv16i8) &&
2436 "All instructions that wants to replicate non-zero byte "
2437 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2438 unsigned B = Value & 0xff;
2439 B |= 0xe00; // cmode = 0b1110
2440 Inst.addOperand(MCOperand::CreateImm(B));
2441 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00002442 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2443 assert(N == 1 && "Invalid number of operands!");
2444 // The immediate encodes the type of constant as well as the value.
2445 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2446 unsigned Value = ~CE->getValue();
2447 if (Value >= 256 && Value <= 0xffff)
2448 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2449 else if (Value > 0xffff && Value <= 0xffffff)
2450 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2451 else if (Value > 0xffffff)
2452 Value = (Value >> 24) | 0x600;
2453 Inst.addOperand(MCOperand::CreateImm(Value));
2454 }
2455
Jim Grosbache4454e02011-10-18 16:18:11 +00002456 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2457 assert(N == 1 && "Invalid number of operands!");
2458 // The immediate encodes the type of constant as well as the value.
2459 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2460 uint64_t Value = CE->getValue();
2461 unsigned Imm = 0;
2462 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2463 Imm |= (Value & 1) << i;
2464 }
2465 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2466 }
2467
Craig Topperca7e3e52014-03-10 03:19:03 +00002468 void print(raw_ostream &OS) const override;
Daniel Dunbarebace222010-08-11 06:37:04 +00002469
David Blaikie960ea3f2014-06-08 16:18:35 +00002470 static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) {
2471 auto Op = make_unique<ARMOperand>(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002472 Op->ITMask.Mask = Mask;
2473 Op->StartLoc = S;
2474 Op->EndLoc = S;
2475 return Op;
2476 }
2477
David Blaikie960ea3f2014-06-08 16:18:35 +00002478 static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC,
2479 SMLoc S) {
2480 auto Op = make_unique<ARMOperand>(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002481 Op->CC.Val = CC;
2482 Op->StartLoc = S;
2483 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002484 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002485 }
2486
David Blaikie960ea3f2014-06-08 16:18:35 +00002487 static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) {
2488 auto Op = make_unique<ARMOperand>(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002489 Op->Cop.Val = CopVal;
2490 Op->StartLoc = S;
2491 Op->EndLoc = S;
2492 return Op;
2493 }
2494
David Blaikie960ea3f2014-06-08 16:18:35 +00002495 static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) {
2496 auto Op = make_unique<ARMOperand>(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002497 Op->Cop.Val = CopVal;
2498 Op->StartLoc = S;
2499 Op->EndLoc = S;
2500 return Op;
2501 }
2502
David Blaikie960ea3f2014-06-08 16:18:35 +00002503 static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S,
2504 SMLoc E) {
2505 auto Op = make_unique<ARMOperand>(k_CoprocOption);
Jim Grosbach48399582011-10-12 17:34:41 +00002506 Op->Cop.Val = Val;
2507 Op->StartLoc = S;
2508 Op->EndLoc = E;
2509 return Op;
2510 }
2511
David Blaikie960ea3f2014-06-08 16:18:35 +00002512 static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) {
2513 auto Op = make_unique<ARMOperand>(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002514 Op->Reg.RegNum = RegNum;
2515 Op->StartLoc = S;
2516 Op->EndLoc = S;
2517 return Op;
2518 }
2519
David Blaikie960ea3f2014-06-08 16:18:35 +00002520 static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) {
2521 auto Op = make_unique<ARMOperand>(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002522 Op->Tok.Data = Str.data();
2523 Op->Tok.Length = Str.size();
2524 Op->StartLoc = S;
2525 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002526 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002527 }
2528
David Blaikie960ea3f2014-06-08 16:18:35 +00002529 static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S,
2530 SMLoc E) {
2531 auto Op = make_unique<ARMOperand>(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002532 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002533 Op->StartLoc = S;
2534 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002535 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002536 }
2537
David Blaikie960ea3f2014-06-08 16:18:35 +00002538 static std::unique_ptr<ARMOperand>
2539 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2540 unsigned ShiftReg, unsigned ShiftImm, SMLoc S,
2541 SMLoc E) {
2542 auto Op = make_unique<ARMOperand>(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002543 Op->RegShiftedReg.ShiftTy = ShTy;
2544 Op->RegShiftedReg.SrcReg = SrcReg;
2545 Op->RegShiftedReg.ShiftReg = ShiftReg;
2546 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002547 Op->StartLoc = S;
2548 Op->EndLoc = E;
2549 return Op;
2550 }
2551
David Blaikie960ea3f2014-06-08 16:18:35 +00002552 static std::unique_ptr<ARMOperand>
2553 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2554 unsigned ShiftImm, SMLoc S, SMLoc E) {
2555 auto Op = make_unique<ARMOperand>(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002556 Op->RegShiftedImm.ShiftTy = ShTy;
2557 Op->RegShiftedImm.SrcReg = SrcReg;
2558 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002559 Op->StartLoc = S;
2560 Op->EndLoc = E;
2561 return Op;
2562 }
2563
David Blaikie960ea3f2014-06-08 16:18:35 +00002564 static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm,
2565 SMLoc S, SMLoc E) {
2566 auto Op = make_unique<ARMOperand>(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002567 Op->ShifterImm.isASR = isASR;
2568 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002569 Op->StartLoc = S;
2570 Op->EndLoc = E;
2571 return Op;
2572 }
2573
David Blaikie960ea3f2014-06-08 16:18:35 +00002574 static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S,
2575 SMLoc E) {
2576 auto Op = make_unique<ARMOperand>(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002577 Op->RotImm.Imm = Imm;
2578 Op->StartLoc = S;
2579 Op->EndLoc = E;
2580 return Op;
2581 }
2582
David Blaikie960ea3f2014-06-08 16:18:35 +00002583 static std::unique_ptr<ARMOperand>
2584 CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) {
2585 auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002586 Op->Bitfield.LSB = LSB;
2587 Op->Bitfield.Width = Width;
2588 Op->StartLoc = S;
2589 Op->EndLoc = E;
2590 return Op;
2591 }
2592
David Blaikie960ea3f2014-06-08 16:18:35 +00002593 static std::unique_ptr<ARMOperand>
2594 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002595 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002596 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002597 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002598
Chad Rosierfa705ee2013-07-01 20:49:23 +00002599 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002600 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002601 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002602 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002603 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002604
Chad Rosierfa705ee2013-07-01 20:49:23 +00002605 // Sort based on the register encoding values.
2606 array_pod_sort(Regs.begin(), Regs.end());
2607
David Blaikie960ea3f2014-06-08 16:18:35 +00002608 auto Op = make_unique<ARMOperand>(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002609 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002610 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002611 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002612 Op->StartLoc = StartLoc;
2613 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002614 return Op;
2615 }
2616
David Blaikie960ea3f2014-06-08 16:18:35 +00002617 static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum,
2618 unsigned Count,
2619 bool isDoubleSpaced,
2620 SMLoc S, SMLoc E) {
2621 auto Op = make_unique<ARMOperand>(k_VectorList);
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002622 Op->VectorList.RegNum = RegNum;
2623 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002624 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002625 Op->StartLoc = S;
2626 Op->EndLoc = E;
2627 return Op;
2628 }
2629
David Blaikie960ea3f2014-06-08 16:18:35 +00002630 static std::unique_ptr<ARMOperand>
2631 CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced,
2632 SMLoc S, SMLoc E) {
2633 auto Op = make_unique<ARMOperand>(k_VectorListAllLanes);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002634 Op->VectorList.RegNum = RegNum;
2635 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002636 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002637 Op->StartLoc = S;
2638 Op->EndLoc = E;
2639 return Op;
2640 }
2641
David Blaikie960ea3f2014-06-08 16:18:35 +00002642 static std::unique_ptr<ARMOperand>
2643 CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index,
2644 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2645 auto Op = make_unique<ARMOperand>(k_VectorListIndexed);
Jim Grosbach04945c42011-12-02 00:35:16 +00002646 Op->VectorList.RegNum = RegNum;
2647 Op->VectorList.Count = Count;
2648 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002649 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002650 Op->StartLoc = S;
2651 Op->EndLoc = E;
2652 return Op;
2653 }
2654
David Blaikie960ea3f2014-06-08 16:18:35 +00002655 static std::unique_ptr<ARMOperand>
2656 CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) {
2657 auto Op = make_unique<ARMOperand>(k_VectorIndex);
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002658 Op->VectorIndex.Val = Idx;
2659 Op->StartLoc = S;
2660 Op->EndLoc = E;
2661 return Op;
2662 }
2663
David Blaikie960ea3f2014-06-08 16:18:35 +00002664 static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S,
2665 SMLoc E) {
2666 auto Op = make_unique<ARMOperand>(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002667 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002668 Op->StartLoc = S;
2669 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002670 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002671 }
2672
David Blaikie960ea3f2014-06-08 16:18:35 +00002673 static std::unique_ptr<ARMOperand>
2674 CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm,
2675 unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType,
2676 unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S,
2677 SMLoc E, SMLoc AlignmentLoc = SMLoc()) {
2678 auto Op = make_unique<ARMOperand>(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002679 Op->Memory.BaseRegNum = BaseRegNum;
2680 Op->Memory.OffsetImm = OffsetImm;
2681 Op->Memory.OffsetRegNum = OffsetRegNum;
2682 Op->Memory.ShiftType = ShiftType;
2683 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002684 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002685 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002686 Op->StartLoc = S;
2687 Op->EndLoc = E;
Kevin Enderby488f20b2014-04-10 20:18:58 +00002688 Op->AlignmentLoc = AlignmentLoc;
Jim Grosbachd3595712011-08-03 23:50:40 +00002689 return Op;
2690 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002691
David Blaikie960ea3f2014-06-08 16:18:35 +00002692 static std::unique_ptr<ARMOperand>
2693 CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy,
2694 unsigned ShiftImm, SMLoc S, SMLoc E) {
2695 auto Op = make_unique<ARMOperand>(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002696 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002697 Op->PostIdxReg.isAdd = isAdd;
2698 Op->PostIdxReg.ShiftTy = ShiftTy;
2699 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002700 Op->StartLoc = S;
2701 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002702 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002703 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002704
David Blaikie960ea3f2014-06-08 16:18:35 +00002705 static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt,
2706 SMLoc S) {
2707 auto Op = make_unique<ARMOperand>(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002708 Op->MBOpt.Val = Opt;
2709 Op->StartLoc = S;
2710 Op->EndLoc = S;
2711 return Op;
2712 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002713
David Blaikie960ea3f2014-06-08 16:18:35 +00002714 static std::unique_ptr<ARMOperand>
2715 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) {
2716 auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002717 Op->ISBOpt.Val = Opt;
2718 Op->StartLoc = S;
2719 Op->EndLoc = S;
2720 return Op;
2721 }
2722
David Blaikie960ea3f2014-06-08 16:18:35 +00002723 static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags,
2724 SMLoc S) {
2725 auto Op = make_unique<ARMOperand>(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002726 Op->IFlags.Val = IFlags;
2727 Op->StartLoc = S;
2728 Op->EndLoc = S;
2729 return Op;
2730 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002731
David Blaikie960ea3f2014-06-08 16:18:35 +00002732 static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) {
2733 auto Op = make_unique<ARMOperand>(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002734 Op->MMask.Val = MMask;
2735 Op->StartLoc = S;
2736 Op->EndLoc = S;
2737 return Op;
2738 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002739};
2740
2741} // end anonymous namespace.
2742
Jim Grosbach602aa902011-07-13 15:34:57 +00002743void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002744 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002745 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002746 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002747 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002748 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002749 OS << "<ccout " << getReg() << ">";
2750 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002751 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002752 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002753 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2754 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2755 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002756 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2757 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2758 break;
2759 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002760 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002761 OS << "<coprocessor number: " << getCoproc() << ">";
2762 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002763 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002764 OS << "<coprocessor register: " << getCoproc() << ">";
2765 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002766 case k_CoprocOption:
2767 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2768 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002769 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002770 OS << "<mask: " << getMSRMask() << ">";
2771 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002772 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002773 getImm()->print(OS);
2774 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002775 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002776 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002777 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002778 case k_InstSyncBarrierOpt:
2779 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2780 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002781 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002782 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002783 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002784 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002785 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002786 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002787 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2788 << PostIdxReg.RegNum;
2789 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2790 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2791 << PostIdxReg.ShiftImm;
2792 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002793 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002794 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002795 OS << "<ARM_PROC::";
2796 unsigned IFlags = getProcIFlags();
2797 for (int i=2; i >= 0; --i)
2798 if (IFlags & (1 << i))
2799 OS << ARM_PROC::IFlagsToString(1 << i);
2800 OS << ">";
2801 break;
2802 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002803 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002804 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002805 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002806 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002807 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2808 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002809 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002810 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002811 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002812 << RegShiftedReg.SrcReg << " "
2813 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2814 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002815 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002816 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002817 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002818 << RegShiftedImm.SrcReg << " "
2819 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2820 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002821 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002822 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002823 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2824 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002825 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002826 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2827 << ", width: " << Bitfield.Width << ">";
2828 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002829 case k_RegisterList:
2830 case k_DPRRegisterList:
2831 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002832 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002833
Bill Wendlingbed94652010-11-09 23:28:44 +00002834 const SmallVectorImpl<unsigned> &RegList = getRegList();
2835 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002836 I = RegList.begin(), E = RegList.end(); I != E; ) {
2837 OS << *I;
2838 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002839 }
2840
2841 OS << ">";
2842 break;
2843 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002844 case k_VectorList:
2845 OS << "<vector_list " << VectorList.Count << " * "
2846 << VectorList.RegNum << ">";
2847 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002848 case k_VectorListAllLanes:
2849 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2850 << VectorList.RegNum << ">";
2851 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002852 case k_VectorListIndexed:
2853 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2854 << VectorList.Count << " * " << VectorList.RegNum << ">";
2855 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002856 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002857 OS << "'" << getToken() << "'";
2858 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002859 case k_VectorIndex:
2860 OS << "<vectorindex " << getVectorIndex() << ">";
2861 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002862 }
2863}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002864
2865/// @name Auto-generated Match Functions
2866/// {
2867
2868static unsigned MatchRegisterName(StringRef Name);
2869
2870/// }
2871
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002872bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2873 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002874 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002875 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002876 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002877
2878 return (RegNo == (unsigned)-1);
2879}
2880
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002881/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002882/// and if it is a register name the token is eaten and the register number is
2883/// returned. Otherwise return -1.
2884///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002885int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002886 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002887 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002888
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002889 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002890 unsigned RegNum = MatchRegisterName(lowerCase);
2891 if (!RegNum) {
2892 RegNum = StringSwitch<unsigned>(lowerCase)
2893 .Case("r13", ARM::SP)
2894 .Case("r14", ARM::LR)
2895 .Case("r15", ARM::PC)
2896 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002897 // Additional register name aliases for 'gas' compatibility.
2898 .Case("a1", ARM::R0)
2899 .Case("a2", ARM::R1)
2900 .Case("a3", ARM::R2)
2901 .Case("a4", ARM::R3)
2902 .Case("v1", ARM::R4)
2903 .Case("v2", ARM::R5)
2904 .Case("v3", ARM::R6)
2905 .Case("v4", ARM::R7)
2906 .Case("v5", ARM::R8)
2907 .Case("v6", ARM::R9)
2908 .Case("v7", ARM::R10)
2909 .Case("v8", ARM::R11)
2910 .Case("sb", ARM::R9)
2911 .Case("sl", ARM::R10)
2912 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002913 .Default(0);
2914 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002915 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002916 // Check for aliases registered via .req. Canonicalize to lower case.
2917 // That's more consistent since register names are case insensitive, and
2918 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2919 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002920 // If no match, return failure.
2921 if (Entry == RegisterReqs.end())
2922 return -1;
2923 Parser.Lex(); // Eat identifier token.
2924 return Entry->getValue();
2925 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002926
Chris Lattner44e5981c2010-10-30 04:09:10 +00002927 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002928
Chris Lattner44e5981c2010-10-30 04:09:10 +00002929 return RegNum;
2930}
Jim Grosbach99710a82010-11-01 16:44:21 +00002931
Jim Grosbachbb24c592011-07-13 18:49:30 +00002932// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2933// If a recoverable error occurs, return 1. If an irrecoverable error
2934// occurs, return -1. An irrecoverable error is one where tokens have been
2935// consumed in the process of trying to parse the shifter (i.e., when it is
2936// indeed a shifter operand, but malformed).
David Blaikie960ea3f2014-06-08 16:18:35 +00002937int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002938 SMLoc S = Parser.getTok().getLoc();
2939 const AsmToken &Tok = Parser.getTok();
Kevin Enderby62873712014-02-17 21:45:27 +00002940 if (Tok.isNot(AsmToken::Identifier))
2941 return -1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002942
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002943 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002944 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002945 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002946 .Case("lsl", ARM_AM::lsl)
2947 .Case("lsr", ARM_AM::lsr)
2948 .Case("asr", ARM_AM::asr)
2949 .Case("ror", ARM_AM::ror)
2950 .Case("rrx", ARM_AM::rrx)
2951 .Default(ARM_AM::no_shift);
2952
2953 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002954 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002955
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002956 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002957
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002958 // The source register for the shift has already been added to the
2959 // operand list, so we need to pop it off and combine it into the shifted
2960 // register operand instead.
David Blaikie960ea3f2014-06-08 16:18:35 +00002961 std::unique_ptr<ARMOperand> PrevOp(
2962 (ARMOperand *)Operands.pop_back_val().release());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002963 if (!PrevOp->isReg())
2964 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2965 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002966
2967 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002968 int64_t Imm = 0;
2969 int ShiftReg = 0;
2970 if (ShiftTy == ARM_AM::rrx) {
2971 // RRX Doesn't have an explicit shift amount. The encoder expects
2972 // the shift register to be the same as the source register. Seems odd,
2973 // but OK.
2974 ShiftReg = SrcReg;
2975 } else {
2976 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002977 if (Parser.getTok().is(AsmToken::Hash) ||
2978 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002979 Parser.Lex(); // Eat hash.
2980 SMLoc ImmLoc = Parser.getTok().getLoc();
Craig Topper062a2ba2014-04-25 05:30:21 +00002981 const MCExpr *ShiftExpr = nullptr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002982 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002983 Error(ImmLoc, "invalid immediate shift value");
2984 return -1;
2985 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002986 // The expression must be evaluatable as an immediate.
2987 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002988 if (!CE) {
2989 Error(ImmLoc, "invalid immediate shift value");
2990 return -1;
2991 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002992 // Range check the immediate.
2993 // lsl, ror: 0 <= imm <= 31
2994 // lsr, asr: 0 <= imm <= 32
2995 Imm = CE->getValue();
2996 if (Imm < 0 ||
2997 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2998 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002999 Error(ImmLoc, "immediate shift value out of range");
3000 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003001 }
Jim Grosbach21488b82011-12-22 17:37:00 +00003002 // shift by zero is a nop. Always send it through as lsl.
3003 // ('as' compatibility)
3004 if (Imm == 0)
3005 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003006 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003007 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003008 EndLoc = Parser.getTok().getEndLoc();
3009 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00003010 if (ShiftReg == -1) {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003011 Error(L, "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003012 return -1;
3013 }
3014 } else {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003015 Error(Parser.getTok().getLoc(),
3016 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003017 return -1;
3018 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003019 }
3020
Owen Andersonb595ed02011-07-21 18:54:16 +00003021 if (ShiftReg && ShiftTy != ARM_AM::rrx)
3022 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00003023 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003024 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00003025 else
3026 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003027 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003028
Jim Grosbachbb24c592011-07-13 18:49:30 +00003029 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003030}
3031
3032
Bill Wendling2063b842010-11-18 23:43:05 +00003033/// Try to parse a register name. The token must be an Identifier when called.
3034/// If it's a register, an AsmOperand is created. Another AsmOperand is created
3035/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00003036///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00003037/// TODO this is likely to change to allow different register types and or to
3038/// parse for a specific register type.
David Blaikie960ea3f2014-06-08 16:18:35 +00003039bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003040 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003041 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00003042 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00003043 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00003044
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003045 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
3046 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003047
Chris Lattner44e5981c2010-10-30 04:09:10 +00003048 const AsmToken &ExclaimTok = Parser.getTok();
3049 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00003050 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
3051 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00003052 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003053 return false;
3054 }
3055
3056 // Also check for an index operand. This is only legal for vector registers,
3057 // but that'll get caught OK in operand matching, so we don't need to
3058 // explicitly filter everything else out here.
3059 if (Parser.getTok().is(AsmToken::LBrac)) {
3060 SMLoc SIdx = Parser.getTok().getLoc();
3061 Parser.Lex(); // Eat left bracket token.
3062
3063 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003064 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00003065 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003066 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003067 if (!MCE)
3068 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003069
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003070 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003071 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003072
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003073 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003074 Parser.Lex(); // Eat right bracket token.
3075
3076 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
3077 SIdx, E,
3078 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00003079 }
3080
Bill Wendling2063b842010-11-18 23:43:05 +00003081 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003082}
3083
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003084/// MatchCoprocessorOperandName - Try to parse an coprocessor related
3085/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
3086/// "c5", ...
3087static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003088 // Use the same layout as the tablegen'erated register name matcher. Ugly,
3089 // but efficient.
3090 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00003091 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003092 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003093 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003094 return -1;
3095 switch (Name[1]) {
3096 default: return -1;
3097 case '0': return 0;
3098 case '1': return 1;
3099 case '2': return 2;
3100 case '3': return 3;
3101 case '4': return 4;
3102 case '5': return 5;
3103 case '6': return 6;
3104 case '7': return 7;
3105 case '8': return 8;
3106 case '9': return 9;
3107 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003108 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003109 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003110 return -1;
3111 switch (Name[2]) {
3112 default: return -1;
Artyom Skrobov86534432013-11-08 09:16:31 +00003113 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
3114 case '0': return CoprocOp == 'p'? -1: 10;
3115 case '1': return CoprocOp == 'p'? -1: 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003116 case '2': return 12;
3117 case '3': return 13;
3118 case '4': return 14;
3119 case '5': return 15;
3120 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003121 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003122}
3123
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003124/// parseITCondCode - Try to parse a condition code for an IT instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003125ARMAsmParser::OperandMatchResultTy
3126ARMAsmParser::parseITCondCode(OperandVector &Operands) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003127 SMLoc S = Parser.getTok().getLoc();
3128 const AsmToken &Tok = Parser.getTok();
3129 if (!Tok.is(AsmToken::Identifier))
3130 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00003131 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003132 .Case("eq", ARMCC::EQ)
3133 .Case("ne", ARMCC::NE)
3134 .Case("hs", ARMCC::HS)
3135 .Case("cs", ARMCC::HS)
3136 .Case("lo", ARMCC::LO)
3137 .Case("cc", ARMCC::LO)
3138 .Case("mi", ARMCC::MI)
3139 .Case("pl", ARMCC::PL)
3140 .Case("vs", ARMCC::VS)
3141 .Case("vc", ARMCC::VC)
3142 .Case("hi", ARMCC::HI)
3143 .Case("ls", ARMCC::LS)
3144 .Case("ge", ARMCC::GE)
3145 .Case("lt", ARMCC::LT)
3146 .Case("gt", ARMCC::GT)
3147 .Case("le", ARMCC::LE)
3148 .Case("al", ARMCC::AL)
3149 .Default(~0U);
3150 if (CC == ~0U)
3151 return MatchOperand_NoMatch;
3152 Parser.Lex(); // Eat the token.
3153
3154 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3155
3156 return MatchOperand_Success;
3157}
3158
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003159/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003160/// token must be an Identifier when called, and if it is a coprocessor
3161/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003162ARMAsmParser::OperandMatchResultTy
3163ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003164 SMLoc S = Parser.getTok().getLoc();
3165 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003166 if (Tok.isNot(AsmToken::Identifier))
3167 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003168
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003169 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003170 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003171 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003172
3173 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003174 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003175 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003176}
3177
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003178/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003179/// token must be an Identifier when called, and if it is a coprocessor
3180/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003181ARMAsmParser::OperandMatchResultTy
3182ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003183 SMLoc S = Parser.getTok().getLoc();
3184 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003185 if (Tok.isNot(AsmToken::Identifier))
3186 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003187
3188 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3189 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003190 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003191
3192 Parser.Lex(); // Eat identifier token.
3193 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003194 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003195}
3196
Jim Grosbach48399582011-10-12 17:34:41 +00003197/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3198/// coproc_option : '{' imm0_255 '}'
David Blaikie960ea3f2014-06-08 16:18:35 +00003199ARMAsmParser::OperandMatchResultTy
3200ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) {
Jim Grosbach48399582011-10-12 17:34:41 +00003201 SMLoc S = Parser.getTok().getLoc();
3202
3203 // If this isn't a '{', this isn't a coprocessor immediate operand.
3204 if (Parser.getTok().isNot(AsmToken::LCurly))
3205 return MatchOperand_NoMatch;
3206 Parser.Lex(); // Eat the '{'
3207
3208 const MCExpr *Expr;
3209 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003210 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003211 Error(Loc, "illegal expression");
3212 return MatchOperand_ParseFail;
3213 }
3214 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3215 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3216 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3217 return MatchOperand_ParseFail;
3218 }
3219 int Val = CE->getValue();
3220
3221 // Check for and consume the closing '}'
3222 if (Parser.getTok().isNot(AsmToken::RCurly))
3223 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003224 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003225 Parser.Lex(); // Eat the '}'
3226
3227 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3228 return MatchOperand_Success;
3229}
3230
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003231// For register list parsing, we need to map from raw GPR register numbering
3232// to the enumeration values. The enumeration values aren't sorted by
3233// register number due to our using "sp", "lr" and "pc" as canonical names.
3234static unsigned getNextRegister(unsigned Reg) {
3235 // If this is a GPR, we need to do it manually, otherwise we can rely
3236 // on the sort ordering of the enumeration since the other reg-classes
3237 // are sane.
3238 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3239 return Reg + 1;
3240 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003241 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003242 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3243 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3244 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3245 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3246 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3247 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3248 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3249 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3250 }
3251}
3252
Jim Grosbach85a23432011-11-11 21:27:40 +00003253// Return the low-subreg of a given Q register.
3254static unsigned getDRegFromQReg(unsigned QReg) {
3255 switch (QReg) {
3256 default: llvm_unreachable("expected a Q register!");
3257 case ARM::Q0: return ARM::D0;
3258 case ARM::Q1: return ARM::D2;
3259 case ARM::Q2: return ARM::D4;
3260 case ARM::Q3: return ARM::D6;
3261 case ARM::Q4: return ARM::D8;
3262 case ARM::Q5: return ARM::D10;
3263 case ARM::Q6: return ARM::D12;
3264 case ARM::Q7: return ARM::D14;
3265 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003266 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003267 case ARM::Q10: return ARM::D20;
3268 case ARM::Q11: return ARM::D22;
3269 case ARM::Q12: return ARM::D24;
3270 case ARM::Q13: return ARM::D26;
3271 case ARM::Q14: return ARM::D28;
3272 case ARM::Q15: return ARM::D30;
3273 }
3274}
3275
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003276/// Parse a register list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003277bool ARMAsmParser::parseRegisterList(OperandVector &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003278 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003279 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003280 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003281 Parser.Lex(); // Eat '{' token.
3282 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003283
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003284 // Check the first register in the list to see what register class
3285 // this is a list of.
3286 int Reg = tryParseRegister();
3287 if (Reg == -1)
3288 return Error(RegLoc, "register expected");
3289
Jim Grosbach85a23432011-11-11 21:27:40 +00003290 // The reglist instructions have at most 16 registers, so reserve
3291 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003292 int EReg = 0;
3293 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003294
3295 // Allow Q regs and just interpret them as the two D sub-registers.
3296 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3297 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003298 EReg = MRI->getEncodingValue(Reg);
3299 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003300 ++Reg;
3301 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003302 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003303 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3304 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3305 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3306 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3307 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3308 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3309 else
3310 return Error(RegLoc, "invalid register in register list");
3311
Jim Grosbach85a23432011-11-11 21:27:40 +00003312 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003313 EReg = MRI->getEncodingValue(Reg);
3314 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003315
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003316 // This starts immediately after the first register token in the list,
3317 // so we can see either a comma or a minus (range separator) as a legal
3318 // next token.
3319 while (Parser.getTok().is(AsmToken::Comma) ||
3320 Parser.getTok().is(AsmToken::Minus)) {
3321 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003322 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003323 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003324 int EndReg = tryParseRegister();
3325 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003326 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003327 // Allow Q regs and just interpret them as the two D sub-registers.
3328 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3329 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003330 // If the register is the same as the start reg, there's nothing
3331 // more to do.
3332 if (Reg == EndReg)
3333 continue;
3334 // The register must be in the same register class as the first.
3335 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003336 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003337 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003338 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003339 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003340
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003341 // Add all the registers in the range to the register list.
3342 while (Reg != EndReg) {
3343 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003344 EReg = MRI->getEncodingValue(Reg);
3345 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003346 }
3347 continue;
3348 }
3349 Parser.Lex(); // Eat the comma.
3350 RegLoc = Parser.getTok().getLoc();
3351 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003352 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003353 Reg = tryParseRegister();
3354 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003355 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003356 // Allow Q regs and just interpret them as the two D sub-registers.
3357 bool isQReg = false;
3358 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3359 Reg = getDRegFromQReg(Reg);
3360 isQReg = true;
3361 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003362 // The register must be in the same register class as the first.
3363 if (!RC->contains(Reg))
3364 return Error(RegLoc, "invalid register in register list");
3365 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003366 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003367 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3368 Warning(RegLoc, "register list not in ascending order");
3369 else
3370 return Error(RegLoc, "register list not in ascending order");
3371 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003372 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003373 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3374 ") in register list");
3375 continue;
3376 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003377 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003378 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3379 Reg != OldReg + 1)
3380 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003381 EReg = MRI->getEncodingValue(Reg);
3382 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3383 if (isQReg) {
3384 EReg = MRI->getEncodingValue(++Reg);
3385 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3386 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003387 }
3388
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003389 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003390 return Error(Parser.getTok().getLoc(), "'}' expected");
3391 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003392 Parser.Lex(); // Eat '}' token.
3393
Jim Grosbach18bf3632011-12-13 21:48:29 +00003394 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003395 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003396
3397 // The ARM system instruction variants for LDM/STM have a '^' token here.
3398 if (Parser.getTok().is(AsmToken::Caret)) {
3399 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3400 Parser.Lex(); // Eat '^' token.
3401 }
3402
Bill Wendling2063b842010-11-18 23:43:05 +00003403 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003404}
3405
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003406// Helper function to parse the lane index for vector lists.
3407ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003408parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003409 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003410 if (Parser.getTok().is(AsmToken::LBrac)) {
3411 Parser.Lex(); // Eat the '['.
3412 if (Parser.getTok().is(AsmToken::RBrac)) {
3413 // "Dn[]" is the 'all lanes' syntax.
3414 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003415 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003416 Parser.Lex(); // Eat the ']'.
3417 return MatchOperand_Success;
3418 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003419
3420 // There's an optional '#' token here. Normally there wouldn't be, but
3421 // inline assemble puts one in, and it's friendly to accept that.
3422 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003423 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003424
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003425 const MCExpr *LaneIndex;
3426 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003427 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003428 Error(Loc, "illegal expression");
3429 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003430 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003431 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3432 if (!CE) {
3433 Error(Loc, "lane index must be empty or an integer");
3434 return MatchOperand_ParseFail;
3435 }
3436 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3437 Error(Parser.getTok().getLoc(), "']' expected");
3438 return MatchOperand_ParseFail;
3439 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003440 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003441 Parser.Lex(); // Eat the ']'.
3442 int64_t Val = CE->getValue();
3443
3444 // FIXME: Make this range check context sensitive for .8, .16, .32.
3445 if (Val < 0 || Val > 7) {
3446 Error(Parser.getTok().getLoc(), "lane index out of range");
3447 return MatchOperand_ParseFail;
3448 }
3449 Index = Val;
3450 LaneKind = IndexedLane;
3451 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003452 }
3453 LaneKind = NoLanes;
3454 return MatchOperand_Success;
3455}
3456
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003457// parse a vector register list
David Blaikie960ea3f2014-06-08 16:18:35 +00003458ARMAsmParser::OperandMatchResultTy
3459ARMAsmParser::parseVectorList(OperandVector &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003460 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003461 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003462 SMLoc S = Parser.getTok().getLoc();
3463 // As an extension (to match gas), support a plain D register or Q register
3464 // (without encosing curly braces) as a single or double entry list,
3465 // respectively.
3466 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003467 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003468 int Reg = tryParseRegister();
3469 if (Reg == -1)
3470 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003471 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003472 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003473 if (Res != MatchOperand_Success)
3474 return Res;
3475 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003476 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003477 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003478 break;
3479 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003480 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3481 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003482 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003483 case IndexedLane:
3484 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003485 LaneIndex,
3486 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003487 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003488 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003489 return MatchOperand_Success;
3490 }
3491 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3492 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003493 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003494 if (Res != MatchOperand_Success)
3495 return Res;
3496 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003497 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003498 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003499 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003500 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003501 break;
3502 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003503 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3504 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003505 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3506 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003507 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003508 case IndexedLane:
3509 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003510 LaneIndex,
3511 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003512 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003513 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003514 return MatchOperand_Success;
3515 }
3516 Error(S, "vector register expected");
3517 return MatchOperand_ParseFail;
3518 }
3519
3520 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003521 return MatchOperand_NoMatch;
3522
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003523 Parser.Lex(); // Eat '{' token.
3524 SMLoc RegLoc = Parser.getTok().getLoc();
3525
3526 int Reg = tryParseRegister();
3527 if (Reg == -1) {
3528 Error(RegLoc, "register expected");
3529 return MatchOperand_ParseFail;
3530 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003531 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003532 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003533 unsigned FirstReg = Reg;
3534 // The list is of D registers, but we also allow Q regs and just interpret
3535 // them as the two D sub-registers.
3536 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3537 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003538 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3539 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003540 ++Reg;
3541 ++Count;
3542 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003543
3544 SMLoc E;
3545 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003546 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003547
Jim Grosbache891fe82011-11-15 23:19:15 +00003548 while (Parser.getTok().is(AsmToken::Comma) ||
3549 Parser.getTok().is(AsmToken::Minus)) {
3550 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003551 if (!Spacing)
3552 Spacing = 1; // Register range implies a single spaced list.
3553 else if (Spacing == 2) {
3554 Error(Parser.getTok().getLoc(),
3555 "sequential registers in double spaced list");
3556 return MatchOperand_ParseFail;
3557 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003558 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003559 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003560 int EndReg = tryParseRegister();
3561 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003562 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003563 return MatchOperand_ParseFail;
3564 }
3565 // Allow Q regs and just interpret them as the two D sub-registers.
3566 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3567 EndReg = getDRegFromQReg(EndReg) + 1;
3568 // If the register is the same as the start reg, there's nothing
3569 // more to do.
3570 if (Reg == EndReg)
3571 continue;
3572 // The register must be in the same register class as the first.
3573 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003574 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003575 return MatchOperand_ParseFail;
3576 }
3577 // Ranges must go from low to high.
3578 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003579 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003580 return MatchOperand_ParseFail;
3581 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003582 // Parse the lane specifier if present.
3583 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003584 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003585 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3586 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003587 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003588 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003589 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003590 return MatchOperand_ParseFail;
3591 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003592
3593 // Add all the registers in the range to the register list.
3594 Count += EndReg - Reg;
3595 Reg = EndReg;
3596 continue;
3597 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003598 Parser.Lex(); // Eat the comma.
3599 RegLoc = Parser.getTok().getLoc();
3600 int OldReg = Reg;
3601 Reg = tryParseRegister();
3602 if (Reg == -1) {
3603 Error(RegLoc, "register expected");
3604 return MatchOperand_ParseFail;
3605 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003606 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003607 // It's OK to use the enumeration values directly here rather, as the
3608 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003609 //
3610 // The list is of D registers, but we also allow Q regs and just interpret
3611 // them as the two D sub-registers.
3612 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003613 if (!Spacing)
3614 Spacing = 1; // Register range implies a single spaced list.
3615 else if (Spacing == 2) {
3616 Error(RegLoc,
3617 "invalid register in double-spaced list (must be 'D' register')");
3618 return MatchOperand_ParseFail;
3619 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003620 Reg = getDRegFromQReg(Reg);
3621 if (Reg != OldReg + 1) {
3622 Error(RegLoc, "non-contiguous register range");
3623 return MatchOperand_ParseFail;
3624 }
3625 ++Reg;
3626 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003627 // Parse the lane specifier if present.
3628 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003629 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003630 SMLoc LaneLoc = Parser.getTok().getLoc();
3631 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3632 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003633 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003634 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003635 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003636 return MatchOperand_ParseFail;
3637 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003638 continue;
3639 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003640 // Normal D register.
3641 // Figure out the register spacing (single or double) of the list if
3642 // we don't know it already.
3643 if (!Spacing)
3644 Spacing = 1 + (Reg == OldReg + 2);
3645
3646 // Just check that it's contiguous and keep going.
3647 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003648 Error(RegLoc, "non-contiguous register range");
3649 return MatchOperand_ParseFail;
3650 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003651 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003652 // Parse the lane specifier if present.
3653 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003654 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003655 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003656 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003657 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003658 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003659 Error(EndLoc, "mismatched lane index in register list");
3660 return MatchOperand_ParseFail;
3661 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003662 }
3663
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003664 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003665 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003666 return MatchOperand_ParseFail;
3667 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003668 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003669 Parser.Lex(); // Eat '}' token.
3670
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003671 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003672 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003673 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003674 // composite register classes.
3675 if (Count == 2) {
3676 const MCRegisterClass *RC = (Spacing == 1) ?
3677 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3678 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3679 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3680 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003681
Jim Grosbach2f50e922011-12-15 21:44:33 +00003682 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3683 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003684 break;
3685 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003686 // Two-register operands have been converted to the
3687 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003688 if (Count == 2) {
3689 const MCRegisterClass *RC = (Spacing == 1) ?
3690 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3691 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003692 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3693 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003694 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003695 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003696 S, E));
3697 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003698 case IndexedLane:
3699 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003700 LaneIndex,
3701 (Spacing == 2),
3702 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003703 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003704 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003705 return MatchOperand_Success;
3706}
3707
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003708/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003709ARMAsmParser::OperandMatchResultTy
3710ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003711 SMLoc S = Parser.getTok().getLoc();
3712 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003713 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003714
Jiangning Liu288e1af2012-08-02 08:21:27 +00003715 if (Tok.is(AsmToken::Identifier)) {
3716 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003717
Jiangning Liu288e1af2012-08-02 08:21:27 +00003718 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3719 .Case("sy", ARM_MB::SY)
3720 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003721 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003722 .Case("sh", ARM_MB::ISH)
3723 .Case("ish", ARM_MB::ISH)
3724 .Case("shst", ARM_MB::ISHST)
3725 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003726 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003727 .Case("nsh", ARM_MB::NSH)
3728 .Case("un", ARM_MB::NSH)
3729 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003730 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003731 .Case("unst", ARM_MB::NSHST)
3732 .Case("osh", ARM_MB::OSH)
3733 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003734 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003735 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003736
Joey Gouly926d3f52013-09-05 15:35:24 +00003737 // ishld, oshld, nshld and ld are only available from ARMv8.
3738 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3739 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3740 Opt = ~0U;
3741
Jiangning Liu288e1af2012-08-02 08:21:27 +00003742 if (Opt == ~0U)
3743 return MatchOperand_NoMatch;
3744
3745 Parser.Lex(); // Eat identifier token.
3746 } else if (Tok.is(AsmToken::Hash) ||
3747 Tok.is(AsmToken::Dollar) ||
3748 Tok.is(AsmToken::Integer)) {
3749 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003750 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003751 SMLoc Loc = Parser.getTok().getLoc();
3752
3753 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003754 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003755 Error(Loc, "illegal expression");
3756 return MatchOperand_ParseFail;
3757 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00003758
Jiangning Liu288e1af2012-08-02 08:21:27 +00003759 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3760 if (!CE) {
3761 Error(Loc, "constant expression expected");
3762 return MatchOperand_ParseFail;
3763 }
3764
3765 int Val = CE->getValue();
3766 if (Val & ~0xf) {
3767 Error(Loc, "immediate value out of range");
3768 return MatchOperand_ParseFail;
3769 }
3770
3771 Opt = ARM_MB::RESERVED_0 + Val;
3772 } else
3773 return MatchOperand_ParseFail;
3774
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003775 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003776 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003777}
3778
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003779/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003780ARMAsmParser::OperandMatchResultTy
3781ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) {
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003782 SMLoc S = Parser.getTok().getLoc();
3783 const AsmToken &Tok = Parser.getTok();
3784 unsigned Opt;
3785
3786 if (Tok.is(AsmToken::Identifier)) {
3787 StringRef OptStr = Tok.getString();
3788
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003789 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003790 Opt = ARM_ISB::SY;
3791 else
3792 return MatchOperand_NoMatch;
3793
3794 Parser.Lex(); // Eat identifier token.
3795 } else if (Tok.is(AsmToken::Hash) ||
3796 Tok.is(AsmToken::Dollar) ||
3797 Tok.is(AsmToken::Integer)) {
3798 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003799 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003800 SMLoc Loc = Parser.getTok().getLoc();
3801
3802 const MCExpr *ISBarrierID;
3803 if (getParser().parseExpression(ISBarrierID)) {
3804 Error(Loc, "illegal expression");
3805 return MatchOperand_ParseFail;
3806 }
3807
3808 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3809 if (!CE) {
3810 Error(Loc, "constant expression expected");
3811 return MatchOperand_ParseFail;
3812 }
3813
3814 int Val = CE->getValue();
3815 if (Val & ~0xf) {
3816 Error(Loc, "immediate value out of range");
3817 return MatchOperand_ParseFail;
3818 }
3819
3820 Opt = ARM_ISB::RESERVED_0 + Val;
3821 } else
3822 return MatchOperand_ParseFail;
3823
3824 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3825 (ARM_ISB::InstSyncBOpt)Opt, S));
3826 return MatchOperand_Success;
3827}
3828
3829
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003830/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003831ARMAsmParser::OperandMatchResultTy
3832ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003833 SMLoc S = Parser.getTok().getLoc();
3834 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003835 if (!Tok.is(AsmToken::Identifier))
3836 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003837 StringRef IFlagsStr = Tok.getString();
3838
Owen Anderson10c5b122011-10-05 17:16:40 +00003839 // An iflags string of "none" is interpreted to mean that none of the AIF
3840 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003841 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003842 if (IFlagsStr != "none") {
3843 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3844 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3845 .Case("a", ARM_PROC::A)
3846 .Case("i", ARM_PROC::I)
3847 .Case("f", ARM_PROC::F)
3848 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003849
Owen Anderson10c5b122011-10-05 17:16:40 +00003850 // If some specific iflag is already set, it means that some letter is
3851 // present more than once, this is not acceptable.
3852 if (Flag == ~0U || (IFlags & Flag))
3853 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003854
Owen Anderson10c5b122011-10-05 17:16:40 +00003855 IFlags |= Flag;
3856 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003857 }
3858
3859 Parser.Lex(); // Eat identifier token.
3860 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3861 return MatchOperand_Success;
3862}
3863
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003864/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003865ARMAsmParser::OperandMatchResultTy
3866ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003867 SMLoc S = Parser.getTok().getLoc();
3868 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003869 if (!Tok.is(AsmToken::Identifier))
3870 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003871 StringRef Mask = Tok.getString();
3872
James Molloy21efa7d2011-09-28 14:21:38 +00003873 if (isMClass()) {
3874 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003875 std::string Name = Mask.lower();
3876 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003877 // Note: in the documentation:
3878 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3879 // for MSR APSR_nzcvq.
3880 // but we do make it an alias here. This is so to get the "mask encoding"
3881 // bits correct on MSR APSR writes.
3882 //
3883 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3884 // should really only be allowed when writing a special register. Note
3885 // they get dropped in the MRS instruction reading a special register as
3886 // the SYSm field is only 8 bits.
3887 //
3888 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3889 // includes the DSP extension but that is not checked.
3890 .Case("apsr", 0x800)
3891 .Case("apsr_nzcvq", 0x800)
3892 .Case("apsr_g", 0x400)
3893 .Case("apsr_nzcvqg", 0xc00)
3894 .Case("iapsr", 0x801)
3895 .Case("iapsr_nzcvq", 0x801)
3896 .Case("iapsr_g", 0x401)
3897 .Case("iapsr_nzcvqg", 0xc01)
3898 .Case("eapsr", 0x802)
3899 .Case("eapsr_nzcvq", 0x802)
3900 .Case("eapsr_g", 0x402)
3901 .Case("eapsr_nzcvqg", 0xc02)
3902 .Case("xpsr", 0x803)
3903 .Case("xpsr_nzcvq", 0x803)
3904 .Case("xpsr_g", 0x403)
3905 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003906 .Case("ipsr", 0x805)
3907 .Case("epsr", 0x806)
3908 .Case("iepsr", 0x807)
3909 .Case("msp", 0x808)
3910 .Case("psp", 0x809)
3911 .Case("primask", 0x810)
3912 .Case("basepri", 0x811)
3913 .Case("basepri_max", 0x812)
3914 .Case("faultmask", 0x813)
3915 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003916 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003917
James Molloy21efa7d2011-09-28 14:21:38 +00003918 if (FlagsVal == ~0U)
3919 return MatchOperand_NoMatch;
3920
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003921 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003922 // basepri, basepri_max and faultmask only valid for V7m.
3923 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003924
James Molloy21efa7d2011-09-28 14:21:38 +00003925 Parser.Lex(); // Eat identifier token.
3926 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3927 return MatchOperand_Success;
3928 }
3929
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003930 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3931 size_t Start = 0, Next = Mask.find('_');
3932 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003933 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003934 if (Next != StringRef::npos)
3935 Flags = Mask.slice(Next+1, Mask.size());
3936
3937 // FlagsVal contains the complete mask:
3938 // 3-0: Mask
3939 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3940 unsigned FlagsVal = 0;
3941
3942 if (SpecReg == "apsr") {
3943 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003944 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003945 .Case("g", 0x4) // same as CPSR_s
3946 .Case("nzcvqg", 0xc) // same as CPSR_fs
3947 .Default(~0U);
3948
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003949 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003950 if (!Flags.empty())
3951 return MatchOperand_NoMatch;
3952 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003953 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003954 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003955 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003956 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3957 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003958 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003959 for (int i = 0, e = Flags.size(); i != e; ++i) {
3960 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3961 .Case("c", 1)
3962 .Case("x", 2)
3963 .Case("s", 4)
3964 .Case("f", 8)
3965 .Default(~0U);
3966
3967 // If some specific flag is already set, it means that some letter is
3968 // present more than once, this is not acceptable.
3969 if (FlagsVal == ~0U || (FlagsVal & Flag))
3970 return MatchOperand_NoMatch;
3971 FlagsVal |= Flag;
3972 }
3973 } else // No match for special register.
3974 return MatchOperand_NoMatch;
3975
Owen Anderson03a173e2011-10-21 18:43:28 +00003976 // Special register without flags is NOT equivalent to "fc" flags.
3977 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3978 // two lines would enable gas compatibility at the expense of breaking
3979 // round-tripping.
3980 //
3981 // if (!FlagsVal)
3982 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003983
3984 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3985 if (SpecReg == "spsr")
3986 FlagsVal |= 16;
3987
3988 Parser.Lex(); // Eat identifier token.
3989 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3990 return MatchOperand_Success;
3991}
3992
David Blaikie960ea3f2014-06-08 16:18:35 +00003993ARMAsmParser::OperandMatchResultTy
3994ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low,
3995 int High) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003996 const AsmToken &Tok = Parser.getTok();
3997 if (Tok.isNot(AsmToken::Identifier)) {
3998 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3999 return MatchOperand_ParseFail;
4000 }
4001 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004002 std::string LowerOp = Op.lower();
4003 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004004 if (ShiftName != LowerOp && ShiftName != UpperOp) {
4005 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4006 return MatchOperand_ParseFail;
4007 }
4008 Parser.Lex(); // Eat shift type token.
4009
4010 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004011 if (Parser.getTok().isNot(AsmToken::Hash) &&
4012 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004013 Error(Parser.getTok().getLoc(), "'#' expected");
4014 return MatchOperand_ParseFail;
4015 }
4016 Parser.Lex(); // Eat hash token.
4017
4018 const MCExpr *ShiftAmount;
4019 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004020 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004021 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004022 Error(Loc, "illegal expression");
4023 return MatchOperand_ParseFail;
4024 }
4025 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4026 if (!CE) {
4027 Error(Loc, "constant expression expected");
4028 return MatchOperand_ParseFail;
4029 }
4030 int Val = CE->getValue();
4031 if (Val < Low || Val > High) {
4032 Error(Loc, "immediate value out of range");
4033 return MatchOperand_ParseFail;
4034 }
4035
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004036 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00004037
4038 return MatchOperand_Success;
4039}
4040
David Blaikie960ea3f2014-06-08 16:18:35 +00004041ARMAsmParser::OperandMatchResultTy
4042ARMAsmParser::parseSetEndImm(OperandVector &Operands) {
Jim Grosbach0a547702011-07-22 17:44:50 +00004043 const AsmToken &Tok = Parser.getTok();
4044 SMLoc S = Tok.getLoc();
4045 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004046 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004047 return MatchOperand_ParseFail;
4048 }
Tim Northover4d141442013-05-31 15:58:45 +00004049 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00004050 .Case("be", 1)
4051 .Case("le", 0)
4052 .Default(-1);
4053 Parser.Lex(); // Eat the token.
4054
4055 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004056 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004057 return MatchOperand_ParseFail;
4058 }
4059 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4060 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004061 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00004062 return MatchOperand_Success;
4063}
4064
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004065/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
4066/// instructions. Legal values are:
4067/// lsl #n 'n' in [0,31]
4068/// asr #n 'n' in [1,32]
4069/// n == 32 encoded as n == 0.
David Blaikie960ea3f2014-06-08 16:18:35 +00004070ARMAsmParser::OperandMatchResultTy
4071ARMAsmParser::parseShifterImm(OperandVector &Operands) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004072 const AsmToken &Tok = Parser.getTok();
4073 SMLoc S = Tok.getLoc();
4074 if (Tok.isNot(AsmToken::Identifier)) {
4075 Error(S, "shift operator 'asr' or 'lsl' expected");
4076 return MatchOperand_ParseFail;
4077 }
4078 StringRef ShiftName = Tok.getString();
4079 bool isASR;
4080 if (ShiftName == "lsl" || ShiftName == "LSL")
4081 isASR = false;
4082 else if (ShiftName == "asr" || ShiftName == "ASR")
4083 isASR = true;
4084 else {
4085 Error(S, "shift operator 'asr' or 'lsl' expected");
4086 return MatchOperand_ParseFail;
4087 }
4088 Parser.Lex(); // Eat the operator.
4089
4090 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004091 if (Parser.getTok().isNot(AsmToken::Hash) &&
4092 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004093 Error(Parser.getTok().getLoc(), "'#' expected");
4094 return MatchOperand_ParseFail;
4095 }
4096 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004097 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004098
4099 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004100 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004101 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004102 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004103 return MatchOperand_ParseFail;
4104 }
4105 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4106 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004107 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004108 return MatchOperand_ParseFail;
4109 }
4110
4111 int64_t Val = CE->getValue();
4112 if (isASR) {
4113 // Shift amount must be in [1,32]
4114 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004115 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004116 return MatchOperand_ParseFail;
4117 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00004118 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4119 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004120 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00004121 return MatchOperand_ParseFail;
4122 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004123 if (Val == 32) Val = 0;
4124 } else {
4125 // Shift amount must be in [1,32]
4126 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004127 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004128 return MatchOperand_ParseFail;
4129 }
4130 }
4131
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004132 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004133
4134 return MatchOperand_Success;
4135}
4136
Jim Grosbach833b9d32011-07-27 20:15:40 +00004137/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4138/// of instructions. Legal values are:
4139/// ror #n 'n' in {0, 8, 16, 24}
David Blaikie960ea3f2014-06-08 16:18:35 +00004140ARMAsmParser::OperandMatchResultTy
4141ARMAsmParser::parseRotImm(OperandVector &Operands) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004142 const AsmToken &Tok = Parser.getTok();
4143 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00004144 if (Tok.isNot(AsmToken::Identifier))
4145 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004146 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00004147 if (ShiftName != "ror" && ShiftName != "ROR")
4148 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004149 Parser.Lex(); // Eat the operator.
4150
4151 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004152 if (Parser.getTok().isNot(AsmToken::Hash) &&
4153 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004154 Error(Parser.getTok().getLoc(), "'#' expected");
4155 return MatchOperand_ParseFail;
4156 }
4157 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004158 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004159
4160 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004161 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004162 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004163 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004164 return MatchOperand_ParseFail;
4165 }
4166 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4167 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004168 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004169 return MatchOperand_ParseFail;
4170 }
4171
4172 int64_t Val = CE->getValue();
4173 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4174 // normally, zero is represented in asm by omitting the rotate operand
4175 // entirely.
4176 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004177 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004178 return MatchOperand_ParseFail;
4179 }
4180
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004181 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004182
4183 return MatchOperand_Success;
4184}
4185
David Blaikie960ea3f2014-06-08 16:18:35 +00004186ARMAsmParser::OperandMatchResultTy
4187ARMAsmParser::parseBitfield(OperandVector &Operands) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004188 SMLoc S = Parser.getTok().getLoc();
4189 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004190 if (Parser.getTok().isNot(AsmToken::Hash) &&
4191 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004192 Error(Parser.getTok().getLoc(), "'#' expected");
4193 return MatchOperand_ParseFail;
4194 }
4195 Parser.Lex(); // Eat hash token.
4196
4197 const MCExpr *LSBExpr;
4198 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004199 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004200 Error(E, "malformed immediate expression");
4201 return MatchOperand_ParseFail;
4202 }
4203 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4204 if (!CE) {
4205 Error(E, "'lsb' operand must be an immediate");
4206 return MatchOperand_ParseFail;
4207 }
4208
4209 int64_t LSB = CE->getValue();
4210 // The LSB must be in the range [0,31]
4211 if (LSB < 0 || LSB > 31) {
4212 Error(E, "'lsb' operand must be in the range [0,31]");
4213 return MatchOperand_ParseFail;
4214 }
4215 E = Parser.getTok().getLoc();
4216
4217 // Expect another immediate operand.
4218 if (Parser.getTok().isNot(AsmToken::Comma)) {
4219 Error(Parser.getTok().getLoc(), "too few operands");
4220 return MatchOperand_ParseFail;
4221 }
4222 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004223 if (Parser.getTok().isNot(AsmToken::Hash) &&
4224 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004225 Error(Parser.getTok().getLoc(), "'#' expected");
4226 return MatchOperand_ParseFail;
4227 }
4228 Parser.Lex(); // Eat hash token.
4229
4230 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004231 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004232 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004233 Error(E, "malformed immediate expression");
4234 return MatchOperand_ParseFail;
4235 }
4236 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4237 if (!CE) {
4238 Error(E, "'width' operand must be an immediate");
4239 return MatchOperand_ParseFail;
4240 }
4241
4242 int64_t Width = CE->getValue();
4243 // The LSB must be in the range [1,32-lsb]
4244 if (Width < 1 || Width > 32 - LSB) {
4245 Error(E, "'width' operand must be in the range [1,32-lsb]");
4246 return MatchOperand_ParseFail;
4247 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004248
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004249 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004250
4251 return MatchOperand_Success;
4252}
4253
David Blaikie960ea3f2014-06-08 16:18:35 +00004254ARMAsmParser::OperandMatchResultTy
4255ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
Jim Grosbachd3595712011-08-03 23:50:40 +00004256 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004257 // postidx_reg := '+' register {, shift}
4258 // | '-' register {, shift}
4259 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004260
4261 // This method must return MatchOperand_NoMatch without consuming any tokens
4262 // in the case where there is no match, as other alternatives take other
4263 // parse methods.
4264 AsmToken Tok = Parser.getTok();
4265 SMLoc S = Tok.getLoc();
4266 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004267 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004268 if (Tok.is(AsmToken::Plus)) {
4269 Parser.Lex(); // Eat the '+' token.
4270 haveEaten = true;
4271 } else if (Tok.is(AsmToken::Minus)) {
4272 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004273 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004274 haveEaten = true;
4275 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004276
4277 SMLoc E = Parser.getTok().getEndLoc();
4278 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004279 if (Reg == -1) {
4280 if (!haveEaten)
4281 return MatchOperand_NoMatch;
4282 Error(Parser.getTok().getLoc(), "register expected");
4283 return MatchOperand_ParseFail;
4284 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004285
Jim Grosbachc320c852011-08-05 21:28:30 +00004286 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4287 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004288 if (Parser.getTok().is(AsmToken::Comma)) {
4289 Parser.Lex(); // Eat the ','.
4290 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4291 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004292
4293 // FIXME: Only approximates end...may include intervening whitespace.
4294 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004295 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004296
4297 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4298 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004299
4300 return MatchOperand_Success;
4301}
4302
David Blaikie960ea3f2014-06-08 16:18:35 +00004303ARMAsmParser::OperandMatchResultTy
4304ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004305 // Check for a post-index addressing register operand. Specifically:
4306 // am3offset := '+' register
4307 // | '-' register
4308 // | register
4309 // | # imm
4310 // | # + imm
4311 // | # - imm
4312
4313 // This method must return MatchOperand_NoMatch without consuming any tokens
4314 // in the case where there is no match, as other alternatives take other
4315 // parse methods.
4316 AsmToken Tok = Parser.getTok();
4317 SMLoc S = Tok.getLoc();
4318
4319 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004320 if (Parser.getTok().is(AsmToken::Hash) ||
4321 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004322 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004323 // Explicitly look for a '-', as we need to encode negative zero
4324 // differently.
4325 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4326 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004327 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004328 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004329 return MatchOperand_ParseFail;
4330 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4331 if (!CE) {
4332 Error(S, "constant expression expected");
4333 return MatchOperand_ParseFail;
4334 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004335 // Negative zero is encoded as the flag value INT32_MIN.
4336 int32_t Val = CE->getValue();
4337 if (isNegative && Val == 0)
4338 Val = INT32_MIN;
4339
4340 Operands.push_back(
4341 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4342
4343 return MatchOperand_Success;
4344 }
4345
4346
4347 bool haveEaten = false;
4348 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004349 if (Tok.is(AsmToken::Plus)) {
4350 Parser.Lex(); // Eat the '+' token.
4351 haveEaten = true;
4352 } else if (Tok.is(AsmToken::Minus)) {
4353 Parser.Lex(); // Eat the '-' token.
4354 isAdd = false;
4355 haveEaten = true;
4356 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004357
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004358 Tok = Parser.getTok();
4359 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004360 if (Reg == -1) {
4361 if (!haveEaten)
4362 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004363 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004364 return MatchOperand_ParseFail;
4365 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004366
4367 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004368 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004369
4370 return MatchOperand_Success;
4371}
4372
Tim Northovereb5e4d52013-07-22 09:06:12 +00004373/// Convert parsed operands to MCInst. Needed here because this instruction
4374/// only has two register operands, but multiplication is commutative so
4375/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
David Blaikie960ea3f2014-06-08 16:18:35 +00004376void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
4377 const OperandVector &Operands) {
4378 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1);
4379 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004380 // If we have a three-operand form, make sure to set Rn to be the operand
4381 // that isn't the same as Rd.
4382 unsigned RegOp = 4;
4383 if (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00004384 ((ARMOperand &)*Operands[4]).getReg() ==
4385 ((ARMOperand &)*Operands[3]).getReg())
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004386 RegOp = 5;
David Blaikie960ea3f2014-06-08 16:18:35 +00004387 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004388 Inst.addOperand(Inst.getOperand(0));
David Blaikie960ea3f2014-06-08 16:18:35 +00004389 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004390}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004391
David Blaikie960ea3f2014-06-08 16:18:35 +00004392void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
4393 const OperandVector &Operands) {
Mihai Popaad18d3c2013-08-09 10:38:32 +00004394 int CondOp = -1, ImmOp = -1;
4395 switch(Inst.getOpcode()) {
4396 case ARM::tB:
4397 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4398
4399 case ARM::t2B:
4400 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4401
4402 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4403 }
4404 // first decide whether or not the branch should be conditional
4405 // by looking at it's location relative to an IT block
4406 if(inITBlock()) {
4407 // inside an IT block we cannot have any conditional branches. any
4408 // such instructions needs to be converted to unconditional form
4409 switch(Inst.getOpcode()) {
4410 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4411 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4412 }
4413 } else {
4414 // outside IT blocks we can only have unconditional branches with AL
4415 // condition code or conditional branches with non-AL condition code
David Blaikie960ea3f2014-06-08 16:18:35 +00004416 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode();
Mihai Popaad18d3c2013-08-09 10:38:32 +00004417 switch(Inst.getOpcode()) {
4418 case ARM::tB:
4419 case ARM::tBcc:
4420 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4421 break;
4422 case ARM::t2B:
4423 case ARM::t2Bcc:
4424 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4425 break;
4426 }
4427 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004428
Mihai Popaad18d3c2013-08-09 10:38:32 +00004429 // now decide on encoding size based on branch target range
4430 switch(Inst.getOpcode()) {
4431 // classify tB as either t2B or t1B based on range of immediate operand
4432 case ARM::tB: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004433 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4434 if (!op.isSignedOffset<11, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004435 Inst.setOpcode(ARM::t2B);
4436 break;
4437 }
4438 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4439 case ARM::tBcc: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004440 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4441 if (!op.isSignedOffset<8, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004442 Inst.setOpcode(ARM::t2Bcc);
4443 break;
4444 }
4445 }
David Blaikie960ea3f2014-06-08 16:18:35 +00004446 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1);
4447 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2);
Mihai Popaad18d3c2013-08-09 10:38:32 +00004448}
4449
Bill Wendlinge18980a2010-11-06 22:36:58 +00004450/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004451/// or an error. The first token must be a '[' when called.
David Blaikie960ea3f2014-06-08 16:18:35 +00004452bool ARMAsmParser::parseMemory(OperandVector &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004453 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004454 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004455 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004456 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004457 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004458
Sean Callanan936b0d32010-01-19 21:44:56 +00004459 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004460 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004461 if (BaseRegNum == -1)
4462 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004463
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004464 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004465 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004466 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4467 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004468 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004469
Jim Grosbachd3595712011-08-03 23:50:40 +00004470 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004471 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004472 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004473
Craig Topper062a2ba2014-04-25 05:30:21 +00004474 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4475 ARM_AM::no_shift, 0, 0, false,
4476 S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004477
Jim Grosbach40700e02011-09-19 18:42:21 +00004478 // If there's a pre-indexing writeback marker, '!', just add it as a token
4479 // operand. It's rather odd, but syntactically valid.
4480 if (Parser.getTok().is(AsmToken::Exclaim)) {
4481 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4482 Parser.Lex(); // Eat the '!'.
4483 }
4484
Jim Grosbachd3595712011-08-03 23:50:40 +00004485 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004486 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004487
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004488 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4489 "Lost colon or comma in memory operand?!");
4490 if (Tok.is(AsmToken::Comma)) {
4491 Parser.Lex(); // Eat the comma.
4492 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004493
Jim Grosbacha95ec992011-10-11 17:29:55 +00004494 // If we have a ':', it's an alignment specifier.
4495 if (Parser.getTok().is(AsmToken::Colon)) {
4496 Parser.Lex(); // Eat the ':'.
4497 E = Parser.getTok().getLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00004498 SMLoc AlignmentLoc = Tok.getLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004499
4500 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004501 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004502 return true;
4503
4504 // The expression has to be a constant. Memory references with relocations
4505 // don't come through here, as they use the <label> forms of the relevant
4506 // instructions.
4507 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4508 if (!CE)
4509 return Error (E, "constant expression expected");
4510
4511 unsigned Align = 0;
4512 switch (CE->getValue()) {
4513 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004514 return Error(E,
4515 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4516 case 16: Align = 2; break;
4517 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004518 case 64: Align = 8; break;
4519 case 128: Align = 16; break;
4520 case 256: Align = 32; break;
4521 }
4522
4523 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004524 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004525 return Error(Parser.getTok().getLoc(), "']' expected");
4526 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004527 Parser.Lex(); // Eat right bracket token.
4528
4529 // Don't worry about range checking the value here. That's handled by
4530 // the is*() predicates.
Craig Topper062a2ba2014-04-25 05:30:21 +00004531 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004532 ARM_AM::no_shift, 0, Align,
Kevin Enderby488f20b2014-04-10 20:18:58 +00004533 false, S, E, AlignmentLoc));
Jim Grosbacha95ec992011-10-11 17:29:55 +00004534
4535 // If there's a pre-indexing writeback marker, '!', just add it as a token
4536 // operand.
4537 if (Parser.getTok().is(AsmToken::Exclaim)) {
4538 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4539 Parser.Lex(); // Eat the '!'.
4540 }
4541
4542 return false;
4543 }
4544
4545 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004546 // offset. Be friendly and also accept a plain integer (without a leading
4547 // hash) for gas compatibility.
4548 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004549 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004550 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004551 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004552 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004553 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004554
Owen Anderson967674d2011-08-29 19:36:44 +00004555 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004556 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004557 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004558 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004559
4560 // The expression has to be a constant. Memory references with relocations
4561 // don't come through here, as they use the <label> forms of the relevant
4562 // instructions.
4563 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4564 if (!CE)
4565 return Error (E, "constant expression expected");
4566
Owen Anderson967674d2011-08-29 19:36:44 +00004567 // If the constant was #-0, represent it as INT32_MIN.
4568 int32_t Val = CE->getValue();
4569 if (isNegative && Val == 0)
4570 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4571
Jim Grosbachd3595712011-08-03 23:50:40 +00004572 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004573 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004574 return Error(Parser.getTok().getLoc(), "']' expected");
4575 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004576 Parser.Lex(); // Eat right bracket token.
4577
4578 // Don't worry about range checking the value here. That's handled by
4579 // the is*() predicates.
4580 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004581 ARM_AM::no_shift, 0, 0,
4582 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004583
4584 // If there's a pre-indexing writeback marker, '!', just add it as a token
4585 // operand.
4586 if (Parser.getTok().is(AsmToken::Exclaim)) {
4587 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4588 Parser.Lex(); // Eat the '!'.
4589 }
4590
4591 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004592 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004593
4594 // The register offset is optionally preceded by a '+' or '-'
4595 bool isNegative = false;
4596 if (Parser.getTok().is(AsmToken::Minus)) {
4597 isNegative = true;
4598 Parser.Lex(); // Eat the '-'.
4599 } else if (Parser.getTok().is(AsmToken::Plus)) {
4600 // Nothing to do.
4601 Parser.Lex(); // Eat the '+'.
4602 }
4603
4604 E = Parser.getTok().getLoc();
4605 int OffsetRegNum = tryParseRegister();
4606 if (OffsetRegNum == -1)
4607 return Error(E, "register expected");
4608
4609 // If there's a shift operator, handle it.
4610 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004611 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004612 if (Parser.getTok().is(AsmToken::Comma)) {
4613 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004614 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004615 return true;
4616 }
4617
4618 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004619 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004620 return Error(Parser.getTok().getLoc(), "']' expected");
4621 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004622 Parser.Lex(); // Eat right bracket token.
4623
Craig Topper062a2ba2014-04-25 05:30:21 +00004624 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004625 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004626 S, E));
4627
Jim Grosbachc320c852011-08-05 21:28:30 +00004628 // If there's a pre-indexing writeback marker, '!', just add it as a token
4629 // operand.
4630 if (Parser.getTok().is(AsmToken::Exclaim)) {
4631 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4632 Parser.Lex(); // Eat the '!'.
4633 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004634
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004635 return false;
4636}
4637
Jim Grosbachd3595712011-08-03 23:50:40 +00004638/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004639/// ( lsl | lsr | asr | ror ) , # shift_amount
4640/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004641/// return true if it parses a shift otherwise it returns false.
4642bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4643 unsigned &Amount) {
4644 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004645 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004646 if (Tok.isNot(AsmToken::Identifier))
4647 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004648 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004649 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4650 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004651 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004652 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004653 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004654 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004655 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004656 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004657 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004658 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004659 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004660 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004661 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004662 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004663
Jim Grosbachd3595712011-08-03 23:50:40 +00004664 // rrx stands alone.
4665 Amount = 0;
4666 if (St != ARM_AM::rrx) {
4667 Loc = Parser.getTok().getLoc();
4668 // A '#' and a shift amount.
4669 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004670 if (HashTok.isNot(AsmToken::Hash) &&
4671 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004672 return Error(HashTok.getLoc(), "'#' expected");
4673 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004674
Jim Grosbachd3595712011-08-03 23:50:40 +00004675 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004676 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004677 return true;
4678 // Range check the immediate.
4679 // lsl, ror: 0 <= imm <= 31
4680 // lsr, asr: 0 <= imm <= 32
4681 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4682 if (!CE)
4683 return Error(Loc, "shift amount must be an immediate");
4684 int64_t Imm = CE->getValue();
4685 if (Imm < 0 ||
4686 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4687 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4688 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004689 // If <ShiftTy> #0, turn it into a no_shift.
4690 if (Imm == 0)
4691 St = ARM_AM::lsl;
4692 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4693 if (Imm == 32)
4694 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004695 Amount = Imm;
4696 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004697
4698 return false;
4699}
4700
Jim Grosbache7fbce72011-10-03 23:38:36 +00004701/// parseFPImm - A floating point immediate expression operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00004702ARMAsmParser::OperandMatchResultTy
4703ARMAsmParser::parseFPImm(OperandVector &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004704 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004705 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004706 // integer only.
4707 //
4708 // This routine still creates a generic Immediate operand, containing
4709 // a bitcast of the 64-bit floating point value. The various operands
4710 // that accept floats can check whether the value is valid for them
4711 // via the standard is*() predicates.
4712
Jim Grosbache7fbce72011-10-03 23:38:36 +00004713 SMLoc S = Parser.getTok().getLoc();
4714
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004715 if (Parser.getTok().isNot(AsmToken::Hash) &&
4716 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004717 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004718
4719 // Disambiguate the VMOV forms that can accept an FP immediate.
4720 // vmov.f32 <sreg>, #imm
4721 // vmov.f64 <dreg>, #imm
4722 // vmov.f32 <dreg>, #imm @ vector f32x2
4723 // vmov.f32 <qreg>, #imm @ vector f32x4
4724 //
4725 // There are also the NEON VMOV instructions which expect an
4726 // integer constant. Make sure we don't try to parse an FPImm
4727 // for these:
4728 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
David Blaikie960ea3f2014-06-08 16:18:35 +00004729 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]);
4730 bool isVmovf = TyOp.isToken() &&
4731 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64");
4732 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
4733 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
4734 Mnemonic.getToken() == "fconsts");
David Peixottoa872e0e2014-01-07 18:19:23 +00004735 if (!(isVmovf || isFconst))
Jim Grosbach741cd732011-10-17 22:26:03 +00004736 return MatchOperand_NoMatch;
4737
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004738 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004739
4740 // Handle negation, as that still comes through as a separate token.
4741 bool isNegative = false;
4742 if (Parser.getTok().is(AsmToken::Minus)) {
4743 isNegative = true;
4744 Parser.Lex();
4745 }
4746 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004747 SMLoc Loc = Tok.getLoc();
David Peixottoa872e0e2014-01-07 18:19:23 +00004748 if (Tok.is(AsmToken::Real) && isVmovf) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004749 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004750 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4751 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004752 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004753 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004754 Operands.push_back(ARMOperand::CreateImm(
4755 MCConstantExpr::Create(IntVal, getContext()),
4756 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004757 return MatchOperand_Success;
4758 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004759 // Also handle plain integers. Instructions which allow floating point
4760 // immediates also allow a raw encoded 8-bit value.
David Peixottoa872e0e2014-01-07 18:19:23 +00004761 if (Tok.is(AsmToken::Integer) && isFconst) {
Jim Grosbache7fbce72011-10-03 23:38:36 +00004762 int64_t Val = Tok.getIntVal();
4763 Parser.Lex(); // Eat the token.
4764 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004765 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004766 return MatchOperand_ParseFail;
4767 }
David Peixottoa872e0e2014-01-07 18:19:23 +00004768 float RealVal = ARM_AM::getFPImmFloat(Val);
4769 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
4770
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004771 Operands.push_back(ARMOperand::CreateImm(
4772 MCConstantExpr::Create(Val, getContext()), S,
4773 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004774 return MatchOperand_Success;
4775 }
4776
Jim Grosbach235c8d22012-01-19 02:47:30 +00004777 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004778 return MatchOperand_ParseFail;
4779}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004780
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004781/// Parse a arm instruction operand. For now this parses the operand regardless
4782/// of the mnemonic.
David Blaikie960ea3f2014-06-08 16:18:35 +00004783bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004784 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004785
4786 // Check if the current operand has a custom associated parser, if so, try to
4787 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004788 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4789 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004790 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004791 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4792 // there was a match, but an error occurred, in which case, just return that
4793 // the operand parsing failed.
4794 if (ResTy == MatchOperand_ParseFail)
4795 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004796
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004797 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004798 default:
4799 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004800 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004801 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004802 // If we've seen a branch mnemonic, the next operand must be a label. This
4803 // is true even if the label is a register name. So "br r1" means branch to
4804 // label "r1".
4805 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4806 if (!ExpectLabel) {
4807 if (!tryParseRegisterWithWriteBack(Operands))
4808 return false;
4809 int Res = tryParseShiftRegister(Operands);
4810 if (Res == 0) // success
4811 return false;
4812 else if (Res == -1) // irrecoverable error
4813 return true;
4814 // If this is VMRS, check for the apsr_nzcv operand.
4815 if (Mnemonic == "vmrs" &&
4816 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4817 S = Parser.getTok().getLoc();
4818 Parser.Lex();
4819 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4820 return false;
4821 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004822 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004823
4824 // Fall though for the Identifier case that is not a register or a
4825 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004826 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004827 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004828 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004829 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004830 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004831 // This was not a register so parse other operands that start with an
4832 // identifier (like labels) as expressions and create them as immediates.
4833 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004834 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004835 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004836 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004837 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004838 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4839 return false;
4840 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004841 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004842 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004843 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004844 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004845 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004846 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004847 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004848 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004849 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004850
4851 if (Parser.getTok().isNot(AsmToken::Colon)) {
4852 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4853 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004854 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004855 return true;
4856 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4857 if (CE) {
4858 int32_t Val = CE->getValue();
4859 if (isNegative && Val == 0)
4860 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4861 }
4862 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4863 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004864
4865 // There can be a trailing '!' on operands that we want as a separate
Saleem Abdulrasool83e37702013-12-28 03:07:12 +00004866 // '!' Token operand. Handle that here. For example, the compatibility
Jim Grosbach9be2d712013-02-23 00:52:09 +00004867 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4868 if (Parser.getTok().is(AsmToken::Exclaim)) {
4869 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4870 Parser.getTok().getLoc()));
4871 Parser.Lex(); // Eat exclaim token
4872 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004873 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004874 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004875 // w/ a ':' after the '#', it's just like a plain ':'.
4876 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004877 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004878 case AsmToken::Colon: {
4879 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004880 // FIXME: Check it's an expression prefix,
4881 // e.g. (FOO - :lower16:BAR) isn't legal.
4882 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004883 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004884 return true;
4885
Evan Cheng965b3c72011-01-13 07:58:56 +00004886 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004887 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004888 return true;
4889
Evan Cheng965b3c72011-01-13 07:58:56 +00004890 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004891 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004892 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004893 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004894 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004895 }
David Peixottoe407d092013-12-19 18:12:36 +00004896 case AsmToken::Equal: {
4897 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4898 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4899
David Peixottoe407d092013-12-19 18:12:36 +00004900 Parser.Lex(); // Eat '='
4901 const MCExpr *SubExprVal;
4902 if (getParser().parseExpression(SubExprVal))
4903 return true;
4904 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4905
David Peixottob9b73622014-02-04 17:22:40 +00004906 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
David Peixottoe407d092013-12-19 18:12:36 +00004907 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4908 return false;
4909 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004910 }
4911}
4912
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004913// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004914// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004915bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004916 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004917
Saleem Abdulrasool435f4562014-01-10 04:38:40 +00004918 // consume an optional '#' (GNU compatibility)
4919 if (getLexer().is(AsmToken::Hash))
4920 Parser.Lex();
4921
Jason W Kim1f7bc072011-01-11 23:53:41 +00004922 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004923 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004924 Parser.Lex(); // Eat ':'
4925
4926 if (getLexer().isNot(AsmToken::Identifier)) {
4927 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4928 return true;
4929 }
4930
4931 StringRef IDVal = Parser.getTok().getIdentifier();
4932 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004933 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004934 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004935 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004936 } else {
4937 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4938 return true;
4939 }
4940 Parser.Lex();
4941
4942 if (getLexer().isNot(AsmToken::Colon)) {
4943 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4944 return true;
4945 }
4946 Parser.Lex(); // Eat the last ':'
4947 return false;
4948}
4949
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004950/// \brief Given a mnemonic, split out possible predication code and carry
4951/// setting letters to form a canonical mnemonic and flags.
4952//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004953// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004954// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004955StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004956 unsigned &PredicationCode,
4957 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004958 unsigned &ProcessorIMod,
4959 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004960 PredicationCode = ARMCC::AL;
4961 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004962 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004963
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004964 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004965 //
4966 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004967 if ((Mnemonic == "movs" && isThumb()) ||
4968 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4969 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4970 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4971 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004972 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004973 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4974 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004975 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004976 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004977 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4978 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4979 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004980 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004981
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004982 // First, split out any predication code. Ignore mnemonics we know aren't
4983 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004984 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004985 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004986 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004987 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004988 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4989 .Case("eq", ARMCC::EQ)
4990 .Case("ne", ARMCC::NE)
4991 .Case("hs", ARMCC::HS)
4992 .Case("cs", ARMCC::HS)
4993 .Case("lo", ARMCC::LO)
4994 .Case("cc", ARMCC::LO)
4995 .Case("mi", ARMCC::MI)
4996 .Case("pl", ARMCC::PL)
4997 .Case("vs", ARMCC::VS)
4998 .Case("vc", ARMCC::VC)
4999 .Case("hi", ARMCC::HI)
5000 .Case("ls", ARMCC::LS)
5001 .Case("ge", ARMCC::GE)
5002 .Case("lt", ARMCC::LT)
5003 .Case("gt", ARMCC::GT)
5004 .Case("le", ARMCC::LE)
5005 .Case("al", ARMCC::AL)
5006 .Default(~0U);
5007 if (CC != ~0U) {
5008 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
5009 PredicationCode = CC;
5010 }
Bill Wendling193961b2010-10-29 23:50:21 +00005011 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005012
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005013 // Next, determine if we have a carry setting bit. We explicitly ignore all
5014 // the instructions we know end in 's'.
5015 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00005016 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005017 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
5018 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
5019 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00005020 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00005021 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00005022 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00005023 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
David Peixottoa872e0e2014-01-07 18:19:23 +00005024 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00005025 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005026 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
5027 CarrySetting = true;
5028 }
5029
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005030 // The "cps" instruction can have a interrupt mode operand which is glued into
5031 // the mnemonic. Check if this is the case, split it and parse the imod op
5032 if (Mnemonic.startswith("cps")) {
5033 // Split out any imod code.
5034 unsigned IMod =
5035 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
5036 .Case("ie", ARM_PROC::IE)
5037 .Case("id", ARM_PROC::ID)
5038 .Default(~0U);
5039 if (IMod != ~0U) {
5040 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5041 ProcessorIMod = IMod;
5042 }
5043 }
5044
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005045 // The "it" instruction has the condition mask on the end of the mnemonic.
5046 if (Mnemonic.startswith("it")) {
5047 ITMask = Mnemonic.slice(2, Mnemonic.size());
5048 Mnemonic = Mnemonic.slice(0, 2);
5049 }
5050
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005051 return Mnemonic;
5052}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005053
5054/// \brief Given a canonical mnemonic, determine if the instruction ever allows
5055/// inclusion of carry set or predication code operands.
5056//
5057// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00005058void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00005059getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5060 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005061 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5062 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005063 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005064 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005065 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005066 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005067 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00005068 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005069 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005070 Mnemonic == "mla" || Mnemonic == "smlal" ||
5071 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005072 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00005073 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00005074 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005075
Tim Northover2c45a382013-06-26 16:52:40 +00005076 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5077 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00005078 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
5079 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
5080 Mnemonic.startswith("vsel") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00005081 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005082 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
5083 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00005084 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
5085 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5086 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00005087 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005088 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005089 } else if (!isThumb()) {
5090 // Some instructions are only predicable in Thumb mode
5091 CanAcceptPredicationCode
5092 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5093 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5094 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5095 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5096 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5097 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5098 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5099 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00005100 if (hasV6MOps())
5101 CanAcceptPredicationCode = Mnemonic != "movs";
5102 else
5103 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005104 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005105 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005106}
5107
Jim Grosbach7283da92011-08-16 21:12:37 +00005108bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
David Blaikie960ea3f2014-06-08 16:18:35 +00005109 OperandVector &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005110 // FIXME: This is all horribly hacky. We really need a better way to deal
5111 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005112
5113 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5114 // another does not. Specifically, the MOVW instruction does not. So we
5115 // special case it here and remove the defaulted (non-setting) cc_out
5116 // operand if that's the instruction we're trying to match.
5117 //
5118 // We do this as post-processing of the explicit operands rather than just
5119 // conditionally adding the cc_out in the first place because we need
5120 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005121 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005122 !static_cast<ARMOperand &>(*Operands[4]).isARMSOImm() &&
5123 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
5124 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach7283da92011-08-16 21:12:37 +00005125 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005126
5127 // Register-register 'add' for thumb does not have a cc_out operand
5128 // when there are only two register operands.
5129 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005130 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5131 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5132 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005133 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005134 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005135 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5136 // have to check the immediate range here since Thumb2 has a variant
5137 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005138 if (((isThumb() && Mnemonic == "add") ||
5139 (isThumbTwo() && Mnemonic == "sub")) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005140 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5141 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5142 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
5143 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5144 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
5145 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005146 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005147 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5148 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005149 // selecting via the generic "add" mnemonic, so to know that we
5150 // should remove the cc_out operand, we have to explicitly check that
5151 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005152 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005153 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5154 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5155 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005156 // Nest conditions rather than one big 'if' statement for readability.
5157 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005158 // If both registers are low, we're in an IT block, and the immediate is
5159 // in range, we should use encoding T1 instead, which has a cc_out.
5160 if (inITBlock() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005161 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
5162 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
5163 static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005164 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005165 // Check against T3. If the second register is the PC, this is an
5166 // alternate form of ADR, which uses encoding T4, so check for that too.
David Blaikie960ea3f2014-06-08 16:18:35 +00005167 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
5168 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm())
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005169 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005170
5171 // Otherwise, we use encoding T4, which does not have a cc_out
5172 // operand.
5173 return true;
5174 }
5175
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005176 // The thumb2 multiply instruction doesn't have a CCOut register, so
5177 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5178 // use the 16-bit encoding or not.
5179 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005180 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5181 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5182 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5183 static_cast<ARMOperand &>(*Operands[5]).isReg() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005184 // If the registers aren't low regs, the destination reg isn't the
5185 // same as one of the source regs, or the cc_out operand is zero
5186 // outside of an IT block, we have to use the 32-bit encoding, so
5187 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005188 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5189 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5190 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
5191 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5192 static_cast<ARMOperand &>(*Operands[5]).getReg() &&
5193 static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5194 static_cast<ARMOperand &>(*Operands[4]).getReg())))
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005195 return true;
5196
Jim Grosbachefa7e952011-11-15 19:55:16 +00005197 // Also check the 'mul' syntax variant that doesn't specify an explicit
5198 // destination register.
5199 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005200 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5201 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5202 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
Jim Grosbachefa7e952011-11-15 19:55:16 +00005203 // If the registers aren't low regs or the cc_out operand is zero
5204 // outside of an IT block, we have to use the 32-bit encoding, so
5205 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005206 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5207 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
Jim Grosbachefa7e952011-11-15 19:55:16 +00005208 !inITBlock()))
5209 return true;
5210
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005211
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005212
Jim Grosbach4b701af2011-08-24 21:42:27 +00005213 // Register-register 'add/sub' for thumb does not have a cc_out operand
5214 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5215 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5216 // right, this will result in better diagnostics (which operand is off)
5217 // anyway.
5218 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5219 (Operands.size() == 5 || Operands.size() == 6) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005220 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5221 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
5222 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5223 (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005224 (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005225 static_cast<ARMOperand &>(*Operands[5]).isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005226 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005227
Jim Grosbach7283da92011-08-16 21:12:37 +00005228 return false;
5229}
5230
David Blaikie960ea3f2014-06-08 16:18:35 +00005231bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
5232 OperandVector &Operands) {
Joey Goulye8602552013-07-19 16:34:16 +00005233 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5234 unsigned RegIdx = 3;
5235 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005236 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") {
5237 if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5238 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32")
Joey Goulye8602552013-07-19 16:34:16 +00005239 RegIdx = 4;
5240
David Blaikie960ea3f2014-06-08 16:18:35 +00005241 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
5242 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
5243 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
5244 ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
5245 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
Joey Goulye8602552013-07-19 16:34:16 +00005246 return true;
5247 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005248 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005249}
5250
Jim Grosbach12952fe2011-11-11 23:08:10 +00005251static bool isDataTypeToken(StringRef Tok) {
5252 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5253 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5254 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5255 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5256 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5257 Tok == ".f" || Tok == ".d";
5258}
5259
5260// FIXME: This bit should probably be handled via an explicit match class
5261// in the .td files that matches the suffix instead of having it be
5262// a literal string token the way it is now.
5263static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5264 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5265}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005266static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5267 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005268
5269static bool RequiresVFPRegListValidation(StringRef Inst,
5270 bool &AcceptSinglePrecisionOnly,
5271 bool &AcceptDoublePrecisionOnly) {
5272 if (Inst.size() < 7)
5273 return false;
5274
5275 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5276 StringRef AddressingMode = Inst.substr(4, 2);
5277 if (AddressingMode == "ia" || AddressingMode == "db" ||
5278 AddressingMode == "ea" || AddressingMode == "fd") {
5279 AcceptSinglePrecisionOnly = Inst[6] == 's';
5280 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5281 return true;
5282 }
5283 }
5284
5285 return false;
5286}
5287
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005288/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005289bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
David Blaikie960ea3f2014-06-08 16:18:35 +00005290 SMLoc NameLoc, OperandVector &Operands) {
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005291 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005292 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005293 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005294 bool AcceptDoublePrecisionOnly;
5295 RequireVFPRegisterListCheck =
5296 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5297 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005298
Jim Grosbach8be2f652011-12-09 23:34:09 +00005299 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005300 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005301 // The generic tblgen'erated code does this later, at the start of
5302 // MatchInstructionImpl(), but that's too late for aliases that include
5303 // any sort of suffix.
5304 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005305 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5306 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005307
Jim Grosbachab5830e2011-12-14 02:16:11 +00005308 // First check for the ARM-specific .req directive.
5309 if (Parser.getTok().is(AsmToken::Identifier) &&
5310 Parser.getTok().getIdentifier() == ".req") {
5311 parseDirectiveReq(Name, NameLoc);
5312 // We always return 'error' for this, as we're done with this
5313 // statement and don't need to match the 'instruction."
5314 return true;
5315 }
5316
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005317 // Create the leading tokens for the mnemonic, split by '.' characters.
5318 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005319 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005320
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005321 // Split out the predication code and carry setting flag from the mnemonic.
5322 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005323 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005324 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005325 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005326 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005327 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005328
Jim Grosbach1c171b12011-08-25 17:23:55 +00005329 // In Thumb1, only the branch (B) instruction can be predicated.
5330 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005331 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005332 return Error(NameLoc, "conditional execution not supported in Thumb1");
5333 }
5334
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005335 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5336
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005337 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5338 // is the mask as it will be for the IT encoding if the conditional
5339 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5340 // where the conditional bit0 is zero, the instruction post-processing
5341 // will adjust the mask accordingly.
5342 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005343 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5344 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005345 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005346 return Error(Loc, "too many conditions on IT instruction");
5347 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005348 unsigned Mask = 8;
5349 for (unsigned i = ITMask.size(); i != 0; --i) {
5350 char pos = ITMask[i - 1];
5351 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005352 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005353 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005354 }
5355 Mask >>= 1;
5356 if (ITMask[i - 1] == 't')
5357 Mask |= 8;
5358 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005359 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005360 }
5361
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005362 // FIXME: This is all a pretty gross hack. We should automatically handle
5363 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005364
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005365 // Next, add the CCOut and ConditionCode operands, if needed.
5366 //
5367 // For mnemonics which can ever incorporate a carry setting bit or predication
5368 // code, our matching model involves us always generating CCOut and
5369 // ConditionCode operands to match the mnemonic "as written" and then we let
5370 // the matcher deal with finding the right instruction or generating an
5371 // appropriate error.
5372 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005373 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005374
Jim Grosbach03a8a162011-07-14 22:04:21 +00005375 // If we had a carry-set on an instruction that can't do that, issue an
5376 // error.
5377 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005378 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005379 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005380 "' can not set flags, but 's' suffix specified");
5381 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005382 // If we had a predication code on an instruction that can't do that, issue an
5383 // error.
5384 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005385 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005386 return Error(NameLoc, "instruction '" + Mnemonic +
5387 "' is not predicable, but condition code specified");
5388 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005389
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005390 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005391 if (CanAcceptCarrySet) {
5392 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005393 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005394 Loc));
5395 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005396
5397 // Add the predication code operand, if necessary.
5398 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005399 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5400 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005401 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005402 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005403 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005404
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005405 // Add the processor imod operand, if necessary.
5406 if (ProcessorIMod) {
5407 Operands.push_back(ARMOperand::CreateImm(
5408 MCConstantExpr::Create(ProcessorIMod, getContext()),
5409 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005410 }
5411
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005412 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005413 while (Next != StringRef::npos) {
5414 Start = Next;
5415 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005416 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005417
Jim Grosbach12952fe2011-11-11 23:08:10 +00005418 // Some NEON instructions have an optional datatype suffix that is
5419 // completely ignored. Check for that.
5420 if (isDataTypeToken(ExtraToken) &&
5421 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5422 continue;
5423
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005424 // For for ARM mode generate an error if the .n qualifier is used.
5425 if (ExtraToken == ".n" && !isThumb()) {
5426 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005427 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005428 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5429 "arm mode");
5430 }
5431
5432 // The .n qualifier is always discarded as that is what the tables
5433 // and matcher expect. In ARM mode the .w qualifier has no effect,
5434 // so discard it to avoid errors that can be caused by the matcher.
5435 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005436 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5437 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5438 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005439 }
5440
5441 // Read the remaining operands.
5442 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005443 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005444 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005445 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005446 return true;
5447 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005448
5449 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005450 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005451
5452 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005453 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005454 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005455 return true;
5456 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005457 }
5458 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005459
Chris Lattnera2a9d162010-09-11 16:18:25 +00005460 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005461 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005462 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005463 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005464 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005465
Chris Lattner91689c12010-09-08 05:10:46 +00005466 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005467
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005468 if (RequireVFPRegisterListCheck) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005469 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back());
5470 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList())
5471 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005472 "VFP/Neon single precision register expected");
David Blaikie960ea3f2014-06-08 16:18:35 +00005473 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList())
5474 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005475 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005476 }
5477
Jim Grosbach7283da92011-08-16 21:12:37 +00005478 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5479 // do and don't have a cc_out optional-def operand. With some spot-checks
5480 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005481 // parse and adjust accordingly before actually matching. We shouldn't ever
5482 // try to remove a cc_out operand that was explicitly set on the the
5483 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5484 // table driven matcher doesn't fit well with the ARM instruction set.
David Blaikie960ea3f2014-06-08 16:18:35 +00005485 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005486 Operands.erase(Operands.begin() + 1);
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005487
Joey Goulye8602552013-07-19 16:34:16 +00005488 // Some instructions have the same mnemonic, but don't always
5489 // have a predicate. Distinguish them here and delete the
5490 // predicate if needed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005491 if (shouldOmitPredicateOperand(Mnemonic, Operands))
Joey Goulye8602552013-07-19 16:34:16 +00005492 Operands.erase(Operands.begin() + 1);
Joey Goulye8602552013-07-19 16:34:16 +00005493
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005494 // ARM mode 'blx' need special handling, as the register operand version
5495 // is predicable, but the label operand version is not. So, we can't rely
5496 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005497 // a k_CondCode operand in the list. If we're trying to match the label
5498 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005499 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005500 static_cast<ARMOperand &>(*Operands[2]).isImm())
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005501 Operands.erase(Operands.begin() + 1);
Jim Grosbach8cffa282011-08-11 23:51:13 +00005502
Weiming Zhao8f56f882012-11-16 21:55:34 +00005503 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5504 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5505 // a single GPRPair reg operand is used in the .td file to replace the two
5506 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5507 // expressed as a GPRPair, so we have to manually merge them.
5508 // FIXME: We would really like to be able to tablegen'erate this.
5509 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005510 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5511 Mnemonic == "stlexd")) {
5512 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005513 unsigned Idx = isLoad ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005514 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
5515 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005516
5517 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5518 // Adjust only if Op1 and Op2 are GPRs.
David Blaikie960ea3f2014-06-08 16:18:35 +00005519 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
5520 MRC.contains(Op2.getReg())) {
5521 unsigned Reg1 = Op1.getReg();
5522 unsigned Reg2 = Op2.getReg();
Weiming Zhao8f56f882012-11-16 21:55:34 +00005523 unsigned Rt = MRI->getEncodingValue(Reg1);
5524 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5525
5526 // Rt2 must be Rt + 1 and Rt must be even.
5527 if (Rt + 1 != Rt2 || (Rt & 1)) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005528 Error(Op2.getStartLoc(), isLoad
5529 ? "destination operands must be sequential"
5530 : "source operands must be sequential");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005531 return true;
5532 }
5533 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5534 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
David Blaikie960ea3f2014-06-08 16:18:35 +00005535 Operands[Idx] =
5536 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
5537 Operands.erase(Operands.begin() + Idx + 1);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005538 }
5539 }
5540
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005541 // GNU Assembler extension (compatibility)
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005542 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005543 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5544 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5545 if (Op3.isMem()) {
5546 assert(Op2.isReg() && "expected register argument");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005547
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005548 unsigned SuperReg = MRI->getMatchingSuperReg(
David Blaikie960ea3f2014-06-08 16:18:35 +00005549 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005550
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005551 assert(SuperReg && "expected register pair");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005552
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005553 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005554
David Blaikie960ea3f2014-06-08 16:18:35 +00005555 Operands.insert(
5556 Operands.begin() + 3,
5557 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005558 }
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005559 }
5560
Kevin Enderby78f95722013-07-31 21:05:30 +00005561 // FIXME: As said above, this is all a pretty gross hack. This instruction
5562 // does not fit with other "subs" and tblgen.
5563 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5564 // so the Mnemonic is the original name "subs" and delete the predicate
5565 // operand so it will match the table entry.
5566 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005567 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5568 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
5569 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5570 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
5571 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5572 Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
Kevin Enderby78f95722013-07-31 21:05:30 +00005573 Operands.erase(Operands.begin() + 1);
Kevin Enderby78f95722013-07-31 21:05:30 +00005574 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005575 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005576}
5577
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005578// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005579
5580// return 'true' if register list contains non-low GPR registers,
5581// 'false' otherwise. If Reg is in the register list or is HiReg, set
5582// 'containsReg' to true.
5583static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5584 unsigned HiReg, bool &containsReg) {
5585 containsReg = false;
5586 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5587 unsigned OpReg = Inst.getOperand(i).getReg();
5588 if (OpReg == Reg)
5589 containsReg = true;
5590 // Anything other than a low register isn't legal here.
5591 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5592 return true;
5593 }
5594 return false;
5595}
5596
Jim Grosbacha31f2232011-09-07 18:05:34 +00005597// Check if the specified regisgter is in the register list of the inst,
5598// starting at the indicated operand number.
5599static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5600 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5601 unsigned OpReg = Inst.getOperand(i).getReg();
5602 if (OpReg == Reg)
5603 return true;
5604 }
5605 return false;
5606}
5607
Richard Barton8d519fe2013-09-05 14:14:19 +00005608// Return true if instruction has the interesting property of being
5609// allowed in IT blocks, but not being predicable.
5610static bool instIsBreakpoint(const MCInst &Inst) {
5611 return Inst.getOpcode() == ARM::tBKPT ||
5612 Inst.getOpcode() == ARM::BKPT ||
5613 Inst.getOpcode() == ARM::tHLT ||
5614 Inst.getOpcode() == ARM::HLT;
5615
5616}
5617
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005618// FIXME: We would really like to be able to tablegen'erate this.
David Blaikie960ea3f2014-06-08 16:18:35 +00005619bool ARMAsmParser::validateInstruction(MCInst &Inst,
5620 const OperandVector &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005621 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005622 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005623
Jim Grosbached16ec42011-08-29 22:24:09 +00005624 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005625 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005626 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005627 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005628 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005629 if (ITState.FirstCond)
5630 ITState.FirstCond = false;
5631 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005632 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005633 // The instruction must be predicable.
5634 if (!MCID.isPredicable())
5635 return Error(Loc, "instructions in IT block must be predicable");
5636 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005637 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005638 ARMCC::getOppositeCondition(ITState.Cond);
5639 if (Cond != ITCond) {
5640 // Find the condition code Operand to get its SMLoc information.
5641 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005642 for (unsigned I = 1; I < Operands.size(); ++I)
David Blaikie960ea3f2014-06-08 16:18:35 +00005643 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
Tilmann Schellerbe904772013-09-30 17:57:30 +00005644 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005645 return Error(CondLoc, "incorrect condition in IT block; got '" +
5646 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5647 "', but expected '" +
5648 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5649 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005650 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005651 } else if (isThumbTwo() && MCID.isPredicable() &&
5652 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005653 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5654 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005655 return Error(Loc, "predicated instructions must be in IT block");
5656
Tilmann Scheller255722b2013-09-30 16:11:48 +00005657 const unsigned Opcode = Inst.getOpcode();
5658 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005659 case ARM::LDRD:
5660 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005661 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005662 const unsigned RtReg = Inst.getOperand(0).getReg();
5663
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005664 // Rt can't be R14.
5665 if (RtReg == ARM::LR)
5666 return Error(Operands[3]->getStartLoc(),
5667 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005668
5669 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005670 // Rt must be even-numbered.
5671 if ((Rt & 1) == 1)
5672 return Error(Operands[3]->getStartLoc(),
5673 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005674
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005675 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005676 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005677 if (Rt2 != Rt + 1)
5678 return Error(Operands[3]->getStartLoc(),
5679 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005680
5681 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5682 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5683 // For addressing modes with writeback, the base register needs to be
5684 // different from the destination registers.
5685 if (Rn == Rt || Rn == Rt2)
5686 return Error(Operands[3]->getStartLoc(),
5687 "base register needs to be different from destination "
5688 "registers");
5689 }
5690
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005691 return false;
5692 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005693 case ARM::t2LDRDi8:
5694 case ARM::t2LDRD_PRE:
5695 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005696 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005697 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5698 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5699 if (Rt2 == Rt)
5700 return Error(Operands[3]->getStartLoc(),
5701 "destination operands can't be identical");
5702 return false;
5703 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005704 case ARM::STRD: {
5705 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005706 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5707 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005708 if (Rt2 != Rt + 1)
5709 return Error(Operands[3]->getStartLoc(),
5710 "source operands must be sequential");
5711 return false;
5712 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005713 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005714 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005715 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005716 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5717 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005718 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005719 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005720 "source operands must be sequential");
5721 return false;
5722 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005723 case ARM::SBFX:
5724 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005725 // Width must be in range [1, 32-lsb].
5726 unsigned LSB = Inst.getOperand(2).getImm();
5727 unsigned Widthm1 = Inst.getOperand(3).getImm();
5728 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005729 return Error(Operands[5]->getStartLoc(),
5730 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005731 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005732 }
Tim Northover08a86602013-10-22 19:00:39 +00005733 // Notionally handles ARM::tLDMIA_UPD too.
Jim Grosbach90103cc2011-08-18 21:50:53 +00005734 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005735 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005736 // most cases that are normally illegal for a Thumb1 LDM instruction.
5737 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005738 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005739 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005740 // in the register list.
5741 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005742 bool HasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00005743 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5744 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005745 bool ListContainsBase;
5746 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5747 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005748 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005749 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005750 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005751 return Error(Operands[2]->getStartLoc(),
5752 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005753 // If we should not have writeback, there must not be a '!'. This is
5754 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005755 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005756 return Error(Operands[3]->getStartLoc(),
5757 "writeback operator '!' not allowed when base register "
5758 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005759
5760 break;
5761 }
Tim Northover08a86602013-10-22 19:00:39 +00005762 case ARM::LDMIA_UPD:
5763 case ARM::LDMDB_UPD:
5764 case ARM::LDMIB_UPD:
5765 case ARM::LDMDA_UPD:
5766 // ARM variants loading and updating the same register are only officially
5767 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5768 if (!hasV7Ops())
5769 break;
5770 // Fallthrough
5771 case ARM::t2LDMIA_UPD:
5772 case ARM::t2LDMDB_UPD:
5773 case ARM::t2STMIA_UPD:
5774 case ARM::t2STMDB_UPD: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005775 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
Tim Northover741e6ef2013-10-24 09:37:18 +00005776 return Error(Operands.back()->getStartLoc(),
5777 "writeback register not allowed in register list");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005778 break;
5779 }
Tim Northover8eaf1542013-11-12 21:32:41 +00005780 case ARM::sysLDMIA_UPD:
5781 case ARM::sysLDMDA_UPD:
5782 case ARM::sysLDMDB_UPD:
5783 case ARM::sysLDMIB_UPD:
5784 if (!listContainsReg(Inst, 3, ARM::PC))
5785 return Error(Operands[4]->getStartLoc(),
5786 "writeback register only allowed on system LDM "
5787 "if PC in register-list");
5788 break;
5789 case ARM::sysSTMIA_UPD:
5790 case ARM::sysSTMDA_UPD:
5791 case ARM::sysSTMDB_UPD:
5792 case ARM::sysSTMIB_UPD:
5793 return Error(Operands[2]->getStartLoc(),
5794 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005795 case ARM::tMUL: {
5796 // The second source operand must be the same register as the destination
5797 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005798 //
5799 // In this case, we must directly check the parsed operands because the
5800 // cvtThumbMultiply() function is written in such a way that it guarantees
5801 // this first statement is always true for the new Inst. Essentially, the
5802 // destination is unconditionally copied into the second source operand
5803 // without checking to see if it matches what we actually parsed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005804 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
5805 ((ARMOperand &)*Operands[5]).getReg()) &&
5806 (((ARMOperand &)*Operands[3]).getReg() !=
5807 ((ARMOperand &)*Operands[4]).getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005808 return Error(Operands[3]->getStartLoc(),
5809 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005810 }
5811 break;
5812 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005813 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5814 // so only issue a diagnostic for thumb1. The instructions will be
5815 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005816 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005817 bool ListContainsBase;
5818 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005819 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005820 return Error(Operands[2]->getStartLoc(),
5821 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005822 break;
5823 }
5824 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005825 bool ListContainsBase;
5826 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005827 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005828 return Error(Operands[2]->getStartLoc(),
5829 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005830 break;
5831 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005832 case ARM::tSTMIA_UPD: {
Tim Northover08a86602013-10-22 19:00:39 +00005833 bool ListContainsBase, InvalidLowList;
5834 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5835 0, ListContainsBase);
5836 if (InvalidLowList && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005837 return Error(Operands[4]->getStartLoc(),
5838 "registers must be in range r0-r7");
Tim Northover08a86602013-10-22 19:00:39 +00005839
5840 // This would be converted to a 32-bit stm, but that's not valid if the
5841 // writeback register is in the list.
5842 if (InvalidLowList && ListContainsBase)
5843 return Error(Operands[4]->getStartLoc(),
5844 "writeback operator '!' not allowed when base register "
5845 "in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00005846 break;
5847 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005848 case ARM::tADDrSP: {
5849 // If the non-SP source operand and the destination operand are not the
5850 // same, we need thumb2 (for the wide encoding), or we have an error.
5851 if (!isThumbTwo() &&
5852 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5853 return Error(Operands[4]->getStartLoc(),
5854 "source register must be the same as destination");
5855 }
5856 break;
5857 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005858 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005859 case ARM::tB:
David Blaikie960ea3f2014-06-08 16:18:35 +00005860 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00005861 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005862 break;
5863 case ARM::t2B: {
5864 int op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005865 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00005866 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005867 break;
5868 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005869 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005870 case ARM::tBcc:
David Blaikie960ea3f2014-06-08 16:18:35 +00005871 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00005872 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005873 break;
5874 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005875 int Op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005876 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00005877 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005878 break;
5879 }
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00005880 case ARM::MOVi16:
5881 case ARM::t2MOVi16:
5882 case ARM::t2MOVTi16:
5883 {
5884 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
5885 // especially when we turn it into a movw and the expression <symbol> does
5886 // not have a :lower16: or :upper16 as part of the expression. We don't
5887 // want the behavior of silently truncating, which can be unexpected and
5888 // lead to bugs that are difficult to find since this is an easy mistake
5889 // to make.
5890 int i = (Operands[3]->isImm()) ? 3 : 4;
David Blaikie960ea3f2014-06-08 16:18:35 +00005891 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
5892 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00005893 if (CE) break;
David Blaikie960ea3f2014-06-08 16:18:35 +00005894 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00005895 if (!E) break;
5896 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
5897 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005898 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
5899 return Error(
5900 Op.getStartLoc(),
5901 "immediate expression for mov requires :lower16: or :upper16");
5902 break;
5903 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005904 }
5905
5906 return false;
5907}
5908
Jim Grosbach1a747242012-01-23 23:45:44 +00005909static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005910 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005911 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005912 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005913 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5914 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5915 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5916 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5917 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5918 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5919 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5920 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5921 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005922
5923 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005924 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5925 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5926 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5927 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5928 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005929
Jim Grosbach1e946a42012-01-24 00:43:12 +00005930 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5931 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5932 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5933 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5934 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005935
Jim Grosbach1e946a42012-01-24 00:43:12 +00005936 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5937 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5938 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5939 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5940 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005941
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005942 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005943 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5944 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5945 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5946 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5947 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5948 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5949 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5950 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5951 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5952 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5953 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5954 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5955 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5956 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5957 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005958
Jim Grosbach1a747242012-01-23 23:45:44 +00005959 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005960 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5961 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5962 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5963 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5964 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5965 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5966 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5967 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5968 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5969 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5970 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5971 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5972 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5973 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5974 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5975 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5976 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5977 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005978
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005979 // VST4LN
5980 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5981 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5982 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5983 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5984 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5985 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5986 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5987 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5988 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5989 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5990 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5991 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5992 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5993 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5994 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5995
Jim Grosbachda70eac2012-01-24 00:58:13 +00005996 // VST4
5997 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5998 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5999 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6000 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6001 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6002 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6003 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6004 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6005 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6006 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6007 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6008 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6009 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6010 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6011 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6012 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6013 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6014 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00006015 }
6016}
6017
Jim Grosbach1a747242012-01-23 23:45:44 +00006018static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00006019 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006020 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006021 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006022 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6023 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6024 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6025 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6026 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6027 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6028 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6029 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6030 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006031
6032 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006033 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6034 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6035 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6036 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6037 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6038 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6039 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6040 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6041 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6042 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6043 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6044 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6045 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6046 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6047 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006048
Jim Grosbachb78403c2012-01-24 23:47:04 +00006049 // VLD3DUP
6050 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6051 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6052 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6053 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
Kevin Enderbyd88fec32014-04-08 18:00:52 +00006054 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
Jim Grosbachb78403c2012-01-24 23:47:04 +00006055 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6056 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6057 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6058 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6059 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6060 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6061 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6062 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6063 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6064 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6065 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6066 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6067 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6068
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006069 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006070 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6071 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6072 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6073 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6074 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6075 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6076 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6077 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6078 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6079 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6080 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6081 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6082 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6083 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6084 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006085
6086 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006087 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6088 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6089 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6090 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6091 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6092 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6093 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6094 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6095 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6096 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6097 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6098 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6099 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6100 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6101 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6102 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6103 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6104 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00006105
Jim Grosbach14952a02012-01-24 18:37:25 +00006106 // VLD4LN
6107 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6108 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6109 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00006110 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00006111 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6112 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6113 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6114 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6115 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6116 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6117 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6118 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6119 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6120 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6121 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6122
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006123 // VLD4DUP
6124 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6125 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6126 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6127 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6128 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6129 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6130 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6131 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6132 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6133 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6134 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6135 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6136 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6137 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6138 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6139 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6140 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6141 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6142
Jim Grosbached561fc2012-01-24 00:43:17 +00006143 // VLD4
6144 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6145 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6146 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6147 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6148 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6149 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6150 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6151 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6152 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6153 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6154 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6155 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6156 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6157 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6158 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6159 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6160 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6161 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006162 }
6163}
6164
David Blaikie960ea3f2014-06-08 16:18:35 +00006165bool ARMAsmParser::processInstruction(MCInst &Inst,
6166 const OperandVector &Operands) {
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006167 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006168 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6169 case ARM::LDRT_POST:
6170 case ARM::LDRBT_POST: {
6171 const unsigned Opcode =
6172 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6173 : ARM::LDRBT_POST_IMM;
6174 MCInst TmpInst;
6175 TmpInst.setOpcode(Opcode);
6176 TmpInst.addOperand(Inst.getOperand(0));
6177 TmpInst.addOperand(Inst.getOperand(1));
6178 TmpInst.addOperand(Inst.getOperand(1));
6179 TmpInst.addOperand(MCOperand::CreateReg(0));
6180 TmpInst.addOperand(MCOperand::CreateImm(0));
6181 TmpInst.addOperand(Inst.getOperand(2));
6182 TmpInst.addOperand(Inst.getOperand(3));
6183 Inst = TmpInst;
6184 return true;
6185 }
6186 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6187 case ARM::STRT_POST:
6188 case ARM::STRBT_POST: {
6189 const unsigned Opcode =
6190 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6191 : ARM::STRBT_POST_IMM;
6192 MCInst TmpInst;
6193 TmpInst.setOpcode(Opcode);
6194 TmpInst.addOperand(Inst.getOperand(1));
6195 TmpInst.addOperand(Inst.getOperand(0));
6196 TmpInst.addOperand(Inst.getOperand(1));
6197 TmpInst.addOperand(MCOperand::CreateReg(0));
6198 TmpInst.addOperand(MCOperand::CreateImm(0));
6199 TmpInst.addOperand(Inst.getOperand(2));
6200 TmpInst.addOperand(Inst.getOperand(3));
6201 Inst = TmpInst;
6202 return true;
6203 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006204 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6205 case ARM::ADDri: {
6206 if (Inst.getOperand(1).getReg() != ARM::PC ||
6207 Inst.getOperand(5).getReg() != 0)
6208 return false;
6209 MCInst TmpInst;
6210 TmpInst.setOpcode(ARM::ADR);
6211 TmpInst.addOperand(Inst.getOperand(0));
6212 TmpInst.addOperand(Inst.getOperand(2));
6213 TmpInst.addOperand(Inst.getOperand(3));
6214 TmpInst.addOperand(Inst.getOperand(4));
6215 Inst = TmpInst;
6216 return true;
6217 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006218 // Aliases for alternate PC+imm syntax of LDR instructions.
6219 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006220 // Select the narrow version if the immediate will fit.
6221 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006222 Inst.getOperand(1).getImm() <= 0xff &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006223 !(static_cast<ARMOperand &>(*Operands[2]).isToken() &&
6224 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006225 Inst.setOpcode(ARM::tLDRpci);
6226 else
6227 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006228 return true;
6229 case ARM::t2LDRBpcrel:
6230 Inst.setOpcode(ARM::t2LDRBpci);
6231 return true;
6232 case ARM::t2LDRHpcrel:
6233 Inst.setOpcode(ARM::t2LDRHpci);
6234 return true;
6235 case ARM::t2LDRSBpcrel:
6236 Inst.setOpcode(ARM::t2LDRSBpci);
6237 return true;
6238 case ARM::t2LDRSHpcrel:
6239 Inst.setOpcode(ARM::t2LDRSHpci);
6240 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006241 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006242 case ARM::VST1LNdWB_register_Asm_8:
6243 case ARM::VST1LNdWB_register_Asm_16:
6244 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006245 MCInst TmpInst;
6246 // Shuffle the operands around so the lane index operand is in the
6247 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006248 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006249 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006250 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6251 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6252 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6253 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6254 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6255 TmpInst.addOperand(Inst.getOperand(1)); // lane
6256 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6257 TmpInst.addOperand(Inst.getOperand(6));
6258 Inst = TmpInst;
6259 return true;
6260 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006261
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006262 case ARM::VST2LNdWB_register_Asm_8:
6263 case ARM::VST2LNdWB_register_Asm_16:
6264 case ARM::VST2LNdWB_register_Asm_32:
6265 case ARM::VST2LNqWB_register_Asm_16:
6266 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006267 MCInst TmpInst;
6268 // Shuffle the operands around so the lane index operand is in the
6269 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006270 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006271 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006272 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6273 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6274 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6275 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6276 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006277 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6278 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006279 TmpInst.addOperand(Inst.getOperand(1)); // lane
6280 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6281 TmpInst.addOperand(Inst.getOperand(6));
6282 Inst = TmpInst;
6283 return true;
6284 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006285
6286 case ARM::VST3LNdWB_register_Asm_8:
6287 case ARM::VST3LNdWB_register_Asm_16:
6288 case ARM::VST3LNdWB_register_Asm_32:
6289 case ARM::VST3LNqWB_register_Asm_16:
6290 case ARM::VST3LNqWB_register_Asm_32: {
6291 MCInst TmpInst;
6292 // Shuffle the operands around so the lane index operand is in the
6293 // right place.
6294 unsigned Spacing;
6295 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6296 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6297 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6298 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6299 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6300 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6301 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6302 Spacing));
6303 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6304 Spacing * 2));
6305 TmpInst.addOperand(Inst.getOperand(1)); // lane
6306 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6307 TmpInst.addOperand(Inst.getOperand(6));
6308 Inst = TmpInst;
6309 return true;
6310 }
6311
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006312 case ARM::VST4LNdWB_register_Asm_8:
6313 case ARM::VST4LNdWB_register_Asm_16:
6314 case ARM::VST4LNdWB_register_Asm_32:
6315 case ARM::VST4LNqWB_register_Asm_16:
6316 case ARM::VST4LNqWB_register_Asm_32: {
6317 MCInst TmpInst;
6318 // Shuffle the operands around so the lane index operand is in the
6319 // right place.
6320 unsigned Spacing;
6321 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6322 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6323 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6324 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6325 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6326 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6327 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6328 Spacing));
6329 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6330 Spacing * 2));
6331 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6332 Spacing * 3));
6333 TmpInst.addOperand(Inst.getOperand(1)); // lane
6334 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6335 TmpInst.addOperand(Inst.getOperand(6));
6336 Inst = TmpInst;
6337 return true;
6338 }
6339
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006340 case ARM::VST1LNdWB_fixed_Asm_8:
6341 case ARM::VST1LNdWB_fixed_Asm_16:
6342 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006343 MCInst TmpInst;
6344 // Shuffle the operands around so the lane index operand is in the
6345 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006346 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006347 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006348 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6349 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6350 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6351 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6352 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6353 TmpInst.addOperand(Inst.getOperand(1)); // lane
6354 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6355 TmpInst.addOperand(Inst.getOperand(5));
6356 Inst = TmpInst;
6357 return true;
6358 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006359
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006360 case ARM::VST2LNdWB_fixed_Asm_8:
6361 case ARM::VST2LNdWB_fixed_Asm_16:
6362 case ARM::VST2LNdWB_fixed_Asm_32:
6363 case ARM::VST2LNqWB_fixed_Asm_16:
6364 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006365 MCInst TmpInst;
6366 // Shuffle the operands around so the lane index operand is in the
6367 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006368 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006369 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006370 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6371 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6372 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6373 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6374 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006375 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6376 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006377 TmpInst.addOperand(Inst.getOperand(1)); // lane
6378 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6379 TmpInst.addOperand(Inst.getOperand(5));
6380 Inst = TmpInst;
6381 return true;
6382 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006383
6384 case ARM::VST3LNdWB_fixed_Asm_8:
6385 case ARM::VST3LNdWB_fixed_Asm_16:
6386 case ARM::VST3LNdWB_fixed_Asm_32:
6387 case ARM::VST3LNqWB_fixed_Asm_16:
6388 case ARM::VST3LNqWB_fixed_Asm_32: {
6389 MCInst TmpInst;
6390 // Shuffle the operands around so the lane index operand is in the
6391 // right place.
6392 unsigned Spacing;
6393 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6394 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6395 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6396 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6397 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6398 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6399 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6400 Spacing));
6401 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6402 Spacing * 2));
6403 TmpInst.addOperand(Inst.getOperand(1)); // lane
6404 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6405 TmpInst.addOperand(Inst.getOperand(5));
6406 Inst = TmpInst;
6407 return true;
6408 }
6409
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006410 case ARM::VST4LNdWB_fixed_Asm_8:
6411 case ARM::VST4LNdWB_fixed_Asm_16:
6412 case ARM::VST4LNdWB_fixed_Asm_32:
6413 case ARM::VST4LNqWB_fixed_Asm_16:
6414 case ARM::VST4LNqWB_fixed_Asm_32: {
6415 MCInst TmpInst;
6416 // Shuffle the operands around so the lane index operand is in the
6417 // right place.
6418 unsigned Spacing;
6419 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6420 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6421 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6422 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6423 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6424 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6425 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6426 Spacing));
6427 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6428 Spacing * 2));
6429 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6430 Spacing * 3));
6431 TmpInst.addOperand(Inst.getOperand(1)); // lane
6432 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6433 TmpInst.addOperand(Inst.getOperand(5));
6434 Inst = TmpInst;
6435 return true;
6436 }
6437
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006438 case ARM::VST1LNdAsm_8:
6439 case ARM::VST1LNdAsm_16:
6440 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006441 MCInst TmpInst;
6442 // Shuffle the operands around so the lane index operand is in the
6443 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006444 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006445 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006446 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6447 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6448 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6449 TmpInst.addOperand(Inst.getOperand(1)); // lane
6450 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6451 TmpInst.addOperand(Inst.getOperand(5));
6452 Inst = TmpInst;
6453 return true;
6454 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006455
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006456 case ARM::VST2LNdAsm_8:
6457 case ARM::VST2LNdAsm_16:
6458 case ARM::VST2LNdAsm_32:
6459 case ARM::VST2LNqAsm_16:
6460 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006461 MCInst TmpInst;
6462 // Shuffle the operands around so the lane index operand is in the
6463 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006464 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006465 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006466 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6467 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6468 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006469 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6470 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006471 TmpInst.addOperand(Inst.getOperand(1)); // lane
6472 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6473 TmpInst.addOperand(Inst.getOperand(5));
6474 Inst = TmpInst;
6475 return true;
6476 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006477
6478 case ARM::VST3LNdAsm_8:
6479 case ARM::VST3LNdAsm_16:
6480 case ARM::VST3LNdAsm_32:
6481 case ARM::VST3LNqAsm_16:
6482 case ARM::VST3LNqAsm_32: {
6483 MCInst TmpInst;
6484 // Shuffle the operands around so the lane index operand is in the
6485 // right place.
6486 unsigned Spacing;
6487 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6488 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6489 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6490 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6491 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6492 Spacing));
6493 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6494 Spacing * 2));
6495 TmpInst.addOperand(Inst.getOperand(1)); // lane
6496 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6497 TmpInst.addOperand(Inst.getOperand(5));
6498 Inst = TmpInst;
6499 return true;
6500 }
6501
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006502 case ARM::VST4LNdAsm_8:
6503 case ARM::VST4LNdAsm_16:
6504 case ARM::VST4LNdAsm_32:
6505 case ARM::VST4LNqAsm_16:
6506 case ARM::VST4LNqAsm_32: {
6507 MCInst TmpInst;
6508 // Shuffle the operands around so the lane index operand is in the
6509 // right place.
6510 unsigned Spacing;
6511 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6512 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6513 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6514 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6515 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6516 Spacing));
6517 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6518 Spacing * 2));
6519 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6520 Spacing * 3));
6521 TmpInst.addOperand(Inst.getOperand(1)); // lane
6522 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6523 TmpInst.addOperand(Inst.getOperand(5));
6524 Inst = TmpInst;
6525 return true;
6526 }
6527
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006528 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006529 case ARM::VLD1LNdWB_register_Asm_8:
6530 case ARM::VLD1LNdWB_register_Asm_16:
6531 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006532 MCInst TmpInst;
6533 // Shuffle the operands around so the lane index operand is in the
6534 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006535 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006536 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006537 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6538 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6539 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6540 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6541 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6542 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6543 TmpInst.addOperand(Inst.getOperand(1)); // lane
6544 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6545 TmpInst.addOperand(Inst.getOperand(6));
6546 Inst = TmpInst;
6547 return true;
6548 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006549
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006550 case ARM::VLD2LNdWB_register_Asm_8:
6551 case ARM::VLD2LNdWB_register_Asm_16:
6552 case ARM::VLD2LNdWB_register_Asm_32:
6553 case ARM::VLD2LNqWB_register_Asm_16:
6554 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006555 MCInst TmpInst;
6556 // Shuffle the operands around so the lane index operand is in the
6557 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006558 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006559 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006560 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006561 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6562 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006563 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6564 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6565 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6566 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6567 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006568 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6569 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006570 TmpInst.addOperand(Inst.getOperand(1)); // lane
6571 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6572 TmpInst.addOperand(Inst.getOperand(6));
6573 Inst = TmpInst;
6574 return true;
6575 }
6576
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006577 case ARM::VLD3LNdWB_register_Asm_8:
6578 case ARM::VLD3LNdWB_register_Asm_16:
6579 case ARM::VLD3LNdWB_register_Asm_32:
6580 case ARM::VLD3LNqWB_register_Asm_16:
6581 case ARM::VLD3LNqWB_register_Asm_32: {
6582 MCInst TmpInst;
6583 // Shuffle the operands around so the lane index operand is in the
6584 // right place.
6585 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006586 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006587 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6588 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6589 Spacing));
6590 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006591 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006592 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6593 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6594 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6595 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6596 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6598 Spacing));
6599 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006600 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006601 TmpInst.addOperand(Inst.getOperand(1)); // lane
6602 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6603 TmpInst.addOperand(Inst.getOperand(6));
6604 Inst = TmpInst;
6605 return true;
6606 }
6607
Jim Grosbach14952a02012-01-24 18:37:25 +00006608 case ARM::VLD4LNdWB_register_Asm_8:
6609 case ARM::VLD4LNdWB_register_Asm_16:
6610 case ARM::VLD4LNdWB_register_Asm_32:
6611 case ARM::VLD4LNqWB_register_Asm_16:
6612 case ARM::VLD4LNqWB_register_Asm_32: {
6613 MCInst TmpInst;
6614 // Shuffle the operands around so the lane index operand is in the
6615 // right place.
6616 unsigned Spacing;
6617 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6618 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6620 Spacing));
6621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6622 Spacing * 2));
6623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6624 Spacing * 3));
6625 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6626 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6627 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6628 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6629 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6630 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6631 Spacing));
6632 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6633 Spacing * 2));
6634 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6635 Spacing * 3));
6636 TmpInst.addOperand(Inst.getOperand(1)); // lane
6637 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6638 TmpInst.addOperand(Inst.getOperand(6));
6639 Inst = TmpInst;
6640 return true;
6641 }
6642
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006643 case ARM::VLD1LNdWB_fixed_Asm_8:
6644 case ARM::VLD1LNdWB_fixed_Asm_16:
6645 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006646 MCInst TmpInst;
6647 // Shuffle the operands around so the lane index operand is in the
6648 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006649 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006650 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006651 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6652 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6653 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6654 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6655 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6656 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6657 TmpInst.addOperand(Inst.getOperand(1)); // lane
6658 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6659 TmpInst.addOperand(Inst.getOperand(5));
6660 Inst = TmpInst;
6661 return true;
6662 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006663
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006664 case ARM::VLD2LNdWB_fixed_Asm_8:
6665 case ARM::VLD2LNdWB_fixed_Asm_16:
6666 case ARM::VLD2LNdWB_fixed_Asm_32:
6667 case ARM::VLD2LNqWB_fixed_Asm_16:
6668 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006669 MCInst TmpInst;
6670 // Shuffle the operands around so the lane index operand is in the
6671 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006672 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006673 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006674 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006675 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6676 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006677 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6678 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6679 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6680 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6681 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006682 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6683 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006684 TmpInst.addOperand(Inst.getOperand(1)); // lane
6685 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6686 TmpInst.addOperand(Inst.getOperand(5));
6687 Inst = TmpInst;
6688 return true;
6689 }
6690
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006691 case ARM::VLD3LNdWB_fixed_Asm_8:
6692 case ARM::VLD3LNdWB_fixed_Asm_16:
6693 case ARM::VLD3LNdWB_fixed_Asm_32:
6694 case ARM::VLD3LNqWB_fixed_Asm_16:
6695 case ARM::VLD3LNqWB_fixed_Asm_32: {
6696 MCInst TmpInst;
6697 // Shuffle the operands around so the lane index operand is in the
6698 // right place.
6699 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006700 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006701 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6702 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6703 Spacing));
6704 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006705 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006706 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6707 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6708 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6709 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6710 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6711 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6712 Spacing));
6713 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006714 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006715 TmpInst.addOperand(Inst.getOperand(1)); // lane
6716 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6717 TmpInst.addOperand(Inst.getOperand(5));
6718 Inst = TmpInst;
6719 return true;
6720 }
6721
Jim Grosbach14952a02012-01-24 18:37:25 +00006722 case ARM::VLD4LNdWB_fixed_Asm_8:
6723 case ARM::VLD4LNdWB_fixed_Asm_16:
6724 case ARM::VLD4LNdWB_fixed_Asm_32:
6725 case ARM::VLD4LNqWB_fixed_Asm_16:
6726 case ARM::VLD4LNqWB_fixed_Asm_32: {
6727 MCInst TmpInst;
6728 // Shuffle the operands around so the lane index operand is in the
6729 // right place.
6730 unsigned Spacing;
6731 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6732 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6733 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6734 Spacing));
6735 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6736 Spacing * 2));
6737 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6738 Spacing * 3));
6739 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6740 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6741 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6742 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6743 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6744 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6745 Spacing));
6746 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6747 Spacing * 2));
6748 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6749 Spacing * 3));
6750 TmpInst.addOperand(Inst.getOperand(1)); // lane
6751 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6752 TmpInst.addOperand(Inst.getOperand(5));
6753 Inst = TmpInst;
6754 return true;
6755 }
6756
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006757 case ARM::VLD1LNdAsm_8:
6758 case ARM::VLD1LNdAsm_16:
6759 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006760 MCInst TmpInst;
6761 // Shuffle the operands around so the lane index operand is in the
6762 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006763 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006764 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006765 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6766 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6767 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6768 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6769 TmpInst.addOperand(Inst.getOperand(1)); // lane
6770 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6771 TmpInst.addOperand(Inst.getOperand(5));
6772 Inst = TmpInst;
6773 return true;
6774 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006775
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006776 case ARM::VLD2LNdAsm_8:
6777 case ARM::VLD2LNdAsm_16:
6778 case ARM::VLD2LNdAsm_32:
6779 case ARM::VLD2LNqAsm_16:
6780 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006781 MCInst TmpInst;
6782 // Shuffle the operands around so the lane index operand is in the
6783 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006784 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006785 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006786 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006787 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6788 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006789 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6790 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6791 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006792 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6793 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006794 TmpInst.addOperand(Inst.getOperand(1)); // lane
6795 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6796 TmpInst.addOperand(Inst.getOperand(5));
6797 Inst = TmpInst;
6798 return true;
6799 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006800
6801 case ARM::VLD3LNdAsm_8:
6802 case ARM::VLD3LNdAsm_16:
6803 case ARM::VLD3LNdAsm_32:
6804 case ARM::VLD3LNqAsm_16:
6805 case ARM::VLD3LNqAsm_32: {
6806 MCInst TmpInst;
6807 // Shuffle the operands around so the lane index operand is in the
6808 // right place.
6809 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006810 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006811 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6812 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6813 Spacing));
6814 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006815 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006816 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6817 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6818 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6819 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6820 Spacing));
6821 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006822 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006823 TmpInst.addOperand(Inst.getOperand(1)); // lane
6824 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6825 TmpInst.addOperand(Inst.getOperand(5));
6826 Inst = TmpInst;
6827 return true;
6828 }
6829
Jim Grosbach14952a02012-01-24 18:37:25 +00006830 case ARM::VLD4LNdAsm_8:
6831 case ARM::VLD4LNdAsm_16:
6832 case ARM::VLD4LNdAsm_32:
6833 case ARM::VLD4LNqAsm_16:
6834 case ARM::VLD4LNqAsm_32: {
6835 MCInst TmpInst;
6836 // Shuffle the operands around so the lane index operand is in the
6837 // right place.
6838 unsigned Spacing;
6839 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6840 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6841 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6842 Spacing));
6843 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6844 Spacing * 2));
6845 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6846 Spacing * 3));
6847 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6848 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6849 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6850 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6851 Spacing));
6852 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6853 Spacing * 2));
6854 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6855 Spacing * 3));
6856 TmpInst.addOperand(Inst.getOperand(1)); // lane
6857 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6858 TmpInst.addOperand(Inst.getOperand(5));
6859 Inst = TmpInst;
6860 return true;
6861 }
6862
Jim Grosbachb78403c2012-01-24 23:47:04 +00006863 // VLD3DUP single 3-element structure to all lanes instructions.
6864 case ARM::VLD3DUPdAsm_8:
6865 case ARM::VLD3DUPdAsm_16:
6866 case ARM::VLD3DUPdAsm_32:
6867 case ARM::VLD3DUPqAsm_8:
6868 case ARM::VLD3DUPqAsm_16:
6869 case ARM::VLD3DUPqAsm_32: {
6870 MCInst TmpInst;
6871 unsigned Spacing;
6872 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6873 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6874 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6875 Spacing));
6876 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6877 Spacing * 2));
6878 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6879 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6880 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6881 TmpInst.addOperand(Inst.getOperand(4));
6882 Inst = TmpInst;
6883 return true;
6884 }
6885
6886 case ARM::VLD3DUPdWB_fixed_Asm_8:
6887 case ARM::VLD3DUPdWB_fixed_Asm_16:
6888 case ARM::VLD3DUPdWB_fixed_Asm_32:
6889 case ARM::VLD3DUPqWB_fixed_Asm_8:
6890 case ARM::VLD3DUPqWB_fixed_Asm_16:
6891 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6892 MCInst TmpInst;
6893 unsigned Spacing;
6894 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6895 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6896 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6897 Spacing));
6898 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6899 Spacing * 2));
6900 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6901 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6902 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6903 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6904 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6905 TmpInst.addOperand(Inst.getOperand(4));
6906 Inst = TmpInst;
6907 return true;
6908 }
6909
6910 case ARM::VLD3DUPdWB_register_Asm_8:
6911 case ARM::VLD3DUPdWB_register_Asm_16:
6912 case ARM::VLD3DUPdWB_register_Asm_32:
6913 case ARM::VLD3DUPqWB_register_Asm_8:
6914 case ARM::VLD3DUPqWB_register_Asm_16:
6915 case ARM::VLD3DUPqWB_register_Asm_32: {
6916 MCInst TmpInst;
6917 unsigned Spacing;
6918 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6919 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6920 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6921 Spacing));
6922 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6923 Spacing * 2));
6924 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6925 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6926 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6927 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6928 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6929 TmpInst.addOperand(Inst.getOperand(5));
6930 Inst = TmpInst;
6931 return true;
6932 }
6933
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006934 // VLD3 multiple 3-element structure instructions.
6935 case ARM::VLD3dAsm_8:
6936 case ARM::VLD3dAsm_16:
6937 case ARM::VLD3dAsm_32:
6938 case ARM::VLD3qAsm_8:
6939 case ARM::VLD3qAsm_16:
6940 case ARM::VLD3qAsm_32: {
6941 MCInst TmpInst;
6942 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006943 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006944 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6945 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6946 Spacing));
6947 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6948 Spacing * 2));
6949 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6950 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6951 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6952 TmpInst.addOperand(Inst.getOperand(4));
6953 Inst = TmpInst;
6954 return true;
6955 }
6956
6957 case ARM::VLD3dWB_fixed_Asm_8:
6958 case ARM::VLD3dWB_fixed_Asm_16:
6959 case ARM::VLD3dWB_fixed_Asm_32:
6960 case ARM::VLD3qWB_fixed_Asm_8:
6961 case ARM::VLD3qWB_fixed_Asm_16:
6962 case ARM::VLD3qWB_fixed_Asm_32: {
6963 MCInst TmpInst;
6964 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006965 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006966 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6967 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6968 Spacing));
6969 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6970 Spacing * 2));
6971 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6972 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6973 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6974 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6975 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6976 TmpInst.addOperand(Inst.getOperand(4));
6977 Inst = TmpInst;
6978 return true;
6979 }
6980
6981 case ARM::VLD3dWB_register_Asm_8:
6982 case ARM::VLD3dWB_register_Asm_16:
6983 case ARM::VLD3dWB_register_Asm_32:
6984 case ARM::VLD3qWB_register_Asm_8:
6985 case ARM::VLD3qWB_register_Asm_16:
6986 case ARM::VLD3qWB_register_Asm_32: {
6987 MCInst TmpInst;
6988 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006989 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006990 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6991 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6992 Spacing));
6993 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6994 Spacing * 2));
6995 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6996 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6997 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6998 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6999 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7000 TmpInst.addOperand(Inst.getOperand(5));
7001 Inst = TmpInst;
7002 return true;
7003 }
7004
Jim Grosbach086cbfa2012-01-25 00:01:08 +00007005 // VLD4DUP single 3-element structure to all lanes instructions.
7006 case ARM::VLD4DUPdAsm_8:
7007 case ARM::VLD4DUPdAsm_16:
7008 case ARM::VLD4DUPdAsm_32:
7009 case ARM::VLD4DUPqAsm_8:
7010 case ARM::VLD4DUPqAsm_16:
7011 case ARM::VLD4DUPqAsm_32: {
7012 MCInst TmpInst;
7013 unsigned Spacing;
7014 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7015 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7016 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7017 Spacing));
7018 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7019 Spacing * 2));
7020 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7021 Spacing * 3));
7022 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7023 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7024 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7025 TmpInst.addOperand(Inst.getOperand(4));
7026 Inst = TmpInst;
7027 return true;
7028 }
7029
7030 case ARM::VLD4DUPdWB_fixed_Asm_8:
7031 case ARM::VLD4DUPdWB_fixed_Asm_16:
7032 case ARM::VLD4DUPdWB_fixed_Asm_32:
7033 case ARM::VLD4DUPqWB_fixed_Asm_8:
7034 case ARM::VLD4DUPqWB_fixed_Asm_16:
7035 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7036 MCInst TmpInst;
7037 unsigned Spacing;
7038 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7039 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7040 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7041 Spacing));
7042 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7043 Spacing * 2));
7044 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7045 Spacing * 3));
7046 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7047 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7048 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7049 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7050 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7051 TmpInst.addOperand(Inst.getOperand(4));
7052 Inst = TmpInst;
7053 return true;
7054 }
7055
7056 case ARM::VLD4DUPdWB_register_Asm_8:
7057 case ARM::VLD4DUPdWB_register_Asm_16:
7058 case ARM::VLD4DUPdWB_register_Asm_32:
7059 case ARM::VLD4DUPqWB_register_Asm_8:
7060 case ARM::VLD4DUPqWB_register_Asm_16:
7061 case ARM::VLD4DUPqWB_register_Asm_32: {
7062 MCInst TmpInst;
7063 unsigned Spacing;
7064 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7065 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7066 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7067 Spacing));
7068 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7069 Spacing * 2));
7070 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7071 Spacing * 3));
7072 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7073 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7074 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7075 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7076 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7077 TmpInst.addOperand(Inst.getOperand(5));
7078 Inst = TmpInst;
7079 return true;
7080 }
7081
7082 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00007083 case ARM::VLD4dAsm_8:
7084 case ARM::VLD4dAsm_16:
7085 case ARM::VLD4dAsm_32:
7086 case ARM::VLD4qAsm_8:
7087 case ARM::VLD4qAsm_16:
7088 case ARM::VLD4qAsm_32: {
7089 MCInst TmpInst;
7090 unsigned Spacing;
7091 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7092 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7093 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7094 Spacing));
7095 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7096 Spacing * 2));
7097 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7098 Spacing * 3));
7099 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7100 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7101 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7102 TmpInst.addOperand(Inst.getOperand(4));
7103 Inst = TmpInst;
7104 return true;
7105 }
7106
7107 case ARM::VLD4dWB_fixed_Asm_8:
7108 case ARM::VLD4dWB_fixed_Asm_16:
7109 case ARM::VLD4dWB_fixed_Asm_32:
7110 case ARM::VLD4qWB_fixed_Asm_8:
7111 case ARM::VLD4qWB_fixed_Asm_16:
7112 case ARM::VLD4qWB_fixed_Asm_32: {
7113 MCInst TmpInst;
7114 unsigned Spacing;
7115 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7116 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7117 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7118 Spacing));
7119 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7120 Spacing * 2));
7121 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7122 Spacing * 3));
7123 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7124 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7125 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7126 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7127 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7128 TmpInst.addOperand(Inst.getOperand(4));
7129 Inst = TmpInst;
7130 return true;
7131 }
7132
7133 case ARM::VLD4dWB_register_Asm_8:
7134 case ARM::VLD4dWB_register_Asm_16:
7135 case ARM::VLD4dWB_register_Asm_32:
7136 case ARM::VLD4qWB_register_Asm_8:
7137 case ARM::VLD4qWB_register_Asm_16:
7138 case ARM::VLD4qWB_register_Asm_32: {
7139 MCInst TmpInst;
7140 unsigned Spacing;
7141 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7142 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7143 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7144 Spacing));
7145 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7146 Spacing * 2));
7147 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7148 Spacing * 3));
7149 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7150 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7151 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7152 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7153 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7154 TmpInst.addOperand(Inst.getOperand(5));
7155 Inst = TmpInst;
7156 return true;
7157 }
7158
Jim Grosbach1a747242012-01-23 23:45:44 +00007159 // VST3 multiple 3-element structure instructions.
7160 case ARM::VST3dAsm_8:
7161 case ARM::VST3dAsm_16:
7162 case ARM::VST3dAsm_32:
7163 case ARM::VST3qAsm_8:
7164 case ARM::VST3qAsm_16:
7165 case ARM::VST3qAsm_32: {
7166 MCInst TmpInst;
7167 unsigned Spacing;
7168 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7169 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7170 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7171 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7172 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7173 Spacing));
7174 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7175 Spacing * 2));
7176 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7177 TmpInst.addOperand(Inst.getOperand(4));
7178 Inst = TmpInst;
7179 return true;
7180 }
7181
7182 case ARM::VST3dWB_fixed_Asm_8:
7183 case ARM::VST3dWB_fixed_Asm_16:
7184 case ARM::VST3dWB_fixed_Asm_32:
7185 case ARM::VST3qWB_fixed_Asm_8:
7186 case ARM::VST3qWB_fixed_Asm_16:
7187 case ARM::VST3qWB_fixed_Asm_32: {
7188 MCInst TmpInst;
7189 unsigned Spacing;
7190 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7191 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7192 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7193 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7194 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7195 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7196 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7197 Spacing));
7198 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7199 Spacing * 2));
7200 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7201 TmpInst.addOperand(Inst.getOperand(4));
7202 Inst = TmpInst;
7203 return true;
7204 }
7205
7206 case ARM::VST3dWB_register_Asm_8:
7207 case ARM::VST3dWB_register_Asm_16:
7208 case ARM::VST3dWB_register_Asm_32:
7209 case ARM::VST3qWB_register_Asm_8:
7210 case ARM::VST3qWB_register_Asm_16:
7211 case ARM::VST3qWB_register_Asm_32: {
7212 MCInst TmpInst;
7213 unsigned Spacing;
7214 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7215 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7216 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7217 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7218 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7219 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7220 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7221 Spacing));
7222 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7223 Spacing * 2));
7224 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7225 TmpInst.addOperand(Inst.getOperand(5));
7226 Inst = TmpInst;
7227 return true;
7228 }
7229
Jim Grosbachda70eac2012-01-24 00:58:13 +00007230 // VST4 multiple 3-element structure instructions.
7231 case ARM::VST4dAsm_8:
7232 case ARM::VST4dAsm_16:
7233 case ARM::VST4dAsm_32:
7234 case ARM::VST4qAsm_8:
7235 case ARM::VST4qAsm_16:
7236 case ARM::VST4qAsm_32: {
7237 MCInst TmpInst;
7238 unsigned Spacing;
7239 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7240 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7241 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7242 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7243 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7244 Spacing));
7245 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7246 Spacing * 2));
7247 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7248 Spacing * 3));
7249 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7250 TmpInst.addOperand(Inst.getOperand(4));
7251 Inst = TmpInst;
7252 return true;
7253 }
7254
7255 case ARM::VST4dWB_fixed_Asm_8:
7256 case ARM::VST4dWB_fixed_Asm_16:
7257 case ARM::VST4dWB_fixed_Asm_32:
7258 case ARM::VST4qWB_fixed_Asm_8:
7259 case ARM::VST4qWB_fixed_Asm_16:
7260 case ARM::VST4qWB_fixed_Asm_32: {
7261 MCInst TmpInst;
7262 unsigned Spacing;
7263 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7264 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7265 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7266 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7267 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7268 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7269 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7270 Spacing));
7271 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7272 Spacing * 2));
7273 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7274 Spacing * 3));
7275 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7276 TmpInst.addOperand(Inst.getOperand(4));
7277 Inst = TmpInst;
7278 return true;
7279 }
7280
7281 case ARM::VST4dWB_register_Asm_8:
7282 case ARM::VST4dWB_register_Asm_16:
7283 case ARM::VST4dWB_register_Asm_32:
7284 case ARM::VST4qWB_register_Asm_8:
7285 case ARM::VST4qWB_register_Asm_16:
7286 case ARM::VST4qWB_register_Asm_32: {
7287 MCInst TmpInst;
7288 unsigned Spacing;
7289 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7290 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7291 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7292 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7293 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7294 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() +
7298 Spacing * 2));
7299 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7300 Spacing * 3));
7301 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7302 TmpInst.addOperand(Inst.getOperand(5));
7303 Inst = TmpInst;
7304 return true;
7305 }
7306
Jim Grosbachad66de12012-04-11 00:15:16 +00007307 // Handle encoding choice for the shift-immediate instructions.
7308 case ARM::t2LSLri:
7309 case ARM::t2LSRri:
7310 case ARM::t2ASRri: {
7311 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7312 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7313 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007314 !(static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7315 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) {
Jim Grosbachad66de12012-04-11 00:15:16 +00007316 unsigned NewOpc;
7317 switch (Inst.getOpcode()) {
7318 default: llvm_unreachable("unexpected opcode");
7319 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7320 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7321 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7322 }
7323 // The Thumb1 operands aren't in the same order. Awesome, eh?
7324 MCInst TmpInst;
7325 TmpInst.setOpcode(NewOpc);
7326 TmpInst.addOperand(Inst.getOperand(0));
7327 TmpInst.addOperand(Inst.getOperand(5));
7328 TmpInst.addOperand(Inst.getOperand(1));
7329 TmpInst.addOperand(Inst.getOperand(2));
7330 TmpInst.addOperand(Inst.getOperand(3));
7331 TmpInst.addOperand(Inst.getOperand(4));
7332 Inst = TmpInst;
7333 return true;
7334 }
7335 return false;
7336 }
7337
Jim Grosbach485e5622011-12-13 22:45:11 +00007338 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007339 case ARM::t2MOVsr:
7340 case ARM::t2MOVSsr: {
7341 // Which instruction to expand to depends on the CCOut operand and
7342 // whether we're in an IT block if the register operands are low
7343 // registers.
7344 bool isNarrow = false;
7345 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7346 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7347 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7348 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7349 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7350 isNarrow = true;
7351 MCInst TmpInst;
7352 unsigned newOpc;
7353 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7354 default: llvm_unreachable("unexpected opcode!");
7355 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7356 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7357 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7358 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7359 }
7360 TmpInst.setOpcode(newOpc);
7361 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7362 if (isNarrow)
7363 TmpInst.addOperand(MCOperand::CreateReg(
7364 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7365 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7366 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7367 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7368 TmpInst.addOperand(Inst.getOperand(5));
7369 if (!isNarrow)
7370 TmpInst.addOperand(MCOperand::CreateReg(
7371 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7372 Inst = TmpInst;
7373 return true;
7374 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007375 case ARM::t2MOVsi:
7376 case ARM::t2MOVSsi: {
7377 // Which instruction to expand to depends on the CCOut operand and
7378 // whether we're in an IT block if the register operands are low
7379 // registers.
7380 bool isNarrow = false;
7381 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7382 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7383 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7384 isNarrow = true;
7385 MCInst TmpInst;
7386 unsigned newOpc;
7387 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7388 default: llvm_unreachable("unexpected opcode!");
7389 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7390 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7391 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7392 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007393 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007394 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007395 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7396 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007397 TmpInst.setOpcode(newOpc);
7398 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7399 if (isNarrow)
7400 TmpInst.addOperand(MCOperand::CreateReg(
7401 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7402 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007403 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007404 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007405 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7406 TmpInst.addOperand(Inst.getOperand(4));
7407 if (!isNarrow)
7408 TmpInst.addOperand(MCOperand::CreateReg(
7409 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7410 Inst = TmpInst;
7411 return true;
7412 }
7413 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007414 case ARM::ASRr:
7415 case ARM::LSRr:
7416 case ARM::LSLr:
7417 case ARM::RORr: {
7418 ARM_AM::ShiftOpc ShiftTy;
7419 switch(Inst.getOpcode()) {
7420 default: llvm_unreachable("unexpected opcode!");
7421 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7422 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7423 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7424 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7425 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007426 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7427 MCInst TmpInst;
7428 TmpInst.setOpcode(ARM::MOVsr);
7429 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7430 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7431 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7432 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7433 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7434 TmpInst.addOperand(Inst.getOperand(4));
7435 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7436 Inst = TmpInst;
7437 return true;
7438 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007439 case ARM::ASRi:
7440 case ARM::LSRi:
7441 case ARM::LSLi:
7442 case ARM::RORi: {
7443 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007444 switch(Inst.getOpcode()) {
7445 default: llvm_unreachable("unexpected opcode!");
7446 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7447 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7448 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7449 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7450 }
7451 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007452 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007453 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007454 // A shift by 32 should be encoded as 0 when permitted
7455 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7456 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007457 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007458 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007459 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007460 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7461 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007462 if (Opc == ARM::MOVsi)
7463 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007464 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7465 TmpInst.addOperand(Inst.getOperand(4));
7466 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7467 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007468 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007469 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007470 case ARM::RRXi: {
7471 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7472 MCInst TmpInst;
7473 TmpInst.setOpcode(ARM::MOVsi);
7474 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7475 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7476 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7477 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7478 TmpInst.addOperand(Inst.getOperand(3));
7479 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7480 Inst = TmpInst;
7481 return true;
7482 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007483 case ARM::t2LDMIA_UPD: {
7484 // If this is a load of a single register, then we should use
7485 // a post-indexed LDR instruction instead, per the ARM ARM.
7486 if (Inst.getNumOperands() != 5)
7487 return false;
7488 MCInst TmpInst;
7489 TmpInst.setOpcode(ARM::t2LDR_POST);
7490 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7491 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7492 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7493 TmpInst.addOperand(MCOperand::CreateImm(4));
7494 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7495 TmpInst.addOperand(Inst.getOperand(3));
7496 Inst = TmpInst;
7497 return true;
7498 }
7499 case ARM::t2STMDB_UPD: {
7500 // If this is a store of a single register, then we should use
7501 // a pre-indexed STR instruction instead, per the ARM ARM.
7502 if (Inst.getNumOperands() != 5)
7503 return false;
7504 MCInst TmpInst;
7505 TmpInst.setOpcode(ARM::t2STR_PRE);
7506 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7507 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7508 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7509 TmpInst.addOperand(MCOperand::CreateImm(-4));
7510 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7511 TmpInst.addOperand(Inst.getOperand(3));
7512 Inst = TmpInst;
7513 return true;
7514 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007515 case ARM::LDMIA_UPD:
7516 // If this is a load of a single register via a 'pop', then we should use
7517 // a post-indexed LDR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00007518 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007519 Inst.getNumOperands() == 5) {
7520 MCInst TmpInst;
7521 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7522 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7523 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7524 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7525 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7526 TmpInst.addOperand(MCOperand::CreateImm(4));
7527 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7528 TmpInst.addOperand(Inst.getOperand(3));
7529 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007530 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007531 }
7532 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007533 case ARM::STMDB_UPD:
7534 // If this is a store of a single register via a 'push', then we should use
7535 // a pre-indexed STR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00007536 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007537 Inst.getNumOperands() == 5) {
7538 MCInst TmpInst;
7539 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7540 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7541 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7542 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7543 TmpInst.addOperand(MCOperand::CreateImm(-4));
7544 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7545 TmpInst.addOperand(Inst.getOperand(3));
7546 Inst = TmpInst;
7547 }
7548 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007549 case ARM::t2ADDri12:
7550 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7551 // mnemonic was used (not "addw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00007552 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00007553 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7554 break;
7555 Inst.setOpcode(ARM::t2ADDri);
7556 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7557 break;
7558 case ARM::t2SUBri12:
7559 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7560 // mnemonic was used (not "subw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00007561 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00007562 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7563 break;
7564 Inst.setOpcode(ARM::t2SUBri);
7565 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7566 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007567 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007568 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007569 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7570 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7571 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007572 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007573 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007574 return true;
7575 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007576 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007577 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007578 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007579 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7580 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7581 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007582 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007583 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007584 return true;
7585 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007586 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007587 case ARM::t2ADDri:
7588 case ARM::t2SUBri: {
7589 // If the destination and first source operand are the same, and
7590 // the flags are compatible with the current IT status, use encoding T2
7591 // instead of T3. For compatibility with the system 'as'. Make sure the
7592 // wide encoding wasn't explicit.
7593 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007594 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007595 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7596 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00007597 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7598 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7599 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbachdef5e342012-03-30 17:20:40 +00007600 break;
7601 MCInst TmpInst;
7602 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7603 ARM::tADDi8 : ARM::tSUBi8);
7604 TmpInst.addOperand(Inst.getOperand(0));
7605 TmpInst.addOperand(Inst.getOperand(5));
7606 TmpInst.addOperand(Inst.getOperand(0));
7607 TmpInst.addOperand(Inst.getOperand(2));
7608 TmpInst.addOperand(Inst.getOperand(3));
7609 TmpInst.addOperand(Inst.getOperand(4));
7610 Inst = TmpInst;
7611 return true;
7612 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007613 case ARM::t2ADDrr: {
7614 // If the destination and first source operand are the same, and
7615 // there's no setting of the flags, use encoding T2 instead of T3.
7616 // Note that this is only for ADD, not SUB. This mirrors the system
7617 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7618 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7619 Inst.getOperand(5).getReg() != 0 ||
David Blaikie960ea3f2014-06-08 16:18:35 +00007620 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7621 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007622 break;
7623 MCInst TmpInst;
7624 TmpInst.setOpcode(ARM::tADDhirr);
7625 TmpInst.addOperand(Inst.getOperand(0));
7626 TmpInst.addOperand(Inst.getOperand(0));
7627 TmpInst.addOperand(Inst.getOperand(2));
7628 TmpInst.addOperand(Inst.getOperand(3));
7629 TmpInst.addOperand(Inst.getOperand(4));
7630 Inst = TmpInst;
7631 return true;
7632 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007633 case ARM::tADDrSP: {
7634 // If the non-SP source operand and the destination operand are not the
7635 // same, we need to use the 32-bit encoding if it's available.
7636 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7637 Inst.setOpcode(ARM::t2ADDrr);
7638 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7639 return true;
7640 }
7641 break;
7642 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007643 case ARM::tB:
7644 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007645 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007646 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007647 return true;
7648 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007649 break;
7650 case ARM::t2B:
7651 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007652 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007653 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007654 return true;
7655 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007656 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007657 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007658 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007659 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007660 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007661 return true;
7662 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007663 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007664 case ARM::tBcc:
7665 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007666 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007667 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007668 return true;
7669 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007670 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007671 case ARM::tLDMIA: {
7672 // If the register list contains any high registers, or if the writeback
7673 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7674 // instead if we're in Thumb2. Otherwise, this should have generated
7675 // an error in validateInstruction().
7676 unsigned Rn = Inst.getOperand(0).getReg();
7677 bool hasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00007678 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7679 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Jim Grosbacha31f2232011-09-07 18:05:34 +00007680 bool listContainsBase;
7681 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7682 (!listContainsBase && !hasWritebackToken) ||
7683 (listContainsBase && hasWritebackToken)) {
7684 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7685 assert (isThumbTwo());
7686 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7687 // If we're switching to the updating version, we need to insert
7688 // the writeback tied operand.
7689 if (hasWritebackToken)
7690 Inst.insert(Inst.begin(),
7691 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007692 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007693 }
7694 break;
7695 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007696 case ARM::tSTMIA_UPD: {
7697 // If the register list contains any high registers, we need to use
7698 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7699 // should have generated an error in validateInstruction().
7700 unsigned Rn = Inst.getOperand(0).getReg();
7701 bool listContainsBase;
7702 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7703 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7704 assert (isThumbTwo());
7705 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007706 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007707 }
7708 break;
7709 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007710 case ARM::tPOP: {
7711 bool listContainsBase;
7712 // If the register list contains any high registers, we need to use
7713 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7714 // should have generated an error in validateInstruction().
7715 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007716 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007717 assert (isThumbTwo());
7718 Inst.setOpcode(ARM::t2LDMIA_UPD);
7719 // Add the base register and writeback operands.
7720 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7721 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007722 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007723 }
7724 case ARM::tPUSH: {
7725 bool listContainsBase;
7726 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007727 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007728 assert (isThumbTwo());
7729 Inst.setOpcode(ARM::t2STMDB_UPD);
7730 // Add the base register and writeback operands.
7731 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7732 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007733 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007734 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007735 case ARM::t2MOVi: {
7736 // If we can use the 16-bit encoding and the user didn't explicitly
7737 // request the 32-bit variant, transform it here.
7738 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007739 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007740 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007741 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7742 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7743 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
7744 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007745 // The operands aren't in the same order for tMOVi8...
7746 MCInst TmpInst;
7747 TmpInst.setOpcode(ARM::tMOVi8);
7748 TmpInst.addOperand(Inst.getOperand(0));
7749 TmpInst.addOperand(Inst.getOperand(4));
7750 TmpInst.addOperand(Inst.getOperand(1));
7751 TmpInst.addOperand(Inst.getOperand(2));
7752 TmpInst.addOperand(Inst.getOperand(3));
7753 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007754 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007755 }
7756 break;
7757 }
7758 case ARM::t2MOVr: {
7759 // If we can use the 16-bit encoding and the user didn't explicitly
7760 // request the 32-bit variant, transform it here.
7761 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7762 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7763 Inst.getOperand(2).getImm() == ARMCC::AL &&
7764 Inst.getOperand(4).getReg() == ARM::CPSR &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007765 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
7766 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007767 // The operands aren't the same for tMOV[S]r... (no cc_out)
7768 MCInst TmpInst;
7769 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7770 TmpInst.addOperand(Inst.getOperand(0));
7771 TmpInst.addOperand(Inst.getOperand(1));
7772 TmpInst.addOperand(Inst.getOperand(2));
7773 TmpInst.addOperand(Inst.getOperand(3));
7774 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007775 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007776 }
7777 break;
7778 }
Jim Grosbach82213192011-09-19 20:29:33 +00007779 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007780 case ARM::t2SXTB:
7781 case ARM::t2UXTH:
7782 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007783 // If we can use the 16-bit encoding and the user didn't explicitly
7784 // request the 32-bit variant, transform it here.
7785 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7786 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7787 Inst.getOperand(2).getImm() == 0 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007788 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
7789 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007790 unsigned NewOpc;
7791 switch (Inst.getOpcode()) {
7792 default: llvm_unreachable("Illegal opcode!");
7793 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7794 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7795 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7796 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7797 }
Jim Grosbach82213192011-09-19 20:29:33 +00007798 // The operands aren't the same for thumb1 (no rotate operand).
7799 MCInst TmpInst;
7800 TmpInst.setOpcode(NewOpc);
7801 TmpInst.addOperand(Inst.getOperand(0));
7802 TmpInst.addOperand(Inst.getOperand(1));
7803 TmpInst.addOperand(Inst.getOperand(3));
7804 TmpInst.addOperand(Inst.getOperand(4));
7805 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007806 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007807 }
7808 break;
7809 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007810 case ARM::MOVsi: {
7811 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007812 // rrx shifts and asr/lsr of #32 is encoded as 0
7813 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7814 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007815 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7816 // Shifting by zero is accepted as a vanilla 'MOVr'
7817 MCInst TmpInst;
7818 TmpInst.setOpcode(ARM::MOVr);
7819 TmpInst.addOperand(Inst.getOperand(0));
7820 TmpInst.addOperand(Inst.getOperand(1));
7821 TmpInst.addOperand(Inst.getOperand(3));
7822 TmpInst.addOperand(Inst.getOperand(4));
7823 TmpInst.addOperand(Inst.getOperand(5));
7824 Inst = TmpInst;
7825 return true;
7826 }
7827 return false;
7828 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007829 case ARM::ANDrsi:
7830 case ARM::ORRrsi:
7831 case ARM::EORrsi:
7832 case ARM::BICrsi:
7833 case ARM::SUBrsi:
7834 case ARM::ADDrsi: {
7835 unsigned newOpc;
7836 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7837 if (SOpc == ARM_AM::rrx) return false;
7838 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007839 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007840 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7841 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7842 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7843 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7844 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7845 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7846 }
7847 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007848 // The exception is for right shifts, where 0 == 32
7849 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7850 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007851 MCInst TmpInst;
7852 TmpInst.setOpcode(newOpc);
7853 TmpInst.addOperand(Inst.getOperand(0));
7854 TmpInst.addOperand(Inst.getOperand(1));
7855 TmpInst.addOperand(Inst.getOperand(2));
7856 TmpInst.addOperand(Inst.getOperand(4));
7857 TmpInst.addOperand(Inst.getOperand(5));
7858 TmpInst.addOperand(Inst.getOperand(6));
7859 Inst = TmpInst;
7860 return true;
7861 }
7862 return false;
7863 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007864 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007865 case ARM::t2IT: {
7866 // The mask bits for all but the first condition are represented as
7867 // the low bit of the condition code value implies 't'. We currently
7868 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007869 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007870 MCOperand &MO = Inst.getOperand(1);
7871 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007872 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007873 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007874 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007875 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007876 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007877 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007878 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007879
7880 // Set up the IT block state according to the IT instruction we just
7881 // matched.
7882 assert(!inITBlock() && "nested IT blocks?!");
7883 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7884 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7885 ITState.CurPosition = 0;
7886 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007887 break;
7888 }
Richard Bartona39625e2012-07-09 16:12:24 +00007889 case ARM::t2LSLrr:
7890 case ARM::t2LSRrr:
7891 case ARM::t2ASRrr:
7892 case ARM::t2SBCrr:
7893 case ARM::t2RORrr:
7894 case ARM::t2BICrr:
7895 {
Richard Bartond5660372012-07-09 16:14:28 +00007896 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007897 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7898 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7899 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007900 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00007901 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7902 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
7903 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
7904 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00007905 unsigned NewOpc;
7906 switch (Inst.getOpcode()) {
7907 default: llvm_unreachable("unexpected opcode");
7908 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7909 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7910 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7911 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7912 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7913 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7914 }
7915 MCInst TmpInst;
7916 TmpInst.setOpcode(NewOpc);
7917 TmpInst.addOperand(Inst.getOperand(0));
7918 TmpInst.addOperand(Inst.getOperand(5));
7919 TmpInst.addOperand(Inst.getOperand(1));
7920 TmpInst.addOperand(Inst.getOperand(2));
7921 TmpInst.addOperand(Inst.getOperand(3));
7922 TmpInst.addOperand(Inst.getOperand(4));
7923 Inst = TmpInst;
7924 return true;
7925 }
7926 return false;
7927 }
7928 case ARM::t2ANDrr:
7929 case ARM::t2EORrr:
7930 case ARM::t2ADCrr:
7931 case ARM::t2ORRrr:
7932 {
Richard Bartond5660372012-07-09 16:14:28 +00007933 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007934 // These instructions are special in that they are commutable, so shorter encodings
7935 // are available more often.
7936 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7937 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7938 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7939 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007940 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00007941 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7942 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
7943 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
7944 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00007945 unsigned NewOpc;
7946 switch (Inst.getOpcode()) {
7947 default: llvm_unreachable("unexpected opcode");
7948 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7949 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7950 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7951 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7952 }
7953 MCInst TmpInst;
7954 TmpInst.setOpcode(NewOpc);
7955 TmpInst.addOperand(Inst.getOperand(0));
7956 TmpInst.addOperand(Inst.getOperand(5));
7957 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7958 TmpInst.addOperand(Inst.getOperand(1));
7959 TmpInst.addOperand(Inst.getOperand(2));
7960 } else {
7961 TmpInst.addOperand(Inst.getOperand(2));
7962 TmpInst.addOperand(Inst.getOperand(1));
7963 }
7964 TmpInst.addOperand(Inst.getOperand(3));
7965 TmpInst.addOperand(Inst.getOperand(4));
7966 Inst = TmpInst;
7967 return true;
7968 }
7969 return false;
7970 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007971 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007972 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007973}
7974
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007975unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7976 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7977 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007978 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007979 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007980 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7981 assert(MCID.hasOptionalDef() &&
7982 "optionally flag setting instruction missing optional def operand");
7983 assert(MCID.NumOperands == Inst.getNumOperands() &&
7984 "operand count mismatch!");
7985 // Find the optional-def operand (cc_out).
7986 unsigned OpNo;
7987 for (OpNo = 0;
7988 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7989 ++OpNo)
7990 ;
7991 // If we're parsing Thumb1, reject it completely.
7992 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7993 return Match_MnemonicFail;
7994 // If we're parsing Thumb2, which form is legal depends on whether we're
7995 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007996 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7997 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007998 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007999 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8000 inITBlock())
8001 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008002 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008003 // Some high-register supporting Thumb1 encodings only allow both registers
8004 // to be from r0-r7 when in Thumb2.
8005 else if (Opc == ARM::tADDhirr && isThumbOne() &&
8006 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8007 isARMLowRegister(Inst.getOperand(2).getReg()))
8008 return Match_RequiresThumb2;
8009 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00008010 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008011 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8012 isARMLowRegister(Inst.getOperand(1).getReg()))
8013 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008014 return Match_Success;
8015}
8016
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008017namespace llvm {
8018template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008019 return true; // In an assembly source, no need to second-guess
8020}
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008021}
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008022
Jim Grosbach5117ef72012-04-24 22:40:08 +00008023static const char *getSubtargetFeatureName(unsigned Val);
David Blaikie960ea3f2014-06-08 16:18:35 +00008024bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
8025 OperandVector &Operands,
8026 MCStreamer &Out, unsigned &ErrorInfo,
8027 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00008028 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00008029 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00008030
Chad Rosier2f480a82012-10-12 22:53:36 +00008031 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00008032 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00008033 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00008034 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008035 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008036 // Context sensitive operand constraints aren't handled by the matcher,
8037 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008038 if (validateInstruction(Inst, Operands)) {
8039 // Still progress the IT block, otherwise one wrong condition causes
8040 // nasty cascading errors.
8041 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008042 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008043 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008044
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008045 { // processInstruction() updates inITBlock state, we need to save it away
8046 bool wasInITBlock = inITBlock();
8047
8048 // Some instructions need post-processing to, for example, tweak which
8049 // encoding is selected. Loop on it while changes happen so the
8050 // individual transformations can chain off each other. E.g.,
8051 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
8052 while (processInstruction(Inst, Operands))
8053 ;
8054
8055 // Only after the instruction is fully processed, we can validate it
8056 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00008057 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008058 Warning(IDLoc, "deprecated instruction in IT block");
8059 }
8060 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008061
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008062 // Only move forward at the very end so that everything in validate
8063 // and process gets a consistent answer about whether we're in an IT
8064 // block.
8065 forwardITPosition();
8066
Jim Grosbach82f76d12012-01-25 19:52:01 +00008067 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8068 // doesn't actually encode.
8069 if (Inst.getOpcode() == ARM::ITasm)
8070 return false;
8071
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00008072 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00008073 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00008074 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008075 case Match_MissingFeature: {
8076 assert(ErrorInfo && "Unknown missing feature!");
8077 // Special case the error message for the very common case where only
8078 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8079 std::string Msg = "instruction requires:";
8080 unsigned Mask = 1;
8081 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8082 if (ErrorInfo & Mask) {
8083 Msg += " ";
8084 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8085 }
8086 Mask <<= 1;
8087 }
8088 return Error(IDLoc, Msg);
8089 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008090 case Match_InvalidOperand: {
8091 SMLoc ErrorLoc = IDLoc;
8092 if (ErrorInfo != ~0U) {
8093 if (ErrorInfo >= Operands.size())
8094 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00008095
David Blaikie960ea3f2014-06-08 16:18:35 +00008096 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008097 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8098 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008099
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008100 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00008101 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008102 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00008103 return Error(IDLoc, "invalid instruction",
David Blaikie960ea3f2014-06-08 16:18:35 +00008104 ((ARMOperand &)*Operands[0]).getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00008105 case Match_RequiresNotITBlock:
8106 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008107 case Match_RequiresITBlock:
8108 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008109 case Match_RequiresV6:
8110 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8111 case Match_RequiresThumb2:
8112 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00008113 case Match_ImmRange0_15: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008114 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Jim Grosbach087affe2012-06-22 23:56:48 +00008115 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8116 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8117 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008118 case Match_ImmRange0_239: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008119 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008120 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8121 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8122 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00008123 case Match_AlignedMemoryRequiresNone:
8124 case Match_DupAlignedMemoryRequiresNone:
8125 case Match_AlignedMemoryRequires16:
8126 case Match_DupAlignedMemoryRequires16:
8127 case Match_AlignedMemoryRequires32:
8128 case Match_DupAlignedMemoryRequires32:
8129 case Match_AlignedMemoryRequires64:
8130 case Match_DupAlignedMemoryRequires64:
8131 case Match_AlignedMemoryRequires64or128:
8132 case Match_DupAlignedMemoryRequires64or128:
8133 case Match_AlignedMemoryRequires64or128or256:
8134 {
David Blaikie960ea3f2014-06-08 16:18:35 +00008135 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00008136 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8137 switch (MatchResult) {
8138 default:
8139 llvm_unreachable("Missing Match_Aligned type");
8140 case Match_AlignedMemoryRequiresNone:
8141 case Match_DupAlignedMemoryRequiresNone:
8142 return Error(ErrorLoc, "alignment must be omitted");
8143 case Match_AlignedMemoryRequires16:
8144 case Match_DupAlignedMemoryRequires16:
8145 return Error(ErrorLoc, "alignment must be 16 or omitted");
8146 case Match_AlignedMemoryRequires32:
8147 case Match_DupAlignedMemoryRequires32:
8148 return Error(ErrorLoc, "alignment must be 32 or omitted");
8149 case Match_AlignedMemoryRequires64:
8150 case Match_DupAlignedMemoryRequires64:
8151 return Error(ErrorLoc, "alignment must be 64 or omitted");
8152 case Match_AlignedMemoryRequires64or128:
8153 case Match_DupAlignedMemoryRequires64or128:
8154 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8155 case Match_AlignedMemoryRequires64or128or256:
8156 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8157 }
8158 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008159 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008160
Eric Christopher91d7b902010-10-29 09:26:59 +00008161 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00008162}
8163
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008164/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00008165bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008166 const MCObjectFileInfo::Environment Format =
8167 getContext().getObjectFileInfo()->getObjectFileType();
8168 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
8169
Kevin Enderbyccab3172009-09-15 00:27:25 +00008170 StringRef IDVal = DirectiveID.getIdentifier();
8171 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008172 return parseLiteralValues(4, DirectiveID.getLoc());
8173 else if (IDVal == ".short" || IDVal == ".hword")
8174 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008175 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008176 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00008177 else if (IDVal == ".arm")
8178 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008179 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008180 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008181 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008182 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008183 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008184 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008185 else if (IDVal == ".unreq")
8186 return parseDirectiveUnreq(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00008187 else if (IDVal == ".fnend")
8188 return parseDirectiveFnEnd(DirectiveID.getLoc());
8189 else if (IDVal == ".cantunwind")
8190 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8191 else if (IDVal == ".personality")
8192 return parseDirectivePersonality(DirectiveID.getLoc());
8193 else if (IDVal == ".handlerdata")
8194 return parseDirectiveHandlerData(DirectiveID.getLoc());
8195 else if (IDVal == ".setfp")
8196 return parseDirectiveSetFP(DirectiveID.getLoc());
8197 else if (IDVal == ".pad")
8198 return parseDirectivePad(DirectiveID.getLoc());
8199 else if (IDVal == ".save")
8200 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8201 else if (IDVal == ".vsave")
8202 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008203 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008204 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008205 else if (IDVal == ".even")
8206 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008207 else if (IDVal == ".personalityindex")
8208 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008209 else if (IDVal == ".unwind_raw")
8210 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008211 else if (IDVal == ".movsp")
8212 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008213 else if (IDVal == ".arch_extension")
8214 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008215 else if (IDVal == ".align")
8216 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008217 else if (IDVal == ".thumb_set")
8218 return parseDirectiveThumbSet(DirectiveID.getLoc());
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008219
8220 if (!IsMachO) {
8221 if (IDVal == ".arch")
8222 return parseDirectiveArch(DirectiveID.getLoc());
8223 else if (IDVal == ".cpu")
8224 return parseDirectiveCPU(DirectiveID.getLoc());
8225 else if (IDVal == ".eabi_attribute")
8226 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8227 else if (IDVal == ".fpu")
8228 return parseDirectiveFPU(DirectiveID.getLoc());
8229 else if (IDVal == ".fnstart")
8230 return parseDirectiveFnStart(DirectiveID.getLoc());
8231 else if (IDVal == ".inst")
8232 return parseDirectiveInst(DirectiveID.getLoc());
8233 else if (IDVal == ".inst.n")
8234 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8235 else if (IDVal == ".inst.w")
8236 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8237 else if (IDVal == ".object_arch")
8238 return parseDirectiveObjectArch(DirectiveID.getLoc());
8239 else if (IDVal == ".tlsdescseq")
8240 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8241 }
8242
Kevin Enderbyccab3172009-09-15 00:27:25 +00008243 return true;
8244}
8245
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008246/// parseLiteralValues
8247/// ::= .hword expression [, expression]*
8248/// ::= .short expression [, expression]*
8249/// ::= .word expression [, expression]*
8250bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00008251 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8252 for (;;) {
8253 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008254 if (getParser().parseExpression(Value)) {
8255 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008256 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008257 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008258
Eric Christopherbf7bc492013-01-09 03:52:05 +00008259 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008260
8261 if (getLexer().is(AsmToken::EndOfStatement))
8262 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008263
Kevin Enderbyccab3172009-09-15 00:27:25 +00008264 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008265 if (getLexer().isNot(AsmToken::Comma)) {
8266 Error(L, "unexpected token in directive");
8267 return false;
8268 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008269 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008270 }
8271 }
8272
Sean Callanana83fd7d2010-01-19 20:27:46 +00008273 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008274 return false;
8275}
8276
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008277/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008278/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008279bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008280 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8281 Error(L, "unexpected token in directive");
8282 return false;
8283 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008284 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008285
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008286 if (!hasThumb()) {
8287 Error(L, "target does not support Thumb mode");
8288 return false;
8289 }
Tim Northovera2292d02013-06-10 23:20:58 +00008290
Jim Grosbach7f882392011-12-07 18:04:19 +00008291 if (!isThumb())
8292 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008293
Jim Grosbach7f882392011-12-07 18:04:19 +00008294 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8295 return false;
8296}
8297
8298/// parseDirectiveARM
8299/// ::= .arm
8300bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008301 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8302 Error(L, "unexpected token in directive");
8303 return false;
8304 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008305 Parser.Lex();
8306
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008307 if (!hasARM()) {
8308 Error(L, "target does not support ARM mode");
8309 return false;
8310 }
Tim Northovera2292d02013-06-10 23:20:58 +00008311
Jim Grosbach7f882392011-12-07 18:04:19 +00008312 if (isThumb())
8313 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008314
Jim Grosbach7f882392011-12-07 18:04:19 +00008315 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008316 return false;
8317}
8318
Tim Northover1744d0a2013-10-25 12:49:50 +00008319void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8320 if (NextSymbolIsThumb) {
8321 getParser().getStreamer().EmitThumbFunc(Symbol);
8322 NextSymbolIsThumb = false;
8323 }
8324}
8325
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008326/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008327/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008328bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00008329 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8330 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008331
Jim Grosbach1152cc02011-12-21 22:30:16 +00008332 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008333 // ELF doesn't
8334 if (isMachO) {
8335 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008336 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008337 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8338 Error(L, "unexpected token in .thumb_func directive");
8339 return false;
8340 }
8341
Tim Northover1744d0a2013-10-25 12:49:50 +00008342 MCSymbol *Func =
8343 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8344 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008345 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008346 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008347 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008348 }
8349
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008350 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8351 Error(L, "unexpected token in directive");
8352 return false;
8353 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008354
Tim Northover1744d0a2013-10-25 12:49:50 +00008355 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008356 return false;
8357}
8358
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008359/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008360/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008361bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008362 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008363 if (Tok.isNot(AsmToken::Identifier)) {
8364 Error(L, "unexpected token in .syntax directive");
8365 return false;
8366 }
8367
Benjamin Kramer92d89982010-07-14 22:38:02 +00008368 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008369 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008370 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008371 } else if (Mode == "divided" || Mode == "DIVIDED") {
8372 Error(L, "'.syntax divided' arm asssembly not supported");
8373 return false;
8374 } else {
8375 Error(L, "unrecognized syntax mode in .syntax directive");
8376 return false;
8377 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008378
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008379 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8380 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8381 return false;
8382 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008383 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008384
8385 // TODO tell the MC streamer the mode
8386 // getParser().getStreamer().Emit???();
8387 return false;
8388}
8389
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008390/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008391/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008392bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008393 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008394 if (Tok.isNot(AsmToken::Integer)) {
8395 Error(L, "unexpected token in .code directive");
8396 return false;
8397 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008398 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008399 if (Val != 16 && Val != 32) {
8400 Error(L, "invalid operand to .code directive");
8401 return false;
8402 }
8403 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008404
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008405 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8406 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8407 return false;
8408 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008409 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008410
Evan Cheng284b4672011-07-08 22:36:29 +00008411 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008412 if (!hasThumb()) {
8413 Error(L, "target does not support Thumb mode");
8414 return false;
8415 }
Tim Northovera2292d02013-06-10 23:20:58 +00008416
Jim Grosbachf471ac32011-09-06 18:46:23 +00008417 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008418 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008419 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008420 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008421 if (!hasARM()) {
8422 Error(L, "target does not support ARM mode");
8423 return false;
8424 }
Tim Northovera2292d02013-06-10 23:20:58 +00008425
Jim Grosbachf471ac32011-09-06 18:46:23 +00008426 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008427 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008428 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008429 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008430
Kevin Enderby146dcf22009-10-15 20:48:48 +00008431 return false;
8432}
8433
Jim Grosbachab5830e2011-12-14 02:16:11 +00008434/// parseDirectiveReq
8435/// ::= name .req registername
8436bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8437 Parser.Lex(); // Eat the '.req' token.
8438 unsigned Reg;
8439 SMLoc SRegLoc, ERegLoc;
8440 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008441 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008442 Error(SRegLoc, "register name expected");
8443 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008444 }
8445
8446 // Shouldn't be anything else.
8447 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008448 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008449 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8450 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008451 }
8452
8453 Parser.Lex(); // Consume the EndOfStatement
8454
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008455 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) {
8456 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8457 return false;
8458 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00008459
8460 return false;
8461}
8462
8463/// parseDirectiveUneq
8464/// ::= .unreq registername
8465bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8466 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008467 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008468 Error(L, "unexpected input in .unreq directive.");
8469 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008470 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00008471 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008472 Parser.Lex(); // Eat the identifier.
8473 return false;
8474}
8475
Jason W Kim135d2442011-12-20 17:38:12 +00008476/// parseDirectiveArch
8477/// ::= .arch token
8478bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00008479 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8480
8481 unsigned ID = StringSwitch<unsigned>(Arch)
8482#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8483 .Case(NAME, ARM::ID)
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +00008484#define ARM_ARCH_ALIAS(NAME, ID) \
8485 .Case(NAME, ARM::ID)
Logan Chien439e8f92013-12-11 17:16:25 +00008486#include "MCTargetDesc/ARMArchName.def"
8487 .Default(ARM::INVALID_ARCH);
8488
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008489 if (ID == ARM::INVALID_ARCH) {
8490 Error(L, "Unknown arch name");
8491 return false;
8492 }
Logan Chien439e8f92013-12-11 17:16:25 +00008493
8494 getTargetStreamer().emitArch(ID);
8495 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008496}
8497
8498/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008499/// ::= .eabi_attribute int, int [, "str"]
8500/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00008501bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008502 int64_t Tag;
8503 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008504 TagLoc = Parser.getTok().getLoc();
8505 if (Parser.getTok().is(AsmToken::Identifier)) {
8506 StringRef Name = Parser.getTok().getIdentifier();
8507 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
8508 if (Tag == -1) {
8509 Error(TagLoc, "attribute name not recognised: " + Name);
8510 Parser.eatToEndOfStatement();
8511 return false;
8512 }
8513 Parser.Lex();
8514 } else {
8515 const MCExpr *AttrExpr;
8516
8517 TagLoc = Parser.getTok().getLoc();
8518 if (Parser.parseExpression(AttrExpr)) {
8519 Parser.eatToEndOfStatement();
8520 return false;
8521 }
8522
8523 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
8524 if (!CE) {
8525 Error(TagLoc, "expected numeric constant");
8526 Parser.eatToEndOfStatement();
8527 return false;
8528 }
8529
8530 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008531 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008532
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008533 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008534 Error(Parser.getTok().getLoc(), "comma expected");
8535 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008536 return false;
8537 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008538 Parser.Lex(); // skip comma
8539
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008540 StringRef StringValue = "";
8541 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00008542
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008543 int64_t IntegerValue = 0;
8544 bool IsIntegerValue = false;
8545
8546 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
8547 IsStringValue = true;
8548 else if (Tag == ARMBuildAttrs::compatibility) {
8549 IsStringValue = true;
8550 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00008551 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008552 IsIntegerValue = true;
8553 else if (Tag % 2 == 1)
8554 IsStringValue = true;
8555 else
8556 llvm_unreachable("invalid tag type");
8557
8558 if (IsIntegerValue) {
8559 const MCExpr *ValueExpr;
8560 SMLoc ValueExprLoc = Parser.getTok().getLoc();
8561 if (Parser.parseExpression(ValueExpr)) {
8562 Parser.eatToEndOfStatement();
8563 return false;
8564 }
8565
8566 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
8567 if (!CE) {
8568 Error(ValueExprLoc, "expected numeric constant");
8569 Parser.eatToEndOfStatement();
8570 return false;
8571 }
8572
8573 IntegerValue = CE->getValue();
8574 }
8575
8576 if (Tag == ARMBuildAttrs::compatibility) {
8577 if (Parser.getTok().isNot(AsmToken::Comma))
8578 IsStringValue = false;
8579 else
8580 Parser.Lex();
8581 }
8582
8583 if (IsStringValue) {
8584 if (Parser.getTok().isNot(AsmToken::String)) {
8585 Error(Parser.getTok().getLoc(), "bad string constant");
8586 Parser.eatToEndOfStatement();
8587 return false;
8588 }
8589
8590 StringValue = Parser.getTok().getStringContents();
8591 Parser.Lex();
8592 }
8593
8594 if (IsIntegerValue && IsStringValue) {
8595 assert(Tag == ARMBuildAttrs::compatibility);
8596 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
8597 } else if (IsIntegerValue)
8598 getTargetStreamer().emitAttribute(Tag, IntegerValue);
8599 else if (IsStringValue)
8600 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00008601 return false;
8602}
8603
8604/// parseDirectiveCPU
8605/// ::= .cpu str
8606bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8607 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8608 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8609 return false;
8610}
8611
8612/// parseDirectiveFPU
8613/// ::= .fpu str
8614bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8615 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8616
8617 unsigned ID = StringSwitch<unsigned>(FPU)
8618#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8619#include "ARMFPUName.def"
8620 .Default(ARM::INVALID_FPU);
8621
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008622 if (ID == ARM::INVALID_FPU) {
8623 Error(L, "Unknown FPU name");
8624 return false;
8625 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008626
8627 getTargetStreamer().emitFPU(ID);
8628 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008629}
8630
Logan Chien4ea23b52013-05-10 16:17:24 +00008631/// parseDirectiveFnStart
8632/// ::= .fnstart
8633bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008634 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008635 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008636 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008637 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008638 }
8639
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008640 // Reset the unwind directives parser state
8641 UC.reset();
8642
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008643 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008644
8645 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00008646 return false;
8647}
8648
8649/// parseDirectiveFnEnd
8650/// ::= .fnend
8651bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8652 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008653 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008654 Error(L, ".fnstart must precede .fnend directive");
8655 return false;
8656 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008657
8658 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008659 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008660
8661 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00008662 return false;
8663}
8664
8665/// parseDirectiveCantUnwind
8666/// ::= .cantunwind
8667bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008668 UC.recordCantUnwind(L);
8669
Logan Chien4ea23b52013-05-10 16:17:24 +00008670 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008671 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008672 Error(L, ".fnstart must precede .cantunwind directive");
8673 return false;
8674 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008675 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008676 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008677 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008678 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008679 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008680 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008681 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008682 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008683 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008684 }
8685
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008686 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00008687 return false;
8688}
8689
8690/// parseDirectivePersonality
8691/// ::= .personality name
8692bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008693 bool HasExistingPersonality = UC.hasPersonality();
8694
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008695 UC.recordPersonality(L);
8696
Logan Chien4ea23b52013-05-10 16:17:24 +00008697 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008698 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008699 Error(L, ".fnstart must precede .personality directive");
8700 return false;
8701 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008702 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008703 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008704 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008705 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008706 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008707 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008708 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008709 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008710 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008711 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008712 if (HasExistingPersonality) {
8713 Parser.eatToEndOfStatement();
8714 Error(L, "multiple personality directives");
8715 UC.emitPersonalityLocNotes();
8716 return false;
8717 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008718
8719 // Parse the name of the personality routine
8720 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8721 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008722 Error(L, "unexpected input in .personality directive.");
8723 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008724 }
8725 StringRef Name(Parser.getTok().getIdentifier());
8726 Parser.Lex();
8727
8728 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008729 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00008730 return false;
8731}
8732
8733/// parseDirectiveHandlerData
8734/// ::= .handlerdata
8735bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008736 UC.recordHandlerData(L);
8737
Logan Chien4ea23b52013-05-10 16:17:24 +00008738 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008739 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008740 Error(L, ".fnstart must precede .personality directive");
8741 return false;
8742 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008743 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008744 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008745 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008746 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008747 }
8748
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008749 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00008750 return false;
8751}
8752
8753/// parseDirectiveSetFP
8754/// ::= .setfp fpreg, spreg [, offset]
8755bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8756 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008757 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008758 Error(L, ".fnstart must precede .setfp directive");
8759 return false;
8760 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008761 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008762 Error(L, ".setfp must precede .handlerdata directive");
8763 return false;
8764 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008765
8766 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008767 SMLoc FPRegLoc = Parser.getTok().getLoc();
8768 int FPReg = tryParseRegister();
8769 if (FPReg == -1) {
8770 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008771 return false;
8772 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008773
8774 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008775 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008776 Error(Parser.getTok().getLoc(), "comma expected");
8777 return false;
8778 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008779 Parser.Lex(); // skip comma
8780
8781 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008782 SMLoc SPRegLoc = Parser.getTok().getLoc();
8783 int SPReg = tryParseRegister();
8784 if (SPReg == -1) {
8785 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008786 return false;
8787 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008788
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008789 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
8790 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008791 return false;
8792 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008793
8794 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008795 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00008796
8797 // Parse offset
8798 int64_t Offset = 0;
8799 if (Parser.getTok().is(AsmToken::Comma)) {
8800 Parser.Lex(); // skip comma
8801
8802 if (Parser.getTok().isNot(AsmToken::Hash) &&
8803 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008804 Error(Parser.getTok().getLoc(), "'#' expected");
8805 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008806 }
8807 Parser.Lex(); // skip hash token.
8808
8809 const MCExpr *OffsetExpr;
8810 SMLoc ExLoc = Parser.getTok().getLoc();
8811 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008812 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8813 Error(ExLoc, "malformed setfp offset");
8814 return false;
8815 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008816 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008817 if (!CE) {
8818 Error(ExLoc, "setfp offset must be an immediate");
8819 return false;
8820 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008821
8822 Offset = CE->getValue();
8823 }
8824
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008825 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
8826 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00008827 return false;
8828}
8829
8830/// parseDirective
8831/// ::= .pad offset
8832bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8833 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008834 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008835 Error(L, ".fnstart must precede .pad directive");
8836 return false;
8837 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008838 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008839 Error(L, ".pad must precede .handlerdata directive");
8840 return false;
8841 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008842
8843 // Parse the offset
8844 if (Parser.getTok().isNot(AsmToken::Hash) &&
8845 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008846 Error(Parser.getTok().getLoc(), "'#' expected");
8847 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008848 }
8849 Parser.Lex(); // skip hash token.
8850
8851 const MCExpr *OffsetExpr;
8852 SMLoc ExLoc = Parser.getTok().getLoc();
8853 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008854 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8855 Error(ExLoc, "malformed pad offset");
8856 return false;
8857 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008858 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008859 if (!CE) {
8860 Error(ExLoc, "pad offset must be an immediate");
8861 return false;
8862 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008863
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008864 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00008865 return false;
8866}
8867
8868/// parseDirectiveRegSave
8869/// ::= .save { registers }
8870/// ::= .vsave { registers }
8871bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8872 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008873 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008874 Error(L, ".fnstart must precede .save or .vsave directives");
8875 return false;
8876 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008877 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008878 Error(L, ".save or .vsave must precede .handlerdata directive");
8879 return false;
8880 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008881
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008882 // RAII object to make sure parsed operands are deleted.
David Blaikie960ea3f2014-06-08 16:18:35 +00008883 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008884
Logan Chien4ea23b52013-05-10 16:17:24 +00008885 // Parse the register list
David Blaikie960ea3f2014-06-08 16:18:35 +00008886 if (parseRegisterList(Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008887 return false;
David Blaikie960ea3f2014-06-08 16:18:35 +00008888 ARMOperand &Op = (ARMOperand &)*Operands[0];
8889 if (!IsVector && !Op.isRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008890 Error(L, ".save expects GPR registers");
8891 return false;
8892 }
David Blaikie960ea3f2014-06-08 16:18:35 +00008893 if (IsVector && !Op.isDPRRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008894 Error(L, ".vsave expects DPR registers");
8895 return false;
8896 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008897
David Blaikie960ea3f2014-06-08 16:18:35 +00008898 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00008899 return false;
8900}
8901
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008902/// parseDirectiveInst
8903/// ::= .inst opcode [, ...]
8904/// ::= .inst.n opcode [, ...]
8905/// ::= .inst.w opcode [, ...]
8906bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8907 int Width;
8908
8909 if (isThumb()) {
8910 switch (Suffix) {
8911 case 'n':
8912 Width = 2;
8913 break;
8914 case 'w':
8915 Width = 4;
8916 break;
8917 default:
8918 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008919 Error(Loc, "cannot determine Thumb instruction size, "
8920 "use inst.n/inst.w instead");
8921 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008922 }
8923 } else {
8924 if (Suffix) {
8925 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008926 Error(Loc, "width suffixes are invalid in ARM mode");
8927 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008928 }
8929 Width = 4;
8930 }
8931
8932 if (getLexer().is(AsmToken::EndOfStatement)) {
8933 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008934 Error(Loc, "expected expression following directive");
8935 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008936 }
8937
8938 for (;;) {
8939 const MCExpr *Expr;
8940
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008941 if (getParser().parseExpression(Expr)) {
8942 Error(Loc, "expected expression");
8943 return false;
8944 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008945
8946 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008947 if (!Value) {
8948 Error(Loc, "expected constant expression");
8949 return false;
8950 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008951
8952 switch (Width) {
8953 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008954 if (Value->getValue() > 0xffff) {
8955 Error(Loc, "inst.n operand is too big, use inst.w instead");
8956 return false;
8957 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008958 break;
8959 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008960 if (Value->getValue() > 0xffffffff) {
8961 Error(Loc,
8962 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8963 return false;
8964 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008965 break;
8966 default:
8967 llvm_unreachable("only supported widths are 2 and 4");
8968 }
8969
8970 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8971
8972 if (getLexer().is(AsmToken::EndOfStatement))
8973 break;
8974
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008975 if (getLexer().isNot(AsmToken::Comma)) {
8976 Error(Loc, "unexpected token in directive");
8977 return false;
8978 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008979
8980 Parser.Lex();
8981 }
8982
8983 Parser.Lex();
8984 return false;
8985}
8986
David Peixotto80c083a2013-12-19 18:26:07 +00008987/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008988/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00008989bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00008990 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00008991 return false;
8992}
8993
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008994bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
8995 const MCSection *Section = getStreamer().getCurrentSection().first;
8996
8997 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8998 TokError("unexpected token in directive");
8999 return false;
9000 }
9001
9002 if (!Section) {
Rafael Espindolaf1440342014-01-23 23:14:14 +00009003 getStreamer().InitSections();
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009004 Section = getStreamer().getCurrentSection().first;
9005 }
9006
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00009007 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009008 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00009009 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009010 else
Rafael Espindola7b514962014-02-04 18:34:04 +00009011 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009012
9013 return false;
9014}
9015
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009016/// parseDirectivePersonalityIndex
9017/// ::= .personalityindex index
9018bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
9019 bool HasExistingPersonality = UC.hasPersonality();
9020
9021 UC.recordPersonalityIndex(L);
9022
9023 if (!UC.hasFnStart()) {
9024 Parser.eatToEndOfStatement();
9025 Error(L, ".fnstart must precede .personalityindex directive");
9026 return false;
9027 }
9028 if (UC.cantUnwind()) {
9029 Parser.eatToEndOfStatement();
9030 Error(L, ".personalityindex cannot be used with .cantunwind");
9031 UC.emitCantUnwindLocNotes();
9032 return false;
9033 }
9034 if (UC.hasHandlerData()) {
9035 Parser.eatToEndOfStatement();
9036 Error(L, ".personalityindex must precede .handlerdata directive");
9037 UC.emitHandlerDataLocNotes();
9038 return false;
9039 }
9040 if (HasExistingPersonality) {
9041 Parser.eatToEndOfStatement();
9042 Error(L, "multiple personality directives");
9043 UC.emitPersonalityLocNotes();
9044 return false;
9045 }
9046
9047 const MCExpr *IndexExpression;
9048 SMLoc IndexLoc = Parser.getTok().getLoc();
9049 if (Parser.parseExpression(IndexExpression)) {
9050 Parser.eatToEndOfStatement();
9051 return false;
9052 }
9053
9054 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9055 if (!CE) {
9056 Parser.eatToEndOfStatement();
9057 Error(IndexLoc, "index must be a constant number");
9058 return false;
9059 }
9060 if (CE->getValue() < 0 ||
9061 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9062 Parser.eatToEndOfStatement();
9063 Error(IndexLoc, "personality routine index should be in range [0-3]");
9064 return false;
9065 }
9066
9067 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9068 return false;
9069}
9070
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009071/// parseDirectiveUnwindRaw
9072/// ::= .unwind_raw offset, opcode [, opcode...]
9073bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
9074 if (!UC.hasFnStart()) {
9075 Parser.eatToEndOfStatement();
9076 Error(L, ".fnstart must precede .unwind_raw directives");
9077 return false;
9078 }
9079
9080 int64_t StackOffset;
9081
9082 const MCExpr *OffsetExpr;
9083 SMLoc OffsetLoc = getLexer().getLoc();
9084 if (getLexer().is(AsmToken::EndOfStatement) ||
9085 getParser().parseExpression(OffsetExpr)) {
9086 Error(OffsetLoc, "expected expression");
9087 Parser.eatToEndOfStatement();
9088 return false;
9089 }
9090
9091 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9092 if (!CE) {
9093 Error(OffsetLoc, "offset must be a constant");
9094 Parser.eatToEndOfStatement();
9095 return false;
9096 }
9097
9098 StackOffset = CE->getValue();
9099
9100 if (getLexer().isNot(AsmToken::Comma)) {
9101 Error(getLexer().getLoc(), "expected comma");
9102 Parser.eatToEndOfStatement();
9103 return false;
9104 }
9105 Parser.Lex();
9106
9107 SmallVector<uint8_t, 16> Opcodes;
9108 for (;;) {
9109 const MCExpr *OE;
9110
9111 SMLoc OpcodeLoc = getLexer().getLoc();
9112 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9113 Error(OpcodeLoc, "expected opcode expression");
9114 Parser.eatToEndOfStatement();
9115 return false;
9116 }
9117
9118 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9119 if (!OC) {
9120 Error(OpcodeLoc, "opcode value must be a constant");
9121 Parser.eatToEndOfStatement();
9122 return false;
9123 }
9124
9125 const int64_t Opcode = OC->getValue();
9126 if (Opcode & ~0xff) {
9127 Error(OpcodeLoc, "invalid opcode");
9128 Parser.eatToEndOfStatement();
9129 return false;
9130 }
9131
9132 Opcodes.push_back(uint8_t(Opcode));
9133
9134 if (getLexer().is(AsmToken::EndOfStatement))
9135 break;
9136
9137 if (getLexer().isNot(AsmToken::Comma)) {
9138 Error(getLexer().getLoc(), "unexpected token in directive");
9139 Parser.eatToEndOfStatement();
9140 return false;
9141 }
9142
9143 Parser.Lex();
9144 }
9145
9146 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9147
9148 Parser.Lex();
9149 return false;
9150}
9151
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009152/// parseDirectiveTLSDescSeq
9153/// ::= .tlsdescseq tls-variable
9154bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
9155 if (getLexer().isNot(AsmToken::Identifier)) {
9156 TokError("expected variable after '.tlsdescseq' directive");
9157 Parser.eatToEndOfStatement();
9158 return false;
9159 }
9160
9161 const MCSymbolRefExpr *SRE =
9162 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9163 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9164 Lex();
9165
9166 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9167 Error(Parser.getTok().getLoc(), "unexpected token");
9168 Parser.eatToEndOfStatement();
9169 return false;
9170 }
9171
9172 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9173 return false;
9174}
9175
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009176/// parseDirectiveMovSP
9177/// ::= .movsp reg [, #offset]
9178bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
9179 if (!UC.hasFnStart()) {
9180 Parser.eatToEndOfStatement();
9181 Error(L, ".fnstart must precede .movsp directives");
9182 return false;
9183 }
9184 if (UC.getFPReg() != ARM::SP) {
9185 Parser.eatToEndOfStatement();
9186 Error(L, "unexpected .movsp directive");
9187 return false;
9188 }
9189
9190 SMLoc SPRegLoc = Parser.getTok().getLoc();
9191 int SPReg = tryParseRegister();
9192 if (SPReg == -1) {
9193 Parser.eatToEndOfStatement();
9194 Error(SPRegLoc, "register expected");
9195 return false;
9196 }
9197
9198 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9199 Parser.eatToEndOfStatement();
9200 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9201 return false;
9202 }
9203
9204 int64_t Offset = 0;
9205 if (Parser.getTok().is(AsmToken::Comma)) {
9206 Parser.Lex();
9207
9208 if (Parser.getTok().isNot(AsmToken::Hash)) {
9209 Error(Parser.getTok().getLoc(), "expected #constant");
9210 Parser.eatToEndOfStatement();
9211 return false;
9212 }
9213 Parser.Lex();
9214
9215 const MCExpr *OffsetExpr;
9216 SMLoc OffsetLoc = Parser.getTok().getLoc();
9217 if (Parser.parseExpression(OffsetExpr)) {
9218 Parser.eatToEndOfStatement();
9219 Error(OffsetLoc, "malformed offset expression");
9220 return false;
9221 }
9222
9223 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9224 if (!CE) {
9225 Parser.eatToEndOfStatement();
9226 Error(OffsetLoc, "offset must be an immediate constant");
9227 return false;
9228 }
9229
9230 Offset = CE->getValue();
9231 }
9232
9233 getTargetStreamer().emitMovSP(SPReg, Offset);
9234 UC.saveFPReg(SPReg);
9235
9236 return false;
9237}
9238
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009239/// parseDirectiveObjectArch
9240/// ::= .object_arch name
9241bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
9242 if (getLexer().isNot(AsmToken::Identifier)) {
9243 Error(getLexer().getLoc(), "unexpected token");
9244 Parser.eatToEndOfStatement();
9245 return false;
9246 }
9247
9248 StringRef Arch = Parser.getTok().getString();
9249 SMLoc ArchLoc = Parser.getTok().getLoc();
9250 getLexer().Lex();
9251
9252 unsigned ID = StringSwitch<unsigned>(Arch)
9253#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9254 .Case(NAME, ARM::ID)
9255#define ARM_ARCH_ALIAS(NAME, ID) \
9256 .Case(NAME, ARM::ID)
9257#include "MCTargetDesc/ARMArchName.def"
9258#undef ARM_ARCH_NAME
9259#undef ARM_ARCH_ALIAS
9260 .Default(ARM::INVALID_ARCH);
9261
9262 if (ID == ARM::INVALID_ARCH) {
9263 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9264 Parser.eatToEndOfStatement();
9265 return false;
9266 }
9267
9268 getTargetStreamer().emitObjectArch(ID);
9269
9270 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9271 Error(getLexer().getLoc(), "unexpected token");
9272 Parser.eatToEndOfStatement();
9273 }
9274
9275 return false;
9276}
9277
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009278/// parseDirectiveAlign
9279/// ::= .align
9280bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9281 // NOTE: if this is not the end of the statement, fall back to the target
9282 // agnostic handling for this directive which will correctly handle this.
9283 if (getLexer().isNot(AsmToken::EndOfStatement))
9284 return true;
9285
9286 // '.align' is target specifically handled to mean 2**2 byte alignment.
9287 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9288 getStreamer().EmitCodeAlignment(4, 0);
9289 else
9290 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9291
9292 return false;
9293}
9294
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009295/// parseDirectiveThumbSet
9296/// ::= .thumb_set name, value
9297bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
9298 StringRef Name;
9299 if (Parser.parseIdentifier(Name)) {
9300 TokError("expected identifier after '.thumb_set'");
9301 Parser.eatToEndOfStatement();
9302 return false;
9303 }
9304
9305 if (getLexer().isNot(AsmToken::Comma)) {
9306 TokError("expected comma after name '" + Name + "'");
9307 Parser.eatToEndOfStatement();
9308 return false;
9309 }
9310 Lex();
9311
9312 const MCExpr *Value;
9313 if (Parser.parseExpression(Value)) {
9314 TokError("missing expression");
9315 Parser.eatToEndOfStatement();
9316 return false;
9317 }
9318
9319 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9320 TokError("unexpected token");
9321 Parser.eatToEndOfStatement();
9322 return false;
9323 }
9324 Lex();
9325
9326 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
Rafael Espindola466d6632014-04-27 20:23:58 +00009327 getTargetStreamer().emitThumbSet(Alias, Value);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009328 return false;
9329}
9330
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009331/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009332extern "C" void LLVMInitializeARMAsmParser() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00009333 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9334 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9335 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9336 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009337}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009338
Chris Lattner3e4582a2010-09-06 19:11:01 +00009339#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009340#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009341#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009342#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009343
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009344static const struct ExtMapEntry {
9345 const char *Extension;
9346 const unsigned ArchCheck;
9347 const uint64_t Features;
9348} Extensions[] = {
9349 { "crc", Feature_HasV8, ARM::FeatureCRC },
9350 { "crypto", Feature_HasV8,
9351 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9352 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
9353 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
9354 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
9355 // FIXME: iWMMXT not supported
9356 { "iwmmxt", Feature_None, 0 },
9357 // FIXME: iWMMXT2 not supported
9358 { "iwmmxt2", Feature_None, 0 },
9359 // FIXME: Maverick not supported
9360 { "maverick", Feature_None, 0 },
9361 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
9362 // FIXME: ARMv6-m OS Extensions feature not checked
9363 { "os", Feature_None, 0 },
9364 // FIXME: Also available in ARMv6-K
9365 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
9366 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9367 // FIXME: Only available in A-class, isel not predicated
9368 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
9369 // FIXME: xscale not supported
9370 { "xscale", Feature_None, 0 },
9371};
9372
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009373/// parseDirectiveArchExtension
9374/// ::= .arch_extension [no]feature
9375bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
9376 if (getLexer().isNot(AsmToken::Identifier)) {
9377 Error(getLexer().getLoc(), "unexpected token");
9378 Parser.eatToEndOfStatement();
9379 return false;
9380 }
9381
9382 StringRef Extension = Parser.getTok().getString();
9383 SMLoc ExtLoc = Parser.getTok().getLoc();
9384 getLexer().Lex();
9385
9386 bool EnableFeature = true;
Benjamin Kramere9391a52014-02-20 17:36:31 +00009387 if (Extension.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009388 EnableFeature = false;
9389 Extension = Extension.substr(2);
9390 }
9391
Benjamin Kramere9391a52014-02-20 17:36:31 +00009392 for (unsigned EI = 0, EE = array_lengthof(Extensions); EI != EE; ++EI) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009393 if (Extensions[EI].Extension != Extension)
9394 continue;
9395
9396 unsigned FB = getAvailableFeatures();
9397 if ((FB & Extensions[EI].ArchCheck) != Extensions[EI].ArchCheck) {
9398 Error(ExtLoc, "architectural extension '" + Extension + "' is not "
9399 "allowed for the current base architecture");
9400 return false;
9401 }
9402
9403 if (!Extensions[EI].Features)
9404 report_fatal_error("unsupported architectural extension: " + Extension);
9405
9406 if (EnableFeature)
9407 FB |= ComputeAvailableFeatures(Extensions[EI].Features);
9408 else
9409 FB &= ~ComputeAvailableFeatures(Extensions[EI].Features);
9410
9411 setAvailableFeatures(FB);
9412 return false;
9413 }
9414
9415 Error(ExtLoc, "unknown architectural extension: " + Extension);
9416 Parser.eatToEndOfStatement();
9417 return false;
9418}
9419
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009420// Define this matcher function after the auto-generated include so we
9421// have the match class enum definitions.
David Blaikie960ea3f2014-06-08 16:18:35 +00009422unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009423 unsigned Kind) {
David Blaikie960ea3f2014-06-08 16:18:35 +00009424 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009425 // If the kind is a token for a literal immediate, check if our asm
9426 // operand matches. This is for InstAliases which have a fixed-value
9427 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009428 switch (Kind) {
9429 default: break;
9430 case MCK__35_0:
David Blaikie960ea3f2014-06-08 16:18:35 +00009431 if (Op.isImm())
9432 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009433 if (CE->getValue() == 0)
9434 return Match_Success;
9435 break;
9436 case MCK_ARMSOImm:
David Blaikie960ea3f2014-06-08 16:18:35 +00009437 if (Op.isImm()) {
9438 const MCExpr *SOExpr = Op.getImm();
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009439 int64_t Value;
9440 if (!SOExpr->EvaluateAsAbsolute(Value))
Stepan Dyatkovskiydf657cc2014-03-29 13:12:40 +00009441 return Match_Success;
Richard Barton3db1d582014-05-01 11:37:44 +00009442 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
9443 "expression value must be representable in 32 bits");
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009444 }
9445 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00009446 case MCK_GPRPair:
David Blaikie960ea3f2014-06-08 16:18:35 +00009447 if (Op.isReg() &&
9448 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00009449 return Match_Success;
9450 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009451 }
9452 return Match_InvalidOperand;
9453}