blob: d0cd04b66d5fccfe858aee91dc240906f9c73ca3 [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
Renato Golinac561c32014-06-26 13:10:53 +00003085/// instruction with a symbolic operand name.
3086/// We accept "crN" syntax for GAS compatibility.
3087/// <operand-name> ::= <prefix><number>
3088/// If CoprocOp is 'c', then:
3089/// <prefix> ::= c | cr
3090/// If CoprocOp is 'p', then :
3091/// <prefix> ::= p
3092/// <number> ::= integer in range [0, 15]
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003093static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003094 // Use the same layout as the tablegen'erated register name matcher. Ugly,
3095 // but efficient.
Renato Golinac561c32014-06-26 13:10:53 +00003096 if (Name.size() < 2 || Name[0] != CoprocOp)
3097 return -1;
3098 Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front();
3099
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003100 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00003101 default: return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003102 case 1:
3103 switch (Name[0]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003104 default: return -1;
3105 case '0': return 0;
3106 case '1': return 1;
3107 case '2': return 2;
3108 case '3': return 3;
3109 case '4': return 4;
3110 case '5': return 5;
3111 case '6': return 6;
3112 case '7': return 7;
3113 case '8': return 8;
3114 case '9': return 9;
3115 }
Renato Golinac561c32014-06-26 13:10:53 +00003116 case 2:
3117 if (Name[0] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003118 return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003119 switch (Name[1]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003120 default: return -1;
Artyom Skrobov86534432013-11-08 09:16:31 +00003121 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
3122 case '0': return CoprocOp == 'p'? -1: 10;
3123 case '1': return CoprocOp == 'p'? -1: 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003124 case '2': return 12;
3125 case '3': return 13;
3126 case '4': return 14;
3127 case '5': return 15;
3128 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003129 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003130}
3131
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003132/// parseITCondCode - Try to parse a condition code for an IT instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003133ARMAsmParser::OperandMatchResultTy
3134ARMAsmParser::parseITCondCode(OperandVector &Operands) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003135 SMLoc S = Parser.getTok().getLoc();
3136 const AsmToken &Tok = Parser.getTok();
3137 if (!Tok.is(AsmToken::Identifier))
3138 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00003139 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003140 .Case("eq", ARMCC::EQ)
3141 .Case("ne", ARMCC::NE)
3142 .Case("hs", ARMCC::HS)
3143 .Case("cs", ARMCC::HS)
3144 .Case("lo", ARMCC::LO)
3145 .Case("cc", ARMCC::LO)
3146 .Case("mi", ARMCC::MI)
3147 .Case("pl", ARMCC::PL)
3148 .Case("vs", ARMCC::VS)
3149 .Case("vc", ARMCC::VC)
3150 .Case("hi", ARMCC::HI)
3151 .Case("ls", ARMCC::LS)
3152 .Case("ge", ARMCC::GE)
3153 .Case("lt", ARMCC::LT)
3154 .Case("gt", ARMCC::GT)
3155 .Case("le", ARMCC::LE)
3156 .Case("al", ARMCC::AL)
3157 .Default(~0U);
3158 if (CC == ~0U)
3159 return MatchOperand_NoMatch;
3160 Parser.Lex(); // Eat the token.
3161
3162 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3163
3164 return MatchOperand_Success;
3165}
3166
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003167/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003168/// token must be an Identifier when called, and if it is a coprocessor
3169/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003170ARMAsmParser::OperandMatchResultTy
3171ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003172 SMLoc S = Parser.getTok().getLoc();
3173 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003174 if (Tok.isNot(AsmToken::Identifier))
3175 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003176
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003177 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003178 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003179 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003180
3181 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003182 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003183 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003184}
3185
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003186/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003187/// token must be an Identifier when called, and if it is a coprocessor
3188/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003189ARMAsmParser::OperandMatchResultTy
3190ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003191 SMLoc S = Parser.getTok().getLoc();
3192 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003193 if (Tok.isNot(AsmToken::Identifier))
3194 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003195
3196 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3197 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003198 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003199
3200 Parser.Lex(); // Eat identifier token.
3201 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003202 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003203}
3204
Jim Grosbach48399582011-10-12 17:34:41 +00003205/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3206/// coproc_option : '{' imm0_255 '}'
David Blaikie960ea3f2014-06-08 16:18:35 +00003207ARMAsmParser::OperandMatchResultTy
3208ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) {
Jim Grosbach48399582011-10-12 17:34:41 +00003209 SMLoc S = Parser.getTok().getLoc();
3210
3211 // If this isn't a '{', this isn't a coprocessor immediate operand.
3212 if (Parser.getTok().isNot(AsmToken::LCurly))
3213 return MatchOperand_NoMatch;
3214 Parser.Lex(); // Eat the '{'
3215
3216 const MCExpr *Expr;
3217 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003218 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003219 Error(Loc, "illegal expression");
3220 return MatchOperand_ParseFail;
3221 }
3222 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3223 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3224 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3225 return MatchOperand_ParseFail;
3226 }
3227 int Val = CE->getValue();
3228
3229 // Check for and consume the closing '}'
3230 if (Parser.getTok().isNot(AsmToken::RCurly))
3231 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003232 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003233 Parser.Lex(); // Eat the '}'
3234
3235 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3236 return MatchOperand_Success;
3237}
3238
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003239// For register list parsing, we need to map from raw GPR register numbering
3240// to the enumeration values. The enumeration values aren't sorted by
3241// register number due to our using "sp", "lr" and "pc" as canonical names.
3242static unsigned getNextRegister(unsigned Reg) {
3243 // If this is a GPR, we need to do it manually, otherwise we can rely
3244 // on the sort ordering of the enumeration since the other reg-classes
3245 // are sane.
3246 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3247 return Reg + 1;
3248 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003249 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003250 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3251 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3252 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3253 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3254 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3255 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3256 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3257 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3258 }
3259}
3260
Jim Grosbach85a23432011-11-11 21:27:40 +00003261// Return the low-subreg of a given Q register.
3262static unsigned getDRegFromQReg(unsigned QReg) {
3263 switch (QReg) {
3264 default: llvm_unreachable("expected a Q register!");
3265 case ARM::Q0: return ARM::D0;
3266 case ARM::Q1: return ARM::D2;
3267 case ARM::Q2: return ARM::D4;
3268 case ARM::Q3: return ARM::D6;
3269 case ARM::Q4: return ARM::D8;
3270 case ARM::Q5: return ARM::D10;
3271 case ARM::Q6: return ARM::D12;
3272 case ARM::Q7: return ARM::D14;
3273 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003274 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003275 case ARM::Q10: return ARM::D20;
3276 case ARM::Q11: return ARM::D22;
3277 case ARM::Q12: return ARM::D24;
3278 case ARM::Q13: return ARM::D26;
3279 case ARM::Q14: return ARM::D28;
3280 case ARM::Q15: return ARM::D30;
3281 }
3282}
3283
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003284/// Parse a register list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003285bool ARMAsmParser::parseRegisterList(OperandVector &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003286 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003287 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003288 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003289 Parser.Lex(); // Eat '{' token.
3290 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003291
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003292 // Check the first register in the list to see what register class
3293 // this is a list of.
3294 int Reg = tryParseRegister();
3295 if (Reg == -1)
3296 return Error(RegLoc, "register expected");
3297
Jim Grosbach85a23432011-11-11 21:27:40 +00003298 // The reglist instructions have at most 16 registers, so reserve
3299 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003300 int EReg = 0;
3301 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003302
3303 // Allow Q regs and just interpret them as the two D sub-registers.
3304 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3305 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003306 EReg = MRI->getEncodingValue(Reg);
3307 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003308 ++Reg;
3309 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003310 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003311 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3312 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3313 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3314 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3315 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3316 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3317 else
3318 return Error(RegLoc, "invalid register in register list");
3319
Jim Grosbach85a23432011-11-11 21:27:40 +00003320 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003321 EReg = MRI->getEncodingValue(Reg);
3322 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003323
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003324 // This starts immediately after the first register token in the list,
3325 // so we can see either a comma or a minus (range separator) as a legal
3326 // next token.
3327 while (Parser.getTok().is(AsmToken::Comma) ||
3328 Parser.getTok().is(AsmToken::Minus)) {
3329 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003330 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003331 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003332 int EndReg = tryParseRegister();
3333 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003334 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003335 // Allow Q regs and just interpret them as the two D sub-registers.
3336 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3337 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003338 // If the register is the same as the start reg, there's nothing
3339 // more to do.
3340 if (Reg == EndReg)
3341 continue;
3342 // The register must be in the same register class as the first.
3343 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003344 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003345 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003346 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003347 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003348
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003349 // Add all the registers in the range to the register list.
3350 while (Reg != EndReg) {
3351 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003352 EReg = MRI->getEncodingValue(Reg);
3353 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003354 }
3355 continue;
3356 }
3357 Parser.Lex(); // Eat the comma.
3358 RegLoc = Parser.getTok().getLoc();
3359 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003360 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003361 Reg = tryParseRegister();
3362 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003363 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003364 // Allow Q regs and just interpret them as the two D sub-registers.
3365 bool isQReg = false;
3366 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3367 Reg = getDRegFromQReg(Reg);
3368 isQReg = true;
3369 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003370 // The register must be in the same register class as the first.
3371 if (!RC->contains(Reg))
3372 return Error(RegLoc, "invalid register in register list");
3373 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003374 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003375 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3376 Warning(RegLoc, "register list not in ascending order");
3377 else
3378 return Error(RegLoc, "register list not in ascending order");
3379 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003380 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003381 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3382 ") in register list");
3383 continue;
3384 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003385 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003386 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3387 Reg != OldReg + 1)
3388 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003389 EReg = MRI->getEncodingValue(Reg);
3390 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3391 if (isQReg) {
3392 EReg = MRI->getEncodingValue(++Reg);
3393 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3394 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003395 }
3396
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003397 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003398 return Error(Parser.getTok().getLoc(), "'}' expected");
3399 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003400 Parser.Lex(); // Eat '}' token.
3401
Jim Grosbach18bf3632011-12-13 21:48:29 +00003402 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003403 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003404
3405 // The ARM system instruction variants for LDM/STM have a '^' token here.
3406 if (Parser.getTok().is(AsmToken::Caret)) {
3407 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3408 Parser.Lex(); // Eat '^' token.
3409 }
3410
Bill Wendling2063b842010-11-18 23:43:05 +00003411 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003412}
3413
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003414// Helper function to parse the lane index for vector lists.
3415ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003416parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003417 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003418 if (Parser.getTok().is(AsmToken::LBrac)) {
3419 Parser.Lex(); // Eat the '['.
3420 if (Parser.getTok().is(AsmToken::RBrac)) {
3421 // "Dn[]" is the 'all lanes' syntax.
3422 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003423 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003424 Parser.Lex(); // Eat the ']'.
3425 return MatchOperand_Success;
3426 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003427
3428 // There's an optional '#' token here. Normally there wouldn't be, but
3429 // inline assemble puts one in, and it's friendly to accept that.
3430 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003431 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003432
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003433 const MCExpr *LaneIndex;
3434 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003435 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003436 Error(Loc, "illegal expression");
3437 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003438 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003439 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3440 if (!CE) {
3441 Error(Loc, "lane index must be empty or an integer");
3442 return MatchOperand_ParseFail;
3443 }
3444 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3445 Error(Parser.getTok().getLoc(), "']' expected");
3446 return MatchOperand_ParseFail;
3447 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003448 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003449 Parser.Lex(); // Eat the ']'.
3450 int64_t Val = CE->getValue();
3451
3452 // FIXME: Make this range check context sensitive for .8, .16, .32.
3453 if (Val < 0 || Val > 7) {
3454 Error(Parser.getTok().getLoc(), "lane index out of range");
3455 return MatchOperand_ParseFail;
3456 }
3457 Index = Val;
3458 LaneKind = IndexedLane;
3459 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003460 }
3461 LaneKind = NoLanes;
3462 return MatchOperand_Success;
3463}
3464
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003465// parse a vector register list
David Blaikie960ea3f2014-06-08 16:18:35 +00003466ARMAsmParser::OperandMatchResultTy
3467ARMAsmParser::parseVectorList(OperandVector &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003468 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003469 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003470 SMLoc S = Parser.getTok().getLoc();
3471 // As an extension (to match gas), support a plain D register or Q register
3472 // (without encosing curly braces) as a single or double entry list,
3473 // respectively.
3474 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003475 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003476 int Reg = tryParseRegister();
3477 if (Reg == -1)
3478 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003479 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003480 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003481 if (Res != MatchOperand_Success)
3482 return Res;
3483 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003484 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003485 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003486 break;
3487 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003488 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3489 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003490 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003491 case IndexedLane:
3492 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003493 LaneIndex,
3494 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003495 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003496 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003497 return MatchOperand_Success;
3498 }
3499 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3500 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003501 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003502 if (Res != MatchOperand_Success)
3503 return Res;
3504 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003505 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003506 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003507 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003508 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003509 break;
3510 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003511 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3512 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003513 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3514 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003515 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003516 case IndexedLane:
3517 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003518 LaneIndex,
3519 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003520 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003521 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003522 return MatchOperand_Success;
3523 }
3524 Error(S, "vector register expected");
3525 return MatchOperand_ParseFail;
3526 }
3527
3528 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003529 return MatchOperand_NoMatch;
3530
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003531 Parser.Lex(); // Eat '{' token.
3532 SMLoc RegLoc = Parser.getTok().getLoc();
3533
3534 int Reg = tryParseRegister();
3535 if (Reg == -1) {
3536 Error(RegLoc, "register expected");
3537 return MatchOperand_ParseFail;
3538 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003539 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003540 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003541 unsigned FirstReg = Reg;
3542 // The list is of D registers, but we also allow Q regs and just interpret
3543 // them as the two D sub-registers.
3544 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3545 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003546 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3547 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003548 ++Reg;
3549 ++Count;
3550 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003551
3552 SMLoc E;
3553 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003554 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003555
Jim Grosbache891fe82011-11-15 23:19:15 +00003556 while (Parser.getTok().is(AsmToken::Comma) ||
3557 Parser.getTok().is(AsmToken::Minus)) {
3558 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003559 if (!Spacing)
3560 Spacing = 1; // Register range implies a single spaced list.
3561 else if (Spacing == 2) {
3562 Error(Parser.getTok().getLoc(),
3563 "sequential registers in double spaced list");
3564 return MatchOperand_ParseFail;
3565 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003566 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003567 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003568 int EndReg = tryParseRegister();
3569 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003570 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003571 return MatchOperand_ParseFail;
3572 }
3573 // Allow Q regs and just interpret them as the two D sub-registers.
3574 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3575 EndReg = getDRegFromQReg(EndReg) + 1;
3576 // If the register is the same as the start reg, there's nothing
3577 // more to do.
3578 if (Reg == EndReg)
3579 continue;
3580 // The register must be in the same register class as the first.
3581 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003582 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003583 return MatchOperand_ParseFail;
3584 }
3585 // Ranges must go from low to high.
3586 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003587 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003588 return MatchOperand_ParseFail;
3589 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003590 // Parse the lane specifier if present.
3591 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003592 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003593 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3594 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003595 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003596 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003597 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003598 return MatchOperand_ParseFail;
3599 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003600
3601 // Add all the registers in the range to the register list.
3602 Count += EndReg - Reg;
3603 Reg = EndReg;
3604 continue;
3605 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003606 Parser.Lex(); // Eat the comma.
3607 RegLoc = Parser.getTok().getLoc();
3608 int OldReg = Reg;
3609 Reg = tryParseRegister();
3610 if (Reg == -1) {
3611 Error(RegLoc, "register expected");
3612 return MatchOperand_ParseFail;
3613 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003614 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003615 // It's OK to use the enumeration values directly here rather, as the
3616 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003617 //
3618 // The list is of D registers, but we also allow Q regs and just interpret
3619 // them as the two D sub-registers.
3620 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003621 if (!Spacing)
3622 Spacing = 1; // Register range implies a single spaced list.
3623 else if (Spacing == 2) {
3624 Error(RegLoc,
3625 "invalid register in double-spaced list (must be 'D' register')");
3626 return MatchOperand_ParseFail;
3627 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003628 Reg = getDRegFromQReg(Reg);
3629 if (Reg != OldReg + 1) {
3630 Error(RegLoc, "non-contiguous register range");
3631 return MatchOperand_ParseFail;
3632 }
3633 ++Reg;
3634 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003635 // Parse the lane specifier if present.
3636 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003637 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003638 SMLoc LaneLoc = Parser.getTok().getLoc();
3639 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3640 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003641 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003642 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003643 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003644 return MatchOperand_ParseFail;
3645 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003646 continue;
3647 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003648 // Normal D register.
3649 // Figure out the register spacing (single or double) of the list if
3650 // we don't know it already.
3651 if (!Spacing)
3652 Spacing = 1 + (Reg == OldReg + 2);
3653
3654 // Just check that it's contiguous and keep going.
3655 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003656 Error(RegLoc, "non-contiguous register range");
3657 return MatchOperand_ParseFail;
3658 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003659 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003660 // Parse the lane specifier if present.
3661 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003662 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003663 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003664 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003665 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003666 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003667 Error(EndLoc, "mismatched lane index in register list");
3668 return MatchOperand_ParseFail;
3669 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003670 }
3671
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003672 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003673 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003674 return MatchOperand_ParseFail;
3675 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003676 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003677 Parser.Lex(); // Eat '}' token.
3678
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003679 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003680 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003681 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003682 // composite register classes.
3683 if (Count == 2) {
3684 const MCRegisterClass *RC = (Spacing == 1) ?
3685 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3686 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3687 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3688 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003689
Jim Grosbach2f50e922011-12-15 21:44:33 +00003690 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3691 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003692 break;
3693 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003694 // Two-register operands have been converted to the
3695 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003696 if (Count == 2) {
3697 const MCRegisterClass *RC = (Spacing == 1) ?
3698 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3699 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003700 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3701 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003702 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003703 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003704 S, E));
3705 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003706 case IndexedLane:
3707 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003708 LaneIndex,
3709 (Spacing == 2),
3710 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003711 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003712 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003713 return MatchOperand_Success;
3714}
3715
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003716/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003717ARMAsmParser::OperandMatchResultTy
3718ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003719 SMLoc S = Parser.getTok().getLoc();
3720 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003721 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003722
Jiangning Liu288e1af2012-08-02 08:21:27 +00003723 if (Tok.is(AsmToken::Identifier)) {
3724 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003725
Jiangning Liu288e1af2012-08-02 08:21:27 +00003726 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3727 .Case("sy", ARM_MB::SY)
3728 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003729 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003730 .Case("sh", ARM_MB::ISH)
3731 .Case("ish", ARM_MB::ISH)
3732 .Case("shst", ARM_MB::ISHST)
3733 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003734 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003735 .Case("nsh", ARM_MB::NSH)
3736 .Case("un", ARM_MB::NSH)
3737 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003738 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003739 .Case("unst", ARM_MB::NSHST)
3740 .Case("osh", ARM_MB::OSH)
3741 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003742 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003743 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003744
Joey Gouly926d3f52013-09-05 15:35:24 +00003745 // ishld, oshld, nshld and ld are only available from ARMv8.
3746 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3747 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3748 Opt = ~0U;
3749
Jiangning Liu288e1af2012-08-02 08:21:27 +00003750 if (Opt == ~0U)
3751 return MatchOperand_NoMatch;
3752
3753 Parser.Lex(); // Eat identifier token.
3754 } else if (Tok.is(AsmToken::Hash) ||
3755 Tok.is(AsmToken::Dollar) ||
3756 Tok.is(AsmToken::Integer)) {
3757 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003758 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003759 SMLoc Loc = Parser.getTok().getLoc();
3760
3761 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003762 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003763 Error(Loc, "illegal expression");
3764 return MatchOperand_ParseFail;
3765 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00003766
Jiangning Liu288e1af2012-08-02 08:21:27 +00003767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3768 if (!CE) {
3769 Error(Loc, "constant expression expected");
3770 return MatchOperand_ParseFail;
3771 }
3772
3773 int Val = CE->getValue();
3774 if (Val & ~0xf) {
3775 Error(Loc, "immediate value out of range");
3776 return MatchOperand_ParseFail;
3777 }
3778
3779 Opt = ARM_MB::RESERVED_0 + Val;
3780 } else
3781 return MatchOperand_ParseFail;
3782
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003783 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003784 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003785}
3786
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003787/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003788ARMAsmParser::OperandMatchResultTy
3789ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) {
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003790 SMLoc S = Parser.getTok().getLoc();
3791 const AsmToken &Tok = Parser.getTok();
3792 unsigned Opt;
3793
3794 if (Tok.is(AsmToken::Identifier)) {
3795 StringRef OptStr = Tok.getString();
3796
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003797 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003798 Opt = ARM_ISB::SY;
3799 else
3800 return MatchOperand_NoMatch;
3801
3802 Parser.Lex(); // Eat identifier token.
3803 } else if (Tok.is(AsmToken::Hash) ||
3804 Tok.is(AsmToken::Dollar) ||
3805 Tok.is(AsmToken::Integer)) {
3806 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003807 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003808 SMLoc Loc = Parser.getTok().getLoc();
3809
3810 const MCExpr *ISBarrierID;
3811 if (getParser().parseExpression(ISBarrierID)) {
3812 Error(Loc, "illegal expression");
3813 return MatchOperand_ParseFail;
3814 }
3815
3816 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3817 if (!CE) {
3818 Error(Loc, "constant expression expected");
3819 return MatchOperand_ParseFail;
3820 }
3821
3822 int Val = CE->getValue();
3823 if (Val & ~0xf) {
3824 Error(Loc, "immediate value out of range");
3825 return MatchOperand_ParseFail;
3826 }
3827
3828 Opt = ARM_ISB::RESERVED_0 + Val;
3829 } else
3830 return MatchOperand_ParseFail;
3831
3832 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3833 (ARM_ISB::InstSyncBOpt)Opt, S));
3834 return MatchOperand_Success;
3835}
3836
3837
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003838/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003839ARMAsmParser::OperandMatchResultTy
3840ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003841 SMLoc S = Parser.getTok().getLoc();
3842 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003843 if (!Tok.is(AsmToken::Identifier))
3844 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003845 StringRef IFlagsStr = Tok.getString();
3846
Owen Anderson10c5b122011-10-05 17:16:40 +00003847 // An iflags string of "none" is interpreted to mean that none of the AIF
3848 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003849 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003850 if (IFlagsStr != "none") {
3851 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3852 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3853 .Case("a", ARM_PROC::A)
3854 .Case("i", ARM_PROC::I)
3855 .Case("f", ARM_PROC::F)
3856 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003857
Owen Anderson10c5b122011-10-05 17:16:40 +00003858 // If some specific iflag is already set, it means that some letter is
3859 // present more than once, this is not acceptable.
3860 if (Flag == ~0U || (IFlags & Flag))
3861 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003862
Owen Anderson10c5b122011-10-05 17:16:40 +00003863 IFlags |= Flag;
3864 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003865 }
3866
3867 Parser.Lex(); // Eat identifier token.
3868 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3869 return MatchOperand_Success;
3870}
3871
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003872/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003873ARMAsmParser::OperandMatchResultTy
3874ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003875 SMLoc S = Parser.getTok().getLoc();
3876 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003877 if (!Tok.is(AsmToken::Identifier))
3878 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003879 StringRef Mask = Tok.getString();
3880
James Molloy21efa7d2011-09-28 14:21:38 +00003881 if (isMClass()) {
3882 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003883 std::string Name = Mask.lower();
3884 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003885 // Note: in the documentation:
3886 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3887 // for MSR APSR_nzcvq.
3888 // but we do make it an alias here. This is so to get the "mask encoding"
3889 // bits correct on MSR APSR writes.
3890 //
3891 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3892 // should really only be allowed when writing a special register. Note
3893 // they get dropped in the MRS instruction reading a special register as
3894 // the SYSm field is only 8 bits.
3895 //
3896 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3897 // includes the DSP extension but that is not checked.
3898 .Case("apsr", 0x800)
3899 .Case("apsr_nzcvq", 0x800)
3900 .Case("apsr_g", 0x400)
3901 .Case("apsr_nzcvqg", 0xc00)
3902 .Case("iapsr", 0x801)
3903 .Case("iapsr_nzcvq", 0x801)
3904 .Case("iapsr_g", 0x401)
3905 .Case("iapsr_nzcvqg", 0xc01)
3906 .Case("eapsr", 0x802)
3907 .Case("eapsr_nzcvq", 0x802)
3908 .Case("eapsr_g", 0x402)
3909 .Case("eapsr_nzcvqg", 0xc02)
3910 .Case("xpsr", 0x803)
3911 .Case("xpsr_nzcvq", 0x803)
3912 .Case("xpsr_g", 0x403)
3913 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003914 .Case("ipsr", 0x805)
3915 .Case("epsr", 0x806)
3916 .Case("iepsr", 0x807)
3917 .Case("msp", 0x808)
3918 .Case("psp", 0x809)
3919 .Case("primask", 0x810)
3920 .Case("basepri", 0x811)
3921 .Case("basepri_max", 0x812)
3922 .Case("faultmask", 0x813)
3923 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003924 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003925
James Molloy21efa7d2011-09-28 14:21:38 +00003926 if (FlagsVal == ~0U)
3927 return MatchOperand_NoMatch;
3928
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003929 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003930 // basepri, basepri_max and faultmask only valid for V7m.
3931 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003932
James Molloy21efa7d2011-09-28 14:21:38 +00003933 Parser.Lex(); // Eat identifier token.
3934 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3935 return MatchOperand_Success;
3936 }
3937
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003938 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3939 size_t Start = 0, Next = Mask.find('_');
3940 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003941 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003942 if (Next != StringRef::npos)
3943 Flags = Mask.slice(Next+1, Mask.size());
3944
3945 // FlagsVal contains the complete mask:
3946 // 3-0: Mask
3947 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3948 unsigned FlagsVal = 0;
3949
3950 if (SpecReg == "apsr") {
3951 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003952 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003953 .Case("g", 0x4) // same as CPSR_s
3954 .Case("nzcvqg", 0xc) // same as CPSR_fs
3955 .Default(~0U);
3956
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003957 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003958 if (!Flags.empty())
3959 return MatchOperand_NoMatch;
3960 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003961 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003962 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003963 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003964 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3965 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003966 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003967 for (int i = 0, e = Flags.size(); i != e; ++i) {
3968 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3969 .Case("c", 1)
3970 .Case("x", 2)
3971 .Case("s", 4)
3972 .Case("f", 8)
3973 .Default(~0U);
3974
3975 // If some specific flag is already set, it means that some letter is
3976 // present more than once, this is not acceptable.
3977 if (FlagsVal == ~0U || (FlagsVal & Flag))
3978 return MatchOperand_NoMatch;
3979 FlagsVal |= Flag;
3980 }
3981 } else // No match for special register.
3982 return MatchOperand_NoMatch;
3983
Owen Anderson03a173e2011-10-21 18:43:28 +00003984 // Special register without flags is NOT equivalent to "fc" flags.
3985 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3986 // two lines would enable gas compatibility at the expense of breaking
3987 // round-tripping.
3988 //
3989 // if (!FlagsVal)
3990 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003991
3992 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3993 if (SpecReg == "spsr")
3994 FlagsVal |= 16;
3995
3996 Parser.Lex(); // Eat identifier token.
3997 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3998 return MatchOperand_Success;
3999}
4000
David Blaikie960ea3f2014-06-08 16:18:35 +00004001ARMAsmParser::OperandMatchResultTy
4002ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low,
4003 int High) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004004 const AsmToken &Tok = Parser.getTok();
4005 if (Tok.isNot(AsmToken::Identifier)) {
4006 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4007 return MatchOperand_ParseFail;
4008 }
4009 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004010 std::string LowerOp = Op.lower();
4011 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004012 if (ShiftName != LowerOp && ShiftName != UpperOp) {
4013 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4014 return MatchOperand_ParseFail;
4015 }
4016 Parser.Lex(); // Eat shift type token.
4017
4018 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004019 if (Parser.getTok().isNot(AsmToken::Hash) &&
4020 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004021 Error(Parser.getTok().getLoc(), "'#' expected");
4022 return MatchOperand_ParseFail;
4023 }
4024 Parser.Lex(); // Eat hash token.
4025
4026 const MCExpr *ShiftAmount;
4027 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004028 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004029 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004030 Error(Loc, "illegal expression");
4031 return MatchOperand_ParseFail;
4032 }
4033 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4034 if (!CE) {
4035 Error(Loc, "constant expression expected");
4036 return MatchOperand_ParseFail;
4037 }
4038 int Val = CE->getValue();
4039 if (Val < Low || Val > High) {
4040 Error(Loc, "immediate value out of range");
4041 return MatchOperand_ParseFail;
4042 }
4043
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004044 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00004045
4046 return MatchOperand_Success;
4047}
4048
David Blaikie960ea3f2014-06-08 16:18:35 +00004049ARMAsmParser::OperandMatchResultTy
4050ARMAsmParser::parseSetEndImm(OperandVector &Operands) {
Jim Grosbach0a547702011-07-22 17:44:50 +00004051 const AsmToken &Tok = Parser.getTok();
4052 SMLoc S = Tok.getLoc();
4053 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004054 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004055 return MatchOperand_ParseFail;
4056 }
Tim Northover4d141442013-05-31 15:58:45 +00004057 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00004058 .Case("be", 1)
4059 .Case("le", 0)
4060 .Default(-1);
4061 Parser.Lex(); // Eat the token.
4062
4063 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004064 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004065 return MatchOperand_ParseFail;
4066 }
4067 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4068 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004069 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00004070 return MatchOperand_Success;
4071}
4072
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004073/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
4074/// instructions. Legal values are:
4075/// lsl #n 'n' in [0,31]
4076/// asr #n 'n' in [1,32]
4077/// n == 32 encoded as n == 0.
David Blaikie960ea3f2014-06-08 16:18:35 +00004078ARMAsmParser::OperandMatchResultTy
4079ARMAsmParser::parseShifterImm(OperandVector &Operands) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004080 const AsmToken &Tok = Parser.getTok();
4081 SMLoc S = Tok.getLoc();
4082 if (Tok.isNot(AsmToken::Identifier)) {
4083 Error(S, "shift operator 'asr' or 'lsl' expected");
4084 return MatchOperand_ParseFail;
4085 }
4086 StringRef ShiftName = Tok.getString();
4087 bool isASR;
4088 if (ShiftName == "lsl" || ShiftName == "LSL")
4089 isASR = false;
4090 else if (ShiftName == "asr" || ShiftName == "ASR")
4091 isASR = true;
4092 else {
4093 Error(S, "shift operator 'asr' or 'lsl' expected");
4094 return MatchOperand_ParseFail;
4095 }
4096 Parser.Lex(); // Eat the operator.
4097
4098 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004099 if (Parser.getTok().isNot(AsmToken::Hash) &&
4100 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004101 Error(Parser.getTok().getLoc(), "'#' expected");
4102 return MatchOperand_ParseFail;
4103 }
4104 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004105 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004106
4107 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004108 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004109 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004110 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004111 return MatchOperand_ParseFail;
4112 }
4113 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4114 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004115 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004116 return MatchOperand_ParseFail;
4117 }
4118
4119 int64_t Val = CE->getValue();
4120 if (isASR) {
4121 // Shift amount must be in [1,32]
4122 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004123 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004124 return MatchOperand_ParseFail;
4125 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00004126 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4127 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004128 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00004129 return MatchOperand_ParseFail;
4130 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004131 if (Val == 32) Val = 0;
4132 } else {
4133 // Shift amount must be in [1,32]
4134 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004135 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004136 return MatchOperand_ParseFail;
4137 }
4138 }
4139
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004140 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004141
4142 return MatchOperand_Success;
4143}
4144
Jim Grosbach833b9d32011-07-27 20:15:40 +00004145/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4146/// of instructions. Legal values are:
4147/// ror #n 'n' in {0, 8, 16, 24}
David Blaikie960ea3f2014-06-08 16:18:35 +00004148ARMAsmParser::OperandMatchResultTy
4149ARMAsmParser::parseRotImm(OperandVector &Operands) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004150 const AsmToken &Tok = Parser.getTok();
4151 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00004152 if (Tok.isNot(AsmToken::Identifier))
4153 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004154 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00004155 if (ShiftName != "ror" && ShiftName != "ROR")
4156 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004157 Parser.Lex(); // Eat the operator.
4158
4159 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004160 if (Parser.getTok().isNot(AsmToken::Hash) &&
4161 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004162 Error(Parser.getTok().getLoc(), "'#' expected");
4163 return MatchOperand_ParseFail;
4164 }
4165 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004166 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004167
4168 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004169 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004170 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004171 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004172 return MatchOperand_ParseFail;
4173 }
4174 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4175 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004176 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004177 return MatchOperand_ParseFail;
4178 }
4179
4180 int64_t Val = CE->getValue();
4181 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4182 // normally, zero is represented in asm by omitting the rotate operand
4183 // entirely.
4184 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004185 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004186 return MatchOperand_ParseFail;
4187 }
4188
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004189 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004190
4191 return MatchOperand_Success;
4192}
4193
David Blaikie960ea3f2014-06-08 16:18:35 +00004194ARMAsmParser::OperandMatchResultTy
4195ARMAsmParser::parseBitfield(OperandVector &Operands) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004196 SMLoc S = Parser.getTok().getLoc();
4197 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004198 if (Parser.getTok().isNot(AsmToken::Hash) &&
4199 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004200 Error(Parser.getTok().getLoc(), "'#' expected");
4201 return MatchOperand_ParseFail;
4202 }
4203 Parser.Lex(); // Eat hash token.
4204
4205 const MCExpr *LSBExpr;
4206 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004207 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004208 Error(E, "malformed immediate expression");
4209 return MatchOperand_ParseFail;
4210 }
4211 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4212 if (!CE) {
4213 Error(E, "'lsb' operand must be an immediate");
4214 return MatchOperand_ParseFail;
4215 }
4216
4217 int64_t LSB = CE->getValue();
4218 // The LSB must be in the range [0,31]
4219 if (LSB < 0 || LSB > 31) {
4220 Error(E, "'lsb' operand must be in the range [0,31]");
4221 return MatchOperand_ParseFail;
4222 }
4223 E = Parser.getTok().getLoc();
4224
4225 // Expect another immediate operand.
4226 if (Parser.getTok().isNot(AsmToken::Comma)) {
4227 Error(Parser.getTok().getLoc(), "too few operands");
4228 return MatchOperand_ParseFail;
4229 }
4230 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004231 if (Parser.getTok().isNot(AsmToken::Hash) &&
4232 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004233 Error(Parser.getTok().getLoc(), "'#' expected");
4234 return MatchOperand_ParseFail;
4235 }
4236 Parser.Lex(); // Eat hash token.
4237
4238 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004239 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004240 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004241 Error(E, "malformed immediate expression");
4242 return MatchOperand_ParseFail;
4243 }
4244 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4245 if (!CE) {
4246 Error(E, "'width' operand must be an immediate");
4247 return MatchOperand_ParseFail;
4248 }
4249
4250 int64_t Width = CE->getValue();
4251 // The LSB must be in the range [1,32-lsb]
4252 if (Width < 1 || Width > 32 - LSB) {
4253 Error(E, "'width' operand must be in the range [1,32-lsb]");
4254 return MatchOperand_ParseFail;
4255 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004256
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004257 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004258
4259 return MatchOperand_Success;
4260}
4261
David Blaikie960ea3f2014-06-08 16:18:35 +00004262ARMAsmParser::OperandMatchResultTy
4263ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
Jim Grosbachd3595712011-08-03 23:50:40 +00004264 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004265 // postidx_reg := '+' register {, shift}
4266 // | '-' register {, shift}
4267 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004268
4269 // This method must return MatchOperand_NoMatch without consuming any tokens
4270 // in the case where there is no match, as other alternatives take other
4271 // parse methods.
4272 AsmToken Tok = Parser.getTok();
4273 SMLoc S = Tok.getLoc();
4274 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004275 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004276 if (Tok.is(AsmToken::Plus)) {
4277 Parser.Lex(); // Eat the '+' token.
4278 haveEaten = true;
4279 } else if (Tok.is(AsmToken::Minus)) {
4280 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004281 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004282 haveEaten = true;
4283 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004284
4285 SMLoc E = Parser.getTok().getEndLoc();
4286 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004287 if (Reg == -1) {
4288 if (!haveEaten)
4289 return MatchOperand_NoMatch;
4290 Error(Parser.getTok().getLoc(), "register expected");
4291 return MatchOperand_ParseFail;
4292 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004293
Jim Grosbachc320c852011-08-05 21:28:30 +00004294 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4295 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004296 if (Parser.getTok().is(AsmToken::Comma)) {
4297 Parser.Lex(); // Eat the ','.
4298 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4299 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004300
4301 // FIXME: Only approximates end...may include intervening whitespace.
4302 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004303 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004304
4305 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4306 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004307
4308 return MatchOperand_Success;
4309}
4310
David Blaikie960ea3f2014-06-08 16:18:35 +00004311ARMAsmParser::OperandMatchResultTy
4312ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004313 // Check for a post-index addressing register operand. Specifically:
4314 // am3offset := '+' register
4315 // | '-' register
4316 // | register
4317 // | # imm
4318 // | # + imm
4319 // | # - imm
4320
4321 // This method must return MatchOperand_NoMatch without consuming any tokens
4322 // in the case where there is no match, as other alternatives take other
4323 // parse methods.
4324 AsmToken Tok = Parser.getTok();
4325 SMLoc S = Tok.getLoc();
4326
4327 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004328 if (Parser.getTok().is(AsmToken::Hash) ||
4329 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004330 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004331 // Explicitly look for a '-', as we need to encode negative zero
4332 // differently.
4333 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4334 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004335 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004336 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004337 return MatchOperand_ParseFail;
4338 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4339 if (!CE) {
4340 Error(S, "constant expression expected");
4341 return MatchOperand_ParseFail;
4342 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004343 // Negative zero is encoded as the flag value INT32_MIN.
4344 int32_t Val = CE->getValue();
4345 if (isNegative && Val == 0)
4346 Val = INT32_MIN;
4347
4348 Operands.push_back(
4349 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4350
4351 return MatchOperand_Success;
4352 }
4353
4354
4355 bool haveEaten = false;
4356 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004357 if (Tok.is(AsmToken::Plus)) {
4358 Parser.Lex(); // Eat the '+' token.
4359 haveEaten = true;
4360 } else if (Tok.is(AsmToken::Minus)) {
4361 Parser.Lex(); // Eat the '-' token.
4362 isAdd = false;
4363 haveEaten = true;
4364 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004365
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004366 Tok = Parser.getTok();
4367 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004368 if (Reg == -1) {
4369 if (!haveEaten)
4370 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004371 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004372 return MatchOperand_ParseFail;
4373 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004374
4375 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004376 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004377
4378 return MatchOperand_Success;
4379}
4380
Tim Northovereb5e4d52013-07-22 09:06:12 +00004381/// Convert parsed operands to MCInst. Needed here because this instruction
4382/// only has two register operands, but multiplication is commutative so
4383/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
David Blaikie960ea3f2014-06-08 16:18:35 +00004384void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
4385 const OperandVector &Operands) {
4386 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1);
4387 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004388 // If we have a three-operand form, make sure to set Rn to be the operand
4389 // that isn't the same as Rd.
4390 unsigned RegOp = 4;
4391 if (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00004392 ((ARMOperand &)*Operands[4]).getReg() ==
4393 ((ARMOperand &)*Operands[3]).getReg())
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004394 RegOp = 5;
David Blaikie960ea3f2014-06-08 16:18:35 +00004395 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004396 Inst.addOperand(Inst.getOperand(0));
David Blaikie960ea3f2014-06-08 16:18:35 +00004397 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004398}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004399
David Blaikie960ea3f2014-06-08 16:18:35 +00004400void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
4401 const OperandVector &Operands) {
Mihai Popaad18d3c2013-08-09 10:38:32 +00004402 int CondOp = -1, ImmOp = -1;
4403 switch(Inst.getOpcode()) {
4404 case ARM::tB:
4405 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4406
4407 case ARM::t2B:
4408 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4409
4410 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4411 }
4412 // first decide whether or not the branch should be conditional
4413 // by looking at it's location relative to an IT block
4414 if(inITBlock()) {
4415 // inside an IT block we cannot have any conditional branches. any
4416 // such instructions needs to be converted to unconditional form
4417 switch(Inst.getOpcode()) {
4418 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4419 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4420 }
4421 } else {
4422 // outside IT blocks we can only have unconditional branches with AL
4423 // condition code or conditional branches with non-AL condition code
David Blaikie960ea3f2014-06-08 16:18:35 +00004424 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode();
Mihai Popaad18d3c2013-08-09 10:38:32 +00004425 switch(Inst.getOpcode()) {
4426 case ARM::tB:
4427 case ARM::tBcc:
4428 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4429 break;
4430 case ARM::t2B:
4431 case ARM::t2Bcc:
4432 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4433 break;
4434 }
4435 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004436
Mihai Popaad18d3c2013-08-09 10:38:32 +00004437 // now decide on encoding size based on branch target range
4438 switch(Inst.getOpcode()) {
4439 // classify tB as either t2B or t1B based on range of immediate operand
4440 case ARM::tB: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004441 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4442 if (!op.isSignedOffset<11, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004443 Inst.setOpcode(ARM::t2B);
4444 break;
4445 }
4446 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4447 case ARM::tBcc: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004448 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4449 if (!op.isSignedOffset<8, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004450 Inst.setOpcode(ARM::t2Bcc);
4451 break;
4452 }
4453 }
David Blaikie960ea3f2014-06-08 16:18:35 +00004454 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1);
4455 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2);
Mihai Popaad18d3c2013-08-09 10:38:32 +00004456}
4457
Bill Wendlinge18980a2010-11-06 22:36:58 +00004458/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004459/// or an error. The first token must be a '[' when called.
David Blaikie960ea3f2014-06-08 16:18:35 +00004460bool ARMAsmParser::parseMemory(OperandVector &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004461 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004462 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004463 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004464 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004465 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004466
Sean Callanan936b0d32010-01-19 21:44:56 +00004467 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004468 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004469 if (BaseRegNum == -1)
4470 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004471
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004472 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004473 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004474 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4475 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004476 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004477
Jim Grosbachd3595712011-08-03 23:50:40 +00004478 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004479 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004480 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004481
Craig Topper062a2ba2014-04-25 05:30:21 +00004482 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4483 ARM_AM::no_shift, 0, 0, false,
4484 S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004485
Jim Grosbach40700e02011-09-19 18:42:21 +00004486 // If there's a pre-indexing writeback marker, '!', just add it as a token
4487 // operand. It's rather odd, but syntactically valid.
4488 if (Parser.getTok().is(AsmToken::Exclaim)) {
4489 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4490 Parser.Lex(); // Eat the '!'.
4491 }
4492
Jim Grosbachd3595712011-08-03 23:50:40 +00004493 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004494 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004495
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004496 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4497 "Lost colon or comma in memory operand?!");
4498 if (Tok.is(AsmToken::Comma)) {
4499 Parser.Lex(); // Eat the comma.
4500 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004501
Jim Grosbacha95ec992011-10-11 17:29:55 +00004502 // If we have a ':', it's an alignment specifier.
4503 if (Parser.getTok().is(AsmToken::Colon)) {
4504 Parser.Lex(); // Eat the ':'.
4505 E = Parser.getTok().getLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00004506 SMLoc AlignmentLoc = Tok.getLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004507
4508 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004509 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004510 return true;
4511
4512 // The expression has to be a constant. Memory references with relocations
4513 // don't come through here, as they use the <label> forms of the relevant
4514 // instructions.
4515 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4516 if (!CE)
4517 return Error (E, "constant expression expected");
4518
4519 unsigned Align = 0;
4520 switch (CE->getValue()) {
4521 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004522 return Error(E,
4523 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4524 case 16: Align = 2; break;
4525 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004526 case 64: Align = 8; break;
4527 case 128: Align = 16; break;
4528 case 256: Align = 32; break;
4529 }
4530
4531 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004532 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004533 return Error(Parser.getTok().getLoc(), "']' expected");
4534 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004535 Parser.Lex(); // Eat right bracket token.
4536
4537 // Don't worry about range checking the value here. That's handled by
4538 // the is*() predicates.
Craig Topper062a2ba2014-04-25 05:30:21 +00004539 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004540 ARM_AM::no_shift, 0, Align,
Kevin Enderby488f20b2014-04-10 20:18:58 +00004541 false, S, E, AlignmentLoc));
Jim Grosbacha95ec992011-10-11 17:29:55 +00004542
4543 // If there's a pre-indexing writeback marker, '!', just add it as a token
4544 // operand.
4545 if (Parser.getTok().is(AsmToken::Exclaim)) {
4546 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4547 Parser.Lex(); // Eat the '!'.
4548 }
4549
4550 return false;
4551 }
4552
4553 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004554 // offset. Be friendly and also accept a plain integer (without a leading
4555 // hash) for gas compatibility.
4556 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004557 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004558 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004559 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004560 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004561 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004562
Owen Anderson967674d2011-08-29 19:36:44 +00004563 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004564 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004565 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004566 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004567
4568 // The expression has to be a constant. Memory references with relocations
4569 // don't come through here, as they use the <label> forms of the relevant
4570 // instructions.
4571 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4572 if (!CE)
4573 return Error (E, "constant expression expected");
4574
Owen Anderson967674d2011-08-29 19:36:44 +00004575 // If the constant was #-0, represent it as INT32_MIN.
4576 int32_t Val = CE->getValue();
4577 if (isNegative && Val == 0)
4578 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4579
Jim Grosbachd3595712011-08-03 23:50:40 +00004580 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004581 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004582 return Error(Parser.getTok().getLoc(), "']' expected");
4583 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004584 Parser.Lex(); // Eat right bracket token.
4585
4586 // Don't worry about range checking the value here. That's handled by
4587 // the is*() predicates.
4588 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004589 ARM_AM::no_shift, 0, 0,
4590 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004591
4592 // If there's a pre-indexing writeback marker, '!', just add it as a token
4593 // operand.
4594 if (Parser.getTok().is(AsmToken::Exclaim)) {
4595 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4596 Parser.Lex(); // Eat the '!'.
4597 }
4598
4599 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004600 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004601
4602 // The register offset is optionally preceded by a '+' or '-'
4603 bool isNegative = false;
4604 if (Parser.getTok().is(AsmToken::Minus)) {
4605 isNegative = true;
4606 Parser.Lex(); // Eat the '-'.
4607 } else if (Parser.getTok().is(AsmToken::Plus)) {
4608 // Nothing to do.
4609 Parser.Lex(); // Eat the '+'.
4610 }
4611
4612 E = Parser.getTok().getLoc();
4613 int OffsetRegNum = tryParseRegister();
4614 if (OffsetRegNum == -1)
4615 return Error(E, "register expected");
4616
4617 // If there's a shift operator, handle it.
4618 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004619 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004620 if (Parser.getTok().is(AsmToken::Comma)) {
4621 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004622 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004623 return true;
4624 }
4625
4626 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004627 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004628 return Error(Parser.getTok().getLoc(), "']' expected");
4629 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004630 Parser.Lex(); // Eat right bracket token.
4631
Craig Topper062a2ba2014-04-25 05:30:21 +00004632 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004633 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004634 S, E));
4635
Jim Grosbachc320c852011-08-05 21:28:30 +00004636 // If there's a pre-indexing writeback marker, '!', just add it as a token
4637 // operand.
4638 if (Parser.getTok().is(AsmToken::Exclaim)) {
4639 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4640 Parser.Lex(); // Eat the '!'.
4641 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004642
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004643 return false;
4644}
4645
Jim Grosbachd3595712011-08-03 23:50:40 +00004646/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004647/// ( lsl | lsr | asr | ror ) , # shift_amount
4648/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004649/// return true if it parses a shift otherwise it returns false.
4650bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4651 unsigned &Amount) {
4652 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004653 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004654 if (Tok.isNot(AsmToken::Identifier))
4655 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004656 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004657 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4658 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004659 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004660 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004661 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004662 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004663 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004664 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004665 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004666 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004667 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004668 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004669 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004670 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004671
Jim Grosbachd3595712011-08-03 23:50:40 +00004672 // rrx stands alone.
4673 Amount = 0;
4674 if (St != ARM_AM::rrx) {
4675 Loc = Parser.getTok().getLoc();
4676 // A '#' and a shift amount.
4677 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004678 if (HashTok.isNot(AsmToken::Hash) &&
4679 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004680 return Error(HashTok.getLoc(), "'#' expected");
4681 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004682
Jim Grosbachd3595712011-08-03 23:50:40 +00004683 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004684 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004685 return true;
4686 // Range check the immediate.
4687 // lsl, ror: 0 <= imm <= 31
4688 // lsr, asr: 0 <= imm <= 32
4689 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4690 if (!CE)
4691 return Error(Loc, "shift amount must be an immediate");
4692 int64_t Imm = CE->getValue();
4693 if (Imm < 0 ||
4694 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4695 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4696 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004697 // If <ShiftTy> #0, turn it into a no_shift.
4698 if (Imm == 0)
4699 St = ARM_AM::lsl;
4700 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4701 if (Imm == 32)
4702 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004703 Amount = Imm;
4704 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004705
4706 return false;
4707}
4708
Jim Grosbache7fbce72011-10-03 23:38:36 +00004709/// parseFPImm - A floating point immediate expression operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00004710ARMAsmParser::OperandMatchResultTy
4711ARMAsmParser::parseFPImm(OperandVector &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004712 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004713 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004714 // integer only.
4715 //
4716 // This routine still creates a generic Immediate operand, containing
4717 // a bitcast of the 64-bit floating point value. The various operands
4718 // that accept floats can check whether the value is valid for them
4719 // via the standard is*() predicates.
4720
Jim Grosbache7fbce72011-10-03 23:38:36 +00004721 SMLoc S = Parser.getTok().getLoc();
4722
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004723 if (Parser.getTok().isNot(AsmToken::Hash) &&
4724 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004725 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004726
4727 // Disambiguate the VMOV forms that can accept an FP immediate.
4728 // vmov.f32 <sreg>, #imm
4729 // vmov.f64 <dreg>, #imm
4730 // vmov.f32 <dreg>, #imm @ vector f32x2
4731 // vmov.f32 <qreg>, #imm @ vector f32x4
4732 //
4733 // There are also the NEON VMOV instructions which expect an
4734 // integer constant. Make sure we don't try to parse an FPImm
4735 // for these:
4736 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
David Blaikie960ea3f2014-06-08 16:18:35 +00004737 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]);
4738 bool isVmovf = TyOp.isToken() &&
4739 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64");
4740 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
4741 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
4742 Mnemonic.getToken() == "fconsts");
David Peixottoa872e0e2014-01-07 18:19:23 +00004743 if (!(isVmovf || isFconst))
Jim Grosbach741cd732011-10-17 22:26:03 +00004744 return MatchOperand_NoMatch;
4745
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004746 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004747
4748 // Handle negation, as that still comes through as a separate token.
4749 bool isNegative = false;
4750 if (Parser.getTok().is(AsmToken::Minus)) {
4751 isNegative = true;
4752 Parser.Lex();
4753 }
4754 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004755 SMLoc Loc = Tok.getLoc();
David Peixottoa872e0e2014-01-07 18:19:23 +00004756 if (Tok.is(AsmToken::Real) && isVmovf) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004757 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004758 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4759 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004760 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004761 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004762 Operands.push_back(ARMOperand::CreateImm(
4763 MCConstantExpr::Create(IntVal, getContext()),
4764 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004765 return MatchOperand_Success;
4766 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004767 // Also handle plain integers. Instructions which allow floating point
4768 // immediates also allow a raw encoded 8-bit value.
David Peixottoa872e0e2014-01-07 18:19:23 +00004769 if (Tok.is(AsmToken::Integer) && isFconst) {
Jim Grosbache7fbce72011-10-03 23:38:36 +00004770 int64_t Val = Tok.getIntVal();
4771 Parser.Lex(); // Eat the token.
4772 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004773 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004774 return MatchOperand_ParseFail;
4775 }
David Peixottoa872e0e2014-01-07 18:19:23 +00004776 float RealVal = ARM_AM::getFPImmFloat(Val);
4777 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
4778
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004779 Operands.push_back(ARMOperand::CreateImm(
4780 MCConstantExpr::Create(Val, getContext()), S,
4781 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004782 return MatchOperand_Success;
4783 }
4784
Jim Grosbach235c8d22012-01-19 02:47:30 +00004785 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004786 return MatchOperand_ParseFail;
4787}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004788
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004789/// Parse a arm instruction operand. For now this parses the operand regardless
4790/// of the mnemonic.
David Blaikie960ea3f2014-06-08 16:18:35 +00004791bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004792 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004793
4794 // Check if the current operand has a custom associated parser, if so, try to
4795 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004796 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4797 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004798 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004799 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4800 // there was a match, but an error occurred, in which case, just return that
4801 // the operand parsing failed.
4802 if (ResTy == MatchOperand_ParseFail)
4803 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004804
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004805 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004806 default:
4807 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004808 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004809 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004810 // If we've seen a branch mnemonic, the next operand must be a label. This
4811 // is true even if the label is a register name. So "br r1" means branch to
4812 // label "r1".
4813 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4814 if (!ExpectLabel) {
4815 if (!tryParseRegisterWithWriteBack(Operands))
4816 return false;
4817 int Res = tryParseShiftRegister(Operands);
4818 if (Res == 0) // success
4819 return false;
4820 else if (Res == -1) // irrecoverable error
4821 return true;
4822 // If this is VMRS, check for the apsr_nzcv operand.
4823 if (Mnemonic == "vmrs" &&
4824 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4825 S = Parser.getTok().getLoc();
4826 Parser.Lex();
4827 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4828 return false;
4829 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004830 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004831
4832 // Fall though for the Identifier case that is not a register or a
4833 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004834 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004835 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004836 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004837 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004838 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004839 // This was not a register so parse other operands that start with an
4840 // identifier (like labels) as expressions and create them as immediates.
4841 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004842 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004843 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004844 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004845 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004846 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4847 return false;
4848 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004849 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004850 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004851 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004852 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004853 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004854 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004855 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004856 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004857 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004858
4859 if (Parser.getTok().isNot(AsmToken::Colon)) {
4860 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4861 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004862 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004863 return true;
4864 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4865 if (CE) {
4866 int32_t Val = CE->getValue();
4867 if (isNegative && Val == 0)
4868 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4869 }
4870 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4871 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004872
4873 // There can be a trailing '!' on operands that we want as a separate
Saleem Abdulrasool83e37702013-12-28 03:07:12 +00004874 // '!' Token operand. Handle that here. For example, the compatibility
Jim Grosbach9be2d712013-02-23 00:52:09 +00004875 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4876 if (Parser.getTok().is(AsmToken::Exclaim)) {
4877 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4878 Parser.getTok().getLoc()));
4879 Parser.Lex(); // Eat exclaim token
4880 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004881 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004882 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004883 // w/ a ':' after the '#', it's just like a plain ':'.
4884 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004885 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004886 case AsmToken::Colon: {
4887 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004888 // FIXME: Check it's an expression prefix,
4889 // e.g. (FOO - :lower16:BAR) isn't legal.
4890 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004891 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004892 return true;
4893
Evan Cheng965b3c72011-01-13 07:58:56 +00004894 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004895 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004896 return true;
4897
Evan Cheng965b3c72011-01-13 07:58:56 +00004898 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004899 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004900 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004901 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004902 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004903 }
David Peixottoe407d092013-12-19 18:12:36 +00004904 case AsmToken::Equal: {
4905 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4906 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4907
David Peixottoe407d092013-12-19 18:12:36 +00004908 Parser.Lex(); // Eat '='
4909 const MCExpr *SubExprVal;
4910 if (getParser().parseExpression(SubExprVal))
4911 return true;
4912 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4913
David Peixottob9b73622014-02-04 17:22:40 +00004914 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
David Peixottoe407d092013-12-19 18:12:36 +00004915 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4916 return false;
4917 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004918 }
4919}
4920
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004921// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004922// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004923bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004924 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004925
Saleem Abdulrasool435f4562014-01-10 04:38:40 +00004926 // consume an optional '#' (GNU compatibility)
4927 if (getLexer().is(AsmToken::Hash))
4928 Parser.Lex();
4929
Jason W Kim1f7bc072011-01-11 23:53:41 +00004930 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004931 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004932 Parser.Lex(); // Eat ':'
4933
4934 if (getLexer().isNot(AsmToken::Identifier)) {
4935 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4936 return true;
4937 }
4938
4939 StringRef IDVal = Parser.getTok().getIdentifier();
4940 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004941 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004942 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004943 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004944 } else {
4945 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4946 return true;
4947 }
4948 Parser.Lex();
4949
4950 if (getLexer().isNot(AsmToken::Colon)) {
4951 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4952 return true;
4953 }
4954 Parser.Lex(); // Eat the last ':'
4955 return false;
4956}
4957
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004958/// \brief Given a mnemonic, split out possible predication code and carry
4959/// setting letters to form a canonical mnemonic and flags.
4960//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004961// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004962// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004963StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004964 unsigned &PredicationCode,
4965 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004966 unsigned &ProcessorIMod,
4967 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004968 PredicationCode = ARMCC::AL;
4969 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004970 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004971
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004972 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004973 //
4974 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004975 if ((Mnemonic == "movs" && isThumb()) ||
4976 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4977 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4978 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4979 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004980 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004981 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4982 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004983 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004984 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004985 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4986 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4987 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004988 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004989
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004990 // First, split out any predication code. Ignore mnemonics we know aren't
4991 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004992 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004993 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004994 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004995 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004996 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4997 .Case("eq", ARMCC::EQ)
4998 .Case("ne", ARMCC::NE)
4999 .Case("hs", ARMCC::HS)
5000 .Case("cs", ARMCC::HS)
5001 .Case("lo", ARMCC::LO)
5002 .Case("cc", ARMCC::LO)
5003 .Case("mi", ARMCC::MI)
5004 .Case("pl", ARMCC::PL)
5005 .Case("vs", ARMCC::VS)
5006 .Case("vc", ARMCC::VC)
5007 .Case("hi", ARMCC::HI)
5008 .Case("ls", ARMCC::LS)
5009 .Case("ge", ARMCC::GE)
5010 .Case("lt", ARMCC::LT)
5011 .Case("gt", ARMCC::GT)
5012 .Case("le", ARMCC::LE)
5013 .Case("al", ARMCC::AL)
5014 .Default(~0U);
5015 if (CC != ~0U) {
5016 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
5017 PredicationCode = CC;
5018 }
Bill Wendling193961b2010-10-29 23:50:21 +00005019 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005020
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005021 // Next, determine if we have a carry setting bit. We explicitly ignore all
5022 // the instructions we know end in 's'.
5023 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00005024 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005025 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
5026 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
5027 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00005028 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00005029 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00005030 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00005031 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
David Peixottoa872e0e2014-01-07 18:19:23 +00005032 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00005033 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005034 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
5035 CarrySetting = true;
5036 }
5037
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005038 // The "cps" instruction can have a interrupt mode operand which is glued into
5039 // the mnemonic. Check if this is the case, split it and parse the imod op
5040 if (Mnemonic.startswith("cps")) {
5041 // Split out any imod code.
5042 unsigned IMod =
5043 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
5044 .Case("ie", ARM_PROC::IE)
5045 .Case("id", ARM_PROC::ID)
5046 .Default(~0U);
5047 if (IMod != ~0U) {
5048 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5049 ProcessorIMod = IMod;
5050 }
5051 }
5052
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005053 // The "it" instruction has the condition mask on the end of the mnemonic.
5054 if (Mnemonic.startswith("it")) {
5055 ITMask = Mnemonic.slice(2, Mnemonic.size());
5056 Mnemonic = Mnemonic.slice(0, 2);
5057 }
5058
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005059 return Mnemonic;
5060}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005061
5062/// \brief Given a canonical mnemonic, determine if the instruction ever allows
5063/// inclusion of carry set or predication code operands.
5064//
5065// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00005066void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00005067getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5068 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005069 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5070 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005071 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005072 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005073 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005074 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005075 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00005076 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005077 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005078 Mnemonic == "mla" || Mnemonic == "smlal" ||
5079 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005080 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00005081 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00005082 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005083
Tim Northover2c45a382013-06-26 16:52:40 +00005084 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5085 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00005086 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
5087 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
5088 Mnemonic.startswith("vsel") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00005089 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005090 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
5091 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00005092 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
5093 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5094 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00005095 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005096 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005097 } else if (!isThumb()) {
5098 // Some instructions are only predicable in Thumb mode
5099 CanAcceptPredicationCode
5100 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5101 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5102 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5103 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5104 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5105 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5106 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5107 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00005108 if (hasV6MOps())
5109 CanAcceptPredicationCode = Mnemonic != "movs";
5110 else
5111 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005112 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005113 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005114}
5115
Jim Grosbach7283da92011-08-16 21:12:37 +00005116bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
David Blaikie960ea3f2014-06-08 16:18:35 +00005117 OperandVector &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005118 // FIXME: This is all horribly hacky. We really need a better way to deal
5119 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005120
5121 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5122 // another does not. Specifically, the MOVW instruction does not. So we
5123 // special case it here and remove the defaulted (non-setting) cc_out
5124 // operand if that's the instruction we're trying to match.
5125 //
5126 // We do this as post-processing of the explicit operands rather than just
5127 // conditionally adding the cc_out in the first place because we need
5128 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005129 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005130 !static_cast<ARMOperand &>(*Operands[4]).isARMSOImm() &&
5131 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
5132 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach7283da92011-08-16 21:12:37 +00005133 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005134
5135 // Register-register 'add' for thumb does not have a cc_out operand
5136 // when there are only two register operands.
5137 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005138 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5139 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5140 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005141 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005142 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005143 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5144 // have to check the immediate range here since Thumb2 has a variant
5145 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005146 if (((isThumb() && Mnemonic == "add") ||
5147 (isThumbTwo() && Mnemonic == "sub")) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005148 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5149 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5150 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
5151 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5152 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
5153 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005154 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005155 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5156 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005157 // selecting via the generic "add" mnemonic, so to know that we
5158 // should remove the cc_out operand, we have to explicitly check that
5159 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005160 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005161 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5162 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5163 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005164 // Nest conditions rather than one big 'if' statement for readability.
5165 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005166 // If both registers are low, we're in an IT block, and the immediate is
5167 // in range, we should use encoding T1 instead, which has a cc_out.
5168 if (inITBlock() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005169 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
5170 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
5171 static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005172 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005173 // Check against T3. If the second register is the PC, this is an
5174 // alternate form of ADR, which uses encoding T4, so check for that too.
David Blaikie960ea3f2014-06-08 16:18:35 +00005175 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
5176 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm())
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005177 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005178
5179 // Otherwise, we use encoding T4, which does not have a cc_out
5180 // operand.
5181 return true;
5182 }
5183
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005184 // The thumb2 multiply instruction doesn't have a CCOut register, so
5185 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5186 // use the 16-bit encoding or not.
5187 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005188 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5189 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5190 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5191 static_cast<ARMOperand &>(*Operands[5]).isReg() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005192 // If the registers aren't low regs, the destination reg isn't the
5193 // same as one of the source regs, or the cc_out operand is zero
5194 // outside of an IT block, we have to use the 32-bit encoding, so
5195 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005196 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5197 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5198 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
5199 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5200 static_cast<ARMOperand &>(*Operands[5]).getReg() &&
5201 static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5202 static_cast<ARMOperand &>(*Operands[4]).getReg())))
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005203 return true;
5204
Jim Grosbachefa7e952011-11-15 19:55:16 +00005205 // Also check the 'mul' syntax variant that doesn't specify an explicit
5206 // destination register.
5207 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005208 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5209 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5210 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
Jim Grosbachefa7e952011-11-15 19:55:16 +00005211 // If the registers aren't low regs or the cc_out operand is zero
5212 // outside of an IT block, we have to use the 32-bit encoding, so
5213 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005214 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5215 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
Jim Grosbachefa7e952011-11-15 19:55:16 +00005216 !inITBlock()))
5217 return true;
5218
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005219
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005220
Jim Grosbach4b701af2011-08-24 21:42:27 +00005221 // Register-register 'add/sub' for thumb does not have a cc_out operand
5222 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5223 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5224 // right, this will result in better diagnostics (which operand is off)
5225 // anyway.
5226 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5227 (Operands.size() == 5 || Operands.size() == 6) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005228 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5229 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
5230 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5231 (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005232 (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005233 static_cast<ARMOperand &>(*Operands[5]).isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005234 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005235
Jim Grosbach7283da92011-08-16 21:12:37 +00005236 return false;
5237}
5238
David Blaikie960ea3f2014-06-08 16:18:35 +00005239bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
5240 OperandVector &Operands) {
Joey Goulye8602552013-07-19 16:34:16 +00005241 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5242 unsigned RegIdx = 3;
5243 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005244 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") {
5245 if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5246 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32")
Joey Goulye8602552013-07-19 16:34:16 +00005247 RegIdx = 4;
5248
David Blaikie960ea3f2014-06-08 16:18:35 +00005249 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
5250 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
5251 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
5252 ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
5253 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
Joey Goulye8602552013-07-19 16:34:16 +00005254 return true;
5255 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005256 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005257}
5258
Jim Grosbach12952fe2011-11-11 23:08:10 +00005259static bool isDataTypeToken(StringRef Tok) {
5260 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5261 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5262 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5263 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5264 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5265 Tok == ".f" || Tok == ".d";
5266}
5267
5268// FIXME: This bit should probably be handled via an explicit match class
5269// in the .td files that matches the suffix instead of having it be
5270// a literal string token the way it is now.
5271static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5272 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5273}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005274static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5275 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005276
5277static bool RequiresVFPRegListValidation(StringRef Inst,
5278 bool &AcceptSinglePrecisionOnly,
5279 bool &AcceptDoublePrecisionOnly) {
5280 if (Inst.size() < 7)
5281 return false;
5282
5283 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5284 StringRef AddressingMode = Inst.substr(4, 2);
5285 if (AddressingMode == "ia" || AddressingMode == "db" ||
5286 AddressingMode == "ea" || AddressingMode == "fd") {
5287 AcceptSinglePrecisionOnly = Inst[6] == 's';
5288 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5289 return true;
5290 }
5291 }
5292
5293 return false;
5294}
5295
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005296/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005297bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
David Blaikie960ea3f2014-06-08 16:18:35 +00005298 SMLoc NameLoc, OperandVector &Operands) {
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005299 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005300 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005301 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005302 bool AcceptDoublePrecisionOnly;
5303 RequireVFPRegisterListCheck =
5304 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5305 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005306
Jim Grosbach8be2f652011-12-09 23:34:09 +00005307 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005308 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005309 // The generic tblgen'erated code does this later, at the start of
5310 // MatchInstructionImpl(), but that's too late for aliases that include
5311 // any sort of suffix.
5312 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005313 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5314 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005315
Jim Grosbachab5830e2011-12-14 02:16:11 +00005316 // First check for the ARM-specific .req directive.
5317 if (Parser.getTok().is(AsmToken::Identifier) &&
5318 Parser.getTok().getIdentifier() == ".req") {
5319 parseDirectiveReq(Name, NameLoc);
5320 // We always return 'error' for this, as we're done with this
5321 // statement and don't need to match the 'instruction."
5322 return true;
5323 }
5324
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005325 // Create the leading tokens for the mnemonic, split by '.' characters.
5326 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005327 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005328
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005329 // Split out the predication code and carry setting flag from the mnemonic.
5330 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005331 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005332 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005333 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005334 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005335 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005336
Jim Grosbach1c171b12011-08-25 17:23:55 +00005337 // In Thumb1, only the branch (B) instruction can be predicated.
5338 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005339 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005340 return Error(NameLoc, "conditional execution not supported in Thumb1");
5341 }
5342
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005343 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5344
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005345 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5346 // is the mask as it will be for the IT encoding if the conditional
5347 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5348 // where the conditional bit0 is zero, the instruction post-processing
5349 // will adjust the mask accordingly.
5350 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005351 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5352 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005353 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005354 return Error(Loc, "too many conditions on IT instruction");
5355 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005356 unsigned Mask = 8;
5357 for (unsigned i = ITMask.size(); i != 0; --i) {
5358 char pos = ITMask[i - 1];
5359 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005360 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005361 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005362 }
5363 Mask >>= 1;
5364 if (ITMask[i - 1] == 't')
5365 Mask |= 8;
5366 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005367 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005368 }
5369
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005370 // FIXME: This is all a pretty gross hack. We should automatically handle
5371 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005372
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005373 // Next, add the CCOut and ConditionCode operands, if needed.
5374 //
5375 // For mnemonics which can ever incorporate a carry setting bit or predication
5376 // code, our matching model involves us always generating CCOut and
5377 // ConditionCode operands to match the mnemonic "as written" and then we let
5378 // the matcher deal with finding the right instruction or generating an
5379 // appropriate error.
5380 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005381 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005382
Jim Grosbach03a8a162011-07-14 22:04:21 +00005383 // If we had a carry-set on an instruction that can't do that, issue an
5384 // error.
5385 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005386 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005387 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005388 "' can not set flags, but 's' suffix specified");
5389 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005390 // If we had a predication code on an instruction that can't do that, issue an
5391 // error.
5392 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005393 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005394 return Error(NameLoc, "instruction '" + Mnemonic +
5395 "' is not predicable, but condition code specified");
5396 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005397
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005398 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005399 if (CanAcceptCarrySet) {
5400 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005401 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005402 Loc));
5403 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005404
5405 // Add the predication code operand, if necessary.
5406 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005407 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5408 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005409 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005410 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005411 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005412
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005413 // Add the processor imod operand, if necessary.
5414 if (ProcessorIMod) {
5415 Operands.push_back(ARMOperand::CreateImm(
5416 MCConstantExpr::Create(ProcessorIMod, getContext()),
5417 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005418 }
5419
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005420 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005421 while (Next != StringRef::npos) {
5422 Start = Next;
5423 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005424 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005425
Jim Grosbach12952fe2011-11-11 23:08:10 +00005426 // Some NEON instructions have an optional datatype suffix that is
5427 // completely ignored. Check for that.
5428 if (isDataTypeToken(ExtraToken) &&
5429 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5430 continue;
5431
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005432 // For for ARM mode generate an error if the .n qualifier is used.
5433 if (ExtraToken == ".n" && !isThumb()) {
5434 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005435 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005436 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5437 "arm mode");
5438 }
5439
5440 // The .n qualifier is always discarded as that is what the tables
5441 // and matcher expect. In ARM mode the .w qualifier has no effect,
5442 // so discard it to avoid errors that can be caused by the matcher.
5443 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005444 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5445 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5446 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005447 }
5448
5449 // Read the remaining operands.
5450 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005451 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005452 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005453 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005454 return true;
5455 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005456
5457 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005458 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005459
5460 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005461 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005462 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005463 return true;
5464 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005465 }
5466 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005467
Chris Lattnera2a9d162010-09-11 16:18:25 +00005468 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005469 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005470 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005471 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005472 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005473
Chris Lattner91689c12010-09-08 05:10:46 +00005474 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005475
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005476 if (RequireVFPRegisterListCheck) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005477 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back());
5478 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList())
5479 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005480 "VFP/Neon single precision register expected");
David Blaikie960ea3f2014-06-08 16:18:35 +00005481 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList())
5482 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005483 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005484 }
5485
Jim Grosbach7283da92011-08-16 21:12:37 +00005486 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5487 // do and don't have a cc_out optional-def operand. With some spot-checks
5488 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005489 // parse and adjust accordingly before actually matching. We shouldn't ever
5490 // try to remove a cc_out operand that was explicitly set on the the
5491 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5492 // table driven matcher doesn't fit well with the ARM instruction set.
David Blaikie960ea3f2014-06-08 16:18:35 +00005493 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005494 Operands.erase(Operands.begin() + 1);
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005495
Joey Goulye8602552013-07-19 16:34:16 +00005496 // Some instructions have the same mnemonic, but don't always
5497 // have a predicate. Distinguish them here and delete the
5498 // predicate if needed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005499 if (shouldOmitPredicateOperand(Mnemonic, Operands))
Joey Goulye8602552013-07-19 16:34:16 +00005500 Operands.erase(Operands.begin() + 1);
Joey Goulye8602552013-07-19 16:34:16 +00005501
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005502 // ARM mode 'blx' need special handling, as the register operand version
5503 // is predicable, but the label operand version is not. So, we can't rely
5504 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005505 // a k_CondCode operand in the list. If we're trying to match the label
5506 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005507 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005508 static_cast<ARMOperand &>(*Operands[2]).isImm())
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005509 Operands.erase(Operands.begin() + 1);
Jim Grosbach8cffa282011-08-11 23:51:13 +00005510
Weiming Zhao8f56f882012-11-16 21:55:34 +00005511 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5512 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5513 // a single GPRPair reg operand is used in the .td file to replace the two
5514 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5515 // expressed as a GPRPair, so we have to manually merge them.
5516 // FIXME: We would really like to be able to tablegen'erate this.
5517 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005518 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5519 Mnemonic == "stlexd")) {
5520 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005521 unsigned Idx = isLoad ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005522 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
5523 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005524
5525 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5526 // Adjust only if Op1 and Op2 are GPRs.
David Blaikie960ea3f2014-06-08 16:18:35 +00005527 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
5528 MRC.contains(Op2.getReg())) {
5529 unsigned Reg1 = Op1.getReg();
5530 unsigned Reg2 = Op2.getReg();
Weiming Zhao8f56f882012-11-16 21:55:34 +00005531 unsigned Rt = MRI->getEncodingValue(Reg1);
5532 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5533
5534 // Rt2 must be Rt + 1 and Rt must be even.
5535 if (Rt + 1 != Rt2 || (Rt & 1)) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005536 Error(Op2.getStartLoc(), isLoad
5537 ? "destination operands must be sequential"
5538 : "source operands must be sequential");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005539 return true;
5540 }
5541 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5542 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
David Blaikie960ea3f2014-06-08 16:18:35 +00005543 Operands[Idx] =
5544 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
5545 Operands.erase(Operands.begin() + Idx + 1);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005546 }
5547 }
5548
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005549 // GNU Assembler extension (compatibility)
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005550 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005551 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5552 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5553 if (Op3.isMem()) {
5554 assert(Op2.isReg() && "expected register argument");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005555
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005556 unsigned SuperReg = MRI->getMatchingSuperReg(
David Blaikie960ea3f2014-06-08 16:18:35 +00005557 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005558
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005559 assert(SuperReg && "expected register pair");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005560
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005561 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005562
David Blaikie960ea3f2014-06-08 16:18:35 +00005563 Operands.insert(
5564 Operands.begin() + 3,
5565 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005566 }
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005567 }
5568
Kevin Enderby78f95722013-07-31 21:05:30 +00005569 // FIXME: As said above, this is all a pretty gross hack. This instruction
5570 // does not fit with other "subs" and tblgen.
5571 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5572 // so the Mnemonic is the original name "subs" and delete the predicate
5573 // operand so it will match the table entry.
5574 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005575 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5576 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
5577 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5578 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
5579 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5580 Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
Kevin Enderby78f95722013-07-31 21:05:30 +00005581 Operands.erase(Operands.begin() + 1);
Kevin Enderby78f95722013-07-31 21:05:30 +00005582 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005583 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005584}
5585
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005586// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005587
5588// return 'true' if register list contains non-low GPR registers,
5589// 'false' otherwise. If Reg is in the register list or is HiReg, set
5590// 'containsReg' to true.
5591static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5592 unsigned HiReg, bool &containsReg) {
5593 containsReg = false;
5594 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5595 unsigned OpReg = Inst.getOperand(i).getReg();
5596 if (OpReg == Reg)
5597 containsReg = true;
5598 // Anything other than a low register isn't legal here.
5599 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5600 return true;
5601 }
5602 return false;
5603}
5604
Jim Grosbacha31f2232011-09-07 18:05:34 +00005605// Check if the specified regisgter is in the register list of the inst,
5606// starting at the indicated operand number.
5607static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5608 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5609 unsigned OpReg = Inst.getOperand(i).getReg();
5610 if (OpReg == Reg)
5611 return true;
5612 }
5613 return false;
5614}
5615
Richard Barton8d519fe2013-09-05 14:14:19 +00005616// Return true if instruction has the interesting property of being
5617// allowed in IT blocks, but not being predicable.
5618static bool instIsBreakpoint(const MCInst &Inst) {
5619 return Inst.getOpcode() == ARM::tBKPT ||
5620 Inst.getOpcode() == ARM::BKPT ||
5621 Inst.getOpcode() == ARM::tHLT ||
5622 Inst.getOpcode() == ARM::HLT;
5623
5624}
5625
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005626// FIXME: We would really like to be able to tablegen'erate this.
David Blaikie960ea3f2014-06-08 16:18:35 +00005627bool ARMAsmParser::validateInstruction(MCInst &Inst,
5628 const OperandVector &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005629 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005630 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005631
Jim Grosbached16ec42011-08-29 22:24:09 +00005632 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005633 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005634 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005635 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005636 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005637 if (ITState.FirstCond)
5638 ITState.FirstCond = false;
5639 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005640 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005641 // The instruction must be predicable.
5642 if (!MCID.isPredicable())
5643 return Error(Loc, "instructions in IT block must be predicable");
5644 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005645 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005646 ARMCC::getOppositeCondition(ITState.Cond);
5647 if (Cond != ITCond) {
5648 // Find the condition code Operand to get its SMLoc information.
5649 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005650 for (unsigned I = 1; I < Operands.size(); ++I)
David Blaikie960ea3f2014-06-08 16:18:35 +00005651 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
Tilmann Schellerbe904772013-09-30 17:57:30 +00005652 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005653 return Error(CondLoc, "incorrect condition in IT block; got '" +
5654 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5655 "', but expected '" +
5656 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5657 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005658 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005659 } else if (isThumbTwo() && MCID.isPredicable() &&
5660 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005661 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5662 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005663 return Error(Loc, "predicated instructions must be in IT block");
5664
Tilmann Scheller255722b2013-09-30 16:11:48 +00005665 const unsigned Opcode = Inst.getOpcode();
5666 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005667 case ARM::LDRD:
5668 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005669 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005670 const unsigned RtReg = Inst.getOperand(0).getReg();
5671
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005672 // Rt can't be R14.
5673 if (RtReg == ARM::LR)
5674 return Error(Operands[3]->getStartLoc(),
5675 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005676
5677 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005678 // Rt must be even-numbered.
5679 if ((Rt & 1) == 1)
5680 return Error(Operands[3]->getStartLoc(),
5681 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005682
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005683 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005684 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005685 if (Rt2 != Rt + 1)
5686 return Error(Operands[3]->getStartLoc(),
5687 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005688
5689 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5690 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5691 // For addressing modes with writeback, the base register needs to be
5692 // different from the destination registers.
5693 if (Rn == Rt || Rn == Rt2)
5694 return Error(Operands[3]->getStartLoc(),
5695 "base register needs to be different from destination "
5696 "registers");
5697 }
5698
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005699 return false;
5700 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005701 case ARM::t2LDRDi8:
5702 case ARM::t2LDRD_PRE:
5703 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005704 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005705 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5706 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5707 if (Rt2 == Rt)
5708 return Error(Operands[3]->getStartLoc(),
5709 "destination operands can't be identical");
5710 return false;
5711 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005712 case ARM::STRD: {
5713 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005714 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5715 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005716 if (Rt2 != Rt + 1)
5717 return Error(Operands[3]->getStartLoc(),
5718 "source operands must be sequential");
5719 return false;
5720 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005721 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005722 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005723 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005724 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5725 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005726 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005727 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005728 "source operands must be sequential");
5729 return false;
5730 }
Tilmann Scheller3352a582014-07-23 12:38:17 +00005731 case ARM::STR_PRE_IMM:
5732 case ARM::STR_PRE_REG:
5733 case ARM::STR_POST_IMM:
Tilmann Scheller27272792014-07-23 13:03:47 +00005734 case ARM::STR_POST_REG:
Tilmann Scheller96ef72e2014-07-24 09:55:46 +00005735 case ARM::STRH_PRE:
5736 case ARM::STRH_POST:
Tilmann Scheller27272792014-07-23 13:03:47 +00005737 case ARM::STRB_PRE_IMM:
5738 case ARM::STRB_PRE_REG:
5739 case ARM::STRB_POST_IMM:
5740 case ARM::STRB_POST_REG: {
Tilmann Scheller3352a582014-07-23 12:38:17 +00005741 // Rt must be different from Rn.
5742 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5743 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5744
5745 if (Rt == Rn)
5746 return Error(Operands[3]->getStartLoc(),
5747 "source register and base register can't be identical");
5748 return false;
5749 }
Tilmann Scheller8ba74302014-08-01 11:08:51 +00005750 case ARM::LDR_PRE_IMM:
5751 case ARM::LDR_PRE_REG:
5752 case ARM::LDR_POST_IMM:
Tilmann Scheller8ff079c2014-08-01 11:33:47 +00005753 case ARM::LDR_POST_REG:
5754 case ARM::LDRH_PRE:
5755 case ARM::LDRH_POST:
5756 case ARM::LDRSH_PRE:
5757 case ARM::LDRSH_POST: {
Tilmann Scheller8ba74302014-08-01 11:08:51 +00005758 // Rt must be different from Rn.
5759 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5760 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5761
5762 if (Rt == Rn)
5763 return Error(Operands[3]->getStartLoc(),
5764 "destination register and base register can't be identical");
5765 return false;
5766 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005767 case ARM::SBFX:
5768 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005769 // Width must be in range [1, 32-lsb].
5770 unsigned LSB = Inst.getOperand(2).getImm();
5771 unsigned Widthm1 = Inst.getOperand(3).getImm();
5772 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005773 return Error(Operands[5]->getStartLoc(),
5774 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005775 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005776 }
Tim Northover08a86602013-10-22 19:00:39 +00005777 // Notionally handles ARM::tLDMIA_UPD too.
Jim Grosbach90103cc2011-08-18 21:50:53 +00005778 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005779 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005780 // most cases that are normally illegal for a Thumb1 LDM instruction.
5781 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005782 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005783 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005784 // in the register list.
5785 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005786 bool HasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00005787 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5788 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005789 bool ListContainsBase;
5790 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5791 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005792 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005793 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005794 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005795 return Error(Operands[2]->getStartLoc(),
5796 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005797 // If we should not have writeback, there must not be a '!'. This is
5798 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005799 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005800 return Error(Operands[3]->getStartLoc(),
5801 "writeback operator '!' not allowed when base register "
5802 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005803
5804 break;
5805 }
Tim Northover08a86602013-10-22 19:00:39 +00005806 case ARM::LDMIA_UPD:
5807 case ARM::LDMDB_UPD:
5808 case ARM::LDMIB_UPD:
5809 case ARM::LDMDA_UPD:
5810 // ARM variants loading and updating the same register are only officially
5811 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5812 if (!hasV7Ops())
5813 break;
5814 // Fallthrough
5815 case ARM::t2LDMIA_UPD:
5816 case ARM::t2LDMDB_UPD:
5817 case ARM::t2STMIA_UPD:
5818 case ARM::t2STMDB_UPD: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005819 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
Tim Northover741e6ef2013-10-24 09:37:18 +00005820 return Error(Operands.back()->getStartLoc(),
5821 "writeback register not allowed in register list");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005822 break;
5823 }
Tim Northover8eaf1542013-11-12 21:32:41 +00005824 case ARM::sysLDMIA_UPD:
5825 case ARM::sysLDMDA_UPD:
5826 case ARM::sysLDMDB_UPD:
5827 case ARM::sysLDMIB_UPD:
5828 if (!listContainsReg(Inst, 3, ARM::PC))
5829 return Error(Operands[4]->getStartLoc(),
5830 "writeback register only allowed on system LDM "
5831 "if PC in register-list");
5832 break;
5833 case ARM::sysSTMIA_UPD:
5834 case ARM::sysSTMDA_UPD:
5835 case ARM::sysSTMDB_UPD:
5836 case ARM::sysSTMIB_UPD:
5837 return Error(Operands[2]->getStartLoc(),
5838 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005839 case ARM::tMUL: {
5840 // The second source operand must be the same register as the destination
5841 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005842 //
5843 // In this case, we must directly check the parsed operands because the
5844 // cvtThumbMultiply() function is written in such a way that it guarantees
5845 // this first statement is always true for the new Inst. Essentially, the
5846 // destination is unconditionally copied into the second source operand
5847 // without checking to see if it matches what we actually parsed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005848 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
5849 ((ARMOperand &)*Operands[5]).getReg()) &&
5850 (((ARMOperand &)*Operands[3]).getReg() !=
5851 ((ARMOperand &)*Operands[4]).getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005852 return Error(Operands[3]->getStartLoc(),
5853 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005854 }
5855 break;
5856 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005857 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5858 // so only issue a diagnostic for thumb1. The instructions will be
5859 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005860 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005861 bool ListContainsBase;
5862 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005863 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005864 return Error(Operands[2]->getStartLoc(),
5865 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005866 break;
5867 }
5868 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005869 bool ListContainsBase;
5870 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005871 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005872 return Error(Operands[2]->getStartLoc(),
5873 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005874 break;
5875 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005876 case ARM::tSTMIA_UPD: {
Tim Northover08a86602013-10-22 19:00:39 +00005877 bool ListContainsBase, InvalidLowList;
5878 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5879 0, ListContainsBase);
5880 if (InvalidLowList && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005881 return Error(Operands[4]->getStartLoc(),
5882 "registers must be in range r0-r7");
Tim Northover08a86602013-10-22 19:00:39 +00005883
5884 // This would be converted to a 32-bit stm, but that's not valid if the
5885 // writeback register is in the list.
5886 if (InvalidLowList && ListContainsBase)
5887 return Error(Operands[4]->getStartLoc(),
5888 "writeback operator '!' not allowed when base register "
5889 "in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00005890 break;
5891 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005892 case ARM::tADDrSP: {
5893 // If the non-SP source operand and the destination operand are not the
5894 // same, we need thumb2 (for the wide encoding), or we have an error.
5895 if (!isThumbTwo() &&
5896 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5897 return Error(Operands[4]->getStartLoc(),
5898 "source register must be the same as destination");
5899 }
5900 break;
5901 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005902 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005903 case ARM::tB:
David Blaikie960ea3f2014-06-08 16:18:35 +00005904 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00005905 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005906 break;
5907 case ARM::t2B: {
5908 int op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005909 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00005910 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005911 break;
5912 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005913 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005914 case ARM::tBcc:
David Blaikie960ea3f2014-06-08 16:18:35 +00005915 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00005916 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005917 break;
5918 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005919 int Op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005920 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00005921 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005922 break;
5923 }
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00005924 case ARM::MOVi16:
5925 case ARM::t2MOVi16:
5926 case ARM::t2MOVTi16:
5927 {
5928 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
5929 // especially when we turn it into a movw and the expression <symbol> does
5930 // not have a :lower16: or :upper16 as part of the expression. We don't
5931 // want the behavior of silently truncating, which can be unexpected and
5932 // lead to bugs that are difficult to find since this is an easy mistake
5933 // to make.
5934 int i = (Operands[3]->isImm()) ? 3 : 4;
David Blaikie960ea3f2014-06-08 16:18:35 +00005935 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
5936 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00005937 if (CE) break;
David Blaikie960ea3f2014-06-08 16:18:35 +00005938 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00005939 if (!E) break;
5940 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
5941 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005942 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
5943 return Error(
5944 Op.getStartLoc(),
5945 "immediate expression for mov requires :lower16: or :upper16");
5946 break;
5947 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005948 }
5949
5950 return false;
5951}
5952
Jim Grosbach1a747242012-01-23 23:45:44 +00005953static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005954 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005955 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005956 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005957 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5958 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5959 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5960 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5961 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5962 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5963 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5964 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5965 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005966
5967 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005968 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5969 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5970 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5971 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5972 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005973
Jim Grosbach1e946a42012-01-24 00:43:12 +00005974 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5975 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5976 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5977 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5978 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005979
Jim Grosbach1e946a42012-01-24 00:43:12 +00005980 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5981 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5982 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5983 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5984 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005985
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005986 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005987 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5988 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5989 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5990 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5991 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5992 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5993 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5994 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5995 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5996 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5997 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5998 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5999 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
6000 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
6001 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006002
Jim Grosbach1a747242012-01-23 23:45:44 +00006003 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006004 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6005 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6006 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6007 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6008 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6009 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6010 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6011 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6012 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6013 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6014 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6015 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6016 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
6017 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
6018 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
6019 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
6020 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
6021 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00006022
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006023 // VST4LN
6024 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6025 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6026 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6027 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
6028 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6029 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6030 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6031 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6032 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
6033 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6034 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
6035 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
6036 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
6037 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
6038 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
6039
Jim Grosbachda70eac2012-01-24 00:58:13 +00006040 // VST4
6041 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6042 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6043 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6044 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6045 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6046 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6047 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6048 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6049 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6050 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6051 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6052 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6053 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6054 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6055 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6056 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6057 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6058 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00006059 }
6060}
6061
Jim Grosbach1a747242012-01-23 23:45:44 +00006062static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00006063 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006064 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006065 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006066 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6067 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6068 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6069 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6070 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6071 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6072 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6073 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6074 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006075
6076 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006077 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6078 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6079 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6080 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6081 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6082 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6083 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6084 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6085 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6086 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6087 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6088 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6089 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6090 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6091 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006092
Jim Grosbachb78403c2012-01-24 23:47:04 +00006093 // VLD3DUP
6094 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6095 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6096 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6097 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
Kevin Enderbyd88fec32014-04-08 18:00:52 +00006098 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
Jim Grosbachb78403c2012-01-24 23:47:04 +00006099 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6100 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6101 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6102 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6103 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6104 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6105 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6106 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6107 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6108 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6109 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6110 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6111 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6112
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006113 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006114 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6115 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6116 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6117 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6118 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6119 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6120 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6121 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6122 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6123 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6124 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6125 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6126 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6127 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6128 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006129
6130 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006131 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6132 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6133 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6134 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6135 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6136 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6137 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6138 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6139 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6140 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6141 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6142 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6143 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6144 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6145 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6146 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6147 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6148 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00006149
Jim Grosbach14952a02012-01-24 18:37:25 +00006150 // VLD4LN
6151 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6152 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6153 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00006154 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00006155 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6156 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6157 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6158 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6159 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6160 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6161 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6162 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6163 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6164 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6165 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6166
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006167 // VLD4DUP
6168 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6169 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6170 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6171 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6172 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6173 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6174 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6175 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6176 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6177 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6178 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6179 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6180 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6181 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6182 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6183 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6184 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6185 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6186
Jim Grosbached561fc2012-01-24 00:43:17 +00006187 // VLD4
6188 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6189 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6190 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6191 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6192 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6193 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6194 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6195 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6196 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6197 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6198 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6199 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6200 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6201 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6202 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6203 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6204 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6205 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006206 }
6207}
6208
David Blaikie960ea3f2014-06-08 16:18:35 +00006209bool ARMAsmParser::processInstruction(MCInst &Inst,
6210 const OperandVector &Operands) {
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006211 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006212 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6213 case ARM::LDRT_POST:
6214 case ARM::LDRBT_POST: {
6215 const unsigned Opcode =
6216 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6217 : ARM::LDRBT_POST_IMM;
6218 MCInst TmpInst;
6219 TmpInst.setOpcode(Opcode);
6220 TmpInst.addOperand(Inst.getOperand(0));
6221 TmpInst.addOperand(Inst.getOperand(1));
6222 TmpInst.addOperand(Inst.getOperand(1));
6223 TmpInst.addOperand(MCOperand::CreateReg(0));
6224 TmpInst.addOperand(MCOperand::CreateImm(0));
6225 TmpInst.addOperand(Inst.getOperand(2));
6226 TmpInst.addOperand(Inst.getOperand(3));
6227 Inst = TmpInst;
6228 return true;
6229 }
6230 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6231 case ARM::STRT_POST:
6232 case ARM::STRBT_POST: {
6233 const unsigned Opcode =
6234 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6235 : ARM::STRBT_POST_IMM;
6236 MCInst TmpInst;
6237 TmpInst.setOpcode(Opcode);
6238 TmpInst.addOperand(Inst.getOperand(1));
6239 TmpInst.addOperand(Inst.getOperand(0));
6240 TmpInst.addOperand(Inst.getOperand(1));
6241 TmpInst.addOperand(MCOperand::CreateReg(0));
6242 TmpInst.addOperand(MCOperand::CreateImm(0));
6243 TmpInst.addOperand(Inst.getOperand(2));
6244 TmpInst.addOperand(Inst.getOperand(3));
6245 Inst = TmpInst;
6246 return true;
6247 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006248 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6249 case ARM::ADDri: {
6250 if (Inst.getOperand(1).getReg() != ARM::PC ||
6251 Inst.getOperand(5).getReg() != 0)
6252 return false;
6253 MCInst TmpInst;
6254 TmpInst.setOpcode(ARM::ADR);
6255 TmpInst.addOperand(Inst.getOperand(0));
6256 TmpInst.addOperand(Inst.getOperand(2));
6257 TmpInst.addOperand(Inst.getOperand(3));
6258 TmpInst.addOperand(Inst.getOperand(4));
6259 Inst = TmpInst;
6260 return true;
6261 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006262 // Aliases for alternate PC+imm syntax of LDR instructions.
6263 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006264 // Select the narrow version if the immediate will fit.
6265 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006266 Inst.getOperand(1).getImm() <= 0xff &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006267 !(static_cast<ARMOperand &>(*Operands[2]).isToken() &&
6268 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006269 Inst.setOpcode(ARM::tLDRpci);
6270 else
6271 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006272 return true;
6273 case ARM::t2LDRBpcrel:
6274 Inst.setOpcode(ARM::t2LDRBpci);
6275 return true;
6276 case ARM::t2LDRHpcrel:
6277 Inst.setOpcode(ARM::t2LDRHpci);
6278 return true;
6279 case ARM::t2LDRSBpcrel:
6280 Inst.setOpcode(ARM::t2LDRSBpci);
6281 return true;
6282 case ARM::t2LDRSHpcrel:
6283 Inst.setOpcode(ARM::t2LDRSHpci);
6284 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006285 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006286 case ARM::VST1LNdWB_register_Asm_8:
6287 case ARM::VST1LNdWB_register_Asm_16:
6288 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006289 MCInst TmpInst;
6290 // Shuffle the operands around so the lane index operand is in the
6291 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006292 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006293 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006294 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6295 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6296 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6297 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6298 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6299 TmpInst.addOperand(Inst.getOperand(1)); // lane
6300 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6301 TmpInst.addOperand(Inst.getOperand(6));
6302 Inst = TmpInst;
6303 return true;
6304 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006305
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006306 case ARM::VST2LNdWB_register_Asm_8:
6307 case ARM::VST2LNdWB_register_Asm_16:
6308 case ARM::VST2LNdWB_register_Asm_32:
6309 case ARM::VST2LNqWB_register_Asm_16:
6310 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006311 MCInst TmpInst;
6312 // Shuffle the operands around so the lane index operand is in the
6313 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006314 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006315 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006316 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6317 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6318 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6319 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6320 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006321 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6322 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006323 TmpInst.addOperand(Inst.getOperand(1)); // lane
6324 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6325 TmpInst.addOperand(Inst.getOperand(6));
6326 Inst = TmpInst;
6327 return true;
6328 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006329
6330 case ARM::VST3LNdWB_register_Asm_8:
6331 case ARM::VST3LNdWB_register_Asm_16:
6332 case ARM::VST3LNdWB_register_Asm_32:
6333 case ARM::VST3LNqWB_register_Asm_16:
6334 case ARM::VST3LNqWB_register_Asm_32: {
6335 MCInst TmpInst;
6336 // Shuffle the operands around so the lane index operand is in the
6337 // right place.
6338 unsigned Spacing;
6339 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6340 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6341 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6342 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6343 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6344 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6345 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6346 Spacing));
6347 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6348 Spacing * 2));
6349 TmpInst.addOperand(Inst.getOperand(1)); // lane
6350 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6351 TmpInst.addOperand(Inst.getOperand(6));
6352 Inst = TmpInst;
6353 return true;
6354 }
6355
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006356 case ARM::VST4LNdWB_register_Asm_8:
6357 case ARM::VST4LNdWB_register_Asm_16:
6358 case ARM::VST4LNdWB_register_Asm_32:
6359 case ARM::VST4LNqWB_register_Asm_16:
6360 case ARM::VST4LNqWB_register_Asm_32: {
6361 MCInst TmpInst;
6362 // Shuffle the operands around so the lane index operand is in the
6363 // right place.
6364 unsigned Spacing;
6365 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6366 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6367 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6368 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6369 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6370 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6371 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6372 Spacing));
6373 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6374 Spacing * 2));
6375 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6376 Spacing * 3));
6377 TmpInst.addOperand(Inst.getOperand(1)); // lane
6378 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6379 TmpInst.addOperand(Inst.getOperand(6));
6380 Inst = TmpInst;
6381 return true;
6382 }
6383
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006384 case ARM::VST1LNdWB_fixed_Asm_8:
6385 case ARM::VST1LNdWB_fixed_Asm_16:
6386 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006387 MCInst TmpInst;
6388 // Shuffle the operands around so the lane index operand is in the
6389 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006390 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006391 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006392 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6393 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6394 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6395 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6396 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6397 TmpInst.addOperand(Inst.getOperand(1)); // lane
6398 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6399 TmpInst.addOperand(Inst.getOperand(5));
6400 Inst = TmpInst;
6401 return true;
6402 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006403
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006404 case ARM::VST2LNdWB_fixed_Asm_8:
6405 case ARM::VST2LNdWB_fixed_Asm_16:
6406 case ARM::VST2LNdWB_fixed_Asm_32:
6407 case ARM::VST2LNqWB_fixed_Asm_16:
6408 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006409 MCInst TmpInst;
6410 // Shuffle the operands around so the lane index operand is in the
6411 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006412 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006413 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006414 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6415 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6416 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6417 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6418 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006419 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6420 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006421 TmpInst.addOperand(Inst.getOperand(1)); // lane
6422 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6423 TmpInst.addOperand(Inst.getOperand(5));
6424 Inst = TmpInst;
6425 return true;
6426 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006427
6428 case ARM::VST3LNdWB_fixed_Asm_8:
6429 case ARM::VST3LNdWB_fixed_Asm_16:
6430 case ARM::VST3LNdWB_fixed_Asm_32:
6431 case ARM::VST3LNqWB_fixed_Asm_16:
6432 case ARM::VST3LNqWB_fixed_Asm_32: {
6433 MCInst TmpInst;
6434 // Shuffle the operands around so the lane index operand is in the
6435 // right place.
6436 unsigned Spacing;
6437 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6438 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6439 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6440 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6441 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6442 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6443 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6444 Spacing));
6445 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6446 Spacing * 2));
6447 TmpInst.addOperand(Inst.getOperand(1)); // lane
6448 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6449 TmpInst.addOperand(Inst.getOperand(5));
6450 Inst = TmpInst;
6451 return true;
6452 }
6453
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006454 case ARM::VST4LNdWB_fixed_Asm_8:
6455 case ARM::VST4LNdWB_fixed_Asm_16:
6456 case ARM::VST4LNdWB_fixed_Asm_32:
6457 case ARM::VST4LNqWB_fixed_Asm_16:
6458 case ARM::VST4LNqWB_fixed_Asm_32: {
6459 MCInst TmpInst;
6460 // Shuffle the operands around so the lane index operand is in the
6461 // right place.
6462 unsigned Spacing;
6463 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6464 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6465 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6466 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6467 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6468 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6469 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6470 Spacing));
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6472 Spacing * 2));
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6474 Spacing * 3));
6475 TmpInst.addOperand(Inst.getOperand(1)); // lane
6476 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6477 TmpInst.addOperand(Inst.getOperand(5));
6478 Inst = TmpInst;
6479 return true;
6480 }
6481
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006482 case ARM::VST1LNdAsm_8:
6483 case ARM::VST1LNdAsm_16:
6484 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006485 MCInst TmpInst;
6486 // Shuffle the operands around so the lane index operand is in the
6487 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006488 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006489 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006490 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6491 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6492 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6493 TmpInst.addOperand(Inst.getOperand(1)); // lane
6494 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6495 TmpInst.addOperand(Inst.getOperand(5));
6496 Inst = TmpInst;
6497 return true;
6498 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006499
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006500 case ARM::VST2LNdAsm_8:
6501 case ARM::VST2LNdAsm_16:
6502 case ARM::VST2LNdAsm_32:
6503 case ARM::VST2LNqAsm_16:
6504 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006505 MCInst TmpInst;
6506 // Shuffle the operands around so the lane index operand is in the
6507 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006508 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006509 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006510 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6511 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6512 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006513 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6514 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006515 TmpInst.addOperand(Inst.getOperand(1)); // lane
6516 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6517 TmpInst.addOperand(Inst.getOperand(5));
6518 Inst = TmpInst;
6519 return true;
6520 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006521
6522 case ARM::VST3LNdAsm_8:
6523 case ARM::VST3LNdAsm_16:
6524 case ARM::VST3LNdAsm_32:
6525 case ARM::VST3LNqAsm_16:
6526 case ARM::VST3LNqAsm_32: {
6527 MCInst TmpInst;
6528 // Shuffle the operands around so the lane index operand is in the
6529 // right place.
6530 unsigned Spacing;
6531 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6532 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6533 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6534 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6535 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6536 Spacing));
6537 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6538 Spacing * 2));
6539 TmpInst.addOperand(Inst.getOperand(1)); // lane
6540 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6541 TmpInst.addOperand(Inst.getOperand(5));
6542 Inst = TmpInst;
6543 return true;
6544 }
6545
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006546 case ARM::VST4LNdAsm_8:
6547 case ARM::VST4LNdAsm_16:
6548 case ARM::VST4LNdAsm_32:
6549 case ARM::VST4LNqAsm_16:
6550 case ARM::VST4LNqAsm_32: {
6551 MCInst TmpInst;
6552 // Shuffle the operands around so the lane index operand is in the
6553 // right place.
6554 unsigned Spacing;
6555 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6556 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6557 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6558 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6559 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6560 Spacing));
6561 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6562 Spacing * 2));
6563 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6564 Spacing * 3));
6565 TmpInst.addOperand(Inst.getOperand(1)); // lane
6566 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6567 TmpInst.addOperand(Inst.getOperand(5));
6568 Inst = TmpInst;
6569 return true;
6570 }
6571
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006572 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006573 case ARM::VLD1LNdWB_register_Asm_8:
6574 case ARM::VLD1LNdWB_register_Asm_16:
6575 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006576 MCInst TmpInst;
6577 // Shuffle the operands around so the lane index operand is in the
6578 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006579 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006580 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006581 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6582 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6583 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6584 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6585 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6586 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6587 TmpInst.addOperand(Inst.getOperand(1)); // lane
6588 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6589 TmpInst.addOperand(Inst.getOperand(6));
6590 Inst = TmpInst;
6591 return true;
6592 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006593
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006594 case ARM::VLD2LNdWB_register_Asm_8:
6595 case ARM::VLD2LNdWB_register_Asm_16:
6596 case ARM::VLD2LNdWB_register_Asm_32:
6597 case ARM::VLD2LNqWB_register_Asm_16:
6598 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006599 MCInst TmpInst;
6600 // Shuffle the operands around so the lane index operand is in the
6601 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006602 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006603 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006604 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006605 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6606 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006607 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6608 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6609 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6610 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6611 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006612 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6613 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006614 TmpInst.addOperand(Inst.getOperand(1)); // lane
6615 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6616 TmpInst.addOperand(Inst.getOperand(6));
6617 Inst = TmpInst;
6618 return true;
6619 }
6620
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006621 case ARM::VLD3LNdWB_register_Asm_8:
6622 case ARM::VLD3LNdWB_register_Asm_16:
6623 case ARM::VLD3LNdWB_register_Asm_32:
6624 case ARM::VLD3LNqWB_register_Asm_16:
6625 case ARM::VLD3LNqWB_register_Asm_32: {
6626 MCInst TmpInst;
6627 // Shuffle the operands around so the lane index operand is in the
6628 // right place.
6629 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006630 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006631 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6632 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6633 Spacing));
6634 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006635 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006636 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6637 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6638 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6639 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6640 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6641 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6642 Spacing));
6643 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006644 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006645 TmpInst.addOperand(Inst.getOperand(1)); // lane
6646 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6647 TmpInst.addOperand(Inst.getOperand(6));
6648 Inst = TmpInst;
6649 return true;
6650 }
6651
Jim Grosbach14952a02012-01-24 18:37:25 +00006652 case ARM::VLD4LNdWB_register_Asm_8:
6653 case ARM::VLD4LNdWB_register_Asm_16:
6654 case ARM::VLD4LNdWB_register_Asm_32:
6655 case ARM::VLD4LNqWB_register_Asm_16:
6656 case ARM::VLD4LNqWB_register_Asm_32: {
6657 MCInst TmpInst;
6658 // Shuffle the operands around so the lane index operand is in the
6659 // right place.
6660 unsigned Spacing;
6661 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6662 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6663 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6664 Spacing));
6665 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6666 Spacing * 2));
6667 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6668 Spacing * 3));
6669 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6670 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6671 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6672 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6673 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6675 Spacing));
6676 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6677 Spacing * 2));
6678 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6679 Spacing * 3));
6680 TmpInst.addOperand(Inst.getOperand(1)); // lane
6681 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6682 TmpInst.addOperand(Inst.getOperand(6));
6683 Inst = TmpInst;
6684 return true;
6685 }
6686
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006687 case ARM::VLD1LNdWB_fixed_Asm_8:
6688 case ARM::VLD1LNdWB_fixed_Asm_16:
6689 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006690 MCInst TmpInst;
6691 // Shuffle the operands around so the lane index operand is in the
6692 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006693 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006694 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006695 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6696 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6697 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6698 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6699 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6700 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6701 TmpInst.addOperand(Inst.getOperand(1)); // lane
6702 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6703 TmpInst.addOperand(Inst.getOperand(5));
6704 Inst = TmpInst;
6705 return true;
6706 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006707
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006708 case ARM::VLD2LNdWB_fixed_Asm_8:
6709 case ARM::VLD2LNdWB_fixed_Asm_16:
6710 case ARM::VLD2LNdWB_fixed_Asm_32:
6711 case ARM::VLD2LNqWB_fixed_Asm_16:
6712 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006713 MCInst TmpInst;
6714 // Shuffle the operands around so the lane index operand is in the
6715 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006716 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006717 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006718 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006719 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6720 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006721 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6722 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6723 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6724 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6725 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006726 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6727 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006728 TmpInst.addOperand(Inst.getOperand(1)); // lane
6729 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6730 TmpInst.addOperand(Inst.getOperand(5));
6731 Inst = TmpInst;
6732 return true;
6733 }
6734
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006735 case ARM::VLD3LNdWB_fixed_Asm_8:
6736 case ARM::VLD3LNdWB_fixed_Asm_16:
6737 case ARM::VLD3LNdWB_fixed_Asm_32:
6738 case ARM::VLD3LNqWB_fixed_Asm_16:
6739 case ARM::VLD3LNqWB_fixed_Asm_32: {
6740 MCInst TmpInst;
6741 // Shuffle the operands around so the lane index operand is in the
6742 // right place.
6743 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006744 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006745 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6746 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6747 Spacing));
6748 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006749 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006750 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6751 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6752 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6753 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6754 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6755 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6756 Spacing));
6757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006758 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006759 TmpInst.addOperand(Inst.getOperand(1)); // lane
6760 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6761 TmpInst.addOperand(Inst.getOperand(5));
6762 Inst = TmpInst;
6763 return true;
6764 }
6765
Jim Grosbach14952a02012-01-24 18:37:25 +00006766 case ARM::VLD4LNdWB_fixed_Asm_8:
6767 case ARM::VLD4LNdWB_fixed_Asm_16:
6768 case ARM::VLD4LNdWB_fixed_Asm_32:
6769 case ARM::VLD4LNqWB_fixed_Asm_16:
6770 case ARM::VLD4LNqWB_fixed_Asm_32: {
6771 MCInst TmpInst;
6772 // Shuffle the operands around so the lane index operand is in the
6773 // right place.
6774 unsigned Spacing;
6775 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6776 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6778 Spacing));
6779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6780 Spacing * 2));
6781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6782 Spacing * 3));
6783 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6784 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6785 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6786 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6787 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6788 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6789 Spacing));
6790 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6791 Spacing * 2));
6792 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6793 Spacing * 3));
6794 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 }
6800
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006801 case ARM::VLD1LNdAsm_8:
6802 case ARM::VLD1LNdAsm_16:
6803 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006804 MCInst TmpInst;
6805 // Shuffle the operands around so the lane index operand is in the
6806 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006807 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006808 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006809 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6810 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6811 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6812 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6813 TmpInst.addOperand(Inst.getOperand(1)); // lane
6814 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6815 TmpInst.addOperand(Inst.getOperand(5));
6816 Inst = TmpInst;
6817 return true;
6818 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006819
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006820 case ARM::VLD2LNdAsm_8:
6821 case ARM::VLD2LNdAsm_16:
6822 case ARM::VLD2LNdAsm_32:
6823 case ARM::VLD2LNqAsm_16:
6824 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006825 MCInst TmpInst;
6826 // Shuffle the operands around so the lane index operand is in the
6827 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006828 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006829 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006830 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006831 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6832 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006833 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6834 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6835 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006836 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6837 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006838 TmpInst.addOperand(Inst.getOperand(1)); // lane
6839 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6840 TmpInst.addOperand(Inst.getOperand(5));
6841 Inst = TmpInst;
6842 return true;
6843 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006844
6845 case ARM::VLD3LNdAsm_8:
6846 case ARM::VLD3LNdAsm_16:
6847 case ARM::VLD3LNdAsm_32:
6848 case ARM::VLD3LNqAsm_16:
6849 case ARM::VLD3LNqAsm_32: {
6850 MCInst TmpInst;
6851 // Shuffle the operands around so the lane index operand is in the
6852 // right place.
6853 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006854 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006855 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6856 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6857 Spacing));
6858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006859 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006860 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6861 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6862 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6863 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6864 Spacing));
6865 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006866 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006867 TmpInst.addOperand(Inst.getOperand(1)); // lane
6868 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6869 TmpInst.addOperand(Inst.getOperand(5));
6870 Inst = TmpInst;
6871 return true;
6872 }
6873
Jim Grosbach14952a02012-01-24 18:37:25 +00006874 case ARM::VLD4LNdAsm_8:
6875 case ARM::VLD4LNdAsm_16:
6876 case ARM::VLD4LNdAsm_32:
6877 case ARM::VLD4LNqAsm_16:
6878 case ARM::VLD4LNqAsm_32: {
6879 MCInst TmpInst;
6880 // Shuffle the operands around so the lane index operand is in the
6881 // right place.
6882 unsigned Spacing;
6883 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6884 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6885 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6886 Spacing));
6887 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6888 Spacing * 2));
6889 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6890 Spacing * 3));
6891 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6892 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6893 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6894 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6895 Spacing));
6896 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6897 Spacing * 2));
6898 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6899 Spacing * 3));
6900 TmpInst.addOperand(Inst.getOperand(1)); // lane
6901 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6902 TmpInst.addOperand(Inst.getOperand(5));
6903 Inst = TmpInst;
6904 return true;
6905 }
6906
Jim Grosbachb78403c2012-01-24 23:47:04 +00006907 // VLD3DUP single 3-element structure to all lanes instructions.
6908 case ARM::VLD3DUPdAsm_8:
6909 case ARM::VLD3DUPdAsm_16:
6910 case ARM::VLD3DUPdAsm_32:
6911 case ARM::VLD3DUPqAsm_8:
6912 case ARM::VLD3DUPqAsm_16:
6913 case ARM::VLD3DUPqAsm_32: {
6914 MCInst TmpInst;
6915 unsigned Spacing;
6916 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6917 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6918 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6919 Spacing));
6920 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6921 Spacing * 2));
6922 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6923 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6924 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6925 TmpInst.addOperand(Inst.getOperand(4));
6926 Inst = TmpInst;
6927 return true;
6928 }
6929
6930 case ARM::VLD3DUPdWB_fixed_Asm_8:
6931 case ARM::VLD3DUPdWB_fixed_Asm_16:
6932 case ARM::VLD3DUPdWB_fixed_Asm_32:
6933 case ARM::VLD3DUPqWB_fixed_Asm_8:
6934 case ARM::VLD3DUPqWB_fixed_Asm_16:
6935 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6936 MCInst TmpInst;
6937 unsigned Spacing;
6938 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6939 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6940 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6941 Spacing));
6942 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6943 Spacing * 2));
6944 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6945 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6946 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6947 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6948 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6949 TmpInst.addOperand(Inst.getOperand(4));
6950 Inst = TmpInst;
6951 return true;
6952 }
6953
6954 case ARM::VLD3DUPdWB_register_Asm_8:
6955 case ARM::VLD3DUPdWB_register_Asm_16:
6956 case ARM::VLD3DUPdWB_register_Asm_32:
6957 case ARM::VLD3DUPqWB_register_Asm_8:
6958 case ARM::VLD3DUPqWB_register_Asm_16:
6959 case ARM::VLD3DUPqWB_register_Asm_32: {
6960 MCInst TmpInst;
6961 unsigned Spacing;
6962 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6963 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6964 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6965 Spacing));
6966 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6967 Spacing * 2));
6968 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6969 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6970 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6971 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6972 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6973 TmpInst.addOperand(Inst.getOperand(5));
6974 Inst = TmpInst;
6975 return true;
6976 }
6977
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006978 // VLD3 multiple 3-element structure instructions.
6979 case ARM::VLD3dAsm_8:
6980 case ARM::VLD3dAsm_16:
6981 case ARM::VLD3dAsm_32:
6982 case ARM::VLD3qAsm_8:
6983 case ARM::VLD3qAsm_16:
6984 case ARM::VLD3qAsm_32: {
6985 MCInst TmpInst;
6986 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006987 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006988 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6989 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6990 Spacing));
6991 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6992 Spacing * 2));
6993 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6994 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6995 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6996 TmpInst.addOperand(Inst.getOperand(4));
6997 Inst = TmpInst;
6998 return true;
6999 }
7000
7001 case ARM::VLD3dWB_fixed_Asm_8:
7002 case ARM::VLD3dWB_fixed_Asm_16:
7003 case ARM::VLD3dWB_fixed_Asm_32:
7004 case ARM::VLD3qWB_fixed_Asm_8:
7005 case ARM::VLD3qWB_fixed_Asm_16:
7006 case ARM::VLD3qWB_fixed_Asm_32: {
7007 MCInst TmpInst;
7008 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007009 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007010 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7011 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7012 Spacing));
7013 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7014 Spacing * 2));
7015 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7016 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7017 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7018 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7019 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7020 TmpInst.addOperand(Inst.getOperand(4));
7021 Inst = TmpInst;
7022 return true;
7023 }
7024
7025 case ARM::VLD3dWB_register_Asm_8:
7026 case ARM::VLD3dWB_register_Asm_16:
7027 case ARM::VLD3dWB_register_Asm_32:
7028 case ARM::VLD3qWB_register_Asm_8:
7029 case ARM::VLD3qWB_register_Asm_16:
7030 case ARM::VLD3qWB_register_Asm_32: {
7031 MCInst TmpInst;
7032 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007033 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007034 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7035 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7036 Spacing));
7037 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7038 Spacing * 2));
7039 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7040 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7041 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7042 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7043 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7044 TmpInst.addOperand(Inst.getOperand(5));
7045 Inst = TmpInst;
7046 return true;
7047 }
7048
Jim Grosbach086cbfa2012-01-25 00:01:08 +00007049 // VLD4DUP single 3-element structure to all lanes instructions.
7050 case ARM::VLD4DUPdAsm_8:
7051 case ARM::VLD4DUPdAsm_16:
7052 case ARM::VLD4DUPdAsm_32:
7053 case ARM::VLD4DUPqAsm_8:
7054 case ARM::VLD4DUPqAsm_16:
7055 case ARM::VLD4DUPqAsm_32: {
7056 MCInst TmpInst;
7057 unsigned Spacing;
7058 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7059 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7060 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7061 Spacing));
7062 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7063 Spacing * 2));
7064 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7065 Spacing * 3));
7066 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7067 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7068 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7069 TmpInst.addOperand(Inst.getOperand(4));
7070 Inst = TmpInst;
7071 return true;
7072 }
7073
7074 case ARM::VLD4DUPdWB_fixed_Asm_8:
7075 case ARM::VLD4DUPdWB_fixed_Asm_16:
7076 case ARM::VLD4DUPdWB_fixed_Asm_32:
7077 case ARM::VLD4DUPqWB_fixed_Asm_8:
7078 case ARM::VLD4DUPqWB_fixed_Asm_16:
7079 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7080 MCInst TmpInst;
7081 unsigned Spacing;
7082 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7083 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7084 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7085 Spacing));
7086 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7087 Spacing * 2));
7088 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7089 Spacing * 3));
7090 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7091 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7092 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7093 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7094 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7095 TmpInst.addOperand(Inst.getOperand(4));
7096 Inst = TmpInst;
7097 return true;
7098 }
7099
7100 case ARM::VLD4DUPdWB_register_Asm_8:
7101 case ARM::VLD4DUPdWB_register_Asm_16:
7102 case ARM::VLD4DUPdWB_register_Asm_32:
7103 case ARM::VLD4DUPqWB_register_Asm_8:
7104 case ARM::VLD4DUPqWB_register_Asm_16:
7105 case ARM::VLD4DUPqWB_register_Asm_32: {
7106 MCInst TmpInst;
7107 unsigned Spacing;
7108 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7109 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7110 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7111 Spacing));
7112 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7113 Spacing * 2));
7114 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7115 Spacing * 3));
7116 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7117 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7118 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7119 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7120 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7121 TmpInst.addOperand(Inst.getOperand(5));
7122 Inst = TmpInst;
7123 return true;
7124 }
7125
7126 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00007127 case ARM::VLD4dAsm_8:
7128 case ARM::VLD4dAsm_16:
7129 case ARM::VLD4dAsm_32:
7130 case ARM::VLD4qAsm_8:
7131 case ARM::VLD4qAsm_16:
7132 case ARM::VLD4qAsm_32: {
7133 MCInst TmpInst;
7134 unsigned Spacing;
7135 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7136 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7137 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7138 Spacing));
7139 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7140 Spacing * 2));
7141 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7142 Spacing * 3));
7143 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7144 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7145 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7146 TmpInst.addOperand(Inst.getOperand(4));
7147 Inst = TmpInst;
7148 return true;
7149 }
7150
7151 case ARM::VLD4dWB_fixed_Asm_8:
7152 case ARM::VLD4dWB_fixed_Asm_16:
7153 case ARM::VLD4dWB_fixed_Asm_32:
7154 case ARM::VLD4qWB_fixed_Asm_8:
7155 case ARM::VLD4qWB_fixed_Asm_16:
7156 case ARM::VLD4qWB_fixed_Asm_32: {
7157 MCInst TmpInst;
7158 unsigned Spacing;
7159 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7160 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7161 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7162 Spacing));
7163 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7164 Spacing * 2));
7165 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7166 Spacing * 3));
7167 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7168 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7169 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7170 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7171 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7172 TmpInst.addOperand(Inst.getOperand(4));
7173 Inst = TmpInst;
7174 return true;
7175 }
7176
7177 case ARM::VLD4dWB_register_Asm_8:
7178 case ARM::VLD4dWB_register_Asm_16:
7179 case ARM::VLD4dWB_register_Asm_32:
7180 case ARM::VLD4qWB_register_Asm_8:
7181 case ARM::VLD4qWB_register_Asm_16:
7182 case ARM::VLD4qWB_register_Asm_32: {
7183 MCInst TmpInst;
7184 unsigned Spacing;
7185 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7186 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7187 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7188 Spacing));
7189 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7190 Spacing * 2));
7191 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7192 Spacing * 3));
7193 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7194 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7195 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7196 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7197 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7198 TmpInst.addOperand(Inst.getOperand(5));
7199 Inst = TmpInst;
7200 return true;
7201 }
7202
Jim Grosbach1a747242012-01-23 23:45:44 +00007203 // VST3 multiple 3-element structure instructions.
7204 case ARM::VST3dAsm_8:
7205 case ARM::VST3dAsm_16:
7206 case ARM::VST3dAsm_32:
7207 case ARM::VST3qAsm_8:
7208 case ARM::VST3qAsm_16:
7209 case ARM::VST3qAsm_32: {
7210 MCInst TmpInst;
7211 unsigned Spacing;
7212 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7213 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7214 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7215 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7216 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7217 Spacing));
7218 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7219 Spacing * 2));
7220 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7221 TmpInst.addOperand(Inst.getOperand(4));
7222 Inst = TmpInst;
7223 return true;
7224 }
7225
7226 case ARM::VST3dWB_fixed_Asm_8:
7227 case ARM::VST3dWB_fixed_Asm_16:
7228 case ARM::VST3dWB_fixed_Asm_32:
7229 case ARM::VST3qWB_fixed_Asm_8:
7230 case ARM::VST3qWB_fixed_Asm_16:
7231 case ARM::VST3qWB_fixed_Asm_32: {
7232 MCInst TmpInst;
7233 unsigned Spacing;
7234 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7235 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7236 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7237 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7238 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7239 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7240 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7241 Spacing));
7242 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7243 Spacing * 2));
7244 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7245 TmpInst.addOperand(Inst.getOperand(4));
7246 Inst = TmpInst;
7247 return true;
7248 }
7249
7250 case ARM::VST3dWB_register_Asm_8:
7251 case ARM::VST3dWB_register_Asm_16:
7252 case ARM::VST3dWB_register_Asm_32:
7253 case ARM::VST3qWB_register_Asm_8:
7254 case ARM::VST3qWB_register_Asm_16:
7255 case ARM::VST3qWB_register_Asm_32: {
7256 MCInst TmpInst;
7257 unsigned Spacing;
7258 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7259 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7260 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7261 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7262 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7263 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7264 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7265 Spacing));
7266 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7267 Spacing * 2));
7268 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7269 TmpInst.addOperand(Inst.getOperand(5));
7270 Inst = TmpInst;
7271 return true;
7272 }
7273
Jim Grosbachda70eac2012-01-24 00:58:13 +00007274 // VST4 multiple 3-element structure instructions.
7275 case ARM::VST4dAsm_8:
7276 case ARM::VST4dAsm_16:
7277 case ARM::VST4dAsm_32:
7278 case ARM::VST4qAsm_8:
7279 case ARM::VST4qAsm_16:
7280 case ARM::VST4qAsm_32: {
7281 MCInst TmpInst;
7282 unsigned Spacing;
7283 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7284 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7285 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7286 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7287 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7288 Spacing));
7289 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7290 Spacing * 2));
7291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7292 Spacing * 3));
7293 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7294 TmpInst.addOperand(Inst.getOperand(4));
7295 Inst = TmpInst;
7296 return true;
7297 }
7298
7299 case ARM::VST4dWB_fixed_Asm_8:
7300 case ARM::VST4dWB_fixed_Asm_16:
7301 case ARM::VST4dWB_fixed_Asm_32:
7302 case ARM::VST4qWB_fixed_Asm_8:
7303 case ARM::VST4qWB_fixed_Asm_16:
7304 case ARM::VST4qWB_fixed_Asm_32: {
7305 MCInst TmpInst;
7306 unsigned Spacing;
7307 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7308 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7309 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7310 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7311 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7312 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7313 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7314 Spacing));
7315 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7316 Spacing * 2));
7317 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7318 Spacing * 3));
7319 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7320 TmpInst.addOperand(Inst.getOperand(4));
7321 Inst = TmpInst;
7322 return true;
7323 }
7324
7325 case ARM::VST4dWB_register_Asm_8:
7326 case ARM::VST4dWB_register_Asm_16:
7327 case ARM::VST4dWB_register_Asm_32:
7328 case ARM::VST4qWB_register_Asm_8:
7329 case ARM::VST4qWB_register_Asm_16:
7330 case ARM::VST4qWB_register_Asm_32: {
7331 MCInst TmpInst;
7332 unsigned Spacing;
7333 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7334 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7335 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7336 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7337 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7338 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7339 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7340 Spacing));
7341 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7342 Spacing * 2));
7343 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7344 Spacing * 3));
7345 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7346 TmpInst.addOperand(Inst.getOperand(5));
7347 Inst = TmpInst;
7348 return true;
7349 }
7350
Jim Grosbachad66de12012-04-11 00:15:16 +00007351 // Handle encoding choice for the shift-immediate instructions.
7352 case ARM::t2LSLri:
7353 case ARM::t2LSRri:
7354 case ARM::t2ASRri: {
7355 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7356 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7357 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007358 !(static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7359 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) {
Jim Grosbachad66de12012-04-11 00:15:16 +00007360 unsigned NewOpc;
7361 switch (Inst.getOpcode()) {
7362 default: llvm_unreachable("unexpected opcode");
7363 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7364 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7365 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7366 }
7367 // The Thumb1 operands aren't in the same order. Awesome, eh?
7368 MCInst TmpInst;
7369 TmpInst.setOpcode(NewOpc);
7370 TmpInst.addOperand(Inst.getOperand(0));
7371 TmpInst.addOperand(Inst.getOperand(5));
7372 TmpInst.addOperand(Inst.getOperand(1));
7373 TmpInst.addOperand(Inst.getOperand(2));
7374 TmpInst.addOperand(Inst.getOperand(3));
7375 TmpInst.addOperand(Inst.getOperand(4));
7376 Inst = TmpInst;
7377 return true;
7378 }
7379 return false;
7380 }
7381
Jim Grosbach485e5622011-12-13 22:45:11 +00007382 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007383 case ARM::t2MOVsr:
7384 case ARM::t2MOVSsr: {
7385 // Which instruction to expand to depends on the CCOut operand and
7386 // whether we're in an IT block if the register operands are low
7387 // registers.
7388 bool isNarrow = false;
7389 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7390 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7391 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7392 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7393 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7394 isNarrow = true;
7395 MCInst TmpInst;
7396 unsigned newOpc;
7397 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7398 default: llvm_unreachable("unexpected opcode!");
7399 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7400 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7401 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7402 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7403 }
7404 TmpInst.setOpcode(newOpc);
7405 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7406 if (isNarrow)
7407 TmpInst.addOperand(MCOperand::CreateReg(
7408 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7409 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7410 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7411 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7412 TmpInst.addOperand(Inst.getOperand(5));
7413 if (!isNarrow)
7414 TmpInst.addOperand(MCOperand::CreateReg(
7415 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7416 Inst = TmpInst;
7417 return true;
7418 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007419 case ARM::t2MOVsi:
7420 case ARM::t2MOVSsi: {
7421 // Which instruction to expand to depends on the CCOut operand and
7422 // whether we're in an IT block if the register operands are low
7423 // registers.
7424 bool isNarrow = false;
7425 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7426 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7427 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7428 isNarrow = true;
7429 MCInst TmpInst;
7430 unsigned newOpc;
7431 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7432 default: llvm_unreachable("unexpected opcode!");
7433 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7434 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7435 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7436 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007437 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007438 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007439 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7440 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007441 TmpInst.setOpcode(newOpc);
7442 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7443 if (isNarrow)
7444 TmpInst.addOperand(MCOperand::CreateReg(
7445 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7446 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007447 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007448 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007449 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7450 TmpInst.addOperand(Inst.getOperand(4));
7451 if (!isNarrow)
7452 TmpInst.addOperand(MCOperand::CreateReg(
7453 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7454 Inst = TmpInst;
7455 return true;
7456 }
7457 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007458 case ARM::ASRr:
7459 case ARM::LSRr:
7460 case ARM::LSLr:
7461 case ARM::RORr: {
7462 ARM_AM::ShiftOpc ShiftTy;
7463 switch(Inst.getOpcode()) {
7464 default: llvm_unreachable("unexpected opcode!");
7465 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7466 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7467 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7468 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7469 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007470 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7471 MCInst TmpInst;
7472 TmpInst.setOpcode(ARM::MOVsr);
7473 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7474 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7475 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7476 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7477 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7478 TmpInst.addOperand(Inst.getOperand(4));
7479 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7480 Inst = TmpInst;
7481 return true;
7482 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007483 case ARM::ASRi:
7484 case ARM::LSRi:
7485 case ARM::LSLi:
7486 case ARM::RORi: {
7487 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007488 switch(Inst.getOpcode()) {
7489 default: llvm_unreachable("unexpected opcode!");
7490 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7491 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7492 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7493 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7494 }
7495 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007496 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007497 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007498 // A shift by 32 should be encoded as 0 when permitted
7499 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7500 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007501 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007502 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007503 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007504 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7505 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007506 if (Opc == ARM::MOVsi)
7507 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007508 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7509 TmpInst.addOperand(Inst.getOperand(4));
7510 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7511 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007512 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007513 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007514 case ARM::RRXi: {
7515 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7516 MCInst TmpInst;
7517 TmpInst.setOpcode(ARM::MOVsi);
7518 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7519 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7520 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7521 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7522 TmpInst.addOperand(Inst.getOperand(3));
7523 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7524 Inst = TmpInst;
7525 return true;
7526 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007527 case ARM::t2LDMIA_UPD: {
7528 // If this is a load of a single register, then we should use
7529 // a post-indexed LDR instruction instead, per the ARM ARM.
7530 if (Inst.getNumOperands() != 5)
7531 return false;
7532 MCInst TmpInst;
7533 TmpInst.setOpcode(ARM::t2LDR_POST);
7534 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7535 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7536 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7537 TmpInst.addOperand(MCOperand::CreateImm(4));
7538 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7539 TmpInst.addOperand(Inst.getOperand(3));
7540 Inst = TmpInst;
7541 return true;
7542 }
7543 case ARM::t2STMDB_UPD: {
7544 // If this is a store of a single register, then we should use
7545 // a pre-indexed STR instruction instead, per the ARM ARM.
7546 if (Inst.getNumOperands() != 5)
7547 return false;
7548 MCInst TmpInst;
7549 TmpInst.setOpcode(ARM::t2STR_PRE);
7550 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7551 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7552 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7553 TmpInst.addOperand(MCOperand::CreateImm(-4));
7554 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7555 TmpInst.addOperand(Inst.getOperand(3));
7556 Inst = TmpInst;
7557 return true;
7558 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007559 case ARM::LDMIA_UPD:
7560 // If this is a load of a single register via a 'pop', then we should use
7561 // a post-indexed LDR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00007562 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007563 Inst.getNumOperands() == 5) {
7564 MCInst TmpInst;
7565 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7566 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7567 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7568 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7569 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7570 TmpInst.addOperand(MCOperand::CreateImm(4));
7571 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7572 TmpInst.addOperand(Inst.getOperand(3));
7573 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007574 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007575 }
7576 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007577 case ARM::STMDB_UPD:
7578 // If this is a store of a single register via a 'push', then we should use
7579 // a pre-indexed STR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00007580 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007581 Inst.getNumOperands() == 5) {
7582 MCInst TmpInst;
7583 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7584 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7585 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7586 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7587 TmpInst.addOperand(MCOperand::CreateImm(-4));
7588 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7589 TmpInst.addOperand(Inst.getOperand(3));
7590 Inst = TmpInst;
7591 }
7592 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007593 case ARM::t2ADDri12:
7594 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7595 // mnemonic was used (not "addw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00007596 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00007597 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7598 break;
7599 Inst.setOpcode(ARM::t2ADDri);
7600 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7601 break;
7602 case ARM::t2SUBri12:
7603 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7604 // mnemonic was used (not "subw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00007605 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00007606 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7607 break;
7608 Inst.setOpcode(ARM::t2SUBri);
7609 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7610 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007611 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007612 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007613 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7614 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7615 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007616 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007617 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007618 return true;
7619 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007620 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007621 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007622 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007623 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7624 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7625 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007626 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007627 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007628 return true;
7629 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007630 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007631 case ARM::t2ADDri:
7632 case ARM::t2SUBri: {
7633 // If the destination and first source operand are the same, and
7634 // the flags are compatible with the current IT status, use encoding T2
7635 // instead of T3. For compatibility with the system 'as'. Make sure the
7636 // wide encoding wasn't explicit.
7637 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007638 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007639 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7640 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00007641 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7642 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7643 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbachdef5e342012-03-30 17:20:40 +00007644 break;
7645 MCInst TmpInst;
7646 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7647 ARM::tADDi8 : ARM::tSUBi8);
7648 TmpInst.addOperand(Inst.getOperand(0));
7649 TmpInst.addOperand(Inst.getOperand(5));
7650 TmpInst.addOperand(Inst.getOperand(0));
7651 TmpInst.addOperand(Inst.getOperand(2));
7652 TmpInst.addOperand(Inst.getOperand(3));
7653 TmpInst.addOperand(Inst.getOperand(4));
7654 Inst = TmpInst;
7655 return true;
7656 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007657 case ARM::t2ADDrr: {
7658 // If the destination and first source operand are the same, and
7659 // there's no setting of the flags, use encoding T2 instead of T3.
7660 // Note that this is only for ADD, not SUB. This mirrors the system
7661 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7662 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7663 Inst.getOperand(5).getReg() != 0 ||
David Blaikie960ea3f2014-06-08 16:18:35 +00007664 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7665 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007666 break;
7667 MCInst TmpInst;
7668 TmpInst.setOpcode(ARM::tADDhirr);
7669 TmpInst.addOperand(Inst.getOperand(0));
7670 TmpInst.addOperand(Inst.getOperand(0));
7671 TmpInst.addOperand(Inst.getOperand(2));
7672 TmpInst.addOperand(Inst.getOperand(3));
7673 TmpInst.addOperand(Inst.getOperand(4));
7674 Inst = TmpInst;
7675 return true;
7676 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007677 case ARM::tADDrSP: {
7678 // If the non-SP source operand and the destination operand are not the
7679 // same, we need to use the 32-bit encoding if it's available.
7680 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7681 Inst.setOpcode(ARM::t2ADDrr);
7682 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7683 return true;
7684 }
7685 break;
7686 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007687 case ARM::tB:
7688 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007689 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007690 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007691 return true;
7692 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007693 break;
7694 case ARM::t2B:
7695 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007696 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007697 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007698 return true;
7699 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007700 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007701 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007702 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007703 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007704 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007705 return true;
7706 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007707 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007708 case ARM::tBcc:
7709 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007710 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007711 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007712 return true;
7713 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007714 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007715 case ARM::tLDMIA: {
7716 // If the register list contains any high registers, or if the writeback
7717 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7718 // instead if we're in Thumb2. Otherwise, this should have generated
7719 // an error in validateInstruction().
7720 unsigned Rn = Inst.getOperand(0).getReg();
7721 bool hasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00007722 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7723 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Jim Grosbacha31f2232011-09-07 18:05:34 +00007724 bool listContainsBase;
7725 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7726 (!listContainsBase && !hasWritebackToken) ||
7727 (listContainsBase && hasWritebackToken)) {
7728 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7729 assert (isThumbTwo());
7730 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7731 // If we're switching to the updating version, we need to insert
7732 // the writeback tied operand.
7733 if (hasWritebackToken)
7734 Inst.insert(Inst.begin(),
7735 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007736 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007737 }
7738 break;
7739 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007740 case ARM::tSTMIA_UPD: {
7741 // If the register list contains any high registers, we need to use
7742 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7743 // should have generated an error in validateInstruction().
7744 unsigned Rn = Inst.getOperand(0).getReg();
7745 bool listContainsBase;
7746 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7747 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7748 assert (isThumbTwo());
7749 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007750 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007751 }
7752 break;
7753 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007754 case ARM::tPOP: {
7755 bool listContainsBase;
7756 // If the register list contains any high registers, we need to use
7757 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7758 // should have generated an error in validateInstruction().
7759 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007760 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007761 assert (isThumbTwo());
7762 Inst.setOpcode(ARM::t2LDMIA_UPD);
7763 // Add the base register and writeback operands.
7764 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7765 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007766 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007767 }
7768 case ARM::tPUSH: {
7769 bool listContainsBase;
7770 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007771 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007772 assert (isThumbTwo());
7773 Inst.setOpcode(ARM::t2STMDB_UPD);
7774 // Add the base register and writeback operands.
7775 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7776 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007777 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007778 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007779 case ARM::t2MOVi: {
7780 // If we can use the 16-bit encoding and the user didn't explicitly
7781 // request the 32-bit variant, transform it here.
7782 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007783 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007784 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007785 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7786 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7787 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
7788 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007789 // The operands aren't in the same order for tMOVi8...
7790 MCInst TmpInst;
7791 TmpInst.setOpcode(ARM::tMOVi8);
7792 TmpInst.addOperand(Inst.getOperand(0));
7793 TmpInst.addOperand(Inst.getOperand(4));
7794 TmpInst.addOperand(Inst.getOperand(1));
7795 TmpInst.addOperand(Inst.getOperand(2));
7796 TmpInst.addOperand(Inst.getOperand(3));
7797 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007798 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007799 }
7800 break;
7801 }
7802 case ARM::t2MOVr: {
7803 // If we can use the 16-bit encoding and the user didn't explicitly
7804 // request the 32-bit variant, transform it here.
7805 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7806 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7807 Inst.getOperand(2).getImm() == ARMCC::AL &&
7808 Inst.getOperand(4).getReg() == ARM::CPSR &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007809 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
7810 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007811 // The operands aren't the same for tMOV[S]r... (no cc_out)
7812 MCInst TmpInst;
7813 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7814 TmpInst.addOperand(Inst.getOperand(0));
7815 TmpInst.addOperand(Inst.getOperand(1));
7816 TmpInst.addOperand(Inst.getOperand(2));
7817 TmpInst.addOperand(Inst.getOperand(3));
7818 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007819 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007820 }
7821 break;
7822 }
Jim Grosbach82213192011-09-19 20:29:33 +00007823 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007824 case ARM::t2SXTB:
7825 case ARM::t2UXTH:
7826 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007827 // If we can use the 16-bit encoding and the user didn't explicitly
7828 // request the 32-bit variant, transform it here.
7829 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7830 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7831 Inst.getOperand(2).getImm() == 0 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007832 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
7833 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007834 unsigned NewOpc;
7835 switch (Inst.getOpcode()) {
7836 default: llvm_unreachable("Illegal opcode!");
7837 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7838 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7839 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7840 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7841 }
Jim Grosbach82213192011-09-19 20:29:33 +00007842 // The operands aren't the same for thumb1 (no rotate operand).
7843 MCInst TmpInst;
7844 TmpInst.setOpcode(NewOpc);
7845 TmpInst.addOperand(Inst.getOperand(0));
7846 TmpInst.addOperand(Inst.getOperand(1));
7847 TmpInst.addOperand(Inst.getOperand(3));
7848 TmpInst.addOperand(Inst.getOperand(4));
7849 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007850 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007851 }
7852 break;
7853 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007854 case ARM::MOVsi: {
7855 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007856 // rrx shifts and asr/lsr of #32 is encoded as 0
7857 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7858 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007859 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7860 // Shifting by zero is accepted as a vanilla 'MOVr'
7861 MCInst TmpInst;
7862 TmpInst.setOpcode(ARM::MOVr);
7863 TmpInst.addOperand(Inst.getOperand(0));
7864 TmpInst.addOperand(Inst.getOperand(1));
7865 TmpInst.addOperand(Inst.getOperand(3));
7866 TmpInst.addOperand(Inst.getOperand(4));
7867 TmpInst.addOperand(Inst.getOperand(5));
7868 Inst = TmpInst;
7869 return true;
7870 }
7871 return false;
7872 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007873 case ARM::ANDrsi:
7874 case ARM::ORRrsi:
7875 case ARM::EORrsi:
7876 case ARM::BICrsi:
7877 case ARM::SUBrsi:
7878 case ARM::ADDrsi: {
7879 unsigned newOpc;
7880 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7881 if (SOpc == ARM_AM::rrx) return false;
7882 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007883 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007884 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7885 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7886 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7887 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7888 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7889 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7890 }
7891 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007892 // The exception is for right shifts, where 0 == 32
7893 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7894 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007895 MCInst TmpInst;
7896 TmpInst.setOpcode(newOpc);
7897 TmpInst.addOperand(Inst.getOperand(0));
7898 TmpInst.addOperand(Inst.getOperand(1));
7899 TmpInst.addOperand(Inst.getOperand(2));
7900 TmpInst.addOperand(Inst.getOperand(4));
7901 TmpInst.addOperand(Inst.getOperand(5));
7902 TmpInst.addOperand(Inst.getOperand(6));
7903 Inst = TmpInst;
7904 return true;
7905 }
7906 return false;
7907 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007908 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007909 case ARM::t2IT: {
7910 // The mask bits for all but the first condition are represented as
7911 // the low bit of the condition code value implies 't'. We currently
7912 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007913 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007914 MCOperand &MO = Inst.getOperand(1);
7915 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007916 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007917 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007918 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007919 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007920 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007921 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007922 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007923
7924 // Set up the IT block state according to the IT instruction we just
7925 // matched.
7926 assert(!inITBlock() && "nested IT blocks?!");
7927 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7928 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7929 ITState.CurPosition = 0;
7930 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007931 break;
7932 }
Richard Bartona39625e2012-07-09 16:12:24 +00007933 case ARM::t2LSLrr:
7934 case ARM::t2LSRrr:
7935 case ARM::t2ASRrr:
7936 case ARM::t2SBCrr:
7937 case ARM::t2RORrr:
7938 case ARM::t2BICrr:
7939 {
Richard Bartond5660372012-07-09 16:14:28 +00007940 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007941 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7942 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7943 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007944 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00007945 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7946 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
7947 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
7948 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00007949 unsigned NewOpc;
7950 switch (Inst.getOpcode()) {
7951 default: llvm_unreachable("unexpected opcode");
7952 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7953 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7954 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7955 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7956 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7957 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7958 }
7959 MCInst TmpInst;
7960 TmpInst.setOpcode(NewOpc);
7961 TmpInst.addOperand(Inst.getOperand(0));
7962 TmpInst.addOperand(Inst.getOperand(5));
7963 TmpInst.addOperand(Inst.getOperand(1));
7964 TmpInst.addOperand(Inst.getOperand(2));
7965 TmpInst.addOperand(Inst.getOperand(3));
7966 TmpInst.addOperand(Inst.getOperand(4));
7967 Inst = TmpInst;
7968 return true;
7969 }
7970 return false;
7971 }
7972 case ARM::t2ANDrr:
7973 case ARM::t2EORrr:
7974 case ARM::t2ADCrr:
7975 case ARM::t2ORRrr:
7976 {
Richard Bartond5660372012-07-09 16:14:28 +00007977 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007978 // These instructions are special in that they are commutable, so shorter encodings
7979 // are available more often.
7980 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7981 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7982 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7983 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007984 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00007985 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7986 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
7987 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
7988 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00007989 unsigned NewOpc;
7990 switch (Inst.getOpcode()) {
7991 default: llvm_unreachable("unexpected opcode");
7992 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7993 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7994 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7995 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7996 }
7997 MCInst TmpInst;
7998 TmpInst.setOpcode(NewOpc);
7999 TmpInst.addOperand(Inst.getOperand(0));
8000 TmpInst.addOperand(Inst.getOperand(5));
8001 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
8002 TmpInst.addOperand(Inst.getOperand(1));
8003 TmpInst.addOperand(Inst.getOperand(2));
8004 } else {
8005 TmpInst.addOperand(Inst.getOperand(2));
8006 TmpInst.addOperand(Inst.getOperand(1));
8007 }
8008 TmpInst.addOperand(Inst.getOperand(3));
8009 TmpInst.addOperand(Inst.getOperand(4));
8010 Inst = TmpInst;
8011 return true;
8012 }
8013 return false;
8014 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008015 }
Jim Grosbachafad0532011-11-10 23:42:14 +00008016 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008017}
8018
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008019unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
8020 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
8021 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008022 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00008023 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008024 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
8025 assert(MCID.hasOptionalDef() &&
8026 "optionally flag setting instruction missing optional def operand");
8027 assert(MCID.NumOperands == Inst.getNumOperands() &&
8028 "operand count mismatch!");
8029 // Find the optional-def operand (cc_out).
8030 unsigned OpNo;
8031 for (OpNo = 0;
8032 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
8033 ++OpNo)
8034 ;
8035 // If we're parsing Thumb1, reject it completely.
8036 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
8037 return Match_MnemonicFail;
8038 // If we're parsing Thumb2, which form is legal depends on whether we're
8039 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00008040 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
8041 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008042 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00008043 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8044 inITBlock())
8045 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008046 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008047 // Some high-register supporting Thumb1 encodings only allow both registers
8048 // to be from r0-r7 when in Thumb2.
8049 else if (Opc == ARM::tADDhirr && isThumbOne() &&
8050 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8051 isARMLowRegister(Inst.getOperand(2).getReg()))
8052 return Match_RequiresThumb2;
8053 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00008054 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008055 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8056 isARMLowRegister(Inst.getOperand(1).getReg()))
8057 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008058 return Match_Success;
8059}
8060
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008061namespace llvm {
8062template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008063 return true; // In an assembly source, no need to second-guess
8064}
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008065}
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008066
Jim Grosbach5117ef72012-04-24 22:40:08 +00008067static const char *getSubtargetFeatureName(unsigned Val);
David Blaikie960ea3f2014-06-08 16:18:35 +00008068bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
8069 OperandVector &Operands,
8070 MCStreamer &Out, unsigned &ErrorInfo,
8071 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00008072 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00008073 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00008074
Chad Rosier2f480a82012-10-12 22:53:36 +00008075 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00008076 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00008077 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00008078 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008079 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008080 // Context sensitive operand constraints aren't handled by the matcher,
8081 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008082 if (validateInstruction(Inst, Operands)) {
8083 // Still progress the IT block, otherwise one wrong condition causes
8084 // nasty cascading errors.
8085 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008086 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008087 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008088
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008089 { // processInstruction() updates inITBlock state, we need to save it away
8090 bool wasInITBlock = inITBlock();
8091
8092 // Some instructions need post-processing to, for example, tweak which
8093 // encoding is selected. Loop on it while changes happen so the
8094 // individual transformations can chain off each other. E.g.,
8095 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
8096 while (processInstruction(Inst, Operands))
8097 ;
8098
8099 // Only after the instruction is fully processed, we can validate it
8100 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00008101 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008102 Warning(IDLoc, "deprecated instruction in IT block");
8103 }
8104 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008105
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008106 // Only move forward at the very end so that everything in validate
8107 // and process gets a consistent answer about whether we're in an IT
8108 // block.
8109 forwardITPosition();
8110
Jim Grosbach82f76d12012-01-25 19:52:01 +00008111 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8112 // doesn't actually encode.
8113 if (Inst.getOpcode() == ARM::ITasm)
8114 return false;
8115
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00008116 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00008117 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00008118 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008119 case Match_MissingFeature: {
8120 assert(ErrorInfo && "Unknown missing feature!");
8121 // Special case the error message for the very common case where only
8122 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8123 std::string Msg = "instruction requires:";
8124 unsigned Mask = 1;
8125 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8126 if (ErrorInfo & Mask) {
8127 Msg += " ";
8128 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8129 }
8130 Mask <<= 1;
8131 }
8132 return Error(IDLoc, Msg);
8133 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008134 case Match_InvalidOperand: {
8135 SMLoc ErrorLoc = IDLoc;
8136 if (ErrorInfo != ~0U) {
8137 if (ErrorInfo >= Operands.size())
8138 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00008139
David Blaikie960ea3f2014-06-08 16:18:35 +00008140 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008141 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8142 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008143
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008144 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00008145 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008146 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00008147 return Error(IDLoc, "invalid instruction",
David Blaikie960ea3f2014-06-08 16:18:35 +00008148 ((ARMOperand &)*Operands[0]).getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00008149 case Match_RequiresNotITBlock:
8150 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008151 case Match_RequiresITBlock:
8152 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008153 case Match_RequiresV6:
8154 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8155 case Match_RequiresThumb2:
8156 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00008157 case Match_ImmRange0_15: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008158 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Jim Grosbach087affe2012-06-22 23:56:48 +00008159 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8160 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8161 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008162 case Match_ImmRange0_239: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008163 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008164 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8165 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8166 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00008167 case Match_AlignedMemoryRequiresNone:
8168 case Match_DupAlignedMemoryRequiresNone:
8169 case Match_AlignedMemoryRequires16:
8170 case Match_DupAlignedMemoryRequires16:
8171 case Match_AlignedMemoryRequires32:
8172 case Match_DupAlignedMemoryRequires32:
8173 case Match_AlignedMemoryRequires64:
8174 case Match_DupAlignedMemoryRequires64:
8175 case Match_AlignedMemoryRequires64or128:
8176 case Match_DupAlignedMemoryRequires64or128:
8177 case Match_AlignedMemoryRequires64or128or256:
8178 {
David Blaikie960ea3f2014-06-08 16:18:35 +00008179 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00008180 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8181 switch (MatchResult) {
8182 default:
8183 llvm_unreachable("Missing Match_Aligned type");
8184 case Match_AlignedMemoryRequiresNone:
8185 case Match_DupAlignedMemoryRequiresNone:
8186 return Error(ErrorLoc, "alignment must be omitted");
8187 case Match_AlignedMemoryRequires16:
8188 case Match_DupAlignedMemoryRequires16:
8189 return Error(ErrorLoc, "alignment must be 16 or omitted");
8190 case Match_AlignedMemoryRequires32:
8191 case Match_DupAlignedMemoryRequires32:
8192 return Error(ErrorLoc, "alignment must be 32 or omitted");
8193 case Match_AlignedMemoryRequires64:
8194 case Match_DupAlignedMemoryRequires64:
8195 return Error(ErrorLoc, "alignment must be 64 or omitted");
8196 case Match_AlignedMemoryRequires64or128:
8197 case Match_DupAlignedMemoryRequires64or128:
8198 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8199 case Match_AlignedMemoryRequires64or128or256:
8200 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8201 }
8202 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008203 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008204
Eric Christopher91d7b902010-10-29 09:26:59 +00008205 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00008206}
8207
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008208/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00008209bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008210 const MCObjectFileInfo::Environment Format =
8211 getContext().getObjectFileInfo()->getObjectFileType();
8212 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
8213
Kevin Enderbyccab3172009-09-15 00:27:25 +00008214 StringRef IDVal = DirectiveID.getIdentifier();
8215 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008216 return parseLiteralValues(4, DirectiveID.getLoc());
8217 else if (IDVal == ".short" || IDVal == ".hword")
8218 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008219 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008220 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00008221 else if (IDVal == ".arm")
8222 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008223 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008224 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008225 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008226 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008227 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008228 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008229 else if (IDVal == ".unreq")
8230 return parseDirectiveUnreq(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00008231 else if (IDVal == ".fnend")
8232 return parseDirectiveFnEnd(DirectiveID.getLoc());
8233 else if (IDVal == ".cantunwind")
8234 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8235 else if (IDVal == ".personality")
8236 return parseDirectivePersonality(DirectiveID.getLoc());
8237 else if (IDVal == ".handlerdata")
8238 return parseDirectiveHandlerData(DirectiveID.getLoc());
8239 else if (IDVal == ".setfp")
8240 return parseDirectiveSetFP(DirectiveID.getLoc());
8241 else if (IDVal == ".pad")
8242 return parseDirectivePad(DirectiveID.getLoc());
8243 else if (IDVal == ".save")
8244 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8245 else if (IDVal == ".vsave")
8246 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008247 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008248 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008249 else if (IDVal == ".even")
8250 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008251 else if (IDVal == ".personalityindex")
8252 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008253 else if (IDVal == ".unwind_raw")
8254 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008255 else if (IDVal == ".movsp")
8256 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008257 else if (IDVal == ".arch_extension")
8258 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008259 else if (IDVal == ".align")
8260 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008261 else if (IDVal == ".thumb_set")
8262 return parseDirectiveThumbSet(DirectiveID.getLoc());
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008263
8264 if (!IsMachO) {
8265 if (IDVal == ".arch")
8266 return parseDirectiveArch(DirectiveID.getLoc());
8267 else if (IDVal == ".cpu")
8268 return parseDirectiveCPU(DirectiveID.getLoc());
8269 else if (IDVal == ".eabi_attribute")
8270 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8271 else if (IDVal == ".fpu")
8272 return parseDirectiveFPU(DirectiveID.getLoc());
8273 else if (IDVal == ".fnstart")
8274 return parseDirectiveFnStart(DirectiveID.getLoc());
8275 else if (IDVal == ".inst")
8276 return parseDirectiveInst(DirectiveID.getLoc());
8277 else if (IDVal == ".inst.n")
8278 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8279 else if (IDVal == ".inst.w")
8280 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8281 else if (IDVal == ".object_arch")
8282 return parseDirectiveObjectArch(DirectiveID.getLoc());
8283 else if (IDVal == ".tlsdescseq")
8284 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8285 }
8286
Kevin Enderbyccab3172009-09-15 00:27:25 +00008287 return true;
8288}
8289
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008290/// parseLiteralValues
8291/// ::= .hword expression [, expression]*
8292/// ::= .short expression [, expression]*
8293/// ::= .word expression [, expression]*
8294bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00008295 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8296 for (;;) {
8297 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008298 if (getParser().parseExpression(Value)) {
8299 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008300 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008301 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008302
Eric Christopherbf7bc492013-01-09 03:52:05 +00008303 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008304
8305 if (getLexer().is(AsmToken::EndOfStatement))
8306 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008307
Kevin Enderbyccab3172009-09-15 00:27:25 +00008308 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008309 if (getLexer().isNot(AsmToken::Comma)) {
8310 Error(L, "unexpected token in directive");
8311 return false;
8312 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008313 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008314 }
8315 }
8316
Sean Callanana83fd7d2010-01-19 20:27:46 +00008317 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008318 return false;
8319}
8320
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008321/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008322/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008323bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008324 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8325 Error(L, "unexpected token in directive");
8326 return false;
8327 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008328 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008329
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008330 if (!hasThumb()) {
8331 Error(L, "target does not support Thumb mode");
8332 return false;
8333 }
Tim Northovera2292d02013-06-10 23:20:58 +00008334
Jim Grosbach7f882392011-12-07 18:04:19 +00008335 if (!isThumb())
8336 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008337
Jim Grosbach7f882392011-12-07 18:04:19 +00008338 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8339 return false;
8340}
8341
8342/// parseDirectiveARM
8343/// ::= .arm
8344bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008345 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8346 Error(L, "unexpected token in directive");
8347 return false;
8348 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008349 Parser.Lex();
8350
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008351 if (!hasARM()) {
8352 Error(L, "target does not support ARM mode");
8353 return false;
8354 }
Tim Northovera2292d02013-06-10 23:20:58 +00008355
Jim Grosbach7f882392011-12-07 18:04:19 +00008356 if (isThumb())
8357 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008358
Jim Grosbach7f882392011-12-07 18:04:19 +00008359 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008360 return false;
8361}
8362
Tim Northover1744d0a2013-10-25 12:49:50 +00008363void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8364 if (NextSymbolIsThumb) {
8365 getParser().getStreamer().EmitThumbFunc(Symbol);
8366 NextSymbolIsThumb = false;
8367 }
8368}
8369
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008370/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008371/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008372bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00008373 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8374 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008375
Jim Grosbach1152cc02011-12-21 22:30:16 +00008376 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008377 // ELF doesn't
8378 if (isMachO) {
8379 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008380 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008381 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8382 Error(L, "unexpected token in .thumb_func directive");
8383 return false;
8384 }
8385
Tim Northover1744d0a2013-10-25 12:49:50 +00008386 MCSymbol *Func =
8387 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8388 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008389 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008390 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008391 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008392 }
8393
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008394 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8395 Error(L, "unexpected token in directive");
8396 return false;
8397 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008398
Tim Northover1744d0a2013-10-25 12:49:50 +00008399 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008400 return false;
8401}
8402
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008403/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008404/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008405bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008406 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008407 if (Tok.isNot(AsmToken::Identifier)) {
8408 Error(L, "unexpected token in .syntax directive");
8409 return false;
8410 }
8411
Benjamin Kramer92d89982010-07-14 22:38:02 +00008412 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008413 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008414 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008415 } else if (Mode == "divided" || Mode == "DIVIDED") {
8416 Error(L, "'.syntax divided' arm asssembly not supported");
8417 return false;
8418 } else {
8419 Error(L, "unrecognized syntax mode in .syntax directive");
8420 return false;
8421 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008422
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008423 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8424 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8425 return false;
8426 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008427 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008428
8429 // TODO tell the MC streamer the mode
8430 // getParser().getStreamer().Emit???();
8431 return false;
8432}
8433
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008434/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008435/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008436bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008437 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008438 if (Tok.isNot(AsmToken::Integer)) {
8439 Error(L, "unexpected token in .code directive");
8440 return false;
8441 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008442 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008443 if (Val != 16 && Val != 32) {
8444 Error(L, "invalid operand to .code directive");
8445 return false;
8446 }
8447 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008448
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008449 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8450 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8451 return false;
8452 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008453 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008454
Evan Cheng284b4672011-07-08 22:36:29 +00008455 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008456 if (!hasThumb()) {
8457 Error(L, "target does not support Thumb mode");
8458 return false;
8459 }
Tim Northovera2292d02013-06-10 23:20:58 +00008460
Jim Grosbachf471ac32011-09-06 18:46:23 +00008461 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008462 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008463 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008464 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008465 if (!hasARM()) {
8466 Error(L, "target does not support ARM mode");
8467 return false;
8468 }
Tim Northovera2292d02013-06-10 23:20:58 +00008469
Jim Grosbachf471ac32011-09-06 18:46:23 +00008470 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008471 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008472 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008473 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008474
Kevin Enderby146dcf22009-10-15 20:48:48 +00008475 return false;
8476}
8477
Jim Grosbachab5830e2011-12-14 02:16:11 +00008478/// parseDirectiveReq
8479/// ::= name .req registername
8480bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8481 Parser.Lex(); // Eat the '.req' token.
8482 unsigned Reg;
8483 SMLoc SRegLoc, ERegLoc;
8484 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008485 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008486 Error(SRegLoc, "register name expected");
8487 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008488 }
8489
8490 // Shouldn't be anything else.
8491 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008492 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008493 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8494 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008495 }
8496
8497 Parser.Lex(); // Consume the EndOfStatement
8498
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008499 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) {
8500 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8501 return false;
8502 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00008503
8504 return false;
8505}
8506
8507/// parseDirectiveUneq
8508/// ::= .unreq registername
8509bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8510 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008511 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008512 Error(L, "unexpected input in .unreq directive.");
8513 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008514 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00008515 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008516 Parser.Lex(); // Eat the identifier.
8517 return false;
8518}
8519
Jason W Kim135d2442011-12-20 17:38:12 +00008520/// parseDirectiveArch
8521/// ::= .arch token
8522bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00008523 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8524
8525 unsigned ID = StringSwitch<unsigned>(Arch)
8526#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8527 .Case(NAME, ARM::ID)
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +00008528#define ARM_ARCH_ALIAS(NAME, ID) \
8529 .Case(NAME, ARM::ID)
Logan Chien439e8f92013-12-11 17:16:25 +00008530#include "MCTargetDesc/ARMArchName.def"
8531 .Default(ARM::INVALID_ARCH);
8532
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008533 if (ID == ARM::INVALID_ARCH) {
8534 Error(L, "Unknown arch name");
8535 return false;
8536 }
Logan Chien439e8f92013-12-11 17:16:25 +00008537
8538 getTargetStreamer().emitArch(ID);
8539 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008540}
8541
8542/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008543/// ::= .eabi_attribute int, int [, "str"]
8544/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00008545bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008546 int64_t Tag;
8547 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008548 TagLoc = Parser.getTok().getLoc();
8549 if (Parser.getTok().is(AsmToken::Identifier)) {
8550 StringRef Name = Parser.getTok().getIdentifier();
8551 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
8552 if (Tag == -1) {
8553 Error(TagLoc, "attribute name not recognised: " + Name);
8554 Parser.eatToEndOfStatement();
8555 return false;
8556 }
8557 Parser.Lex();
8558 } else {
8559 const MCExpr *AttrExpr;
8560
8561 TagLoc = Parser.getTok().getLoc();
8562 if (Parser.parseExpression(AttrExpr)) {
8563 Parser.eatToEndOfStatement();
8564 return false;
8565 }
8566
8567 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
8568 if (!CE) {
8569 Error(TagLoc, "expected numeric constant");
8570 Parser.eatToEndOfStatement();
8571 return false;
8572 }
8573
8574 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008575 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008576
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008577 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008578 Error(Parser.getTok().getLoc(), "comma expected");
8579 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008580 return false;
8581 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008582 Parser.Lex(); // skip comma
8583
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008584 StringRef StringValue = "";
8585 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00008586
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008587 int64_t IntegerValue = 0;
8588 bool IsIntegerValue = false;
8589
8590 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
8591 IsStringValue = true;
8592 else if (Tag == ARMBuildAttrs::compatibility) {
8593 IsStringValue = true;
8594 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00008595 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008596 IsIntegerValue = true;
8597 else if (Tag % 2 == 1)
8598 IsStringValue = true;
8599 else
8600 llvm_unreachable("invalid tag type");
8601
8602 if (IsIntegerValue) {
8603 const MCExpr *ValueExpr;
8604 SMLoc ValueExprLoc = Parser.getTok().getLoc();
8605 if (Parser.parseExpression(ValueExpr)) {
8606 Parser.eatToEndOfStatement();
8607 return false;
8608 }
8609
8610 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
8611 if (!CE) {
8612 Error(ValueExprLoc, "expected numeric constant");
8613 Parser.eatToEndOfStatement();
8614 return false;
8615 }
8616
8617 IntegerValue = CE->getValue();
8618 }
8619
8620 if (Tag == ARMBuildAttrs::compatibility) {
8621 if (Parser.getTok().isNot(AsmToken::Comma))
8622 IsStringValue = false;
8623 else
8624 Parser.Lex();
8625 }
8626
8627 if (IsStringValue) {
8628 if (Parser.getTok().isNot(AsmToken::String)) {
8629 Error(Parser.getTok().getLoc(), "bad string constant");
8630 Parser.eatToEndOfStatement();
8631 return false;
8632 }
8633
8634 StringValue = Parser.getTok().getStringContents();
8635 Parser.Lex();
8636 }
8637
8638 if (IsIntegerValue && IsStringValue) {
8639 assert(Tag == ARMBuildAttrs::compatibility);
8640 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
8641 } else if (IsIntegerValue)
8642 getTargetStreamer().emitAttribute(Tag, IntegerValue);
8643 else if (IsStringValue)
8644 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00008645 return false;
8646}
8647
8648/// parseDirectiveCPU
8649/// ::= .cpu str
8650bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8651 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8652 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8653 return false;
8654}
8655
8656/// parseDirectiveFPU
8657/// ::= .fpu str
8658bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8659 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8660
8661 unsigned ID = StringSwitch<unsigned>(FPU)
8662#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8663#include "ARMFPUName.def"
8664 .Default(ARM::INVALID_FPU);
8665
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008666 if (ID == ARM::INVALID_FPU) {
8667 Error(L, "Unknown FPU name");
8668 return false;
8669 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008670
8671 getTargetStreamer().emitFPU(ID);
8672 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008673}
8674
Logan Chien4ea23b52013-05-10 16:17:24 +00008675/// parseDirectiveFnStart
8676/// ::= .fnstart
8677bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008678 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008679 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008680 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008681 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008682 }
8683
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008684 // Reset the unwind directives parser state
8685 UC.reset();
8686
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008687 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008688
8689 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00008690 return false;
8691}
8692
8693/// parseDirectiveFnEnd
8694/// ::= .fnend
8695bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8696 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008697 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008698 Error(L, ".fnstart must precede .fnend directive");
8699 return false;
8700 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008701
8702 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008703 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008704
8705 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00008706 return false;
8707}
8708
8709/// parseDirectiveCantUnwind
8710/// ::= .cantunwind
8711bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008712 UC.recordCantUnwind(L);
8713
Logan Chien4ea23b52013-05-10 16:17:24 +00008714 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008715 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008716 Error(L, ".fnstart must precede .cantunwind directive");
8717 return false;
8718 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008719 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008720 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008721 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008722 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008723 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008724 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008725 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008726 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008727 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008728 }
8729
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008730 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00008731 return false;
8732}
8733
8734/// parseDirectivePersonality
8735/// ::= .personality name
8736bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008737 bool HasExistingPersonality = UC.hasPersonality();
8738
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008739 UC.recordPersonality(L);
8740
Logan Chien4ea23b52013-05-10 16:17:24 +00008741 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008742 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008743 Error(L, ".fnstart must precede .personality directive");
8744 return false;
8745 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008746 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008747 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008748 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008749 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008750 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008751 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008752 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008753 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008754 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008755 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008756 if (HasExistingPersonality) {
8757 Parser.eatToEndOfStatement();
8758 Error(L, "multiple personality directives");
8759 UC.emitPersonalityLocNotes();
8760 return false;
8761 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008762
8763 // Parse the name of the personality routine
8764 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8765 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008766 Error(L, "unexpected input in .personality directive.");
8767 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008768 }
8769 StringRef Name(Parser.getTok().getIdentifier());
8770 Parser.Lex();
8771
8772 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008773 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00008774 return false;
8775}
8776
8777/// parseDirectiveHandlerData
8778/// ::= .handlerdata
8779bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008780 UC.recordHandlerData(L);
8781
Logan Chien4ea23b52013-05-10 16:17:24 +00008782 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008783 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008784 Error(L, ".fnstart must precede .personality directive");
8785 return false;
8786 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008787 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008788 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008789 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008790 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008791 }
8792
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008793 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00008794 return false;
8795}
8796
8797/// parseDirectiveSetFP
8798/// ::= .setfp fpreg, spreg [, offset]
8799bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8800 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008801 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008802 Error(L, ".fnstart must precede .setfp directive");
8803 return false;
8804 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008805 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008806 Error(L, ".setfp must precede .handlerdata directive");
8807 return false;
8808 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008809
8810 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008811 SMLoc FPRegLoc = Parser.getTok().getLoc();
8812 int FPReg = tryParseRegister();
8813 if (FPReg == -1) {
8814 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008815 return false;
8816 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008817
8818 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008819 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008820 Error(Parser.getTok().getLoc(), "comma expected");
8821 return false;
8822 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008823 Parser.Lex(); // skip comma
8824
8825 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008826 SMLoc SPRegLoc = Parser.getTok().getLoc();
8827 int SPReg = tryParseRegister();
8828 if (SPReg == -1) {
8829 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008830 return false;
8831 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008832
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008833 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
8834 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008835 return false;
8836 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008837
8838 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008839 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00008840
8841 // Parse offset
8842 int64_t Offset = 0;
8843 if (Parser.getTok().is(AsmToken::Comma)) {
8844 Parser.Lex(); // skip comma
8845
8846 if (Parser.getTok().isNot(AsmToken::Hash) &&
8847 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008848 Error(Parser.getTok().getLoc(), "'#' expected");
8849 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008850 }
8851 Parser.Lex(); // skip hash token.
8852
8853 const MCExpr *OffsetExpr;
8854 SMLoc ExLoc = Parser.getTok().getLoc();
8855 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008856 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8857 Error(ExLoc, "malformed setfp offset");
8858 return false;
8859 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008860 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008861 if (!CE) {
8862 Error(ExLoc, "setfp offset must be an immediate");
8863 return false;
8864 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008865
8866 Offset = CE->getValue();
8867 }
8868
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008869 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
8870 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00008871 return false;
8872}
8873
8874/// parseDirective
8875/// ::= .pad offset
8876bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8877 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008878 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008879 Error(L, ".fnstart must precede .pad directive");
8880 return false;
8881 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008882 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008883 Error(L, ".pad must precede .handlerdata directive");
8884 return false;
8885 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008886
8887 // Parse the offset
8888 if (Parser.getTok().isNot(AsmToken::Hash) &&
8889 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008890 Error(Parser.getTok().getLoc(), "'#' expected");
8891 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008892 }
8893 Parser.Lex(); // skip hash token.
8894
8895 const MCExpr *OffsetExpr;
8896 SMLoc ExLoc = Parser.getTok().getLoc();
8897 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008898 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8899 Error(ExLoc, "malformed pad offset");
8900 return false;
8901 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008902 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008903 if (!CE) {
8904 Error(ExLoc, "pad offset must be an immediate");
8905 return false;
8906 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008907
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008908 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00008909 return false;
8910}
8911
8912/// parseDirectiveRegSave
8913/// ::= .save { registers }
8914/// ::= .vsave { registers }
8915bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8916 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008917 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008918 Error(L, ".fnstart must precede .save or .vsave directives");
8919 return false;
8920 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008921 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008922 Error(L, ".save or .vsave must precede .handlerdata directive");
8923 return false;
8924 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008925
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008926 // RAII object to make sure parsed operands are deleted.
David Blaikie960ea3f2014-06-08 16:18:35 +00008927 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008928
Logan Chien4ea23b52013-05-10 16:17:24 +00008929 // Parse the register list
David Blaikie960ea3f2014-06-08 16:18:35 +00008930 if (parseRegisterList(Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008931 return false;
David Blaikie960ea3f2014-06-08 16:18:35 +00008932 ARMOperand &Op = (ARMOperand &)*Operands[0];
8933 if (!IsVector && !Op.isRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008934 Error(L, ".save expects GPR registers");
8935 return false;
8936 }
David Blaikie960ea3f2014-06-08 16:18:35 +00008937 if (IsVector && !Op.isDPRRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008938 Error(L, ".vsave expects DPR registers");
8939 return false;
8940 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008941
David Blaikie960ea3f2014-06-08 16:18:35 +00008942 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00008943 return false;
8944}
8945
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008946/// parseDirectiveInst
8947/// ::= .inst opcode [, ...]
8948/// ::= .inst.n opcode [, ...]
8949/// ::= .inst.w opcode [, ...]
8950bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8951 int Width;
8952
8953 if (isThumb()) {
8954 switch (Suffix) {
8955 case 'n':
8956 Width = 2;
8957 break;
8958 case 'w':
8959 Width = 4;
8960 break;
8961 default:
8962 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008963 Error(Loc, "cannot determine Thumb instruction size, "
8964 "use inst.n/inst.w instead");
8965 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008966 }
8967 } else {
8968 if (Suffix) {
8969 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008970 Error(Loc, "width suffixes are invalid in ARM mode");
8971 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008972 }
8973 Width = 4;
8974 }
8975
8976 if (getLexer().is(AsmToken::EndOfStatement)) {
8977 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008978 Error(Loc, "expected expression following directive");
8979 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008980 }
8981
8982 for (;;) {
8983 const MCExpr *Expr;
8984
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008985 if (getParser().parseExpression(Expr)) {
8986 Error(Loc, "expected expression");
8987 return false;
8988 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008989
8990 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008991 if (!Value) {
8992 Error(Loc, "expected constant expression");
8993 return false;
8994 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008995
8996 switch (Width) {
8997 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008998 if (Value->getValue() > 0xffff) {
8999 Error(Loc, "inst.n operand is too big, use inst.w instead");
9000 return false;
9001 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009002 break;
9003 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009004 if (Value->getValue() > 0xffffffff) {
9005 Error(Loc,
9006 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
9007 return false;
9008 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009009 break;
9010 default:
9011 llvm_unreachable("only supported widths are 2 and 4");
9012 }
9013
9014 getTargetStreamer().emitInst(Value->getValue(), Suffix);
9015
9016 if (getLexer().is(AsmToken::EndOfStatement))
9017 break;
9018
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009019 if (getLexer().isNot(AsmToken::Comma)) {
9020 Error(Loc, "unexpected token in directive");
9021 return false;
9022 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009023
9024 Parser.Lex();
9025 }
9026
9027 Parser.Lex();
9028 return false;
9029}
9030
David Peixotto80c083a2013-12-19 18:26:07 +00009031/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00009032/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00009033bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00009034 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00009035 return false;
9036}
9037
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009038bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9039 const MCSection *Section = getStreamer().getCurrentSection().first;
9040
9041 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9042 TokError("unexpected token in directive");
9043 return false;
9044 }
9045
9046 if (!Section) {
Rafael Espindolaf1440342014-01-23 23:14:14 +00009047 getStreamer().InitSections();
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009048 Section = getStreamer().getCurrentSection().first;
9049 }
9050
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00009051 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009052 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00009053 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009054 else
Rafael Espindola7b514962014-02-04 18:34:04 +00009055 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009056
9057 return false;
9058}
9059
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009060/// parseDirectivePersonalityIndex
9061/// ::= .personalityindex index
9062bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
9063 bool HasExistingPersonality = UC.hasPersonality();
9064
9065 UC.recordPersonalityIndex(L);
9066
9067 if (!UC.hasFnStart()) {
9068 Parser.eatToEndOfStatement();
9069 Error(L, ".fnstart must precede .personalityindex directive");
9070 return false;
9071 }
9072 if (UC.cantUnwind()) {
9073 Parser.eatToEndOfStatement();
9074 Error(L, ".personalityindex cannot be used with .cantunwind");
9075 UC.emitCantUnwindLocNotes();
9076 return false;
9077 }
9078 if (UC.hasHandlerData()) {
9079 Parser.eatToEndOfStatement();
9080 Error(L, ".personalityindex must precede .handlerdata directive");
9081 UC.emitHandlerDataLocNotes();
9082 return false;
9083 }
9084 if (HasExistingPersonality) {
9085 Parser.eatToEndOfStatement();
9086 Error(L, "multiple personality directives");
9087 UC.emitPersonalityLocNotes();
9088 return false;
9089 }
9090
9091 const MCExpr *IndexExpression;
9092 SMLoc IndexLoc = Parser.getTok().getLoc();
9093 if (Parser.parseExpression(IndexExpression)) {
9094 Parser.eatToEndOfStatement();
9095 return false;
9096 }
9097
9098 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9099 if (!CE) {
9100 Parser.eatToEndOfStatement();
9101 Error(IndexLoc, "index must be a constant number");
9102 return false;
9103 }
9104 if (CE->getValue() < 0 ||
9105 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9106 Parser.eatToEndOfStatement();
9107 Error(IndexLoc, "personality routine index should be in range [0-3]");
9108 return false;
9109 }
9110
9111 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9112 return false;
9113}
9114
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009115/// parseDirectiveUnwindRaw
9116/// ::= .unwind_raw offset, opcode [, opcode...]
9117bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
9118 if (!UC.hasFnStart()) {
9119 Parser.eatToEndOfStatement();
9120 Error(L, ".fnstart must precede .unwind_raw directives");
9121 return false;
9122 }
9123
9124 int64_t StackOffset;
9125
9126 const MCExpr *OffsetExpr;
9127 SMLoc OffsetLoc = getLexer().getLoc();
9128 if (getLexer().is(AsmToken::EndOfStatement) ||
9129 getParser().parseExpression(OffsetExpr)) {
9130 Error(OffsetLoc, "expected expression");
9131 Parser.eatToEndOfStatement();
9132 return false;
9133 }
9134
9135 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9136 if (!CE) {
9137 Error(OffsetLoc, "offset must be a constant");
9138 Parser.eatToEndOfStatement();
9139 return false;
9140 }
9141
9142 StackOffset = CE->getValue();
9143
9144 if (getLexer().isNot(AsmToken::Comma)) {
9145 Error(getLexer().getLoc(), "expected comma");
9146 Parser.eatToEndOfStatement();
9147 return false;
9148 }
9149 Parser.Lex();
9150
9151 SmallVector<uint8_t, 16> Opcodes;
9152 for (;;) {
9153 const MCExpr *OE;
9154
9155 SMLoc OpcodeLoc = getLexer().getLoc();
9156 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9157 Error(OpcodeLoc, "expected opcode expression");
9158 Parser.eatToEndOfStatement();
9159 return false;
9160 }
9161
9162 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9163 if (!OC) {
9164 Error(OpcodeLoc, "opcode value must be a constant");
9165 Parser.eatToEndOfStatement();
9166 return false;
9167 }
9168
9169 const int64_t Opcode = OC->getValue();
9170 if (Opcode & ~0xff) {
9171 Error(OpcodeLoc, "invalid opcode");
9172 Parser.eatToEndOfStatement();
9173 return false;
9174 }
9175
9176 Opcodes.push_back(uint8_t(Opcode));
9177
9178 if (getLexer().is(AsmToken::EndOfStatement))
9179 break;
9180
9181 if (getLexer().isNot(AsmToken::Comma)) {
9182 Error(getLexer().getLoc(), "unexpected token in directive");
9183 Parser.eatToEndOfStatement();
9184 return false;
9185 }
9186
9187 Parser.Lex();
9188 }
9189
9190 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9191
9192 Parser.Lex();
9193 return false;
9194}
9195
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009196/// parseDirectiveTLSDescSeq
9197/// ::= .tlsdescseq tls-variable
9198bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
9199 if (getLexer().isNot(AsmToken::Identifier)) {
9200 TokError("expected variable after '.tlsdescseq' directive");
9201 Parser.eatToEndOfStatement();
9202 return false;
9203 }
9204
9205 const MCSymbolRefExpr *SRE =
9206 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9207 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9208 Lex();
9209
9210 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9211 Error(Parser.getTok().getLoc(), "unexpected token");
9212 Parser.eatToEndOfStatement();
9213 return false;
9214 }
9215
9216 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9217 return false;
9218}
9219
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009220/// parseDirectiveMovSP
9221/// ::= .movsp reg [, #offset]
9222bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
9223 if (!UC.hasFnStart()) {
9224 Parser.eatToEndOfStatement();
9225 Error(L, ".fnstart must precede .movsp directives");
9226 return false;
9227 }
9228 if (UC.getFPReg() != ARM::SP) {
9229 Parser.eatToEndOfStatement();
9230 Error(L, "unexpected .movsp directive");
9231 return false;
9232 }
9233
9234 SMLoc SPRegLoc = Parser.getTok().getLoc();
9235 int SPReg = tryParseRegister();
9236 if (SPReg == -1) {
9237 Parser.eatToEndOfStatement();
9238 Error(SPRegLoc, "register expected");
9239 return false;
9240 }
9241
9242 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9243 Parser.eatToEndOfStatement();
9244 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9245 return false;
9246 }
9247
9248 int64_t Offset = 0;
9249 if (Parser.getTok().is(AsmToken::Comma)) {
9250 Parser.Lex();
9251
9252 if (Parser.getTok().isNot(AsmToken::Hash)) {
9253 Error(Parser.getTok().getLoc(), "expected #constant");
9254 Parser.eatToEndOfStatement();
9255 return false;
9256 }
9257 Parser.Lex();
9258
9259 const MCExpr *OffsetExpr;
9260 SMLoc OffsetLoc = Parser.getTok().getLoc();
9261 if (Parser.parseExpression(OffsetExpr)) {
9262 Parser.eatToEndOfStatement();
9263 Error(OffsetLoc, "malformed offset expression");
9264 return false;
9265 }
9266
9267 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9268 if (!CE) {
9269 Parser.eatToEndOfStatement();
9270 Error(OffsetLoc, "offset must be an immediate constant");
9271 return false;
9272 }
9273
9274 Offset = CE->getValue();
9275 }
9276
9277 getTargetStreamer().emitMovSP(SPReg, Offset);
9278 UC.saveFPReg(SPReg);
9279
9280 return false;
9281}
9282
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009283/// parseDirectiveObjectArch
9284/// ::= .object_arch name
9285bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
9286 if (getLexer().isNot(AsmToken::Identifier)) {
9287 Error(getLexer().getLoc(), "unexpected token");
9288 Parser.eatToEndOfStatement();
9289 return false;
9290 }
9291
9292 StringRef Arch = Parser.getTok().getString();
9293 SMLoc ArchLoc = Parser.getTok().getLoc();
9294 getLexer().Lex();
9295
9296 unsigned ID = StringSwitch<unsigned>(Arch)
9297#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9298 .Case(NAME, ARM::ID)
9299#define ARM_ARCH_ALIAS(NAME, ID) \
9300 .Case(NAME, ARM::ID)
9301#include "MCTargetDesc/ARMArchName.def"
9302#undef ARM_ARCH_NAME
9303#undef ARM_ARCH_ALIAS
9304 .Default(ARM::INVALID_ARCH);
9305
9306 if (ID == ARM::INVALID_ARCH) {
9307 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9308 Parser.eatToEndOfStatement();
9309 return false;
9310 }
9311
9312 getTargetStreamer().emitObjectArch(ID);
9313
9314 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9315 Error(getLexer().getLoc(), "unexpected token");
9316 Parser.eatToEndOfStatement();
9317 }
9318
9319 return false;
9320}
9321
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009322/// parseDirectiveAlign
9323/// ::= .align
9324bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9325 // NOTE: if this is not the end of the statement, fall back to the target
9326 // agnostic handling for this directive which will correctly handle this.
9327 if (getLexer().isNot(AsmToken::EndOfStatement))
9328 return true;
9329
9330 // '.align' is target specifically handled to mean 2**2 byte alignment.
9331 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9332 getStreamer().EmitCodeAlignment(4, 0);
9333 else
9334 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9335
9336 return false;
9337}
9338
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009339/// parseDirectiveThumbSet
9340/// ::= .thumb_set name, value
9341bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
9342 StringRef Name;
9343 if (Parser.parseIdentifier(Name)) {
9344 TokError("expected identifier after '.thumb_set'");
9345 Parser.eatToEndOfStatement();
9346 return false;
9347 }
9348
9349 if (getLexer().isNot(AsmToken::Comma)) {
9350 TokError("expected comma after name '" + Name + "'");
9351 Parser.eatToEndOfStatement();
9352 return false;
9353 }
9354 Lex();
9355
9356 const MCExpr *Value;
9357 if (Parser.parseExpression(Value)) {
9358 TokError("missing expression");
9359 Parser.eatToEndOfStatement();
9360 return false;
9361 }
9362
9363 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9364 TokError("unexpected token");
9365 Parser.eatToEndOfStatement();
9366 return false;
9367 }
9368 Lex();
9369
9370 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
Rafael Espindola466d6632014-04-27 20:23:58 +00009371 getTargetStreamer().emitThumbSet(Alias, Value);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009372 return false;
9373}
9374
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009375/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009376extern "C" void LLVMInitializeARMAsmParser() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00009377 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9378 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9379 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9380 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009381}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009382
Chris Lattner3e4582a2010-09-06 19:11:01 +00009383#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009384#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009385#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009386#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009387
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009388static const struct {
9389 const char *Name;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009390 const unsigned ArchCheck;
9391 const uint64_t Features;
9392} Extensions[] = {
9393 { "crc", Feature_HasV8, ARM::FeatureCRC },
9394 { "crypto", Feature_HasV8,
9395 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9396 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
9397 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
9398 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
9399 // FIXME: iWMMXT not supported
9400 { "iwmmxt", Feature_None, 0 },
9401 // FIXME: iWMMXT2 not supported
9402 { "iwmmxt2", Feature_None, 0 },
9403 // FIXME: Maverick not supported
9404 { "maverick", Feature_None, 0 },
9405 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
9406 // FIXME: ARMv6-m OS Extensions feature not checked
9407 { "os", Feature_None, 0 },
9408 // FIXME: Also available in ARMv6-K
9409 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
9410 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9411 // FIXME: Only available in A-class, isel not predicated
9412 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
9413 // FIXME: xscale not supported
9414 { "xscale", Feature_None, 0 },
9415};
9416
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009417/// parseDirectiveArchExtension
9418/// ::= .arch_extension [no]feature
9419bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
9420 if (getLexer().isNot(AsmToken::Identifier)) {
9421 Error(getLexer().getLoc(), "unexpected token");
9422 Parser.eatToEndOfStatement();
9423 return false;
9424 }
9425
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009426 StringRef Name = Parser.getTok().getString();
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009427 SMLoc ExtLoc = Parser.getTok().getLoc();
9428 getLexer().Lex();
9429
9430 bool EnableFeature = true;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009431 if (Name.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009432 EnableFeature = false;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009433 Name = Name.substr(2);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009434 }
9435
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009436 for (const auto &Extension : Extensions) {
9437 if (Extension.Name != Name)
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009438 continue;
9439
Saleem Abdulrasool8988c2a2014-07-27 19:07:09 +00009440 if (!Extension.Features)
9441 report_fatal_error("unsupported architectural extension: " + Name);
9442
9443 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) {
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009444 Error(ExtLoc, "architectural extension '" + Name + "' is not "
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009445 "allowed for the current base architecture");
9446 return false;
9447 }
9448
Saleem Abdulrasool8988c2a2014-07-27 19:07:09 +00009449 bool ToggleFeatures = EnableFeature
9450 ? (~STI.getFeatureBits() & Extension.Features)
9451 : ( STI.getFeatureBits() & Extension.Features);
9452 if (ToggleFeatures) {
9453 unsigned Features =
9454 ComputeAvailableFeatures(STI.ToggleFeature(Extension.Features));
9455 setAvailableFeatures(Features);
9456 }
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009457 return false;
9458 }
9459
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009460 Error(ExtLoc, "unknown architectural extension: " + Name);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009461 Parser.eatToEndOfStatement();
9462 return false;
9463}
9464
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009465// Define this matcher function after the auto-generated include so we
9466// have the match class enum definitions.
David Blaikie960ea3f2014-06-08 16:18:35 +00009467unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009468 unsigned Kind) {
David Blaikie960ea3f2014-06-08 16:18:35 +00009469 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009470 // If the kind is a token for a literal immediate, check if our asm
9471 // operand matches. This is for InstAliases which have a fixed-value
9472 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009473 switch (Kind) {
9474 default: break;
9475 case MCK__35_0:
David Blaikie960ea3f2014-06-08 16:18:35 +00009476 if (Op.isImm())
9477 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009478 if (CE->getValue() == 0)
9479 return Match_Success;
9480 break;
9481 case MCK_ARMSOImm:
David Blaikie960ea3f2014-06-08 16:18:35 +00009482 if (Op.isImm()) {
9483 const MCExpr *SOExpr = Op.getImm();
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009484 int64_t Value;
9485 if (!SOExpr->EvaluateAsAbsolute(Value))
Stepan Dyatkovskiydf657cc2014-03-29 13:12:40 +00009486 return Match_Success;
Richard Barton3db1d582014-05-01 11:37:44 +00009487 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
9488 "expression value must be representable in 32 bits");
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009489 }
9490 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00009491 case MCK_GPRPair:
David Blaikie960ea3f2014-06-08 16:18:35 +00009492 if (Op.isReg() &&
9493 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00009494 return Match_Success;
9495 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009496 }
9497 return Match_InvalidOperand;
9498}