blob: 512b73fa885909b2b7945f8d61b6ecb4cf77bfa7 [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 }
Renato Golin92c816c2014-09-01 11:25:07 +0000268 bool hasThumb2DSP() const {
269 return STI.getFeatureBits() & ARM::FeatureDSPThumb2;
270 }
Tim Northovera2292d02013-06-10 23:20:58 +0000271
Evan Cheng284b4672011-07-08 22:36:29 +0000272 void SwitchMode() {
Tim Northover26bb14e2014-08-18 11:49:42 +0000273 uint64_t FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
Evan Cheng91111d22011-07-09 05:47:46 +0000274 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000275 }
James Molloy21efa7d2011-09-28 14:21:38 +0000276 bool isMClass() const {
277 return STI.getFeatureBits() & ARM::FeatureMClass;
278 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000279
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000280 /// @name Auto-generated Match Functions
281 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000282
Chris Lattner3e4582a2010-09-06 19:11:01 +0000283#define GET_ASSEMBLER_HEADER
284#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000285
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000286 /// }
287
David Blaikie960ea3f2014-06-08 16:18:35 +0000288 OperandMatchResultTy parseITCondCode(OperandVector &);
289 OperandMatchResultTy parseCoprocNumOperand(OperandVector &);
290 OperandMatchResultTy parseCoprocRegOperand(OperandVector &);
291 OperandMatchResultTy parseCoprocOptionOperand(OperandVector &);
292 OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &);
293 OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &);
294 OperandMatchResultTy parseProcIFlagsOperand(OperandVector &);
295 OperandMatchResultTy parseMSRMaskOperand(OperandVector &);
Tim Northoveree843ef2014-08-15 10:47:12 +0000296 OperandMatchResultTy parseBankedRegOperand(OperandVector &);
David Blaikie960ea3f2014-06-08 16:18:35 +0000297 OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low,
298 int High);
299 OperandMatchResultTy parsePKHLSLImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000300 return parsePKHImm(O, "lsl", 0, 31);
301 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000302 OperandMatchResultTy parsePKHASRImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000303 return parsePKHImm(O, "asr", 1, 32);
304 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000305 OperandMatchResultTy parseSetEndImm(OperandVector &);
306 OperandMatchResultTy parseShifterImm(OperandVector &);
307 OperandMatchResultTy parseRotImm(OperandVector &);
308 OperandMatchResultTy parseBitfield(OperandVector &);
309 OperandMatchResultTy parsePostIdxReg(OperandVector &);
310 OperandMatchResultTy parseAM3Offset(OperandVector &);
311 OperandMatchResultTy parseFPImm(OperandVector &);
312 OperandMatchResultTy parseVectorList(OperandVector &);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000313 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
314 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000315
316 // Asm Match Converter Methods
David Blaikie960ea3f2014-06-08 16:18:35 +0000317 void cvtThumbMultiply(MCInst &Inst, const OperandVector &);
318 void cvtThumbBranches(MCInst &Inst, const OperandVector &);
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +0000319
David Blaikie960ea3f2014-06-08 16:18:35 +0000320 bool validateInstruction(MCInst &Inst, const OperandVector &Ops);
321 bool processInstruction(MCInst &Inst, const OperandVector &Ops);
322 bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands);
323 bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands);
324
Kevin Enderbyccab3172009-09-15 00:27:25 +0000325public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000326 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000327 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000328 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000329 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000330 Match_RequiresThumb2,
331#define GET_OPERAND_DIAGNOSTIC_TYPES
332#include "ARMGenAsmMatcher.inc"
333
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000334 };
335
Joey Gouly0e76fa72013-09-12 10:28:05 +0000336 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
Evgeniy Stepanov0a951b72014-04-23 11:16:03 +0000337 const MCInstrInfo &MII,
338 const MCTargetOptions &Options)
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000339 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), UC(_Parser) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000340 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000341
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000342 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000343 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000344
Evan Cheng4d1ca962011-07-08 01:53:10 +0000345 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000346 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000347
348 // Not in an ITBlock to start with.
349 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000350
351 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000352 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000353
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000354 // Implementation of the MCTargetAsmParser interface:
Craig Topperca7e3e52014-03-10 03:19:03 +0000355 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
David Blaikie960ea3f2014-06-08 16:18:35 +0000356 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
357 SMLoc NameLoc, OperandVector &Operands) override;
Craig Topperca7e3e52014-03-10 03:19:03 +0000358 bool ParseDirective(AsmToken DirectiveID) override;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000359
David Blaikie960ea3f2014-06-08 16:18:35 +0000360 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
Craig Topperca7e3e52014-03-10 03:19:03 +0000361 unsigned Kind) override;
362 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000363
Chad Rosier49963552012-10-13 00:26:04 +0000364 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
David Blaikie960ea3f2014-06-08 16:18:35 +0000365 OperandVector &Operands, MCStreamer &Out,
Tim Northover26bb14e2014-08-18 11:49:42 +0000366 uint64_t &ErrorInfo,
Craig Topperca7e3e52014-03-10 03:19:03 +0000367 bool MatchingInlineAsm) override;
368 void onLabelParsed(MCSymbol *Symbol) override;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000369};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000370} // end anonymous namespace
371
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000372namespace {
373
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000374/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000375/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000376class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000377 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000378 k_CondCode,
379 k_CCOut,
380 k_ITCondMask,
381 k_CoprocNum,
382 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000383 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000384 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000385 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000386 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000387 k_Memory,
388 k_PostIndexRegister,
389 k_MSRMask,
Tim Northoveree843ef2014-08-15 10:47:12 +0000390 k_BankedReg,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000391 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000392 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000393 k_Register,
394 k_RegisterList,
395 k_DPRRegisterList,
396 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000397 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000398 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000399 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000400 k_ShiftedRegister,
401 k_ShiftedImmediate,
402 k_ShifterImmediate,
403 k_RotateImmediate,
404 k_BitfieldDescriptor,
405 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000406 } Kind;
407
Kevin Enderby488f20b2014-04-10 20:18:58 +0000408 SMLoc StartLoc, EndLoc, AlignmentLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000409 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000410
Eric Christopher8996c5d2013-03-15 00:42:55 +0000411 struct CCOp {
412 ARMCC::CondCodes Val;
413 };
414
415 struct CopOp {
416 unsigned Val;
417 };
418
419 struct CoprocOptionOp {
420 unsigned Val;
421 };
422
423 struct ITMaskOp {
424 unsigned Mask:4;
425 };
426
427 struct MBOptOp {
428 ARM_MB::MemBOpt Val;
429 };
430
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000431 struct ISBOptOp {
432 ARM_ISB::InstSyncBOpt Val;
433 };
434
Eric Christopher8996c5d2013-03-15 00:42:55 +0000435 struct IFlagsOp {
436 ARM_PROC::IFlags Val;
437 };
438
439 struct MMaskOp {
440 unsigned Val;
441 };
442
Tim Northoveree843ef2014-08-15 10:47:12 +0000443 struct BankedRegOp {
444 unsigned Val;
445 };
446
Eric Christopher8996c5d2013-03-15 00:42:55 +0000447 struct TokOp {
448 const char *Data;
449 unsigned Length;
450 };
451
452 struct RegOp {
453 unsigned RegNum;
454 };
455
456 // A vector register list is a sequential list of 1 to 4 registers.
457 struct VectorListOp {
458 unsigned RegNum;
459 unsigned Count;
460 unsigned LaneIndex;
461 bool isDoubleSpaced;
462 };
463
464 struct VectorIndexOp {
465 unsigned Val;
466 };
467
468 struct ImmOp {
469 const MCExpr *Val;
470 };
471
472 /// Combined record for all forms of ARM address expressions.
473 struct MemoryOp {
474 unsigned BaseRegNum;
475 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
476 // was specified.
477 const MCConstantExpr *OffsetImm; // Offset immediate value
478 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
479 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
480 unsigned ShiftImm; // shift for OffsetReg.
481 unsigned Alignment; // 0 = no alignment specified
482 // n = alignment in bytes (2, 4, 8, 16, or 32)
483 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
484 };
485
486 struct PostIdxRegOp {
487 unsigned RegNum;
488 bool isAdd;
489 ARM_AM::ShiftOpc ShiftTy;
490 unsigned ShiftImm;
491 };
492
493 struct ShifterImmOp {
494 bool isASR;
495 unsigned Imm;
496 };
497
498 struct RegShiftedRegOp {
499 ARM_AM::ShiftOpc ShiftTy;
500 unsigned SrcReg;
501 unsigned ShiftReg;
502 unsigned ShiftImm;
503 };
504
505 struct RegShiftedImmOp {
506 ARM_AM::ShiftOpc ShiftTy;
507 unsigned SrcReg;
508 unsigned ShiftImm;
509 };
510
511 struct RotImmOp {
512 unsigned Imm;
513 };
514
515 struct BitfieldOp {
516 unsigned LSB;
517 unsigned Width;
518 };
519
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000520 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000521 struct CCOp CC;
522 struct CopOp Cop;
523 struct CoprocOptionOp CoprocOption;
524 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000525 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000526 struct ITMaskOp ITMask;
527 struct IFlagsOp IFlags;
528 struct MMaskOp MMask;
Tim Northoveree843ef2014-08-15 10:47:12 +0000529 struct BankedRegOp BankedReg;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000530 struct TokOp Tok;
531 struct RegOp Reg;
532 struct VectorListOp VectorList;
533 struct VectorIndexOp VectorIndex;
534 struct ImmOp Imm;
535 struct MemoryOp Memory;
536 struct PostIdxRegOp PostIdxReg;
537 struct ShifterImmOp ShifterImm;
538 struct RegShiftedRegOp RegShiftedReg;
539 struct RegShiftedImmOp RegShiftedImm;
540 struct RotImmOp RotImm;
541 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000542 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000543
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000544public:
David Blaikie960ea3f2014-06-08 16:18:35 +0000545 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000546 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
547 Kind = o.Kind;
548 StartLoc = o.StartLoc;
549 EndLoc = o.EndLoc;
550 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000551 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000552 CC = o.CC;
553 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000554 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000555 ITMask = o.ITMask;
556 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000557 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000558 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000559 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000560 case k_CCOut:
561 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000562 Reg = o.Reg;
563 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000564 case k_RegisterList:
565 case k_DPRRegisterList:
566 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000567 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000568 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000569 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000570 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000571 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000572 VectorList = o.VectorList;
573 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000574 case k_CoprocNum:
575 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000576 Cop = o.Cop;
577 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000578 case k_CoprocOption:
579 CoprocOption = o.CoprocOption;
580 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000581 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000582 Imm = o.Imm;
583 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000584 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000585 MBOpt = o.MBOpt;
586 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000587 case k_InstSyncBarrierOpt:
588 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000589 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000590 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000591 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000592 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000593 PostIdxReg = o.PostIdxReg;
594 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000595 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000596 MMask = o.MMask;
597 break;
Tim Northoveree843ef2014-08-15 10:47:12 +0000598 case k_BankedReg:
599 BankedReg = o.BankedReg;
600 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000601 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000602 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000603 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000604 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000605 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000606 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000607 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000608 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000609 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000610 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000611 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000612 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000613 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000614 RotImm = o.RotImm;
615 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000616 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000617 Bitfield = o.Bitfield;
618 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000619 case k_VectorIndex:
620 VectorIndex = o.VectorIndex;
621 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000622 }
623 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000624
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000625 /// getStartLoc - Get the location of the first token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000626 SMLoc getStartLoc() const override { return StartLoc; }
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000627 /// getEndLoc - Get the location of the last token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000628 SMLoc getEndLoc() const override { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000629 /// getLocRange - Get the range between the first and last token of this
630 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000631 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
632
Kevin Enderby488f20b2014-04-10 20:18:58 +0000633 /// getAlignmentLoc - Get the location of the Alignment token of this operand.
634 SMLoc getAlignmentLoc() const {
635 assert(Kind == k_Memory && "Invalid access!");
636 return AlignmentLoc;
637 }
638
Daniel Dunbard8042b72010-08-11 06:36:53 +0000639 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000640 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000641 return CC.Val;
642 }
643
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000644 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000645 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000646 return Cop.Val;
647 }
648
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000649 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000650 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000651 return StringRef(Tok.Data, Tok.Length);
652 }
653
Craig Topperca7e3e52014-03-10 03:19:03 +0000654 unsigned getReg() const override {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000655 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000656 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000657 }
658
Bill Wendlingbed94652010-11-09 23:28:44 +0000659 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000660 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
661 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000662 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000663 }
664
Kevin Enderbyf5079942009-10-13 22:19:02 +0000665 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000666 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000667 return Imm.Val;
668 }
669
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000670 unsigned getVectorIndex() const {
671 assert(Kind == k_VectorIndex && "Invalid access!");
672 return VectorIndex.Val;
673 }
674
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000675 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000676 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000677 return MBOpt.Val;
678 }
679
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000680 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
681 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
682 return ISBOpt.Val;
683 }
684
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000685 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000686 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000687 return IFlags.Val;
688 }
689
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000690 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000691 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000692 return MMask.Val;
693 }
694
Tim Northoveree843ef2014-08-15 10:47:12 +0000695 unsigned getBankedReg() const {
696 assert(Kind == k_BankedReg && "Invalid access!");
697 return BankedReg.Val;
698 }
699
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000700 bool isCoprocNum() const { return Kind == k_CoprocNum; }
701 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000702 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000703 bool isCondCode() const { return Kind == k_CondCode; }
704 bool isCCOut() const { return Kind == k_CCOut; }
705 bool isITMask() const { return Kind == k_ITCondMask; }
706 bool isITCondCode() const { return Kind == k_CondCode; }
Craig Topperca7e3e52014-03-10 03:19:03 +0000707 bool isImm() const override { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000708 // checks whether this operand is an unsigned offset which fits is a field
709 // of specified width and scaled by a specific number of bits
710 template<unsigned width, unsigned scale>
711 bool isUnsignedOffset() const {
712 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000713 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000714 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
715 int64_t Val = CE->getValue();
716 int64_t Align = 1LL << scale;
717 int64_t Max = Align * ((1LL << width) - 1);
718 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
719 }
720 return false;
721 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000722 // checks whether this operand is an signed offset which fits is a field
723 // of specified width and scaled by a specific number of bits
724 template<unsigned width, unsigned scale>
725 bool isSignedOffset() const {
726 if (!isImm()) return false;
727 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
728 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
729 int64_t Val = CE->getValue();
730 int64_t Align = 1LL << scale;
731 int64_t Max = Align * ((1LL << (width-1)) - 1);
732 int64_t Min = -Align * (1LL << (width-1));
733 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
734 }
735 return false;
736 }
737
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000738 // checks whether this operand is a memory operand computed as an offset
739 // applied to PC. the offset may have 8 bits of magnitude and is represented
740 // with two bits of shift. textually it may be either [pc, #imm], #imm or
741 // relocable expression...
742 bool isThumbMemPC() const {
743 int64_t Val = 0;
744 if (isImm()) {
745 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
747 if (!CE) return false;
748 Val = CE->getValue();
749 }
750 else if (isMem()) {
751 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
752 if(Memory.BaseRegNum != ARM::PC) return false;
753 Val = Memory.OffsetImm->getValue();
754 }
755 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000756 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000757 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000758 bool isFPImm() const {
759 if (!isImm()) return false;
760 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
761 if (!CE) return false;
762 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
763 return Val != -1;
764 }
Jim Grosbachea231912011-12-22 22:19:05 +0000765 bool isFBits16() const {
766 if (!isImm()) return false;
767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
768 if (!CE) return false;
769 int64_t Value = CE->getValue();
770 return Value >= 0 && Value <= 16;
771 }
772 bool isFBits32() const {
773 if (!isImm()) return false;
774 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
775 if (!CE) return false;
776 int64_t Value = CE->getValue();
777 return Value >= 1 && Value <= 32;
778 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000779 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000780 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000781 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
782 if (!CE) return false;
783 int64_t Value = CE->getValue();
784 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
785 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000786 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000787 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000788 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
789 if (!CE) return false;
790 int64_t Value = CE->getValue();
791 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
792 }
793 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000794 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000795 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
796 if (!CE) return false;
797 int64_t Value = CE->getValue();
798 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
799 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000800 bool isImm0_508s4Neg() const {
801 if (!isImm()) return false;
802 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
803 if (!CE) return false;
804 int64_t Value = -CE->getValue();
805 // explicitly exclude zero. we want that to use the normal 0_508 version.
806 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
807 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000808 bool isImm0_239() const {
809 if (!isImm()) return false;
810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return Value >= 0 && Value < 240;
814 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000815 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000816 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
818 if (!CE) return false;
819 int64_t Value = CE->getValue();
820 return Value >= 0 && Value < 256;
821 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000822 bool isImm0_4095() const {
823 if (!isImm()) return false;
824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
825 if (!CE) return false;
826 int64_t Value = CE->getValue();
827 return Value >= 0 && Value < 4096;
828 }
829 bool isImm0_4095Neg() const {
830 if (!isImm()) return false;
831 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
832 if (!CE) return false;
833 int64_t Value = -CE->getValue();
834 return Value > 0 && Value < 4096;
835 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000836 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000837 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000838 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
839 if (!CE) return false;
840 int64_t Value = CE->getValue();
841 return Value >= 0 && Value < 2;
842 }
843 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000844 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
846 if (!CE) return false;
847 int64_t Value = CE->getValue();
848 return Value >= 0 && Value < 4;
849 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000850 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000851 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
853 if (!CE) return false;
854 int64_t Value = CE->getValue();
855 return Value >= 0 && Value < 8;
856 }
857 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000858 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000859 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
860 if (!CE) return false;
861 int64_t Value = CE->getValue();
862 return Value >= 0 && Value < 16;
863 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000864 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000865 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000866 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
867 if (!CE) return false;
868 int64_t Value = CE->getValue();
869 return Value >= 0 && Value < 32;
870 }
Jim Grosbach00326402011-12-08 01:30:04 +0000871 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000872 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000873 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
874 if (!CE) return false;
875 int64_t Value = CE->getValue();
876 return Value >= 0 && Value < 64;
877 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000878 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000879 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000880 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
881 if (!CE) return false;
882 int64_t Value = CE->getValue();
883 return Value == 8;
884 }
885 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000886 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000887 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
888 if (!CE) return false;
889 int64_t Value = CE->getValue();
890 return Value == 16;
891 }
892 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000893 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000894 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
895 if (!CE) return false;
896 int64_t Value = CE->getValue();
897 return Value == 32;
898 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000899 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000900 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000901 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
902 if (!CE) return false;
903 int64_t Value = CE->getValue();
904 return Value > 0 && Value <= 8;
905 }
906 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000907 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
909 if (!CE) return false;
910 int64_t Value = CE->getValue();
911 return Value > 0 && Value <= 16;
912 }
913 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000914 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
916 if (!CE) return false;
917 int64_t Value = CE->getValue();
918 return Value > 0 && Value <= 32;
919 }
920 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000921 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000922 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
923 if (!CE) return false;
924 int64_t Value = CE->getValue();
925 return Value > 0 && Value <= 64;
926 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000927 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000928 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000929 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
930 if (!CE) return false;
931 int64_t Value = CE->getValue();
932 return Value > 0 && Value < 8;
933 }
934 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000935 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000936 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
937 if (!CE) return false;
938 int64_t Value = CE->getValue();
939 return Value > 0 && Value < 16;
940 }
941 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000942 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
944 if (!CE) return false;
945 int64_t Value = CE->getValue();
946 return Value > 0 && Value < 32;
947 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000948 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000949 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000950 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
951 if (!CE) return false;
952 int64_t Value = CE->getValue();
953 return Value > 0 && Value < 17;
954 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000955 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000956 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000957 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
958 if (!CE) return false;
959 int64_t Value = CE->getValue();
960 return Value > 0 && Value < 33;
961 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000962 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000963 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000964 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
965 if (!CE) return false;
966 int64_t Value = CE->getValue();
967 return Value >= 0 && Value < 33;
968 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000969 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000970 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000971 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
972 if (!CE) return false;
973 int64_t Value = CE->getValue();
974 return Value >= 0 && Value < 65536;
975 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000976 bool isImm256_65535Expr() const {
977 if (!isImm()) return false;
978 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
979 // If it's not a constant expression, it'll generate a fixup and be
980 // handled later.
981 if (!CE) return true;
982 int64_t Value = CE->getValue();
983 return Value >= 256 && Value < 65536;
984 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000985 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000986 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000987 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
988 // If it's not a constant expression, it'll generate a fixup and be
989 // handled later.
990 if (!CE) return true;
991 int64_t Value = CE->getValue();
992 return Value >= 0 && Value < 65536;
993 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000994 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000995 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000996 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
997 if (!CE) return false;
998 int64_t Value = CE->getValue();
999 return Value >= 0 && Value <= 0xffffff;
1000 }
Jim Grosbach46dd4132011-08-17 21:51:27 +00001001 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001002 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +00001003 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1004 if (!CE) return false;
1005 int64_t Value = CE->getValue();
1006 return Value > 0 && Value < 33;
1007 }
Jim Grosbach27c1e252011-07-21 17:23:04 +00001008 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001009 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001010 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1011 if (!CE) return false;
1012 int64_t Value = CE->getValue();
1013 return Value >= 0 && Value < 32;
1014 }
1015 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001016 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001017 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1018 if (!CE) return false;
1019 int64_t Value = CE->getValue();
1020 return Value > 0 && Value <= 32;
1021 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001022 bool isAdrLabel() const {
1023 // If we have an immediate that's not a constant, treat it as a label
1024 // reference needing a fixup. If it is a constant, but it can't fit
1025 // into shift immediate encoding, we reject it.
1026 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1027 else return (isARMSOImm() || isARMSOImmNeg());
1028 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001029 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001030 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001031 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1032 if (!CE) return false;
1033 int64_t Value = CE->getValue();
1034 return ARM_AM::getSOImmVal(Value) != -1;
1035 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001036 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001037 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001038 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1039 if (!CE) return false;
1040 int64_t Value = CE->getValue();
1041 return ARM_AM::getSOImmVal(~Value) != -1;
1042 }
Jim Grosbach30506252011-12-08 00:31:07 +00001043 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001044 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001045 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1046 if (!CE) return false;
1047 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001048 // Only use this when not representable as a plain so_imm.
1049 return ARM_AM::getSOImmVal(Value) == -1 &&
1050 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001051 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001052 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001053 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001054 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1055 if (!CE) return false;
1056 int64_t Value = CE->getValue();
1057 return ARM_AM::getT2SOImmVal(Value) != -1;
1058 }
Jim Grosbachb009a872011-10-28 22:36:30 +00001059 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001060 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +00001061 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1062 if (!CE) return false;
1063 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +00001064 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1065 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +00001066 }
Jim Grosbach30506252011-12-08 00:31:07 +00001067 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001068 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001069 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1070 if (!CE) return false;
1071 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001072 // Only use this when not representable as a plain so_imm.
1073 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1074 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001075 }
Jim Grosbach0a547702011-07-22 17:44:50 +00001076 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001077 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +00001078 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1079 if (!CE) return false;
1080 int64_t Value = CE->getValue();
1081 return Value == 1 || Value == 0;
1082 }
Craig Topperca7e3e52014-03-10 03:19:03 +00001083 bool isReg() const override { return Kind == k_Register; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001084 bool isRegList() const { return Kind == k_RegisterList; }
1085 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1086 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001087 bool isToken() const override { return Kind == k_Token; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001088 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001089 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001090 bool isMem() const override { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001091 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1092 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1093 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1094 bool isRotImm() const { return Kind == k_RotateImmediate; }
1095 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1096 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001097 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001098 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001099 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001100 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const {
Chad Rosier41099832012-09-11 23:02:35 +00001101 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001102 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001103 // No offset of any kind.
Craig Topper062a2ba2014-04-25 05:30:21 +00001104 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
Kevin Enderby488f20b2014-04-10 20:18:58 +00001105 (alignOK || Memory.Alignment == Alignment);
Jim Grosbacha95ec992011-10-11 17:29:55 +00001106 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001107 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001108 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001109 return false;
1110 // Base register must be PC.
1111 if (Memory.BaseRegNum != ARM::PC)
1112 return false;
1113 // Immediate offset in range [-4095, 4095].
1114 if (!Memory.OffsetImm) return true;
1115 int64_t Val = Memory.OffsetImm->getValue();
1116 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1117 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001118 bool isAlignedMemory() const {
1119 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001120 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001121 bool isAlignedMemoryNone() const {
1122 return isMemNoOffset(false, 0);
1123 }
1124 bool isDupAlignedMemoryNone() const {
1125 return isMemNoOffset(false, 0);
1126 }
1127 bool isAlignedMemory16() const {
1128 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1129 return true;
1130 return isMemNoOffset(false, 0);
1131 }
1132 bool isDupAlignedMemory16() const {
1133 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1134 return true;
1135 return isMemNoOffset(false, 0);
1136 }
1137 bool isAlignedMemory32() const {
1138 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1139 return true;
1140 return isMemNoOffset(false, 0);
1141 }
1142 bool isDupAlignedMemory32() const {
1143 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1144 return true;
1145 return isMemNoOffset(false, 0);
1146 }
1147 bool isAlignedMemory64() const {
1148 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1149 return true;
1150 return isMemNoOffset(false, 0);
1151 }
1152 bool isDupAlignedMemory64() const {
1153 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1154 return true;
1155 return isMemNoOffset(false, 0);
1156 }
1157 bool isAlignedMemory64or128() const {
1158 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1159 return true;
1160 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1161 return true;
1162 return isMemNoOffset(false, 0);
1163 }
1164 bool isDupAlignedMemory64or128() const {
1165 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1166 return true;
1167 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1168 return true;
1169 return isMemNoOffset(false, 0);
1170 }
1171 bool isAlignedMemory64or128or256() const {
1172 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1173 return true;
1174 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1175 return true;
1176 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
1177 return true;
1178 return isMemNoOffset(false, 0);
1179 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001180 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001181 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001182 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001183 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001184 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001185 if (!Memory.OffsetImm) return true;
1186 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001187 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001188 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001189 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001190 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001191 // Immediate offset in range [-4095, 4095].
1192 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1193 if (!CE) return false;
1194 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001195 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001196 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001197 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001198 // If we have an immediate that's not a constant, treat it as a label
1199 // reference needing a fixup. If it is a constant, it's something else
1200 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001201 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001202 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001203 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001204 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001205 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001206 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001207 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001208 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001209 if (!Memory.OffsetImm) return true;
1210 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001211 // The #-0 offset is encoded as INT32_MIN, and we have to check
1212 // for this too.
1213 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001214 }
1215 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001216 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001217 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001218 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001219 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1220 // Immediate offset in range [-255, 255].
1221 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1222 if (!CE) return false;
1223 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001224 // Special case, #-0 is INT32_MIN.
1225 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001226 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001227 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001228 // If we have an immediate that's not a constant, treat it as a label
1229 // reference needing a fixup. If it is a constant, it's something else
1230 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001231 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001232 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001233 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001234 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001235 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001236 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001237 if (!Memory.OffsetImm) return true;
1238 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001239 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001240 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001241 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001242 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001243 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001244 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001245 return false;
1246 return true;
1247 }
1248 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001249 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001250 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1251 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001252 return false;
1253 return true;
1254 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001255 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001256 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001257 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001258 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001259 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001260 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001261 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001262 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001263 return false;
1264 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001265 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001266 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001267 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001268 return false;
1269 return true;
1270 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001271 bool isMemThumbRR() const {
1272 // Thumb reg+reg addressing is simple. Just two registers, a base and
1273 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001274 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001275 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001276 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001277 return isARMLowRegister(Memory.BaseRegNum) &&
1278 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001279 }
1280 bool isMemThumbRIs4() 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 Grosbach3fe94e32011-08-19 17:55:24 +00001283 return false;
1284 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001285 if (!Memory.OffsetImm) return true;
1286 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001287 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1288 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001289 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001290 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001291 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001292 return false;
1293 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001294 if (!Memory.OffsetImm) return true;
1295 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001296 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1297 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001298 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001299 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001300 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001301 return false;
1302 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001303 if (!Memory.OffsetImm) return true;
1304 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001305 return Val >= 0 && Val <= 31;
1306 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001307 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001308 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001309 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001310 return false;
1311 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001312 if (!Memory.OffsetImm) return true;
1313 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001314 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001315 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001316 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001317 // If we have an immediate that's not a constant, treat it as a label
1318 // reference needing a fixup. If it is a constant, it's something else
1319 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001320 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001321 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001322 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001323 return false;
1324 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001325 if (!Memory.OffsetImm) return true;
1326 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001327 // Special case, #-0 is INT32_MIN.
1328 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001329 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001330 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001331 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001332 return false;
1333 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001334 if (!Memory.OffsetImm) return true;
1335 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001336 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1337 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001338 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001339 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +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 Grosbachd3595712011-08-03 23:50:40 +00001343 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001344 if (!Memory.OffsetImm) return true;
1345 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001346 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001347 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001348 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001349 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001350 return false;
1351 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001352 if (!Memory.OffsetImm) return true;
1353 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001354 return Val >= 0 && Val < 256;
1355 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001356 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001357 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001358 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001359 // Base reg of PC isn't allowed for these encodings.
1360 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001361 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001362 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001363 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001364 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001365 }
1366 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001367 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001368 return false;
1369 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001370 if (!Memory.OffsetImm) return true;
1371 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001372 return (Val >= 0 && Val < 4096);
1373 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001374 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001375 // If we have an immediate that's not a constant, treat it as a label
1376 // reference needing a fixup. If it is a constant, it's something else
1377 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001378 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001379 return true;
1380
Chad Rosier41099832012-09-11 23:02:35 +00001381 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001382 return false;
1383 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001384 if (!Memory.OffsetImm) return true;
1385 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001386 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001387 }
1388 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001389 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001390 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1391 if (!CE) return false;
1392 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001393 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001394 }
Jim Grosbach93981412011-10-11 21:55:36 +00001395 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001396 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001397 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1398 if (!CE) return false;
1399 int64_t Val = CE->getValue();
1400 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1401 (Val == INT32_MIN);
1402 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001403
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001404 bool isMSRMask() const { return Kind == k_MSRMask; }
Tim Northoveree843ef2014-08-15 10:47:12 +00001405 bool isBankedReg() const { return Kind == k_BankedReg; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001406 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001407
Jim Grosbach741cd732011-10-17 22:26:03 +00001408 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001409 bool isSingleSpacedVectorList() const {
1410 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1411 }
1412 bool isDoubleSpacedVectorList() const {
1413 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1414 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001415 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001416 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001417 return VectorList.Count == 1;
1418 }
1419
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001420 bool isVecListDPair() const {
1421 if (!isSingleSpacedVectorList()) return false;
1422 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1423 .contains(VectorList.RegNum));
1424 }
1425
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001426 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001427 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001428 return VectorList.Count == 3;
1429 }
1430
Jim Grosbach846bcff2011-10-21 20:35:01 +00001431 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001432 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001433 return VectorList.Count == 4;
1434 }
1435
Jim Grosbache5307f92012-03-05 21:43:40 +00001436 bool isVecListDPairSpaced() const {
Kevin Enderby56113982014-03-26 21:54:11 +00001437 if (Kind != k_VectorList) return false;
Kevin Enderby816ca272012-03-20 17:41:51 +00001438 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001439 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1440 .contains(VectorList.RegNum));
1441 }
1442
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001443 bool isVecListThreeQ() const {
1444 if (!isDoubleSpacedVectorList()) return false;
1445 return VectorList.Count == 3;
1446 }
1447
Jim Grosbach1e946a42012-01-24 00:43:12 +00001448 bool isVecListFourQ() const {
1449 if (!isDoubleSpacedVectorList()) return false;
1450 return VectorList.Count == 4;
1451 }
1452
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001453 bool isSingleSpacedVectorAllLanes() const {
1454 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1455 }
1456 bool isDoubleSpacedVectorAllLanes() const {
1457 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1458 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001459 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001460 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001461 return VectorList.Count == 1;
1462 }
1463
Jim Grosbach13a292c2012-03-06 22:01:44 +00001464 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001465 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001466 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1467 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001468 }
1469
Jim Grosbached428bc2012-03-06 23:10:38 +00001470 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001471 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001472 return VectorList.Count == 2;
1473 }
1474
Jim Grosbachb78403c2012-01-24 23:47:04 +00001475 bool isVecListThreeDAllLanes() const {
1476 if (!isSingleSpacedVectorAllLanes()) return false;
1477 return VectorList.Count == 3;
1478 }
1479
1480 bool isVecListThreeQAllLanes() const {
1481 if (!isDoubleSpacedVectorAllLanes()) return false;
1482 return VectorList.Count == 3;
1483 }
1484
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001485 bool isVecListFourDAllLanes() const {
1486 if (!isSingleSpacedVectorAllLanes()) return false;
1487 return VectorList.Count == 4;
1488 }
1489
1490 bool isVecListFourQAllLanes() const {
1491 if (!isDoubleSpacedVectorAllLanes()) return false;
1492 return VectorList.Count == 4;
1493 }
1494
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001495 bool isSingleSpacedVectorIndexed() const {
1496 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1497 }
1498 bool isDoubleSpacedVectorIndexed() const {
1499 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1500 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001501 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001502 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001503 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1504 }
1505
Jim Grosbachda511042011-12-14 23:35:06 +00001506 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001507 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001508 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1509 }
1510
1511 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001512 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001513 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1514 }
1515
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001516 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001517 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001518 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1519 }
1520
Jim Grosbachda511042011-12-14 23:35:06 +00001521 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001522 if (!isSingleSpacedVectorIndexed()) return false;
1523 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1524 }
1525
1526 bool isVecListTwoQWordIndexed() const {
1527 if (!isDoubleSpacedVectorIndexed()) return false;
1528 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1529 }
1530
1531 bool isVecListTwoQHWordIndexed() const {
1532 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001533 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1534 }
1535
1536 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001537 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001538 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1539 }
1540
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001541 bool isVecListThreeDByteIndexed() const {
1542 if (!isSingleSpacedVectorIndexed()) return false;
1543 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1544 }
1545
1546 bool isVecListThreeDHWordIndexed() const {
1547 if (!isSingleSpacedVectorIndexed()) return false;
1548 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1549 }
1550
1551 bool isVecListThreeQWordIndexed() const {
1552 if (!isDoubleSpacedVectorIndexed()) return false;
1553 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1554 }
1555
1556 bool isVecListThreeQHWordIndexed() const {
1557 if (!isDoubleSpacedVectorIndexed()) return false;
1558 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1559 }
1560
1561 bool isVecListThreeDWordIndexed() const {
1562 if (!isSingleSpacedVectorIndexed()) return false;
1563 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1564 }
1565
Jim Grosbach14952a02012-01-24 18:37:25 +00001566 bool isVecListFourDByteIndexed() const {
1567 if (!isSingleSpacedVectorIndexed()) return false;
1568 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1569 }
1570
1571 bool isVecListFourDHWordIndexed() const {
1572 if (!isSingleSpacedVectorIndexed()) return false;
1573 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1574 }
1575
1576 bool isVecListFourQWordIndexed() const {
1577 if (!isDoubleSpacedVectorIndexed()) return false;
1578 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1579 }
1580
1581 bool isVecListFourQHWordIndexed() const {
1582 if (!isDoubleSpacedVectorIndexed()) return false;
1583 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1584 }
1585
1586 bool isVecListFourDWordIndexed() const {
1587 if (!isSingleSpacedVectorIndexed()) return false;
1588 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1589 }
1590
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001591 bool isVectorIndex8() const {
1592 if (Kind != k_VectorIndex) return false;
1593 return VectorIndex.Val < 8;
1594 }
1595 bool isVectorIndex16() const {
1596 if (Kind != k_VectorIndex) return false;
1597 return VectorIndex.Val < 4;
1598 }
1599 bool isVectorIndex32() const {
1600 if (Kind != k_VectorIndex) return false;
1601 return VectorIndex.Val < 2;
1602 }
1603
Jim Grosbach741cd732011-10-17 22:26:03 +00001604 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001605 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001606 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1607 // Must be a constant.
1608 if (!CE) return false;
1609 int64_t Value = CE->getValue();
1610 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1611 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001612 return Value >= 0 && Value < 256;
1613 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001614
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001615 bool isNEONi16splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001616 if (isNEONByteReplicate(2))
1617 return false; // Leave that for bytes replication and forbid by default.
1618 if (!isImm())
1619 return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001620 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1621 // Must be a constant.
1622 if (!CE) return false;
1623 int64_t Value = CE->getValue();
1624 // i16 value in the range [0,255] or [0x0100, 0xff00]
1625 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1626 }
1627
Jim Grosbach8211c052011-10-18 00:22:00 +00001628 bool isNEONi32splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001629 if (isNEONByteReplicate(4))
1630 return false; // Leave that for bytes replication and forbid by default.
1631 if (!isImm())
1632 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001633 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1634 // Must be a constant.
1635 if (!CE) return false;
1636 int64_t Value = CE->getValue();
1637 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1638 return (Value >= 0 && Value < 256) ||
1639 (Value >= 0x0100 && Value <= 0xff00) ||
1640 (Value >= 0x010000 && Value <= 0xff0000) ||
1641 (Value >= 0x01000000 && Value <= 0xff000000);
1642 }
1643
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001644 bool isNEONByteReplicate(unsigned NumBytes) const {
1645 if (!isImm())
1646 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001647 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1648 // Must be a constant.
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001649 if (!CE)
1650 return false;
1651 int64_t Value = CE->getValue();
1652 if (!Value)
1653 return false; // Don't bother with zero.
1654
1655 unsigned char B = Value & 0xff;
1656 for (unsigned i = 1; i < NumBytes; ++i) {
1657 Value >>= 8;
1658 if ((Value & 0xff) != B)
1659 return false;
1660 }
1661 return true;
1662 }
1663 bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); }
1664 bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); }
1665 bool isNEONi32vmov() const {
1666 if (isNEONByteReplicate(4))
1667 return false; // Let it to be classified as byte-replicate case.
1668 if (!isImm())
1669 return false;
1670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1671 // Must be a constant.
1672 if (!CE)
1673 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001674 int64_t Value = CE->getValue();
1675 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1676 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1677 return (Value >= 0 && Value < 256) ||
1678 (Value >= 0x0100 && Value <= 0xff00) ||
1679 (Value >= 0x010000 && Value <= 0xff0000) ||
1680 (Value >= 0x01000000 && Value <= 0xff000000) ||
1681 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1682 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1683 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001684 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001685 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1687 // Must be a constant.
1688 if (!CE) return false;
1689 int64_t Value = ~CE->getValue();
1690 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1691 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1692 return (Value >= 0 && Value < 256) ||
1693 (Value >= 0x0100 && Value <= 0xff00) ||
1694 (Value >= 0x010000 && Value <= 0xff0000) ||
1695 (Value >= 0x01000000 && Value <= 0xff000000) ||
1696 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1697 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1698 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001699
Jim Grosbache4454e02011-10-18 16:18:11 +00001700 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001701 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001702 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1703 // Must be a constant.
1704 if (!CE) return false;
1705 uint64_t Value = CE->getValue();
1706 // i64 value with each byte being either 0 or 0xff.
1707 for (unsigned i = 0; i < 8; ++i)
1708 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1709 return true;
1710 }
1711
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001712 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001713 // Add as immediates when possible. Null MCExpr = 0.
Craig Topper062a2ba2014-04-25 05:30:21 +00001714 if (!Expr)
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001715 Inst.addOperand(MCOperand::CreateImm(0));
1716 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001717 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1718 else
1719 Inst.addOperand(MCOperand::CreateExpr(Expr));
1720 }
1721
Daniel Dunbard8042b72010-08-11 06:36:53 +00001722 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001723 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001724 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001725 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1726 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001727 }
1728
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001729 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1730 assert(N == 1 && "Invalid number of operands!");
1731 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1732 }
1733
Jim Grosbach48399582011-10-12 17:34:41 +00001734 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1735 assert(N == 1 && "Invalid number of operands!");
1736 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1737 }
1738
1739 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1740 assert(N == 1 && "Invalid number of operands!");
1741 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1742 }
1743
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001744 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1745 assert(N == 1 && "Invalid number of operands!");
1746 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1747 }
1748
1749 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1750 assert(N == 1 && "Invalid number of operands!");
1751 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1752 }
1753
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001754 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1755 assert(N == 1 && "Invalid number of operands!");
1756 Inst.addOperand(MCOperand::CreateReg(getReg()));
1757 }
1758
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001759 void addRegOperands(MCInst &Inst, unsigned N) const {
1760 assert(N == 1 && "Invalid number of operands!");
1761 Inst.addOperand(MCOperand::CreateReg(getReg()));
1762 }
1763
Jim Grosbachac798e12011-07-25 20:49:51 +00001764 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001765 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001766 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001767 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001768 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1769 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001770 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001771 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001772 }
1773
Jim Grosbachac798e12011-07-25 20:49:51 +00001774 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001775 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001776 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001777 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001778 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001779 // Shift of #32 is encoded as 0 where permitted
1780 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001781 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001782 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001783 }
1784
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001785 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001786 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001787 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1788 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001789 }
1790
Bill Wendling8d2aa032010-11-08 23:49:57 +00001791 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001792 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001793 const SmallVectorImpl<unsigned> &RegList = getRegList();
1794 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001795 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1796 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001797 }
1798
Bill Wendling9898ac92010-11-17 04:32:08 +00001799 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1800 addRegListOperands(Inst, N);
1801 }
1802
1803 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1804 addRegListOperands(Inst, N);
1805 }
1806
Jim Grosbach833b9d32011-07-27 20:15:40 +00001807 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1808 assert(N == 1 && "Invalid number of operands!");
1809 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1810 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1811 }
1812
Jim Grosbach864b6092011-07-28 21:34:26 +00001813 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1814 assert(N == 1 && "Invalid number of operands!");
1815 // Munge the lsb/width into a bitfield mask.
1816 unsigned lsb = Bitfield.LSB;
1817 unsigned width = Bitfield.Width;
1818 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1819 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1820 (32 - (lsb + width)));
1821 Inst.addOperand(MCOperand::CreateImm(Mask));
1822 }
1823
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001824 void addImmOperands(MCInst &Inst, unsigned N) const {
1825 assert(N == 1 && "Invalid number of operands!");
1826 addExpr(Inst, getImm());
1827 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001828
Jim Grosbachea231912011-12-22 22:19:05 +00001829 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1830 assert(N == 1 && "Invalid number of operands!");
1831 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1832 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1833 }
1834
1835 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1836 assert(N == 1 && "Invalid number of operands!");
1837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1838 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1839 }
1840
Jim Grosbache7fbce72011-10-03 23:38:36 +00001841 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1842 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001843 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1844 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1845 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001846 }
1847
Jim Grosbach7db8d692011-09-08 22:07:06 +00001848 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1849 assert(N == 1 && "Invalid number of operands!");
1850 // FIXME: We really want to scale the value here, but the LDRD/STRD
1851 // instruction don't encode operands that way yet.
1852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1853 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1854 }
1855
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001856 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1857 assert(N == 1 && "Invalid number of operands!");
1858 // The immediate is scaled by four in the encoding and is stored
1859 // in the MCInst as such. Lop off the low two bits here.
1860 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1861 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1862 }
1863
Jim Grosbach930f2f62012-04-05 20:57:13 +00001864 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1865 assert(N == 1 && "Invalid number of operands!");
1866 // The immediate is scaled by four in the encoding and is stored
1867 // in the MCInst as such. Lop off the low two bits here.
1868 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1869 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1870 }
1871
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001872 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1873 assert(N == 1 && "Invalid number of operands!");
1874 // The immediate is scaled by four in the encoding and is stored
1875 // in the MCInst as such. Lop off the low two bits here.
1876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1877 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1878 }
1879
Jim Grosbach475c6db2011-07-25 23:09:14 +00001880 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1881 assert(N == 1 && "Invalid number of operands!");
1882 // The constant encodes as the immediate-1, and we store in the instruction
1883 // the bits as encoded, so subtract off one here.
1884 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1885 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1886 }
1887
Jim Grosbach801e0a32011-07-22 23:16:18 +00001888 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1889 assert(N == 1 && "Invalid number of operands!");
1890 // The constant encodes as the immediate-1, and we store in the instruction
1891 // the bits as encoded, so subtract off one here.
1892 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1893 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1894 }
1895
Jim Grosbach46dd4132011-08-17 21:51:27 +00001896 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1897 assert(N == 1 && "Invalid number of operands!");
1898 // The constant encodes as the immediate, except for 32, which encodes as
1899 // zero.
1900 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1901 unsigned Imm = CE->getValue();
1902 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1903 }
1904
Jim Grosbach27c1e252011-07-21 17:23:04 +00001905 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1906 assert(N == 1 && "Invalid number of operands!");
1907 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1908 // the instruction as well.
1909 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1910 int Val = CE->getValue();
1911 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1912 }
1913
Jim Grosbachb009a872011-10-28 22:36:30 +00001914 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1915 assert(N == 1 && "Invalid number of operands!");
1916 // The operand is actually a t2_so_imm, but we have its bitwise
1917 // negation in the assembly source, so twiddle it here.
1918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1919 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1920 }
1921
Jim Grosbach30506252011-12-08 00:31:07 +00001922 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1923 assert(N == 1 && "Invalid number of operands!");
1924 // The operand is actually a t2_so_imm, but we have its
1925 // negation in the assembly source, so twiddle it here.
1926 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1927 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1928 }
1929
Jim Grosbach930f2f62012-04-05 20:57:13 +00001930 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1931 assert(N == 1 && "Invalid number of operands!");
1932 // The operand is actually an imm0_4095, but we have its
1933 // negation in the assembly source, so twiddle it here.
1934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1935 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1936 }
1937
Mihai Popad36cbaa2013-07-03 09:21:44 +00001938 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1939 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1940 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1941 return;
1942 }
1943
1944 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1945 assert(SR && "Unknown value type!");
1946 Inst.addOperand(MCOperand::CreateExpr(SR));
1947 }
1948
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001949 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1950 assert(N == 1 && "Invalid number of operands!");
1951 if (isImm()) {
1952 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1953 if (CE) {
1954 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1955 return;
1956 }
1957
1958 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1959 assert(SR && "Unknown value type!");
1960 Inst.addOperand(MCOperand::CreateExpr(SR));
1961 return;
1962 }
1963
1964 assert(isMem() && "Unknown value type!");
1965 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1966 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1967 }
1968
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001969 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1970 assert(N == 1 && "Invalid number of operands!");
1971 // The operand is actually a so_imm, but we have its bitwise
1972 // negation in the assembly source, so twiddle it here.
1973 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1974 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1975 }
1976
Jim Grosbach30506252011-12-08 00:31:07 +00001977 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1978 assert(N == 1 && "Invalid number of operands!");
1979 // The operand is actually a so_imm, but we have its
1980 // negation in the assembly source, so twiddle it here.
1981 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1982 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1983 }
1984
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001985 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1986 assert(N == 1 && "Invalid number of operands!");
1987 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1988 }
1989
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001990 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1991 assert(N == 1 && "Invalid number of operands!");
1992 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1993 }
1994
Jim Grosbachd3595712011-08-03 23:50:40 +00001995 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1996 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001997 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001998 }
1999
Jim Grosbach94298a92012-01-18 22:46:46 +00002000 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
2001 assert(N == 1 && "Invalid number of operands!");
2002 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00002003 Inst.addOperand(MCOperand::CreateImm(Imm));
2004 }
2005
Jiangning Liu10dd40e2012-08-02 08:13:13 +00002006 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
2007 assert(N == 1 && "Invalid number of operands!");
2008 assert(isImm() && "Not an immediate!");
2009
2010 // If we have an immediate that's not a constant, treat it as a label
2011 // reference needing a fixup.
2012 if (!isa<MCConstantExpr>(getImm())) {
2013 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2014 return;
2015 }
2016
2017 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2018 int Val = CE->getValue();
2019 Inst.addOperand(MCOperand::CreateImm(Val));
2020 }
2021
Jim Grosbacha95ec992011-10-11 17:29:55 +00002022 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
2023 assert(N == 2 && "Invalid number of operands!");
2024 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2025 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
2026 }
2027
Kevin Enderby488f20b2014-04-10 20:18:58 +00002028 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2029 addAlignedMemoryOperands(Inst, N);
2030 }
2031
2032 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2033 addAlignedMemoryOperands(Inst, N);
2034 }
2035
2036 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2037 addAlignedMemoryOperands(Inst, N);
2038 }
2039
2040 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2041 addAlignedMemoryOperands(Inst, N);
2042 }
2043
2044 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2045 addAlignedMemoryOperands(Inst, N);
2046 }
2047
2048 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2049 addAlignedMemoryOperands(Inst, N);
2050 }
2051
2052 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2053 addAlignedMemoryOperands(Inst, N);
2054 }
2055
2056 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2057 addAlignedMemoryOperands(Inst, N);
2058 }
2059
2060 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2061 addAlignedMemoryOperands(Inst, N);
2062 }
2063
2064 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2065 addAlignedMemoryOperands(Inst, N);
2066 }
2067
2068 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
2069 addAlignedMemoryOperands(Inst, N);
2070 }
2071
Jim Grosbachd3595712011-08-03 23:50:40 +00002072 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
2073 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002074 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2075 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00002076 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2077 // Special case for #-0
2078 if (Val == INT32_MIN) Val = 0;
2079 if (Val < 0) Val = -Val;
2080 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2081 } else {
2082 // For register offset, we encode the shift type and negation flag
2083 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002084 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2085 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002086 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002087 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2088 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002089 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002090 }
2091
Jim Grosbachcd17c122011-08-04 23:01:30 +00002092 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
2093 assert(N == 2 && "Invalid number of operands!");
2094 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2095 assert(CE && "non-constant AM2OffsetImm operand!");
2096 int32_t Val = CE->getValue();
2097 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2098 // Special case for #-0
2099 if (Val == INT32_MIN) Val = 0;
2100 if (Val < 0) Val = -Val;
2101 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2102 Inst.addOperand(MCOperand::CreateReg(0));
2103 Inst.addOperand(MCOperand::CreateImm(Val));
2104 }
2105
Jim Grosbach5b96b802011-08-10 20:29:19 +00002106 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
2107 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002108 // If we have an immediate that's not a constant, treat it as a label
2109 // reference needing a fixup. If it is a constant, it's something else
2110 // and we reject it.
2111 if (isImm()) {
2112 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2113 Inst.addOperand(MCOperand::CreateReg(0));
2114 Inst.addOperand(MCOperand::CreateImm(0));
2115 return;
2116 }
2117
Jim Grosbach871dff72011-10-11 15:59:20 +00002118 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2119 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002120 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2121 // Special case for #-0
2122 if (Val == INT32_MIN) Val = 0;
2123 if (Val < 0) Val = -Val;
2124 Val = ARM_AM::getAM3Opc(AddSub, Val);
2125 } else {
2126 // For register offset, we encode the shift type and negation flag
2127 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002128 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002129 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002130 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2131 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00002132 Inst.addOperand(MCOperand::CreateImm(Val));
2133 }
2134
2135 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
2136 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002137 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002138 int32_t Val =
2139 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
2140 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2141 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002142 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00002143 }
2144
2145 // Constant offset.
2146 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2147 int32_t Val = CE->getValue();
2148 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2149 // Special case for #-0
2150 if (Val == INT32_MIN) Val = 0;
2151 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002152 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002153 Inst.addOperand(MCOperand::CreateReg(0));
2154 Inst.addOperand(MCOperand::CreateImm(Val));
2155 }
2156
Jim Grosbachd3595712011-08-03 23:50:40 +00002157 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2158 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00002159 // If we have an immediate that's not a constant, treat it as a label
2160 // reference needing a fixup. If it is a constant, it's something else
2161 // and we reject it.
2162 if (isImm()) {
2163 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2164 Inst.addOperand(MCOperand::CreateImm(0));
2165 return;
2166 }
2167
Jim Grosbachd3595712011-08-03 23:50:40 +00002168 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002169 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002170 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2171 // Special case for #-0
2172 if (Val == INT32_MIN) Val = 0;
2173 if (Val < 0) Val = -Val;
2174 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002175 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002176 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002177 }
2178
Jim Grosbach7db8d692011-09-08 22:07:06 +00002179 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2180 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002181 // If we have an immediate that's not a constant, treat it as a label
2182 // reference needing a fixup. If it is a constant, it's something else
2183 // and we reject it.
2184 if (isImm()) {
2185 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2186 Inst.addOperand(MCOperand::CreateImm(0));
2187 return;
2188 }
2189
Jim Grosbach871dff72011-10-11 15:59:20 +00002190 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2191 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002192 Inst.addOperand(MCOperand::CreateImm(Val));
2193 }
2194
Jim Grosbacha05627e2011-09-09 18:37:27 +00002195 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2196 assert(N == 2 && "Invalid number of operands!");
2197 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002198 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2199 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002200 Inst.addOperand(MCOperand::CreateImm(Val));
2201 }
2202
Jim Grosbachd3595712011-08-03 23:50:40 +00002203 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2204 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002205 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2206 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002207 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002208 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002209
Jim Grosbach2392c532011-09-07 23:39:14 +00002210 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2211 addMemImm8OffsetOperands(Inst, N);
2212 }
2213
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002214 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002215 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002216 }
2217
2218 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2219 assert(N == 2 && "Invalid number of operands!");
2220 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002221 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002222 addExpr(Inst, getImm());
2223 Inst.addOperand(MCOperand::CreateImm(0));
2224 return;
2225 }
2226
2227 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002228 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2229 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002230 Inst.addOperand(MCOperand::CreateImm(Val));
2231 }
2232
Jim Grosbachd3595712011-08-03 23:50:40 +00002233 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2234 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002235 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002236 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002237 addExpr(Inst, getImm());
2238 Inst.addOperand(MCOperand::CreateImm(0));
2239 return;
2240 }
2241
2242 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002243 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2244 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002245 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002246 }
Bill Wendling811c9362010-11-30 07:44:32 +00002247
Jim Grosbach05541f42011-09-19 22:21:13 +00002248 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2249 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002250 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2251 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002252 }
2253
2254 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2255 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002256 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2257 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002258 }
2259
Jim Grosbachd3595712011-08-03 23:50:40 +00002260 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2261 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002262 unsigned Val =
2263 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2264 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002265 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2266 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002267 Inst.addOperand(MCOperand::CreateImm(Val));
2268 }
2269
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002270 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2271 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002272 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2273 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2274 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002275 }
2276
Jim Grosbachd3595712011-08-03 23:50:40 +00002277 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2278 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002279 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2280 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002281 }
2282
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002283 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2284 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002285 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2286 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002287 Inst.addOperand(MCOperand::CreateImm(Val));
2288 }
2289
Jim Grosbach26d35872011-08-19 18:55:51 +00002290 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2291 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002292 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2293 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002294 Inst.addOperand(MCOperand::CreateImm(Val));
2295 }
2296
Jim Grosbacha32c7532011-08-19 18:49:59 +00002297 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2298 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002299 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2300 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002301 Inst.addOperand(MCOperand::CreateImm(Val));
2302 }
2303
Jim Grosbach23983d62011-08-19 18:13:48 +00002304 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2305 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002306 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2307 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002308 Inst.addOperand(MCOperand::CreateImm(Val));
2309 }
2310
Jim Grosbachd3595712011-08-03 23:50:40 +00002311 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2312 assert(N == 1 && "Invalid number of operands!");
2313 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2314 assert(CE && "non-constant post-idx-imm8 operand!");
2315 int Imm = CE->getValue();
2316 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002317 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002318 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2319 Inst.addOperand(MCOperand::CreateImm(Imm));
2320 }
2321
Jim Grosbach93981412011-10-11 21:55:36 +00002322 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2323 assert(N == 1 && "Invalid number of operands!");
2324 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2325 assert(CE && "non-constant post-idx-imm8s4 operand!");
2326 int Imm = CE->getValue();
2327 bool isAdd = Imm >= 0;
2328 if (Imm == INT32_MIN) Imm = 0;
2329 // Immediate is scaled by 4.
2330 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2331 Inst.addOperand(MCOperand::CreateImm(Imm));
2332 }
2333
Jim Grosbachd3595712011-08-03 23:50:40 +00002334 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2335 assert(N == 2 && "Invalid number of operands!");
2336 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002337 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2338 }
2339
2340 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2341 assert(N == 2 && "Invalid number of operands!");
2342 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2343 // The sign, shift type, and shift amount are encoded in a single operand
2344 // using the AM2 encoding helpers.
2345 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2346 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2347 PostIdxReg.ShiftTy);
2348 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002349 }
2350
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002351 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2352 assert(N == 1 && "Invalid number of operands!");
2353 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2354 }
2355
Tim Northoveree843ef2014-08-15 10:47:12 +00002356 void addBankedRegOperands(MCInst &Inst, unsigned N) const {
2357 assert(N == 1 && "Invalid number of operands!");
2358 Inst.addOperand(MCOperand::CreateImm(unsigned(getBankedReg())));
2359 }
2360
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002361 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2362 assert(N == 1 && "Invalid number of operands!");
2363 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2364 }
2365
Jim Grosbach182b6a02011-11-29 23:51:09 +00002366 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002367 assert(N == 1 && "Invalid number of operands!");
2368 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2369 }
2370
Jim Grosbach04945c42011-12-02 00:35:16 +00002371 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2372 assert(N == 2 && "Invalid number of operands!");
2373 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2374 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2375 }
2376
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002377 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2378 assert(N == 1 && "Invalid number of operands!");
2379 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2380 }
2381
2382 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2383 assert(N == 1 && "Invalid number of operands!");
2384 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2385 }
2386
2387 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2388 assert(N == 1 && "Invalid number of operands!");
2389 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2390 }
2391
Jim Grosbach741cd732011-10-17 22:26:03 +00002392 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2393 assert(N == 1 && "Invalid number of operands!");
2394 // The immediate encodes the type of constant as well as the value.
2395 // Mask in that this is an i8 splat.
2396 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2397 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2398 }
2399
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002400 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2401 assert(N == 1 && "Invalid number of operands!");
2402 // The immediate encodes the type of constant as well as the value.
2403 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2404 unsigned Value = CE->getValue();
2405 if (Value >= 256)
2406 Value = (Value >> 8) | 0xa00;
2407 else
2408 Value |= 0x800;
2409 Inst.addOperand(MCOperand::CreateImm(Value));
2410 }
2411
Jim Grosbach8211c052011-10-18 00:22:00 +00002412 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2413 assert(N == 1 && "Invalid number of operands!");
2414 // The immediate encodes the type of constant as well as the value.
2415 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2416 unsigned Value = CE->getValue();
2417 if (Value >= 256 && Value <= 0xff00)
2418 Value = (Value >> 8) | 0x200;
2419 else if (Value > 0xffff && Value <= 0xff0000)
2420 Value = (Value >> 16) | 0x400;
2421 else if (Value > 0xffffff)
2422 Value = (Value >> 24) | 0x600;
2423 Inst.addOperand(MCOperand::CreateImm(Value));
2424 }
2425
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002426 void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const {
2427 assert(N == 1 && "Invalid number of operands!");
2428 // The immediate encodes the type of constant as well as the value.
2429 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2430 unsigned Value = CE->getValue();
2431 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2432 Inst.getOpcode() == ARM::VMOVv16i8) &&
2433 "All vmvn instructions that wants to replicate non-zero byte "
2434 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2435 unsigned B = ((~Value) & 0xff);
2436 B |= 0xe00; // cmode = 0b1110
2437 Inst.addOperand(MCOperand::CreateImm(B));
2438 }
Jim Grosbach8211c052011-10-18 00:22:00 +00002439 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2440 assert(N == 1 && "Invalid number of operands!");
2441 // The immediate encodes the type of constant as well as the value.
2442 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2443 unsigned Value = CE->getValue();
2444 if (Value >= 256 && Value <= 0xffff)
2445 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2446 else if (Value > 0xffff && Value <= 0xffffff)
2447 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2448 else if (Value > 0xffffff)
2449 Value = (Value >> 24) | 0x600;
2450 Inst.addOperand(MCOperand::CreateImm(Value));
2451 }
2452
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002453 void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const {
2454 assert(N == 1 && "Invalid number of operands!");
2455 // The immediate encodes the type of constant as well as the value.
2456 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2457 unsigned Value = CE->getValue();
2458 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2459 Inst.getOpcode() == ARM::VMOVv16i8) &&
2460 "All instructions that wants to replicate non-zero byte "
2461 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2462 unsigned B = Value & 0xff;
2463 B |= 0xe00; // cmode = 0b1110
2464 Inst.addOperand(MCOperand::CreateImm(B));
2465 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00002466 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2467 assert(N == 1 && "Invalid number of operands!");
2468 // The immediate encodes the type of constant as well as the value.
2469 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2470 unsigned Value = ~CE->getValue();
2471 if (Value >= 256 && Value <= 0xffff)
2472 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2473 else if (Value > 0xffff && Value <= 0xffffff)
2474 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2475 else if (Value > 0xffffff)
2476 Value = (Value >> 24) | 0x600;
2477 Inst.addOperand(MCOperand::CreateImm(Value));
2478 }
2479
Jim Grosbache4454e02011-10-18 16:18:11 +00002480 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2481 assert(N == 1 && "Invalid number of operands!");
2482 // The immediate encodes the type of constant as well as the value.
2483 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2484 uint64_t Value = CE->getValue();
2485 unsigned Imm = 0;
2486 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2487 Imm |= (Value & 1) << i;
2488 }
2489 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2490 }
2491
Craig Topperca7e3e52014-03-10 03:19:03 +00002492 void print(raw_ostream &OS) const override;
Daniel Dunbarebace222010-08-11 06:37:04 +00002493
David Blaikie960ea3f2014-06-08 16:18:35 +00002494 static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) {
2495 auto Op = make_unique<ARMOperand>(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002496 Op->ITMask.Mask = Mask;
2497 Op->StartLoc = S;
2498 Op->EndLoc = S;
2499 return Op;
2500 }
2501
David Blaikie960ea3f2014-06-08 16:18:35 +00002502 static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC,
2503 SMLoc S) {
2504 auto Op = make_unique<ARMOperand>(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002505 Op->CC.Val = CC;
2506 Op->StartLoc = S;
2507 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002508 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002509 }
2510
David Blaikie960ea3f2014-06-08 16:18:35 +00002511 static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) {
2512 auto Op = make_unique<ARMOperand>(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002513 Op->Cop.Val = CopVal;
2514 Op->StartLoc = S;
2515 Op->EndLoc = S;
2516 return Op;
2517 }
2518
David Blaikie960ea3f2014-06-08 16:18:35 +00002519 static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) {
2520 auto Op = make_unique<ARMOperand>(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002521 Op->Cop.Val = CopVal;
2522 Op->StartLoc = S;
2523 Op->EndLoc = S;
2524 return Op;
2525 }
2526
David Blaikie960ea3f2014-06-08 16:18:35 +00002527 static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S,
2528 SMLoc E) {
2529 auto Op = make_unique<ARMOperand>(k_CoprocOption);
Jim Grosbach48399582011-10-12 17:34:41 +00002530 Op->Cop.Val = Val;
2531 Op->StartLoc = S;
2532 Op->EndLoc = E;
2533 return Op;
2534 }
2535
David Blaikie960ea3f2014-06-08 16:18:35 +00002536 static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) {
2537 auto Op = make_unique<ARMOperand>(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002538 Op->Reg.RegNum = RegNum;
2539 Op->StartLoc = S;
2540 Op->EndLoc = S;
2541 return Op;
2542 }
2543
David Blaikie960ea3f2014-06-08 16:18:35 +00002544 static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) {
2545 auto Op = make_unique<ARMOperand>(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002546 Op->Tok.Data = Str.data();
2547 Op->Tok.Length = Str.size();
2548 Op->StartLoc = S;
2549 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002550 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002551 }
2552
David Blaikie960ea3f2014-06-08 16:18:35 +00002553 static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S,
2554 SMLoc E) {
2555 auto Op = make_unique<ARMOperand>(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002556 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002557 Op->StartLoc = S;
2558 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002559 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002560 }
2561
David Blaikie960ea3f2014-06-08 16:18:35 +00002562 static std::unique_ptr<ARMOperand>
2563 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2564 unsigned ShiftReg, unsigned ShiftImm, SMLoc S,
2565 SMLoc E) {
2566 auto Op = make_unique<ARMOperand>(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002567 Op->RegShiftedReg.ShiftTy = ShTy;
2568 Op->RegShiftedReg.SrcReg = SrcReg;
2569 Op->RegShiftedReg.ShiftReg = ShiftReg;
2570 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002571 Op->StartLoc = S;
2572 Op->EndLoc = E;
2573 return Op;
2574 }
2575
David Blaikie960ea3f2014-06-08 16:18:35 +00002576 static std::unique_ptr<ARMOperand>
2577 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2578 unsigned ShiftImm, SMLoc S, SMLoc E) {
2579 auto Op = make_unique<ARMOperand>(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002580 Op->RegShiftedImm.ShiftTy = ShTy;
2581 Op->RegShiftedImm.SrcReg = SrcReg;
2582 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002583 Op->StartLoc = S;
2584 Op->EndLoc = E;
2585 return Op;
2586 }
2587
David Blaikie960ea3f2014-06-08 16:18:35 +00002588 static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm,
2589 SMLoc S, SMLoc E) {
2590 auto Op = make_unique<ARMOperand>(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002591 Op->ShifterImm.isASR = isASR;
2592 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002593 Op->StartLoc = S;
2594 Op->EndLoc = E;
2595 return Op;
2596 }
2597
David Blaikie960ea3f2014-06-08 16:18:35 +00002598 static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S,
2599 SMLoc E) {
2600 auto Op = make_unique<ARMOperand>(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002601 Op->RotImm.Imm = Imm;
2602 Op->StartLoc = S;
2603 Op->EndLoc = E;
2604 return Op;
2605 }
2606
David Blaikie960ea3f2014-06-08 16:18:35 +00002607 static std::unique_ptr<ARMOperand>
2608 CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) {
2609 auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002610 Op->Bitfield.LSB = LSB;
2611 Op->Bitfield.Width = Width;
2612 Op->StartLoc = S;
2613 Op->EndLoc = E;
2614 return Op;
2615 }
2616
David Blaikie960ea3f2014-06-08 16:18:35 +00002617 static std::unique_ptr<ARMOperand>
2618 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002619 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002620 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002621 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002622
Chad Rosierfa705ee2013-07-01 20:49:23 +00002623 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002624 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002625 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002626 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002627 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002628
Chad Rosierfa705ee2013-07-01 20:49:23 +00002629 // Sort based on the register encoding values.
2630 array_pod_sort(Regs.begin(), Regs.end());
2631
David Blaikie960ea3f2014-06-08 16:18:35 +00002632 auto Op = make_unique<ARMOperand>(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002633 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002634 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002635 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002636 Op->StartLoc = StartLoc;
2637 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002638 return Op;
2639 }
2640
David Blaikie960ea3f2014-06-08 16:18:35 +00002641 static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum,
2642 unsigned Count,
2643 bool isDoubleSpaced,
2644 SMLoc S, SMLoc E) {
2645 auto Op = make_unique<ARMOperand>(k_VectorList);
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002646 Op->VectorList.RegNum = RegNum;
2647 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002648 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002649 Op->StartLoc = S;
2650 Op->EndLoc = E;
2651 return Op;
2652 }
2653
David Blaikie960ea3f2014-06-08 16:18:35 +00002654 static std::unique_ptr<ARMOperand>
2655 CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced,
2656 SMLoc S, SMLoc E) {
2657 auto Op = make_unique<ARMOperand>(k_VectorListAllLanes);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002658 Op->VectorList.RegNum = RegNum;
2659 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002660 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002661 Op->StartLoc = S;
2662 Op->EndLoc = E;
2663 return Op;
2664 }
2665
David Blaikie960ea3f2014-06-08 16:18:35 +00002666 static std::unique_ptr<ARMOperand>
2667 CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index,
2668 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2669 auto Op = make_unique<ARMOperand>(k_VectorListIndexed);
Jim Grosbach04945c42011-12-02 00:35:16 +00002670 Op->VectorList.RegNum = RegNum;
2671 Op->VectorList.Count = Count;
2672 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002673 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002674 Op->StartLoc = S;
2675 Op->EndLoc = E;
2676 return Op;
2677 }
2678
David Blaikie960ea3f2014-06-08 16:18:35 +00002679 static std::unique_ptr<ARMOperand>
2680 CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) {
2681 auto Op = make_unique<ARMOperand>(k_VectorIndex);
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002682 Op->VectorIndex.Val = Idx;
2683 Op->StartLoc = S;
2684 Op->EndLoc = E;
2685 return Op;
2686 }
2687
David Blaikie960ea3f2014-06-08 16:18:35 +00002688 static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S,
2689 SMLoc E) {
2690 auto Op = make_unique<ARMOperand>(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002691 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002692 Op->StartLoc = S;
2693 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002694 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002695 }
2696
David Blaikie960ea3f2014-06-08 16:18:35 +00002697 static std::unique_ptr<ARMOperand>
2698 CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm,
2699 unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType,
2700 unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S,
2701 SMLoc E, SMLoc AlignmentLoc = SMLoc()) {
2702 auto Op = make_unique<ARMOperand>(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002703 Op->Memory.BaseRegNum = BaseRegNum;
2704 Op->Memory.OffsetImm = OffsetImm;
2705 Op->Memory.OffsetRegNum = OffsetRegNum;
2706 Op->Memory.ShiftType = ShiftType;
2707 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002708 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002709 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002710 Op->StartLoc = S;
2711 Op->EndLoc = E;
Kevin Enderby488f20b2014-04-10 20:18:58 +00002712 Op->AlignmentLoc = AlignmentLoc;
Jim Grosbachd3595712011-08-03 23:50:40 +00002713 return Op;
2714 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002715
David Blaikie960ea3f2014-06-08 16:18:35 +00002716 static std::unique_ptr<ARMOperand>
2717 CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy,
2718 unsigned ShiftImm, SMLoc S, SMLoc E) {
2719 auto Op = make_unique<ARMOperand>(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002720 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002721 Op->PostIdxReg.isAdd = isAdd;
2722 Op->PostIdxReg.ShiftTy = ShiftTy;
2723 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002724 Op->StartLoc = S;
2725 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002726 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002727 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002728
David Blaikie960ea3f2014-06-08 16:18:35 +00002729 static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt,
2730 SMLoc S) {
2731 auto Op = make_unique<ARMOperand>(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002732 Op->MBOpt.Val = Opt;
2733 Op->StartLoc = S;
2734 Op->EndLoc = S;
2735 return Op;
2736 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002737
David Blaikie960ea3f2014-06-08 16:18:35 +00002738 static std::unique_ptr<ARMOperand>
2739 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) {
2740 auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002741 Op->ISBOpt.Val = Opt;
2742 Op->StartLoc = S;
2743 Op->EndLoc = S;
2744 return Op;
2745 }
2746
David Blaikie960ea3f2014-06-08 16:18:35 +00002747 static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags,
2748 SMLoc S) {
2749 auto Op = make_unique<ARMOperand>(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002750 Op->IFlags.Val = IFlags;
2751 Op->StartLoc = S;
2752 Op->EndLoc = S;
2753 return Op;
2754 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002755
David Blaikie960ea3f2014-06-08 16:18:35 +00002756 static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) {
2757 auto Op = make_unique<ARMOperand>(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002758 Op->MMask.Val = MMask;
2759 Op->StartLoc = S;
2760 Op->EndLoc = S;
2761 return Op;
2762 }
Tim Northoveree843ef2014-08-15 10:47:12 +00002763
2764 static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) {
2765 auto Op = make_unique<ARMOperand>(k_BankedReg);
2766 Op->BankedReg.Val = Reg;
2767 Op->StartLoc = S;
2768 Op->EndLoc = S;
2769 return Op;
2770 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002771};
2772
2773} // end anonymous namespace.
2774
Jim Grosbach602aa902011-07-13 15:34:57 +00002775void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002776 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002777 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002778 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002779 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002780 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002781 OS << "<ccout " << getReg() << ">";
2782 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002783 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002784 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002785 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2786 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2787 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002788 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2789 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2790 break;
2791 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002792 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002793 OS << "<coprocessor number: " << getCoproc() << ">";
2794 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002795 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002796 OS << "<coprocessor register: " << getCoproc() << ">";
2797 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002798 case k_CoprocOption:
2799 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2800 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002801 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002802 OS << "<mask: " << getMSRMask() << ">";
2803 break;
Tim Northoveree843ef2014-08-15 10:47:12 +00002804 case k_BankedReg:
2805 OS << "<banked reg: " << getBankedReg() << ">";
2806 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002807 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002808 getImm()->print(OS);
2809 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002810 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002811 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002812 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002813 case k_InstSyncBarrierOpt:
2814 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2815 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002816 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002817 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002818 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002819 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002820 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002821 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002822 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2823 << PostIdxReg.RegNum;
2824 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2825 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2826 << PostIdxReg.ShiftImm;
2827 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002828 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002829 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002830 OS << "<ARM_PROC::";
2831 unsigned IFlags = getProcIFlags();
2832 for (int i=2; i >= 0; --i)
2833 if (IFlags & (1 << i))
2834 OS << ARM_PROC::IFlagsToString(1 << i);
2835 OS << ">";
2836 break;
2837 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002838 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002839 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002840 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002841 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002842 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2843 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002844 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002845 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002846 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002847 << RegShiftedReg.SrcReg << " "
2848 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2849 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002850 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002851 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002852 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002853 << RegShiftedImm.SrcReg << " "
2854 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2855 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002856 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002857 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002858 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2859 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002860 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002861 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2862 << ", width: " << Bitfield.Width << ">";
2863 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002864 case k_RegisterList:
2865 case k_DPRRegisterList:
2866 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002867 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002868
Bill Wendlingbed94652010-11-09 23:28:44 +00002869 const SmallVectorImpl<unsigned> &RegList = getRegList();
2870 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002871 I = RegList.begin(), E = RegList.end(); I != E; ) {
2872 OS << *I;
2873 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002874 }
2875
2876 OS << ">";
2877 break;
2878 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002879 case k_VectorList:
2880 OS << "<vector_list " << VectorList.Count << " * "
2881 << VectorList.RegNum << ">";
2882 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002883 case k_VectorListAllLanes:
2884 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2885 << VectorList.RegNum << ">";
2886 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002887 case k_VectorListIndexed:
2888 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2889 << VectorList.Count << " * " << VectorList.RegNum << ">";
2890 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002891 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002892 OS << "'" << getToken() << "'";
2893 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002894 case k_VectorIndex:
2895 OS << "<vectorindex " << getVectorIndex() << ">";
2896 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002897 }
2898}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002899
2900/// @name Auto-generated Match Functions
2901/// {
2902
2903static unsigned MatchRegisterName(StringRef Name);
2904
2905/// }
2906
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002907bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2908 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002909 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002910 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002911 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002912
2913 return (RegNo == (unsigned)-1);
2914}
2915
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002916/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002917/// and if it is a register name the token is eaten and the register number is
2918/// returned. Otherwise return -1.
2919///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002920int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002921 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002922 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002923
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002924 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002925 unsigned RegNum = MatchRegisterName(lowerCase);
2926 if (!RegNum) {
2927 RegNum = StringSwitch<unsigned>(lowerCase)
2928 .Case("r13", ARM::SP)
2929 .Case("r14", ARM::LR)
2930 .Case("r15", ARM::PC)
2931 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002932 // Additional register name aliases for 'gas' compatibility.
2933 .Case("a1", ARM::R0)
2934 .Case("a2", ARM::R1)
2935 .Case("a3", ARM::R2)
2936 .Case("a4", ARM::R3)
2937 .Case("v1", ARM::R4)
2938 .Case("v2", ARM::R5)
2939 .Case("v3", ARM::R6)
2940 .Case("v4", ARM::R7)
2941 .Case("v5", ARM::R8)
2942 .Case("v6", ARM::R9)
2943 .Case("v7", ARM::R10)
2944 .Case("v8", ARM::R11)
2945 .Case("sb", ARM::R9)
2946 .Case("sl", ARM::R10)
2947 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002948 .Default(0);
2949 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002950 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002951 // Check for aliases registered via .req. Canonicalize to lower case.
2952 // That's more consistent since register names are case insensitive, and
2953 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2954 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002955 // If no match, return failure.
2956 if (Entry == RegisterReqs.end())
2957 return -1;
2958 Parser.Lex(); // Eat identifier token.
2959 return Entry->getValue();
2960 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002961
Chris Lattner44e5981c2010-10-30 04:09:10 +00002962 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002963
Chris Lattner44e5981c2010-10-30 04:09:10 +00002964 return RegNum;
2965}
Jim Grosbach99710a82010-11-01 16:44:21 +00002966
Jim Grosbachbb24c592011-07-13 18:49:30 +00002967// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2968// If a recoverable error occurs, return 1. If an irrecoverable error
2969// occurs, return -1. An irrecoverable error is one where tokens have been
2970// consumed in the process of trying to parse the shifter (i.e., when it is
2971// indeed a shifter operand, but malformed).
David Blaikie960ea3f2014-06-08 16:18:35 +00002972int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002973 SMLoc S = Parser.getTok().getLoc();
2974 const AsmToken &Tok = Parser.getTok();
Kevin Enderby62873712014-02-17 21:45:27 +00002975 if (Tok.isNot(AsmToken::Identifier))
2976 return -1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002977
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002978 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002979 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002980 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002981 .Case("lsl", ARM_AM::lsl)
2982 .Case("lsr", ARM_AM::lsr)
2983 .Case("asr", ARM_AM::asr)
2984 .Case("ror", ARM_AM::ror)
2985 .Case("rrx", ARM_AM::rrx)
2986 .Default(ARM_AM::no_shift);
2987
2988 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002989 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002990
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002991 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002992
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002993 // The source register for the shift has already been added to the
2994 // operand list, so we need to pop it off and combine it into the shifted
2995 // register operand instead.
David Blaikie960ea3f2014-06-08 16:18:35 +00002996 std::unique_ptr<ARMOperand> PrevOp(
2997 (ARMOperand *)Operands.pop_back_val().release());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002998 if (!PrevOp->isReg())
2999 return Error(PrevOp->getStartLoc(), "shift must be of a register");
3000 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003001
3002 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003003 int64_t Imm = 0;
3004 int ShiftReg = 0;
3005 if (ShiftTy == ARM_AM::rrx) {
3006 // RRX Doesn't have an explicit shift amount. The encoder expects
3007 // the shift register to be the same as the source register. Seems odd,
3008 // but OK.
3009 ShiftReg = SrcReg;
3010 } else {
3011 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003012 if (Parser.getTok().is(AsmToken::Hash) ||
3013 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003014 Parser.Lex(); // Eat hash.
3015 SMLoc ImmLoc = Parser.getTok().getLoc();
Craig Topper062a2ba2014-04-25 05:30:21 +00003016 const MCExpr *ShiftExpr = nullptr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003017 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003018 Error(ImmLoc, "invalid immediate shift value");
3019 return -1;
3020 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003021 // The expression must be evaluatable as an immediate.
3022 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00003023 if (!CE) {
3024 Error(ImmLoc, "invalid immediate shift value");
3025 return -1;
3026 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003027 // Range check the immediate.
3028 // lsl, ror: 0 <= imm <= 31
3029 // lsr, asr: 0 <= imm <= 32
3030 Imm = CE->getValue();
3031 if (Imm < 0 ||
3032 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
3033 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003034 Error(ImmLoc, "immediate shift value out of range");
3035 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003036 }
Jim Grosbach21488b82011-12-22 17:37:00 +00003037 // shift by zero is a nop. Always send it through as lsl.
3038 // ('as' compatibility)
3039 if (Imm == 0)
3040 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003041 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003042 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003043 EndLoc = Parser.getTok().getEndLoc();
3044 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00003045 if (ShiftReg == -1) {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003046 Error(L, "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003047 return -1;
3048 }
3049 } else {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003050 Error(Parser.getTok().getLoc(),
3051 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003052 return -1;
3053 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003054 }
3055
Owen Andersonb595ed02011-07-21 18:54:16 +00003056 if (ShiftReg && ShiftTy != ARM_AM::rrx)
3057 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00003058 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003059 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00003060 else
3061 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003062 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003063
Jim Grosbachbb24c592011-07-13 18:49:30 +00003064 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003065}
3066
3067
Bill Wendling2063b842010-11-18 23:43:05 +00003068/// Try to parse a register name. The token must be an Identifier when called.
3069/// If it's a register, an AsmOperand is created. Another AsmOperand is created
3070/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00003071///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00003072/// TODO this is likely to change to allow different register types and or to
3073/// parse for a specific register type.
David Blaikie960ea3f2014-06-08 16:18:35 +00003074bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003075 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003076 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00003077 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00003078 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00003079
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003080 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
3081 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003082
Chris Lattner44e5981c2010-10-30 04:09:10 +00003083 const AsmToken &ExclaimTok = Parser.getTok();
3084 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00003085 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
3086 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00003087 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003088 return false;
3089 }
3090
3091 // Also check for an index operand. This is only legal for vector registers,
3092 // but that'll get caught OK in operand matching, so we don't need to
3093 // explicitly filter everything else out here.
3094 if (Parser.getTok().is(AsmToken::LBrac)) {
3095 SMLoc SIdx = Parser.getTok().getLoc();
3096 Parser.Lex(); // Eat left bracket token.
3097
3098 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003099 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00003100 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003101 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003102 if (!MCE)
3103 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003104
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003105 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003106 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003107
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003108 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003109 Parser.Lex(); // Eat right bracket token.
3110
3111 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
3112 SIdx, E,
3113 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00003114 }
3115
Bill Wendling2063b842010-11-18 23:43:05 +00003116 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003117}
3118
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003119/// MatchCoprocessorOperandName - Try to parse an coprocessor related
Renato Golinac561c32014-06-26 13:10:53 +00003120/// instruction with a symbolic operand name.
3121/// We accept "crN" syntax for GAS compatibility.
3122/// <operand-name> ::= <prefix><number>
3123/// If CoprocOp is 'c', then:
3124/// <prefix> ::= c | cr
3125/// If CoprocOp is 'p', then :
3126/// <prefix> ::= p
3127/// <number> ::= integer in range [0, 15]
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003128static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003129 // Use the same layout as the tablegen'erated register name matcher. Ugly,
3130 // but efficient.
Renato Golinac561c32014-06-26 13:10:53 +00003131 if (Name.size() < 2 || Name[0] != CoprocOp)
3132 return -1;
3133 Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front();
3134
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003135 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00003136 default: return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003137 case 1:
3138 switch (Name[0]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003139 default: return -1;
3140 case '0': return 0;
3141 case '1': return 1;
3142 case '2': return 2;
3143 case '3': return 3;
3144 case '4': return 4;
3145 case '5': return 5;
3146 case '6': return 6;
3147 case '7': return 7;
3148 case '8': return 8;
3149 case '9': return 9;
3150 }
Renato Golinac561c32014-06-26 13:10:53 +00003151 case 2:
3152 if (Name[0] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003153 return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003154 switch (Name[1]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003155 default: return -1;
Renato Golinbc0b0372014-08-04 23:21:56 +00003156 // CP10 and CP11 are VFP/NEON and so vector instructions should be used.
3157 // However, old cores (v5/v6) did use them in that way.
3158 case '0': return 10;
3159 case '1': return 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003160 case '2': return 12;
3161 case '3': return 13;
3162 case '4': return 14;
3163 case '5': return 15;
3164 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003165 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003166}
3167
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003168/// parseITCondCode - Try to parse a condition code for an IT instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003169ARMAsmParser::OperandMatchResultTy
3170ARMAsmParser::parseITCondCode(OperandVector &Operands) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003171 SMLoc S = Parser.getTok().getLoc();
3172 const AsmToken &Tok = Parser.getTok();
3173 if (!Tok.is(AsmToken::Identifier))
3174 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00003175 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003176 .Case("eq", ARMCC::EQ)
3177 .Case("ne", ARMCC::NE)
3178 .Case("hs", ARMCC::HS)
3179 .Case("cs", ARMCC::HS)
3180 .Case("lo", ARMCC::LO)
3181 .Case("cc", ARMCC::LO)
3182 .Case("mi", ARMCC::MI)
3183 .Case("pl", ARMCC::PL)
3184 .Case("vs", ARMCC::VS)
3185 .Case("vc", ARMCC::VC)
3186 .Case("hi", ARMCC::HI)
3187 .Case("ls", ARMCC::LS)
3188 .Case("ge", ARMCC::GE)
3189 .Case("lt", ARMCC::LT)
3190 .Case("gt", ARMCC::GT)
3191 .Case("le", ARMCC::LE)
3192 .Case("al", ARMCC::AL)
3193 .Default(~0U);
3194 if (CC == ~0U)
3195 return MatchOperand_NoMatch;
3196 Parser.Lex(); // Eat the token.
3197
3198 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3199
3200 return MatchOperand_Success;
3201}
3202
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003203/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003204/// token must be an Identifier when called, and if it is a coprocessor
3205/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003206ARMAsmParser::OperandMatchResultTy
3207ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003208 SMLoc S = Parser.getTok().getLoc();
3209 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003210 if (Tok.isNot(AsmToken::Identifier))
3211 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003212
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003213 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003214 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003215 return MatchOperand_NoMatch;
Renato Golinbc0b0372014-08-04 23:21:56 +00003216 // ARMv7 and v8 don't allow cp10/cp11 due to VFP/NEON specific instructions
3217 if ((hasV7Ops() || hasV8Ops()) && (Num == 10 || Num == 11))
3218 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003219
3220 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003221 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003222 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003223}
3224
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003225/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003226/// token must be an Identifier when called, and if it is a coprocessor
3227/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003228ARMAsmParser::OperandMatchResultTy
3229ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003230 SMLoc S = Parser.getTok().getLoc();
3231 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003232 if (Tok.isNot(AsmToken::Identifier))
3233 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003234
3235 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3236 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003237 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003238
3239 Parser.Lex(); // Eat identifier token.
3240 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003241 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003242}
3243
Jim Grosbach48399582011-10-12 17:34:41 +00003244/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3245/// coproc_option : '{' imm0_255 '}'
David Blaikie960ea3f2014-06-08 16:18:35 +00003246ARMAsmParser::OperandMatchResultTy
3247ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) {
Jim Grosbach48399582011-10-12 17:34:41 +00003248 SMLoc S = Parser.getTok().getLoc();
3249
3250 // If this isn't a '{', this isn't a coprocessor immediate operand.
3251 if (Parser.getTok().isNot(AsmToken::LCurly))
3252 return MatchOperand_NoMatch;
3253 Parser.Lex(); // Eat the '{'
3254
3255 const MCExpr *Expr;
3256 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003257 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003258 Error(Loc, "illegal expression");
3259 return MatchOperand_ParseFail;
3260 }
3261 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3262 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3263 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3264 return MatchOperand_ParseFail;
3265 }
3266 int Val = CE->getValue();
3267
3268 // Check for and consume the closing '}'
3269 if (Parser.getTok().isNot(AsmToken::RCurly))
3270 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003271 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003272 Parser.Lex(); // Eat the '}'
3273
3274 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3275 return MatchOperand_Success;
3276}
3277
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003278// For register list parsing, we need to map from raw GPR register numbering
3279// to the enumeration values. The enumeration values aren't sorted by
3280// register number due to our using "sp", "lr" and "pc" as canonical names.
3281static unsigned getNextRegister(unsigned Reg) {
3282 // If this is a GPR, we need to do it manually, otherwise we can rely
3283 // on the sort ordering of the enumeration since the other reg-classes
3284 // are sane.
3285 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3286 return Reg + 1;
3287 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003288 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003289 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3290 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3291 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3292 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3293 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3294 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3295 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3296 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3297 }
3298}
3299
Jim Grosbach85a23432011-11-11 21:27:40 +00003300// Return the low-subreg of a given Q register.
3301static unsigned getDRegFromQReg(unsigned QReg) {
3302 switch (QReg) {
3303 default: llvm_unreachable("expected a Q register!");
3304 case ARM::Q0: return ARM::D0;
3305 case ARM::Q1: return ARM::D2;
3306 case ARM::Q2: return ARM::D4;
3307 case ARM::Q3: return ARM::D6;
3308 case ARM::Q4: return ARM::D8;
3309 case ARM::Q5: return ARM::D10;
3310 case ARM::Q6: return ARM::D12;
3311 case ARM::Q7: return ARM::D14;
3312 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003313 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003314 case ARM::Q10: return ARM::D20;
3315 case ARM::Q11: return ARM::D22;
3316 case ARM::Q12: return ARM::D24;
3317 case ARM::Q13: return ARM::D26;
3318 case ARM::Q14: return ARM::D28;
3319 case ARM::Q15: return ARM::D30;
3320 }
3321}
3322
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003323/// Parse a register list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003324bool ARMAsmParser::parseRegisterList(OperandVector &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003325 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003326 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003327 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003328 Parser.Lex(); // Eat '{' token.
3329 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003330
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003331 // Check the first register in the list to see what register class
3332 // this is a list of.
3333 int Reg = tryParseRegister();
3334 if (Reg == -1)
3335 return Error(RegLoc, "register expected");
3336
Jim Grosbach85a23432011-11-11 21:27:40 +00003337 // The reglist instructions have at most 16 registers, so reserve
3338 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003339 int EReg = 0;
3340 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003341
3342 // Allow Q regs and just interpret them as the two D sub-registers.
3343 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3344 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003345 EReg = MRI->getEncodingValue(Reg);
3346 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003347 ++Reg;
3348 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003349 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003350 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3351 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3352 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3353 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3354 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3355 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3356 else
3357 return Error(RegLoc, "invalid register in register list");
3358
Jim Grosbach85a23432011-11-11 21:27:40 +00003359 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003360 EReg = MRI->getEncodingValue(Reg);
3361 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003362
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003363 // This starts immediately after the first register token in the list,
3364 // so we can see either a comma or a minus (range separator) as a legal
3365 // next token.
3366 while (Parser.getTok().is(AsmToken::Comma) ||
3367 Parser.getTok().is(AsmToken::Minus)) {
3368 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003369 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003370 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003371 int EndReg = tryParseRegister();
3372 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003373 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003374 // Allow Q regs and just interpret them as the two D sub-registers.
3375 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3376 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003377 // If the register is the same as the start reg, there's nothing
3378 // more to do.
3379 if (Reg == EndReg)
3380 continue;
3381 // The register must be in the same register class as the first.
3382 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003383 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003384 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003385 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003386 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003387
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003388 // Add all the registers in the range to the register list.
3389 while (Reg != EndReg) {
3390 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003391 EReg = MRI->getEncodingValue(Reg);
3392 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003393 }
3394 continue;
3395 }
3396 Parser.Lex(); // Eat the comma.
3397 RegLoc = Parser.getTok().getLoc();
3398 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003399 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003400 Reg = tryParseRegister();
3401 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003402 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003403 // Allow Q regs and just interpret them as the two D sub-registers.
3404 bool isQReg = false;
3405 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3406 Reg = getDRegFromQReg(Reg);
3407 isQReg = true;
3408 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003409 // The register must be in the same register class as the first.
3410 if (!RC->contains(Reg))
3411 return Error(RegLoc, "invalid register in register list");
3412 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003413 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003414 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3415 Warning(RegLoc, "register list not in ascending order");
3416 else
3417 return Error(RegLoc, "register list not in ascending order");
3418 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003419 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003420 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3421 ") in register list");
3422 continue;
3423 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003424 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003425 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3426 Reg != OldReg + 1)
3427 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003428 EReg = MRI->getEncodingValue(Reg);
3429 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3430 if (isQReg) {
3431 EReg = MRI->getEncodingValue(++Reg);
3432 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3433 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003434 }
3435
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003436 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003437 return Error(Parser.getTok().getLoc(), "'}' expected");
3438 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003439 Parser.Lex(); // Eat '}' token.
3440
Jim Grosbach18bf3632011-12-13 21:48:29 +00003441 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003442 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003443
3444 // The ARM system instruction variants for LDM/STM have a '^' token here.
3445 if (Parser.getTok().is(AsmToken::Caret)) {
3446 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3447 Parser.Lex(); // Eat '^' token.
3448 }
3449
Bill Wendling2063b842010-11-18 23:43:05 +00003450 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003451}
3452
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003453// Helper function to parse the lane index for vector lists.
3454ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003455parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003456 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003457 if (Parser.getTok().is(AsmToken::LBrac)) {
3458 Parser.Lex(); // Eat the '['.
3459 if (Parser.getTok().is(AsmToken::RBrac)) {
3460 // "Dn[]" is the 'all lanes' syntax.
3461 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003462 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003463 Parser.Lex(); // Eat the ']'.
3464 return MatchOperand_Success;
3465 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003466
3467 // There's an optional '#' token here. Normally there wouldn't be, but
3468 // inline assemble puts one in, and it's friendly to accept that.
3469 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003470 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003471
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003472 const MCExpr *LaneIndex;
3473 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003474 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003475 Error(Loc, "illegal expression");
3476 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003477 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003478 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3479 if (!CE) {
3480 Error(Loc, "lane index must be empty or an integer");
3481 return MatchOperand_ParseFail;
3482 }
3483 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3484 Error(Parser.getTok().getLoc(), "']' expected");
3485 return MatchOperand_ParseFail;
3486 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003487 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003488 Parser.Lex(); // Eat the ']'.
3489 int64_t Val = CE->getValue();
3490
3491 // FIXME: Make this range check context sensitive for .8, .16, .32.
3492 if (Val < 0 || Val > 7) {
3493 Error(Parser.getTok().getLoc(), "lane index out of range");
3494 return MatchOperand_ParseFail;
3495 }
3496 Index = Val;
3497 LaneKind = IndexedLane;
3498 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003499 }
3500 LaneKind = NoLanes;
3501 return MatchOperand_Success;
3502}
3503
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003504// parse a vector register list
David Blaikie960ea3f2014-06-08 16:18:35 +00003505ARMAsmParser::OperandMatchResultTy
3506ARMAsmParser::parseVectorList(OperandVector &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003507 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003508 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003509 SMLoc S = Parser.getTok().getLoc();
3510 // As an extension (to match gas), support a plain D register or Q register
3511 // (without encosing curly braces) as a single or double entry list,
3512 // respectively.
3513 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003514 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003515 int Reg = tryParseRegister();
3516 if (Reg == -1)
3517 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003518 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003519 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003520 if (Res != MatchOperand_Success)
3521 return Res;
3522 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003523 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003524 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003525 break;
3526 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003527 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3528 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003529 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003530 case IndexedLane:
3531 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003532 LaneIndex,
3533 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003534 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003535 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003536 return MatchOperand_Success;
3537 }
3538 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3539 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003540 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003541 if (Res != MatchOperand_Success)
3542 return Res;
3543 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003544 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003545 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003546 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003547 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003548 break;
3549 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003550 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3551 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003552 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3553 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003554 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003555 case IndexedLane:
3556 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003557 LaneIndex,
3558 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003559 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003560 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003561 return MatchOperand_Success;
3562 }
3563 Error(S, "vector register expected");
3564 return MatchOperand_ParseFail;
3565 }
3566
3567 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003568 return MatchOperand_NoMatch;
3569
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003570 Parser.Lex(); // Eat '{' token.
3571 SMLoc RegLoc = Parser.getTok().getLoc();
3572
3573 int Reg = tryParseRegister();
3574 if (Reg == -1) {
3575 Error(RegLoc, "register expected");
3576 return MatchOperand_ParseFail;
3577 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003578 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003579 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003580 unsigned FirstReg = Reg;
3581 // The list is of D registers, but we also allow Q regs and just interpret
3582 // them as the two D sub-registers.
3583 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3584 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003585 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3586 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003587 ++Reg;
3588 ++Count;
3589 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003590
3591 SMLoc E;
3592 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003593 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003594
Jim Grosbache891fe82011-11-15 23:19:15 +00003595 while (Parser.getTok().is(AsmToken::Comma) ||
3596 Parser.getTok().is(AsmToken::Minus)) {
3597 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003598 if (!Spacing)
3599 Spacing = 1; // Register range implies a single spaced list.
3600 else if (Spacing == 2) {
3601 Error(Parser.getTok().getLoc(),
3602 "sequential registers in double spaced list");
3603 return MatchOperand_ParseFail;
3604 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003605 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003606 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003607 int EndReg = tryParseRegister();
3608 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003609 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003610 return MatchOperand_ParseFail;
3611 }
3612 // Allow Q regs and just interpret them as the two D sub-registers.
3613 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3614 EndReg = getDRegFromQReg(EndReg) + 1;
3615 // If the register is the same as the start reg, there's nothing
3616 // more to do.
3617 if (Reg == EndReg)
3618 continue;
3619 // The register must be in the same register class as the first.
3620 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003621 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003622 return MatchOperand_ParseFail;
3623 }
3624 // Ranges must go from low to high.
3625 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003626 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003627 return MatchOperand_ParseFail;
3628 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003629 // Parse the lane specifier if present.
3630 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003631 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003632 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3633 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003634 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003635 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003636 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003637 return MatchOperand_ParseFail;
3638 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003639
3640 // Add all the registers in the range to the register list.
3641 Count += EndReg - Reg;
3642 Reg = EndReg;
3643 continue;
3644 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003645 Parser.Lex(); // Eat the comma.
3646 RegLoc = Parser.getTok().getLoc();
3647 int OldReg = Reg;
3648 Reg = tryParseRegister();
3649 if (Reg == -1) {
3650 Error(RegLoc, "register expected");
3651 return MatchOperand_ParseFail;
3652 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003653 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003654 // It's OK to use the enumeration values directly here rather, as the
3655 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003656 //
3657 // The list is of D registers, but we also allow Q regs and just interpret
3658 // them as the two D sub-registers.
3659 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003660 if (!Spacing)
3661 Spacing = 1; // Register range implies a single spaced list.
3662 else if (Spacing == 2) {
3663 Error(RegLoc,
3664 "invalid register in double-spaced list (must be 'D' register')");
3665 return MatchOperand_ParseFail;
3666 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003667 Reg = getDRegFromQReg(Reg);
3668 if (Reg != OldReg + 1) {
3669 Error(RegLoc, "non-contiguous register range");
3670 return MatchOperand_ParseFail;
3671 }
3672 ++Reg;
3673 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003674 // Parse the lane specifier if present.
3675 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003676 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003677 SMLoc LaneLoc = Parser.getTok().getLoc();
3678 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3679 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003680 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003681 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003682 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003683 return MatchOperand_ParseFail;
3684 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003685 continue;
3686 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003687 // Normal D register.
3688 // Figure out the register spacing (single or double) of the list if
3689 // we don't know it already.
3690 if (!Spacing)
3691 Spacing = 1 + (Reg == OldReg + 2);
3692
3693 // Just check that it's contiguous and keep going.
3694 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003695 Error(RegLoc, "non-contiguous register range");
3696 return MatchOperand_ParseFail;
3697 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003698 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003699 // Parse the lane specifier if present.
3700 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003701 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003702 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003703 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003704 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003705 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003706 Error(EndLoc, "mismatched lane index in register list");
3707 return MatchOperand_ParseFail;
3708 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003709 }
3710
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003711 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003712 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003713 return MatchOperand_ParseFail;
3714 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003715 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003716 Parser.Lex(); // Eat '}' token.
3717
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003718 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003719 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003720 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003721 // composite register classes.
3722 if (Count == 2) {
3723 const MCRegisterClass *RC = (Spacing == 1) ?
3724 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3725 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3726 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3727 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003728
Jim Grosbach2f50e922011-12-15 21:44:33 +00003729 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3730 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003731 break;
3732 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003733 // Two-register operands have been converted to the
3734 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003735 if (Count == 2) {
3736 const MCRegisterClass *RC = (Spacing == 1) ?
3737 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3738 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003739 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3740 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003741 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003742 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003743 S, E));
3744 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003745 case IndexedLane:
3746 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003747 LaneIndex,
3748 (Spacing == 2),
3749 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003750 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003751 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003752 return MatchOperand_Success;
3753}
3754
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003755/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003756ARMAsmParser::OperandMatchResultTy
3757ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003758 SMLoc S = Parser.getTok().getLoc();
3759 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003760 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003761
Jiangning Liu288e1af2012-08-02 08:21:27 +00003762 if (Tok.is(AsmToken::Identifier)) {
3763 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003764
Jiangning Liu288e1af2012-08-02 08:21:27 +00003765 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3766 .Case("sy", ARM_MB::SY)
3767 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003768 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003769 .Case("sh", ARM_MB::ISH)
3770 .Case("ish", ARM_MB::ISH)
3771 .Case("shst", ARM_MB::ISHST)
3772 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003773 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003774 .Case("nsh", ARM_MB::NSH)
3775 .Case("un", ARM_MB::NSH)
3776 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003777 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003778 .Case("unst", ARM_MB::NSHST)
3779 .Case("osh", ARM_MB::OSH)
3780 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003781 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003782 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003783
Joey Gouly926d3f52013-09-05 15:35:24 +00003784 // ishld, oshld, nshld and ld are only available from ARMv8.
3785 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3786 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3787 Opt = ~0U;
3788
Jiangning Liu288e1af2012-08-02 08:21:27 +00003789 if (Opt == ~0U)
3790 return MatchOperand_NoMatch;
3791
3792 Parser.Lex(); // Eat identifier token.
3793 } else if (Tok.is(AsmToken::Hash) ||
3794 Tok.is(AsmToken::Dollar) ||
3795 Tok.is(AsmToken::Integer)) {
3796 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003797 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003798 SMLoc Loc = Parser.getTok().getLoc();
3799
3800 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003801 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003802 Error(Loc, "illegal expression");
3803 return MatchOperand_ParseFail;
3804 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00003805
Jiangning Liu288e1af2012-08-02 08:21:27 +00003806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3807 if (!CE) {
3808 Error(Loc, "constant expression expected");
3809 return MatchOperand_ParseFail;
3810 }
3811
3812 int Val = CE->getValue();
3813 if (Val & ~0xf) {
3814 Error(Loc, "immediate value out of range");
3815 return MatchOperand_ParseFail;
3816 }
3817
3818 Opt = ARM_MB::RESERVED_0 + Val;
3819 } else
3820 return MatchOperand_ParseFail;
3821
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003822 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003823 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003824}
3825
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003826/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003827ARMAsmParser::OperandMatchResultTy
3828ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) {
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003829 SMLoc S = Parser.getTok().getLoc();
3830 const AsmToken &Tok = Parser.getTok();
3831 unsigned Opt;
3832
3833 if (Tok.is(AsmToken::Identifier)) {
3834 StringRef OptStr = Tok.getString();
3835
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003836 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003837 Opt = ARM_ISB::SY;
3838 else
3839 return MatchOperand_NoMatch;
3840
3841 Parser.Lex(); // Eat identifier token.
3842 } else if (Tok.is(AsmToken::Hash) ||
3843 Tok.is(AsmToken::Dollar) ||
3844 Tok.is(AsmToken::Integer)) {
3845 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003846 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003847 SMLoc Loc = Parser.getTok().getLoc();
3848
3849 const MCExpr *ISBarrierID;
3850 if (getParser().parseExpression(ISBarrierID)) {
3851 Error(Loc, "illegal expression");
3852 return MatchOperand_ParseFail;
3853 }
3854
3855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3856 if (!CE) {
3857 Error(Loc, "constant expression expected");
3858 return MatchOperand_ParseFail;
3859 }
3860
3861 int Val = CE->getValue();
3862 if (Val & ~0xf) {
3863 Error(Loc, "immediate value out of range");
3864 return MatchOperand_ParseFail;
3865 }
3866
3867 Opt = ARM_ISB::RESERVED_0 + Val;
3868 } else
3869 return MatchOperand_ParseFail;
3870
3871 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3872 (ARM_ISB::InstSyncBOpt)Opt, S));
3873 return MatchOperand_Success;
3874}
3875
3876
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003877/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003878ARMAsmParser::OperandMatchResultTy
3879ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003880 SMLoc S = Parser.getTok().getLoc();
3881 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003882 if (!Tok.is(AsmToken::Identifier))
3883 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003884 StringRef IFlagsStr = Tok.getString();
3885
Owen Anderson10c5b122011-10-05 17:16:40 +00003886 // An iflags string of "none" is interpreted to mean that none of the AIF
3887 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003888 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003889 if (IFlagsStr != "none") {
3890 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3891 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3892 .Case("a", ARM_PROC::A)
3893 .Case("i", ARM_PROC::I)
3894 .Case("f", ARM_PROC::F)
3895 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003896
Owen Anderson10c5b122011-10-05 17:16:40 +00003897 // If some specific iflag is already set, it means that some letter is
3898 // present more than once, this is not acceptable.
3899 if (Flag == ~0U || (IFlags & Flag))
3900 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003901
Owen Anderson10c5b122011-10-05 17:16:40 +00003902 IFlags |= Flag;
3903 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003904 }
3905
3906 Parser.Lex(); // Eat identifier token.
3907 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3908 return MatchOperand_Success;
3909}
3910
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003911/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003912ARMAsmParser::OperandMatchResultTy
3913ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003914 SMLoc S = Parser.getTok().getLoc();
3915 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003916 if (!Tok.is(AsmToken::Identifier))
3917 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003918 StringRef Mask = Tok.getString();
3919
James Molloy21efa7d2011-09-28 14:21:38 +00003920 if (isMClass()) {
3921 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003922 std::string Name = Mask.lower();
3923 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003924 // Note: in the documentation:
3925 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3926 // for MSR APSR_nzcvq.
3927 // but we do make it an alias here. This is so to get the "mask encoding"
3928 // bits correct on MSR APSR writes.
3929 //
3930 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3931 // should really only be allowed when writing a special register. Note
3932 // they get dropped in the MRS instruction reading a special register as
3933 // the SYSm field is only 8 bits.
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003934 .Case("apsr", 0x800)
3935 .Case("apsr_nzcvq", 0x800)
3936 .Case("apsr_g", 0x400)
3937 .Case("apsr_nzcvqg", 0xc00)
3938 .Case("iapsr", 0x801)
3939 .Case("iapsr_nzcvq", 0x801)
3940 .Case("iapsr_g", 0x401)
3941 .Case("iapsr_nzcvqg", 0xc01)
3942 .Case("eapsr", 0x802)
3943 .Case("eapsr_nzcvq", 0x802)
3944 .Case("eapsr_g", 0x402)
3945 .Case("eapsr_nzcvqg", 0xc02)
3946 .Case("xpsr", 0x803)
3947 .Case("xpsr_nzcvq", 0x803)
3948 .Case("xpsr_g", 0x403)
3949 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003950 .Case("ipsr", 0x805)
3951 .Case("epsr", 0x806)
3952 .Case("iepsr", 0x807)
3953 .Case("msp", 0x808)
3954 .Case("psp", 0x809)
3955 .Case("primask", 0x810)
3956 .Case("basepri", 0x811)
3957 .Case("basepri_max", 0x812)
3958 .Case("faultmask", 0x813)
3959 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003960 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003961
James Molloy21efa7d2011-09-28 14:21:38 +00003962 if (FlagsVal == ~0U)
3963 return MatchOperand_NoMatch;
3964
Renato Golin92c816c2014-09-01 11:25:07 +00003965 if (!hasThumb2DSP() && (FlagsVal & 0x400))
3966 // The _g and _nzcvqg versions are only valid if the DSP extension is
3967 // available.
3968 return MatchOperand_NoMatch;
3969
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003970 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003971 // basepri, basepri_max and faultmask only valid for V7m.
3972 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003973
James Molloy21efa7d2011-09-28 14:21:38 +00003974 Parser.Lex(); // Eat identifier token.
3975 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3976 return MatchOperand_Success;
3977 }
3978
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003979 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3980 size_t Start = 0, Next = Mask.find('_');
3981 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003982 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003983 if (Next != StringRef::npos)
3984 Flags = Mask.slice(Next+1, Mask.size());
3985
3986 // FlagsVal contains the complete mask:
3987 // 3-0: Mask
3988 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3989 unsigned FlagsVal = 0;
3990
3991 if (SpecReg == "apsr") {
3992 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003993 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003994 .Case("g", 0x4) // same as CPSR_s
3995 .Case("nzcvqg", 0xc) // same as CPSR_fs
3996 .Default(~0U);
3997
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003998 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003999 if (!Flags.empty())
4000 return MatchOperand_NoMatch;
4001 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00004002 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00004003 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004004 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00004005 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
4006 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00004007 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004008 for (int i = 0, e = Flags.size(); i != e; ++i) {
4009 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
4010 .Case("c", 1)
4011 .Case("x", 2)
4012 .Case("s", 4)
4013 .Case("f", 8)
4014 .Default(~0U);
4015
4016 // If some specific flag is already set, it means that some letter is
4017 // present more than once, this is not acceptable.
4018 if (FlagsVal == ~0U || (FlagsVal & Flag))
4019 return MatchOperand_NoMatch;
4020 FlagsVal |= Flag;
4021 }
4022 } else // No match for special register.
4023 return MatchOperand_NoMatch;
4024
Owen Anderson03a173e2011-10-21 18:43:28 +00004025 // Special register without flags is NOT equivalent to "fc" flags.
4026 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
4027 // two lines would enable gas compatibility at the expense of breaking
4028 // round-tripping.
4029 //
4030 // if (!FlagsVal)
4031 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004032
4033 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4034 if (SpecReg == "spsr")
4035 FlagsVal |= 16;
4036
4037 Parser.Lex(); // Eat identifier token.
4038 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4039 return MatchOperand_Success;
4040}
4041
Tim Northoveree843ef2014-08-15 10:47:12 +00004042/// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for
4043/// use in the MRS/MSR instructions added to support virtualization.
4044ARMAsmParser::OperandMatchResultTy
4045ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) {
4046 SMLoc S = Parser.getTok().getLoc();
4047 const AsmToken &Tok = Parser.getTok();
4048 if (!Tok.is(AsmToken::Identifier))
4049 return MatchOperand_NoMatch;
4050 StringRef RegName = Tok.getString();
4051
4052 // The values here come from B9.2.3 of the ARM ARM, where bits 4-0 are SysM
4053 // and bit 5 is R.
4054 unsigned Encoding = StringSwitch<unsigned>(RegName.lower())
4055 .Case("r8_usr", 0x00)
4056 .Case("r9_usr", 0x01)
4057 .Case("r10_usr", 0x02)
4058 .Case("r11_usr", 0x03)
4059 .Case("r12_usr", 0x04)
4060 .Case("sp_usr", 0x05)
4061 .Case("lr_usr", 0x06)
4062 .Case("r8_fiq", 0x08)
4063 .Case("r9_fiq", 0x09)
4064 .Case("r10_fiq", 0x0a)
4065 .Case("r11_fiq", 0x0b)
4066 .Case("r12_fiq", 0x0c)
4067 .Case("sp_fiq", 0x0d)
4068 .Case("lr_fiq", 0x0e)
4069 .Case("lr_irq", 0x10)
4070 .Case("sp_irq", 0x11)
4071 .Case("lr_svc", 0x12)
4072 .Case("sp_svc", 0x13)
4073 .Case("lr_abt", 0x14)
4074 .Case("sp_abt", 0x15)
4075 .Case("lr_und", 0x16)
4076 .Case("sp_und", 0x17)
4077 .Case("lr_mon", 0x1c)
4078 .Case("sp_mon", 0x1d)
4079 .Case("elr_hyp", 0x1e)
4080 .Case("sp_hyp", 0x1f)
4081 .Case("spsr_fiq", 0x2e)
4082 .Case("spsr_irq", 0x30)
4083 .Case("spsr_svc", 0x32)
4084 .Case("spsr_abt", 0x34)
4085 .Case("spsr_und", 0x36)
4086 .Case("spsr_mon", 0x3c)
4087 .Case("spsr_hyp", 0x3e)
4088 .Default(~0U);
4089
4090 if (Encoding == ~0U)
4091 return MatchOperand_NoMatch;
4092
4093 Parser.Lex(); // Eat identifier token.
4094 Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S));
4095 return MatchOperand_Success;
4096}
4097
David Blaikie960ea3f2014-06-08 16:18:35 +00004098ARMAsmParser::OperandMatchResultTy
4099ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low,
4100 int High) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004101 const AsmToken &Tok = Parser.getTok();
4102 if (Tok.isNot(AsmToken::Identifier)) {
4103 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4104 return MatchOperand_ParseFail;
4105 }
4106 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004107 std::string LowerOp = Op.lower();
4108 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004109 if (ShiftName != LowerOp && ShiftName != UpperOp) {
4110 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4111 return MatchOperand_ParseFail;
4112 }
4113 Parser.Lex(); // Eat shift type token.
4114
4115 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004116 if (Parser.getTok().isNot(AsmToken::Hash) &&
4117 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004118 Error(Parser.getTok().getLoc(), "'#' expected");
4119 return MatchOperand_ParseFail;
4120 }
4121 Parser.Lex(); // Eat hash token.
4122
4123 const MCExpr *ShiftAmount;
4124 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004125 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004126 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004127 Error(Loc, "illegal expression");
4128 return MatchOperand_ParseFail;
4129 }
4130 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4131 if (!CE) {
4132 Error(Loc, "constant expression expected");
4133 return MatchOperand_ParseFail;
4134 }
4135 int Val = CE->getValue();
4136 if (Val < Low || Val > High) {
4137 Error(Loc, "immediate value out of range");
4138 return MatchOperand_ParseFail;
4139 }
4140
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004141 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00004142
4143 return MatchOperand_Success;
4144}
4145
David Blaikie960ea3f2014-06-08 16:18:35 +00004146ARMAsmParser::OperandMatchResultTy
4147ARMAsmParser::parseSetEndImm(OperandVector &Operands) {
Jim Grosbach0a547702011-07-22 17:44:50 +00004148 const AsmToken &Tok = Parser.getTok();
4149 SMLoc S = Tok.getLoc();
4150 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004151 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004152 return MatchOperand_ParseFail;
4153 }
Tim Northover4d141442013-05-31 15:58:45 +00004154 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00004155 .Case("be", 1)
4156 .Case("le", 0)
4157 .Default(-1);
4158 Parser.Lex(); // Eat the token.
4159
4160 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004161 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004162 return MatchOperand_ParseFail;
4163 }
4164 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4165 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004166 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00004167 return MatchOperand_Success;
4168}
4169
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004170/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
4171/// instructions. Legal values are:
4172/// lsl #n 'n' in [0,31]
4173/// asr #n 'n' in [1,32]
4174/// n == 32 encoded as n == 0.
David Blaikie960ea3f2014-06-08 16:18:35 +00004175ARMAsmParser::OperandMatchResultTy
4176ARMAsmParser::parseShifterImm(OperandVector &Operands) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004177 const AsmToken &Tok = Parser.getTok();
4178 SMLoc S = Tok.getLoc();
4179 if (Tok.isNot(AsmToken::Identifier)) {
4180 Error(S, "shift operator 'asr' or 'lsl' expected");
4181 return MatchOperand_ParseFail;
4182 }
4183 StringRef ShiftName = Tok.getString();
4184 bool isASR;
4185 if (ShiftName == "lsl" || ShiftName == "LSL")
4186 isASR = false;
4187 else if (ShiftName == "asr" || ShiftName == "ASR")
4188 isASR = true;
4189 else {
4190 Error(S, "shift operator 'asr' or 'lsl' expected");
4191 return MatchOperand_ParseFail;
4192 }
4193 Parser.Lex(); // Eat the operator.
4194
4195 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004196 if (Parser.getTok().isNot(AsmToken::Hash) &&
4197 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004198 Error(Parser.getTok().getLoc(), "'#' expected");
4199 return MatchOperand_ParseFail;
4200 }
4201 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004202 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004203
4204 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004205 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004206 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004207 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004208 return MatchOperand_ParseFail;
4209 }
4210 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4211 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004212 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004213 return MatchOperand_ParseFail;
4214 }
4215
4216 int64_t Val = CE->getValue();
4217 if (isASR) {
4218 // Shift amount must be in [1,32]
4219 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004220 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004221 return MatchOperand_ParseFail;
4222 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00004223 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4224 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004225 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00004226 return MatchOperand_ParseFail;
4227 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004228 if (Val == 32) Val = 0;
4229 } else {
4230 // Shift amount must be in [1,32]
4231 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004232 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004233 return MatchOperand_ParseFail;
4234 }
4235 }
4236
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004237 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004238
4239 return MatchOperand_Success;
4240}
4241
Jim Grosbach833b9d32011-07-27 20:15:40 +00004242/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4243/// of instructions. Legal values are:
4244/// ror #n 'n' in {0, 8, 16, 24}
David Blaikie960ea3f2014-06-08 16:18:35 +00004245ARMAsmParser::OperandMatchResultTy
4246ARMAsmParser::parseRotImm(OperandVector &Operands) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004247 const AsmToken &Tok = Parser.getTok();
4248 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00004249 if (Tok.isNot(AsmToken::Identifier))
4250 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004251 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00004252 if (ShiftName != "ror" && ShiftName != "ROR")
4253 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004254 Parser.Lex(); // Eat the operator.
4255
4256 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004257 if (Parser.getTok().isNot(AsmToken::Hash) &&
4258 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004259 Error(Parser.getTok().getLoc(), "'#' expected");
4260 return MatchOperand_ParseFail;
4261 }
4262 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004263 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004264
4265 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004266 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004267 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004268 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004269 return MatchOperand_ParseFail;
4270 }
4271 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4272 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004273 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004274 return MatchOperand_ParseFail;
4275 }
4276
4277 int64_t Val = CE->getValue();
4278 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4279 // normally, zero is represented in asm by omitting the rotate operand
4280 // entirely.
4281 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004282 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004283 return MatchOperand_ParseFail;
4284 }
4285
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004286 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004287
4288 return MatchOperand_Success;
4289}
4290
David Blaikie960ea3f2014-06-08 16:18:35 +00004291ARMAsmParser::OperandMatchResultTy
4292ARMAsmParser::parseBitfield(OperandVector &Operands) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004293 SMLoc S = Parser.getTok().getLoc();
4294 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004295 if (Parser.getTok().isNot(AsmToken::Hash) &&
4296 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004297 Error(Parser.getTok().getLoc(), "'#' expected");
4298 return MatchOperand_ParseFail;
4299 }
4300 Parser.Lex(); // Eat hash token.
4301
4302 const MCExpr *LSBExpr;
4303 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004304 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004305 Error(E, "malformed immediate expression");
4306 return MatchOperand_ParseFail;
4307 }
4308 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4309 if (!CE) {
4310 Error(E, "'lsb' operand must be an immediate");
4311 return MatchOperand_ParseFail;
4312 }
4313
4314 int64_t LSB = CE->getValue();
4315 // The LSB must be in the range [0,31]
4316 if (LSB < 0 || LSB > 31) {
4317 Error(E, "'lsb' operand must be in the range [0,31]");
4318 return MatchOperand_ParseFail;
4319 }
4320 E = Parser.getTok().getLoc();
4321
4322 // Expect another immediate operand.
4323 if (Parser.getTok().isNot(AsmToken::Comma)) {
4324 Error(Parser.getTok().getLoc(), "too few operands");
4325 return MatchOperand_ParseFail;
4326 }
4327 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004328 if (Parser.getTok().isNot(AsmToken::Hash) &&
4329 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004330 Error(Parser.getTok().getLoc(), "'#' expected");
4331 return MatchOperand_ParseFail;
4332 }
4333 Parser.Lex(); // Eat hash token.
4334
4335 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004336 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004337 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004338 Error(E, "malformed immediate expression");
4339 return MatchOperand_ParseFail;
4340 }
4341 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4342 if (!CE) {
4343 Error(E, "'width' operand must be an immediate");
4344 return MatchOperand_ParseFail;
4345 }
4346
4347 int64_t Width = CE->getValue();
4348 // The LSB must be in the range [1,32-lsb]
4349 if (Width < 1 || Width > 32 - LSB) {
4350 Error(E, "'width' operand must be in the range [1,32-lsb]");
4351 return MatchOperand_ParseFail;
4352 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004353
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004354 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004355
4356 return MatchOperand_Success;
4357}
4358
David Blaikie960ea3f2014-06-08 16:18:35 +00004359ARMAsmParser::OperandMatchResultTy
4360ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
Jim Grosbachd3595712011-08-03 23:50:40 +00004361 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004362 // postidx_reg := '+' register {, shift}
4363 // | '-' register {, shift}
4364 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004365
4366 // This method must return MatchOperand_NoMatch without consuming any tokens
4367 // in the case where there is no match, as other alternatives take other
4368 // parse methods.
4369 AsmToken Tok = Parser.getTok();
4370 SMLoc S = Tok.getLoc();
4371 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004372 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004373 if (Tok.is(AsmToken::Plus)) {
4374 Parser.Lex(); // Eat the '+' token.
4375 haveEaten = true;
4376 } else if (Tok.is(AsmToken::Minus)) {
4377 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004378 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004379 haveEaten = true;
4380 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004381
4382 SMLoc E = Parser.getTok().getEndLoc();
4383 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004384 if (Reg == -1) {
4385 if (!haveEaten)
4386 return MatchOperand_NoMatch;
4387 Error(Parser.getTok().getLoc(), "register expected");
4388 return MatchOperand_ParseFail;
4389 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004390
Jim Grosbachc320c852011-08-05 21:28:30 +00004391 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4392 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004393 if (Parser.getTok().is(AsmToken::Comma)) {
4394 Parser.Lex(); // Eat the ','.
4395 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4396 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004397
4398 // FIXME: Only approximates end...may include intervening whitespace.
4399 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004400 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004401
4402 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4403 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004404
4405 return MatchOperand_Success;
4406}
4407
David Blaikie960ea3f2014-06-08 16:18:35 +00004408ARMAsmParser::OperandMatchResultTy
4409ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004410 // Check for a post-index addressing register operand. Specifically:
4411 // am3offset := '+' register
4412 // | '-' register
4413 // | register
4414 // | # imm
4415 // | # + imm
4416 // | # - imm
4417
4418 // This method must return MatchOperand_NoMatch without consuming any tokens
4419 // in the case where there is no match, as other alternatives take other
4420 // parse methods.
4421 AsmToken Tok = Parser.getTok();
4422 SMLoc S = Tok.getLoc();
4423
4424 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004425 if (Parser.getTok().is(AsmToken::Hash) ||
4426 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004427 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004428 // Explicitly look for a '-', as we need to encode negative zero
4429 // differently.
4430 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4431 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004432 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004433 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004434 return MatchOperand_ParseFail;
4435 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4436 if (!CE) {
4437 Error(S, "constant expression expected");
4438 return MatchOperand_ParseFail;
4439 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004440 // Negative zero is encoded as the flag value INT32_MIN.
4441 int32_t Val = CE->getValue();
4442 if (isNegative && Val == 0)
4443 Val = INT32_MIN;
4444
4445 Operands.push_back(
4446 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4447
4448 return MatchOperand_Success;
4449 }
4450
4451
4452 bool haveEaten = false;
4453 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004454 if (Tok.is(AsmToken::Plus)) {
4455 Parser.Lex(); // Eat the '+' token.
4456 haveEaten = true;
4457 } else if (Tok.is(AsmToken::Minus)) {
4458 Parser.Lex(); // Eat the '-' token.
4459 isAdd = false;
4460 haveEaten = true;
4461 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004462
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004463 Tok = Parser.getTok();
4464 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004465 if (Reg == -1) {
4466 if (!haveEaten)
4467 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004468 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004469 return MatchOperand_ParseFail;
4470 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004471
4472 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004473 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004474
4475 return MatchOperand_Success;
4476}
4477
Tim Northovereb5e4d52013-07-22 09:06:12 +00004478/// Convert parsed operands to MCInst. Needed here because this instruction
4479/// only has two register operands, but multiplication is commutative so
4480/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
David Blaikie960ea3f2014-06-08 16:18:35 +00004481void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
4482 const OperandVector &Operands) {
4483 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1);
4484 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004485 // If we have a three-operand form, make sure to set Rn to be the operand
4486 // that isn't the same as Rd.
4487 unsigned RegOp = 4;
4488 if (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00004489 ((ARMOperand &)*Operands[4]).getReg() ==
4490 ((ARMOperand &)*Operands[3]).getReg())
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004491 RegOp = 5;
David Blaikie960ea3f2014-06-08 16:18:35 +00004492 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004493 Inst.addOperand(Inst.getOperand(0));
David Blaikie960ea3f2014-06-08 16:18:35 +00004494 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004495}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004496
David Blaikie960ea3f2014-06-08 16:18:35 +00004497void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
4498 const OperandVector &Operands) {
Mihai Popaad18d3c2013-08-09 10:38:32 +00004499 int CondOp = -1, ImmOp = -1;
4500 switch(Inst.getOpcode()) {
4501 case ARM::tB:
4502 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4503
4504 case ARM::t2B:
4505 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4506
4507 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4508 }
4509 // first decide whether or not the branch should be conditional
4510 // by looking at it's location relative to an IT block
4511 if(inITBlock()) {
4512 // inside an IT block we cannot have any conditional branches. any
4513 // such instructions needs to be converted to unconditional form
4514 switch(Inst.getOpcode()) {
4515 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4516 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4517 }
4518 } else {
4519 // outside IT blocks we can only have unconditional branches with AL
4520 // condition code or conditional branches with non-AL condition code
David Blaikie960ea3f2014-06-08 16:18:35 +00004521 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode();
Mihai Popaad18d3c2013-08-09 10:38:32 +00004522 switch(Inst.getOpcode()) {
4523 case ARM::tB:
4524 case ARM::tBcc:
4525 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4526 break;
4527 case ARM::t2B:
4528 case ARM::t2Bcc:
4529 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4530 break;
4531 }
4532 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004533
Mihai Popaad18d3c2013-08-09 10:38:32 +00004534 // now decide on encoding size based on branch target range
4535 switch(Inst.getOpcode()) {
4536 // classify tB as either t2B or t1B based on range of immediate operand
4537 case ARM::tB: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004538 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4539 if (!op.isSignedOffset<11, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004540 Inst.setOpcode(ARM::t2B);
4541 break;
4542 }
4543 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4544 case ARM::tBcc: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004545 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4546 if (!op.isSignedOffset<8, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004547 Inst.setOpcode(ARM::t2Bcc);
4548 break;
4549 }
4550 }
David Blaikie960ea3f2014-06-08 16:18:35 +00004551 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1);
4552 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2);
Mihai Popaad18d3c2013-08-09 10:38:32 +00004553}
4554
Bill Wendlinge18980a2010-11-06 22:36:58 +00004555/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004556/// or an error. The first token must be a '[' when called.
David Blaikie960ea3f2014-06-08 16:18:35 +00004557bool ARMAsmParser::parseMemory(OperandVector &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004558 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004559 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004560 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004561 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004562 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004563
Sean Callanan936b0d32010-01-19 21:44:56 +00004564 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004565 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004566 if (BaseRegNum == -1)
4567 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004568
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004569 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004570 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004571 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4572 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004573 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004574
Jim Grosbachd3595712011-08-03 23:50:40 +00004575 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004576 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004577 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004578
Craig Topper062a2ba2014-04-25 05:30:21 +00004579 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4580 ARM_AM::no_shift, 0, 0, false,
4581 S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004582
Jim Grosbach40700e02011-09-19 18:42:21 +00004583 // If there's a pre-indexing writeback marker, '!', just add it as a token
4584 // operand. It's rather odd, but syntactically valid.
4585 if (Parser.getTok().is(AsmToken::Exclaim)) {
4586 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4587 Parser.Lex(); // Eat the '!'.
4588 }
4589
Jim Grosbachd3595712011-08-03 23:50:40 +00004590 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004591 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004592
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004593 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4594 "Lost colon or comma in memory operand?!");
4595 if (Tok.is(AsmToken::Comma)) {
4596 Parser.Lex(); // Eat the comma.
4597 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004598
Jim Grosbacha95ec992011-10-11 17:29:55 +00004599 // If we have a ':', it's an alignment specifier.
4600 if (Parser.getTok().is(AsmToken::Colon)) {
4601 Parser.Lex(); // Eat the ':'.
4602 E = Parser.getTok().getLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00004603 SMLoc AlignmentLoc = Tok.getLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004604
4605 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004606 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004607 return true;
4608
4609 // The expression has to be a constant. Memory references with relocations
4610 // don't come through here, as they use the <label> forms of the relevant
4611 // instructions.
4612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4613 if (!CE)
4614 return Error (E, "constant expression expected");
4615
4616 unsigned Align = 0;
4617 switch (CE->getValue()) {
4618 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004619 return Error(E,
4620 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4621 case 16: Align = 2; break;
4622 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004623 case 64: Align = 8; break;
4624 case 128: Align = 16; break;
4625 case 256: Align = 32; break;
4626 }
4627
4628 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004629 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004630 return Error(Parser.getTok().getLoc(), "']' expected");
4631 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004632 Parser.Lex(); // Eat right bracket token.
4633
4634 // Don't worry about range checking the value here. That's handled by
4635 // the is*() predicates.
Craig Topper062a2ba2014-04-25 05:30:21 +00004636 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004637 ARM_AM::no_shift, 0, Align,
Kevin Enderby488f20b2014-04-10 20:18:58 +00004638 false, S, E, AlignmentLoc));
Jim Grosbacha95ec992011-10-11 17:29:55 +00004639
4640 // If there's a pre-indexing writeback marker, '!', just add it as a token
4641 // operand.
4642 if (Parser.getTok().is(AsmToken::Exclaim)) {
4643 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4644 Parser.Lex(); // Eat the '!'.
4645 }
4646
4647 return false;
4648 }
4649
4650 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004651 // offset. Be friendly and also accept a plain integer (without a leading
4652 // hash) for gas compatibility.
4653 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004654 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004655 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004656 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004657 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004658 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004659
Owen Anderson967674d2011-08-29 19:36:44 +00004660 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004661 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004662 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004663 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004664
4665 // The expression has to be a constant. Memory references with relocations
4666 // don't come through here, as they use the <label> forms of the relevant
4667 // instructions.
4668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4669 if (!CE)
4670 return Error (E, "constant expression expected");
4671
Owen Anderson967674d2011-08-29 19:36:44 +00004672 // If the constant was #-0, represent it as INT32_MIN.
4673 int32_t Val = CE->getValue();
4674 if (isNegative && Val == 0)
4675 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4676
Jim Grosbachd3595712011-08-03 23:50:40 +00004677 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004678 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004679 return Error(Parser.getTok().getLoc(), "']' expected");
4680 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004681 Parser.Lex(); // Eat right bracket token.
4682
4683 // Don't worry about range checking the value here. That's handled by
4684 // the is*() predicates.
4685 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004686 ARM_AM::no_shift, 0, 0,
4687 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004688
4689 // If there's a pre-indexing writeback marker, '!', just add it as a token
4690 // operand.
4691 if (Parser.getTok().is(AsmToken::Exclaim)) {
4692 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4693 Parser.Lex(); // Eat the '!'.
4694 }
4695
4696 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004697 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004698
4699 // The register offset is optionally preceded by a '+' or '-'
4700 bool isNegative = false;
4701 if (Parser.getTok().is(AsmToken::Minus)) {
4702 isNegative = true;
4703 Parser.Lex(); // Eat the '-'.
4704 } else if (Parser.getTok().is(AsmToken::Plus)) {
4705 // Nothing to do.
4706 Parser.Lex(); // Eat the '+'.
4707 }
4708
4709 E = Parser.getTok().getLoc();
4710 int OffsetRegNum = tryParseRegister();
4711 if (OffsetRegNum == -1)
4712 return Error(E, "register expected");
4713
4714 // If there's a shift operator, handle it.
4715 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004716 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004717 if (Parser.getTok().is(AsmToken::Comma)) {
4718 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004719 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004720 return true;
4721 }
4722
4723 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004724 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004725 return Error(Parser.getTok().getLoc(), "']' expected");
4726 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004727 Parser.Lex(); // Eat right bracket token.
4728
Craig Topper062a2ba2014-04-25 05:30:21 +00004729 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004730 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004731 S, E));
4732
Jim Grosbachc320c852011-08-05 21:28:30 +00004733 // If there's a pre-indexing writeback marker, '!', just add it as a token
4734 // operand.
4735 if (Parser.getTok().is(AsmToken::Exclaim)) {
4736 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4737 Parser.Lex(); // Eat the '!'.
4738 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004739
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004740 return false;
4741}
4742
Jim Grosbachd3595712011-08-03 23:50:40 +00004743/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004744/// ( lsl | lsr | asr | ror ) , # shift_amount
4745/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004746/// return true if it parses a shift otherwise it returns false.
4747bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4748 unsigned &Amount) {
4749 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004750 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004751 if (Tok.isNot(AsmToken::Identifier))
4752 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004753 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004754 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4755 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004756 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004757 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004758 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004759 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004760 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004761 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004762 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004763 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004764 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004765 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004766 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004767 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004768
Jim Grosbachd3595712011-08-03 23:50:40 +00004769 // rrx stands alone.
4770 Amount = 0;
4771 if (St != ARM_AM::rrx) {
4772 Loc = Parser.getTok().getLoc();
4773 // A '#' and a shift amount.
4774 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004775 if (HashTok.isNot(AsmToken::Hash) &&
4776 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004777 return Error(HashTok.getLoc(), "'#' expected");
4778 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004779
Jim Grosbachd3595712011-08-03 23:50:40 +00004780 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004781 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004782 return true;
4783 // Range check the immediate.
4784 // lsl, ror: 0 <= imm <= 31
4785 // lsr, asr: 0 <= imm <= 32
4786 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4787 if (!CE)
4788 return Error(Loc, "shift amount must be an immediate");
4789 int64_t Imm = CE->getValue();
4790 if (Imm < 0 ||
4791 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4792 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4793 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004794 // If <ShiftTy> #0, turn it into a no_shift.
4795 if (Imm == 0)
4796 St = ARM_AM::lsl;
4797 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4798 if (Imm == 32)
4799 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004800 Amount = Imm;
4801 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004802
4803 return false;
4804}
4805
Jim Grosbache7fbce72011-10-03 23:38:36 +00004806/// parseFPImm - A floating point immediate expression operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00004807ARMAsmParser::OperandMatchResultTy
4808ARMAsmParser::parseFPImm(OperandVector &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004809 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004810 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004811 // integer only.
4812 //
4813 // This routine still creates a generic Immediate operand, containing
4814 // a bitcast of the 64-bit floating point value. The various operands
4815 // that accept floats can check whether the value is valid for them
4816 // via the standard is*() predicates.
4817
Jim Grosbache7fbce72011-10-03 23:38:36 +00004818 SMLoc S = Parser.getTok().getLoc();
4819
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004820 if (Parser.getTok().isNot(AsmToken::Hash) &&
4821 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004822 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004823
4824 // Disambiguate the VMOV forms that can accept an FP immediate.
4825 // vmov.f32 <sreg>, #imm
4826 // vmov.f64 <dreg>, #imm
4827 // vmov.f32 <dreg>, #imm @ vector f32x2
4828 // vmov.f32 <qreg>, #imm @ vector f32x4
4829 //
4830 // There are also the NEON VMOV instructions which expect an
4831 // integer constant. Make sure we don't try to parse an FPImm
4832 // for these:
4833 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
David Blaikie960ea3f2014-06-08 16:18:35 +00004834 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]);
4835 bool isVmovf = TyOp.isToken() &&
4836 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64");
4837 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
4838 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
4839 Mnemonic.getToken() == "fconsts");
David Peixottoa872e0e2014-01-07 18:19:23 +00004840 if (!(isVmovf || isFconst))
Jim Grosbach741cd732011-10-17 22:26:03 +00004841 return MatchOperand_NoMatch;
4842
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004843 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004844
4845 // Handle negation, as that still comes through as a separate token.
4846 bool isNegative = false;
4847 if (Parser.getTok().is(AsmToken::Minus)) {
4848 isNegative = true;
4849 Parser.Lex();
4850 }
4851 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004852 SMLoc Loc = Tok.getLoc();
David Peixottoa872e0e2014-01-07 18:19:23 +00004853 if (Tok.is(AsmToken::Real) && isVmovf) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004854 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004855 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4856 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004857 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004858 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004859 Operands.push_back(ARMOperand::CreateImm(
4860 MCConstantExpr::Create(IntVal, getContext()),
4861 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004862 return MatchOperand_Success;
4863 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004864 // Also handle plain integers. Instructions which allow floating point
4865 // immediates also allow a raw encoded 8-bit value.
David Peixottoa872e0e2014-01-07 18:19:23 +00004866 if (Tok.is(AsmToken::Integer) && isFconst) {
Jim Grosbache7fbce72011-10-03 23:38:36 +00004867 int64_t Val = Tok.getIntVal();
4868 Parser.Lex(); // Eat the token.
4869 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004870 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004871 return MatchOperand_ParseFail;
4872 }
David Peixottoa872e0e2014-01-07 18:19:23 +00004873 float RealVal = ARM_AM::getFPImmFloat(Val);
4874 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
4875
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004876 Operands.push_back(ARMOperand::CreateImm(
4877 MCConstantExpr::Create(Val, getContext()), S,
4878 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004879 return MatchOperand_Success;
4880 }
4881
Jim Grosbach235c8d22012-01-19 02:47:30 +00004882 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004883 return MatchOperand_ParseFail;
4884}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004885
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004886/// Parse a arm instruction operand. For now this parses the operand regardless
4887/// of the mnemonic.
David Blaikie960ea3f2014-06-08 16:18:35 +00004888bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004889 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004890
4891 // Check if the current operand has a custom associated parser, if so, try to
4892 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004893 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4894 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004895 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004896 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4897 // there was a match, but an error occurred, in which case, just return that
4898 // the operand parsing failed.
4899 if (ResTy == MatchOperand_ParseFail)
4900 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004901
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004902 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004903 default:
4904 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004905 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004906 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004907 // If we've seen a branch mnemonic, the next operand must be a label. This
4908 // is true even if the label is a register name. So "br r1" means branch to
4909 // label "r1".
4910 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4911 if (!ExpectLabel) {
4912 if (!tryParseRegisterWithWriteBack(Operands))
4913 return false;
4914 int Res = tryParseShiftRegister(Operands);
4915 if (Res == 0) // success
4916 return false;
4917 else if (Res == -1) // irrecoverable error
4918 return true;
4919 // If this is VMRS, check for the apsr_nzcv operand.
4920 if (Mnemonic == "vmrs" &&
4921 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4922 S = Parser.getTok().getLoc();
4923 Parser.Lex();
4924 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4925 return false;
4926 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004927 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004928
4929 // Fall though for the Identifier case that is not a register or a
4930 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004931 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004932 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004933 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004934 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004935 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004936 // This was not a register so parse other operands that start with an
4937 // identifier (like labels) as expressions and create them as immediates.
4938 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004939 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004940 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004941 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004942 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004943 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4944 return false;
4945 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004946 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004947 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004948 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004949 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004950 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004951 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004952 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004953 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004954 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004955
4956 if (Parser.getTok().isNot(AsmToken::Colon)) {
4957 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4958 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004959 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004960 return true;
4961 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4962 if (CE) {
4963 int32_t Val = CE->getValue();
4964 if (isNegative && Val == 0)
4965 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4966 }
4967 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4968 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004969
4970 // There can be a trailing '!' on operands that we want as a separate
Saleem Abdulrasool83e37702013-12-28 03:07:12 +00004971 // '!' Token operand. Handle that here. For example, the compatibility
Jim Grosbach9be2d712013-02-23 00:52:09 +00004972 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4973 if (Parser.getTok().is(AsmToken::Exclaim)) {
4974 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4975 Parser.getTok().getLoc()));
4976 Parser.Lex(); // Eat exclaim token
4977 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004978 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004979 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004980 // w/ a ':' after the '#', it's just like a plain ':'.
4981 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004982 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004983 case AsmToken::Colon: {
4984 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004985 // FIXME: Check it's an expression prefix,
4986 // e.g. (FOO - :lower16:BAR) isn't legal.
4987 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004988 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004989 return true;
4990
Evan Cheng965b3c72011-01-13 07:58:56 +00004991 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004992 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004993 return true;
4994
Evan Cheng965b3c72011-01-13 07:58:56 +00004995 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004996 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004997 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004998 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004999 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005000 }
David Peixottoe407d092013-12-19 18:12:36 +00005001 case AsmToken::Equal: {
5002 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
5003 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
5004
David Peixottoe407d092013-12-19 18:12:36 +00005005 Parser.Lex(); // Eat '='
5006 const MCExpr *SubExprVal;
5007 if (getParser().parseExpression(SubExprVal))
5008 return true;
5009 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5010
David Peixottob9b73622014-02-04 17:22:40 +00005011 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
David Peixottoe407d092013-12-19 18:12:36 +00005012 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
5013 return false;
5014 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005015 }
5016}
5017
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005018// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00005019// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005020bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00005021 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005022
Saleem Abdulrasool435f4562014-01-10 04:38:40 +00005023 // consume an optional '#' (GNU compatibility)
5024 if (getLexer().is(AsmToken::Hash))
5025 Parser.Lex();
5026
Jason W Kim1f7bc072011-01-11 23:53:41 +00005027 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00005028 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00005029 Parser.Lex(); // Eat ':'
5030
5031 if (getLexer().isNot(AsmToken::Identifier)) {
5032 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
5033 return true;
5034 }
5035
5036 StringRef IDVal = Parser.getTok().getIdentifier();
5037 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00005038 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005039 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00005040 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005041 } else {
5042 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
5043 return true;
5044 }
5045 Parser.Lex();
5046
5047 if (getLexer().isNot(AsmToken::Colon)) {
5048 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
5049 return true;
5050 }
5051 Parser.Lex(); // Eat the last ':'
5052 return false;
5053}
5054
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005055/// \brief Given a mnemonic, split out possible predication code and carry
5056/// setting letters to form a canonical mnemonic and flags.
5057//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005058// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005059// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005060StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005061 unsigned &PredicationCode,
5062 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005063 unsigned &ProcessorIMod,
5064 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005065 PredicationCode = ARMCC::AL;
5066 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005067 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005068
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005069 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005070 //
5071 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005072 if ((Mnemonic == "movs" && isThumb()) ||
5073 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
5074 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
5075 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
5076 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00005077 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005078 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
5079 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00005080 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00005081 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005082 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
5083 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
5084 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005085 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005086
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005087 // First, split out any predication code. Ignore mnemonics we know aren't
5088 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00005089 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00005090 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00005091 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00005092 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005093 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
5094 .Case("eq", ARMCC::EQ)
5095 .Case("ne", ARMCC::NE)
5096 .Case("hs", ARMCC::HS)
5097 .Case("cs", ARMCC::HS)
5098 .Case("lo", ARMCC::LO)
5099 .Case("cc", ARMCC::LO)
5100 .Case("mi", ARMCC::MI)
5101 .Case("pl", ARMCC::PL)
5102 .Case("vs", ARMCC::VS)
5103 .Case("vc", ARMCC::VC)
5104 .Case("hi", ARMCC::HI)
5105 .Case("ls", ARMCC::LS)
5106 .Case("ge", ARMCC::GE)
5107 .Case("lt", ARMCC::LT)
5108 .Case("gt", ARMCC::GT)
5109 .Case("le", ARMCC::LE)
5110 .Case("al", ARMCC::AL)
5111 .Default(~0U);
5112 if (CC != ~0U) {
5113 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
5114 PredicationCode = CC;
5115 }
Bill Wendling193961b2010-10-29 23:50:21 +00005116 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005117
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005118 // Next, determine if we have a carry setting bit. We explicitly ignore all
5119 // the instructions we know end in 's'.
5120 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00005121 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005122 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
5123 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
5124 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00005125 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00005126 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00005127 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00005128 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
David Peixottoa872e0e2014-01-07 18:19:23 +00005129 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00005130 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005131 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
5132 CarrySetting = true;
5133 }
5134
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005135 // The "cps" instruction can have a interrupt mode operand which is glued into
5136 // the mnemonic. Check if this is the case, split it and parse the imod op
5137 if (Mnemonic.startswith("cps")) {
5138 // Split out any imod code.
5139 unsigned IMod =
5140 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
5141 .Case("ie", ARM_PROC::IE)
5142 .Case("id", ARM_PROC::ID)
5143 .Default(~0U);
5144 if (IMod != ~0U) {
5145 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5146 ProcessorIMod = IMod;
5147 }
5148 }
5149
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005150 // The "it" instruction has the condition mask on the end of the mnemonic.
5151 if (Mnemonic.startswith("it")) {
5152 ITMask = Mnemonic.slice(2, Mnemonic.size());
5153 Mnemonic = Mnemonic.slice(0, 2);
5154 }
5155
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005156 return Mnemonic;
5157}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005158
5159/// \brief Given a canonical mnemonic, determine if the instruction ever allows
5160/// inclusion of carry set or predication code operands.
5161//
5162// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00005163void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00005164getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5165 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005166 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5167 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005168 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005169 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005170 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005171 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005172 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00005173 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005174 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005175 Mnemonic == "mla" || Mnemonic == "smlal" ||
5176 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005177 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00005178 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00005179 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005180
Tim Northover2c45a382013-06-26 16:52:40 +00005181 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5182 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00005183 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
5184 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
5185 Mnemonic.startswith("vsel") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00005186 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005187 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
5188 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00005189 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
5190 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5191 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00005192 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005193 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005194 } else if (!isThumb()) {
5195 // Some instructions are only predicable in Thumb mode
5196 CanAcceptPredicationCode
5197 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5198 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5199 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5200 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5201 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5202 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5203 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5204 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00005205 if (hasV6MOps())
5206 CanAcceptPredicationCode = Mnemonic != "movs";
5207 else
5208 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005209 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005210 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005211}
5212
Jim Grosbach7283da92011-08-16 21:12:37 +00005213bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
David Blaikie960ea3f2014-06-08 16:18:35 +00005214 OperandVector &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005215 // FIXME: This is all horribly hacky. We really need a better way to deal
5216 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005217
5218 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5219 // another does not. Specifically, the MOVW instruction does not. So we
5220 // special case it here and remove the defaulted (non-setting) cc_out
5221 // operand if that's the instruction we're trying to match.
5222 //
5223 // We do this as post-processing of the explicit operands rather than just
5224 // conditionally adding the cc_out in the first place because we need
5225 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005226 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005227 !static_cast<ARMOperand &>(*Operands[4]).isARMSOImm() &&
5228 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
5229 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach7283da92011-08-16 21:12:37 +00005230 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005231
5232 // Register-register 'add' for thumb does not have a cc_out operand
5233 // when there are only two register operands.
5234 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005235 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5236 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5237 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005238 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005239 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005240 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5241 // have to check the immediate range here since Thumb2 has a variant
5242 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005243 if (((isThumb() && Mnemonic == "add") ||
5244 (isThumbTwo() && Mnemonic == "sub")) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005245 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5246 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5247 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
5248 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5249 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
5250 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005251 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005252 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5253 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005254 // selecting via the generic "add" mnemonic, so to know that we
5255 // should remove the cc_out operand, we have to explicitly check that
5256 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005257 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005258 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5259 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5260 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005261 // Nest conditions rather than one big 'if' statement for readability.
5262 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005263 // If both registers are low, we're in an IT block, and the immediate is
5264 // in range, we should use encoding T1 instead, which has a cc_out.
5265 if (inITBlock() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005266 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
5267 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
5268 static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005269 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005270 // Check against T3. If the second register is the PC, this is an
5271 // alternate form of ADR, which uses encoding T4, so check for that too.
David Blaikie960ea3f2014-06-08 16:18:35 +00005272 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
5273 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm())
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005274 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005275
5276 // Otherwise, we use encoding T4, which does not have a cc_out
5277 // operand.
5278 return true;
5279 }
5280
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005281 // The thumb2 multiply instruction doesn't have a CCOut register, so
5282 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5283 // use the 16-bit encoding or not.
5284 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005285 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5286 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5287 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5288 static_cast<ARMOperand &>(*Operands[5]).isReg() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005289 // If the registers aren't low regs, the destination reg isn't the
5290 // same as one of the source regs, or the cc_out operand is zero
5291 // outside of an IT block, we have to use the 32-bit encoding, so
5292 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005293 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5294 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5295 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
5296 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5297 static_cast<ARMOperand &>(*Operands[5]).getReg() &&
5298 static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5299 static_cast<ARMOperand &>(*Operands[4]).getReg())))
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005300 return true;
5301
Jim Grosbachefa7e952011-11-15 19:55:16 +00005302 // Also check the 'mul' syntax variant that doesn't specify an explicit
5303 // destination register.
5304 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005305 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5306 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5307 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
Jim Grosbachefa7e952011-11-15 19:55:16 +00005308 // If the registers aren't low regs or the cc_out operand is zero
5309 // outside of an IT block, we have to use the 32-bit encoding, so
5310 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005311 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5312 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
Jim Grosbachefa7e952011-11-15 19:55:16 +00005313 !inITBlock()))
5314 return true;
5315
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005316
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005317
Jim Grosbach4b701af2011-08-24 21:42:27 +00005318 // Register-register 'add/sub' for thumb does not have a cc_out operand
5319 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5320 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5321 // right, this will result in better diagnostics (which operand is off)
5322 // anyway.
5323 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5324 (Operands.size() == 5 || Operands.size() == 6) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005325 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5326 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
5327 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5328 (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005329 (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005330 static_cast<ARMOperand &>(*Operands[5]).isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005331 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005332
Jim Grosbach7283da92011-08-16 21:12:37 +00005333 return false;
5334}
5335
David Blaikie960ea3f2014-06-08 16:18:35 +00005336bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
5337 OperandVector &Operands) {
Joey Goulye8602552013-07-19 16:34:16 +00005338 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5339 unsigned RegIdx = 3;
5340 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005341 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") {
5342 if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5343 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32")
Joey Goulye8602552013-07-19 16:34:16 +00005344 RegIdx = 4;
5345
David Blaikie960ea3f2014-06-08 16:18:35 +00005346 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
5347 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
5348 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
5349 ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
5350 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
Joey Goulye8602552013-07-19 16:34:16 +00005351 return true;
5352 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005353 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005354}
5355
Jim Grosbach12952fe2011-11-11 23:08:10 +00005356static bool isDataTypeToken(StringRef Tok) {
5357 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5358 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5359 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5360 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5361 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5362 Tok == ".f" || Tok == ".d";
5363}
5364
5365// FIXME: This bit should probably be handled via an explicit match class
5366// in the .td files that matches the suffix instead of having it be
5367// a literal string token the way it is now.
5368static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5369 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5370}
Tim Northover26bb14e2014-08-18 11:49:42 +00005371static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features,
Chad Rosier9f7a2212013-04-18 22:35:36 +00005372 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005373
5374static bool RequiresVFPRegListValidation(StringRef Inst,
5375 bool &AcceptSinglePrecisionOnly,
5376 bool &AcceptDoublePrecisionOnly) {
5377 if (Inst.size() < 7)
5378 return false;
5379
5380 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5381 StringRef AddressingMode = Inst.substr(4, 2);
5382 if (AddressingMode == "ia" || AddressingMode == "db" ||
5383 AddressingMode == "ea" || AddressingMode == "fd") {
5384 AcceptSinglePrecisionOnly = Inst[6] == 's';
5385 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5386 return true;
5387 }
5388 }
5389
5390 return false;
5391}
5392
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005393/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005394bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
David Blaikie960ea3f2014-06-08 16:18:35 +00005395 SMLoc NameLoc, OperandVector &Operands) {
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005396 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005397 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005398 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005399 bool AcceptDoublePrecisionOnly;
5400 RequireVFPRegisterListCheck =
5401 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5402 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005403
Jim Grosbach8be2f652011-12-09 23:34:09 +00005404 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005405 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005406 // The generic tblgen'erated code does this later, at the start of
5407 // MatchInstructionImpl(), but that's too late for aliases that include
5408 // any sort of suffix.
Tim Northover26bb14e2014-08-18 11:49:42 +00005409 uint64_t AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005410 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5411 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005412
Jim Grosbachab5830e2011-12-14 02:16:11 +00005413 // First check for the ARM-specific .req directive.
5414 if (Parser.getTok().is(AsmToken::Identifier) &&
5415 Parser.getTok().getIdentifier() == ".req") {
5416 parseDirectiveReq(Name, NameLoc);
5417 // We always return 'error' for this, as we're done with this
5418 // statement and don't need to match the 'instruction."
5419 return true;
5420 }
5421
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005422 // Create the leading tokens for the mnemonic, split by '.' characters.
5423 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005424 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005425
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005426 // Split out the predication code and carry setting flag from the mnemonic.
5427 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005428 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005429 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005430 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005431 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005432 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005433
Jim Grosbach1c171b12011-08-25 17:23:55 +00005434 // In Thumb1, only the branch (B) instruction can be predicated.
5435 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005436 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005437 return Error(NameLoc, "conditional execution not supported in Thumb1");
5438 }
5439
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005440 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5441
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005442 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5443 // is the mask as it will be for the IT encoding if the conditional
5444 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5445 // where the conditional bit0 is zero, the instruction post-processing
5446 // will adjust the mask accordingly.
5447 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005448 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5449 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005450 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005451 return Error(Loc, "too many conditions on IT instruction");
5452 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005453 unsigned Mask = 8;
5454 for (unsigned i = ITMask.size(); i != 0; --i) {
5455 char pos = ITMask[i - 1];
5456 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005457 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005458 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005459 }
5460 Mask >>= 1;
5461 if (ITMask[i - 1] == 't')
5462 Mask |= 8;
5463 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005464 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005465 }
5466
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005467 // FIXME: This is all a pretty gross hack. We should automatically handle
5468 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005469
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005470 // Next, add the CCOut and ConditionCode operands, if needed.
5471 //
5472 // For mnemonics which can ever incorporate a carry setting bit or predication
5473 // code, our matching model involves us always generating CCOut and
5474 // ConditionCode operands to match the mnemonic "as written" and then we let
5475 // the matcher deal with finding the right instruction or generating an
5476 // appropriate error.
5477 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005478 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005479
Jim Grosbach03a8a162011-07-14 22:04:21 +00005480 // If we had a carry-set on an instruction that can't do that, issue an
5481 // error.
5482 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005483 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005484 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005485 "' can not set flags, but 's' suffix specified");
5486 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005487 // If we had a predication code on an instruction that can't do that, issue an
5488 // error.
5489 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005490 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005491 return Error(NameLoc, "instruction '" + Mnemonic +
5492 "' is not predicable, but condition code specified");
5493 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005494
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005495 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005496 if (CanAcceptCarrySet) {
5497 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005498 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005499 Loc));
5500 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005501
5502 // Add the predication code operand, if necessary.
5503 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005504 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5505 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005506 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005507 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005508 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005509
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005510 // Add the processor imod operand, if necessary.
5511 if (ProcessorIMod) {
5512 Operands.push_back(ARMOperand::CreateImm(
5513 MCConstantExpr::Create(ProcessorIMod, getContext()),
5514 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005515 }
5516
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005517 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005518 while (Next != StringRef::npos) {
5519 Start = Next;
5520 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005521 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005522
Jim Grosbach12952fe2011-11-11 23:08:10 +00005523 // Some NEON instructions have an optional datatype suffix that is
5524 // completely ignored. Check for that.
5525 if (isDataTypeToken(ExtraToken) &&
5526 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5527 continue;
5528
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005529 // For for ARM mode generate an error if the .n qualifier is used.
5530 if (ExtraToken == ".n" && !isThumb()) {
5531 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005532 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005533 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5534 "arm mode");
5535 }
5536
5537 // The .n qualifier is always discarded as that is what the tables
5538 // and matcher expect. In ARM mode the .w qualifier has no effect,
5539 // so discard it to avoid errors that can be caused by the matcher.
5540 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005541 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5542 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5543 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005544 }
5545
5546 // Read the remaining operands.
5547 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005548 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005549 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005550 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005551 return true;
5552 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005553
5554 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005555 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005556
5557 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005558 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005559 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005560 return true;
5561 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005562 }
5563 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005564
Chris Lattnera2a9d162010-09-11 16:18:25 +00005565 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005566 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005567 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005568 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005569 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005570
Chris Lattner91689c12010-09-08 05:10:46 +00005571 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005572
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005573 if (RequireVFPRegisterListCheck) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005574 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back());
5575 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList())
5576 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005577 "VFP/Neon single precision register expected");
David Blaikie960ea3f2014-06-08 16:18:35 +00005578 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList())
5579 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005580 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005581 }
5582
Jim Grosbach7283da92011-08-16 21:12:37 +00005583 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5584 // do and don't have a cc_out optional-def operand. With some spot-checks
5585 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005586 // parse and adjust accordingly before actually matching. We shouldn't ever
5587 // try to remove a cc_out operand that was explicitly set on the the
5588 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5589 // table driven matcher doesn't fit well with the ARM instruction set.
David Blaikie960ea3f2014-06-08 16:18:35 +00005590 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005591 Operands.erase(Operands.begin() + 1);
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005592
Joey Goulye8602552013-07-19 16:34:16 +00005593 // Some instructions have the same mnemonic, but don't always
5594 // have a predicate. Distinguish them here and delete the
5595 // predicate if needed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005596 if (shouldOmitPredicateOperand(Mnemonic, Operands))
Joey Goulye8602552013-07-19 16:34:16 +00005597 Operands.erase(Operands.begin() + 1);
Joey Goulye8602552013-07-19 16:34:16 +00005598
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005599 // ARM mode 'blx' need special handling, as the register operand version
5600 // is predicable, but the label operand version is not. So, we can't rely
5601 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005602 // a k_CondCode operand in the list. If we're trying to match the label
5603 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005604 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005605 static_cast<ARMOperand &>(*Operands[2]).isImm())
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005606 Operands.erase(Operands.begin() + 1);
Jim Grosbach8cffa282011-08-11 23:51:13 +00005607
Weiming Zhao8f56f882012-11-16 21:55:34 +00005608 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5609 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5610 // a single GPRPair reg operand is used in the .td file to replace the two
5611 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5612 // expressed as a GPRPair, so we have to manually merge them.
5613 // FIXME: We would really like to be able to tablegen'erate this.
5614 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005615 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5616 Mnemonic == "stlexd")) {
5617 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005618 unsigned Idx = isLoad ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005619 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
5620 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005621
5622 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5623 // Adjust only if Op1 and Op2 are GPRs.
David Blaikie960ea3f2014-06-08 16:18:35 +00005624 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
5625 MRC.contains(Op2.getReg())) {
5626 unsigned Reg1 = Op1.getReg();
5627 unsigned Reg2 = Op2.getReg();
Weiming Zhao8f56f882012-11-16 21:55:34 +00005628 unsigned Rt = MRI->getEncodingValue(Reg1);
5629 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5630
5631 // Rt2 must be Rt + 1 and Rt must be even.
5632 if (Rt + 1 != Rt2 || (Rt & 1)) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005633 Error(Op2.getStartLoc(), isLoad
5634 ? "destination operands must be sequential"
5635 : "source operands must be sequential");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005636 return true;
5637 }
5638 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5639 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
David Blaikie960ea3f2014-06-08 16:18:35 +00005640 Operands[Idx] =
5641 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
5642 Operands.erase(Operands.begin() + Idx + 1);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005643 }
5644 }
5645
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005646 // GNU Assembler extension (compatibility)
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005647 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005648 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5649 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5650 if (Op3.isMem()) {
5651 assert(Op2.isReg() && "expected register argument");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005652
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005653 unsigned SuperReg = MRI->getMatchingSuperReg(
David Blaikie960ea3f2014-06-08 16:18:35 +00005654 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005655
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005656 assert(SuperReg && "expected register pair");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005657
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005658 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005659
David Blaikie960ea3f2014-06-08 16:18:35 +00005660 Operands.insert(
5661 Operands.begin() + 3,
5662 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005663 }
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005664 }
5665
Kevin Enderby78f95722013-07-31 21:05:30 +00005666 // FIXME: As said above, this is all a pretty gross hack. This instruction
5667 // does not fit with other "subs" and tblgen.
5668 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5669 // so the Mnemonic is the original name "subs" and delete the predicate
5670 // operand so it will match the table entry.
5671 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005672 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5673 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
5674 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5675 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
5676 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5677 Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
Kevin Enderby78f95722013-07-31 21:05:30 +00005678 Operands.erase(Operands.begin() + 1);
Kevin Enderby78f95722013-07-31 21:05:30 +00005679 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005680 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005681}
5682
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005683// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005684
5685// return 'true' if register list contains non-low GPR registers,
5686// 'false' otherwise. If Reg is in the register list or is HiReg, set
5687// 'containsReg' to true.
5688static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5689 unsigned HiReg, bool &containsReg) {
5690 containsReg = false;
5691 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5692 unsigned OpReg = Inst.getOperand(i).getReg();
5693 if (OpReg == Reg)
5694 containsReg = true;
5695 // Anything other than a low register isn't legal here.
5696 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5697 return true;
5698 }
5699 return false;
5700}
5701
Jim Grosbacha31f2232011-09-07 18:05:34 +00005702// Check if the specified regisgter is in the register list of the inst,
5703// starting at the indicated operand number.
5704static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5705 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5706 unsigned OpReg = Inst.getOperand(i).getReg();
5707 if (OpReg == Reg)
5708 return true;
5709 }
5710 return false;
5711}
5712
Richard Barton8d519fe2013-09-05 14:14:19 +00005713// Return true if instruction has the interesting property of being
5714// allowed in IT blocks, but not being predicable.
5715static bool instIsBreakpoint(const MCInst &Inst) {
5716 return Inst.getOpcode() == ARM::tBKPT ||
5717 Inst.getOpcode() == ARM::BKPT ||
5718 Inst.getOpcode() == ARM::tHLT ||
5719 Inst.getOpcode() == ARM::HLT;
5720
5721}
5722
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005723// FIXME: We would really like to be able to tablegen'erate this.
David Blaikie960ea3f2014-06-08 16:18:35 +00005724bool ARMAsmParser::validateInstruction(MCInst &Inst,
5725 const OperandVector &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005726 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005727 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005728
Jim Grosbached16ec42011-08-29 22:24:09 +00005729 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005730 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005731 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005732 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005733 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005734 if (ITState.FirstCond)
5735 ITState.FirstCond = false;
5736 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005737 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005738 // The instruction must be predicable.
5739 if (!MCID.isPredicable())
5740 return Error(Loc, "instructions in IT block must be predicable");
5741 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005742 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005743 ARMCC::getOppositeCondition(ITState.Cond);
5744 if (Cond != ITCond) {
5745 // Find the condition code Operand to get its SMLoc information.
5746 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005747 for (unsigned I = 1; I < Operands.size(); ++I)
David Blaikie960ea3f2014-06-08 16:18:35 +00005748 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
Tilmann Schellerbe904772013-09-30 17:57:30 +00005749 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005750 return Error(CondLoc, "incorrect condition in IT block; got '" +
5751 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5752 "', but expected '" +
5753 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5754 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005755 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005756 } else if (isThumbTwo() && MCID.isPredicable() &&
5757 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005758 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5759 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005760 return Error(Loc, "predicated instructions must be in IT block");
5761
Tilmann Scheller255722b2013-09-30 16:11:48 +00005762 const unsigned Opcode = Inst.getOpcode();
5763 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005764 case ARM::LDRD:
5765 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005766 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005767 const unsigned RtReg = Inst.getOperand(0).getReg();
5768
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005769 // Rt can't be R14.
5770 if (RtReg == ARM::LR)
5771 return Error(Operands[3]->getStartLoc(),
5772 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005773
5774 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005775 // Rt must be even-numbered.
5776 if ((Rt & 1) == 1)
5777 return Error(Operands[3]->getStartLoc(),
5778 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005779
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005780 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005781 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005782 if (Rt2 != Rt + 1)
5783 return Error(Operands[3]->getStartLoc(),
5784 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005785
5786 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5787 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5788 // For addressing modes with writeback, the base register needs to be
5789 // different from the destination registers.
5790 if (Rn == Rt || Rn == Rt2)
5791 return Error(Operands[3]->getStartLoc(),
5792 "base register needs to be different from destination "
5793 "registers");
5794 }
5795
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005796 return false;
5797 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005798 case ARM::t2LDRDi8:
5799 case ARM::t2LDRD_PRE:
5800 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005801 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005802 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5803 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5804 if (Rt2 == Rt)
5805 return Error(Operands[3]->getStartLoc(),
5806 "destination operands can't be identical");
5807 return false;
5808 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005809 case ARM::STRD: {
5810 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005811 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5812 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005813 if (Rt2 != Rt + 1)
5814 return Error(Operands[3]->getStartLoc(),
5815 "source operands must be sequential");
5816 return false;
5817 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005818 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005819 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005820 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005821 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5822 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005823 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005824 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005825 "source operands must be sequential");
5826 return false;
5827 }
Tilmann Scheller3352a582014-07-23 12:38:17 +00005828 case ARM::STR_PRE_IMM:
5829 case ARM::STR_PRE_REG:
5830 case ARM::STR_POST_IMM:
Tilmann Scheller27272792014-07-23 13:03:47 +00005831 case ARM::STR_POST_REG:
Tilmann Scheller96ef72e2014-07-24 09:55:46 +00005832 case ARM::STRH_PRE:
5833 case ARM::STRH_POST:
Tilmann Scheller27272792014-07-23 13:03:47 +00005834 case ARM::STRB_PRE_IMM:
5835 case ARM::STRB_PRE_REG:
5836 case ARM::STRB_POST_IMM:
5837 case ARM::STRB_POST_REG: {
Tilmann Scheller3352a582014-07-23 12:38:17 +00005838 // Rt must be different from Rn.
5839 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5840 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5841
5842 if (Rt == Rn)
5843 return Error(Operands[3]->getStartLoc(),
5844 "source register and base register can't be identical");
5845 return false;
5846 }
Tilmann Scheller8ba74302014-08-01 11:08:51 +00005847 case ARM::LDR_PRE_IMM:
5848 case ARM::LDR_PRE_REG:
5849 case ARM::LDR_POST_IMM:
Tilmann Scheller8ff079c2014-08-01 11:33:47 +00005850 case ARM::LDR_POST_REG:
5851 case ARM::LDRH_PRE:
5852 case ARM::LDRH_POST:
5853 case ARM::LDRSH_PRE:
Tilmann Scheller7cc0ed42014-08-01 12:08:04 +00005854 case ARM::LDRSH_POST:
5855 case ARM::LDRB_PRE_IMM:
5856 case ARM::LDRB_PRE_REG:
5857 case ARM::LDRB_POST_IMM:
5858 case ARM::LDRB_POST_REG:
5859 case ARM::LDRSB_PRE:
5860 case ARM::LDRSB_POST: {
Tilmann Scheller8ba74302014-08-01 11:08:51 +00005861 // Rt must be different from Rn.
5862 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5863 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5864
5865 if (Rt == Rn)
5866 return Error(Operands[3]->getStartLoc(),
5867 "destination register and base register can't be identical");
5868 return false;
5869 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005870 case ARM::SBFX:
5871 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005872 // Width must be in range [1, 32-lsb].
5873 unsigned LSB = Inst.getOperand(2).getImm();
5874 unsigned Widthm1 = Inst.getOperand(3).getImm();
5875 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005876 return Error(Operands[5]->getStartLoc(),
5877 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005878 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005879 }
Tim Northover08a86602013-10-22 19:00:39 +00005880 // Notionally handles ARM::tLDMIA_UPD too.
Jim Grosbach90103cc2011-08-18 21:50:53 +00005881 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005882 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005883 // most cases that are normally illegal for a Thumb1 LDM instruction.
5884 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005885 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005886 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005887 // in the register list.
5888 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005889 bool HasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00005890 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5891 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005892 bool ListContainsBase;
5893 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5894 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005895 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005896 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005897 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005898 return Error(Operands[2]->getStartLoc(),
5899 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005900 // If we should not have writeback, there must not be a '!'. This is
5901 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005902 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005903 return Error(Operands[3]->getStartLoc(),
5904 "writeback operator '!' not allowed when base register "
5905 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005906
5907 break;
5908 }
Tim Northover08a86602013-10-22 19:00:39 +00005909 case ARM::LDMIA_UPD:
5910 case ARM::LDMDB_UPD:
5911 case ARM::LDMIB_UPD:
5912 case ARM::LDMDA_UPD:
5913 // ARM variants loading and updating the same register are only officially
5914 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5915 if (!hasV7Ops())
5916 break;
5917 // Fallthrough
5918 case ARM::t2LDMIA_UPD:
5919 case ARM::t2LDMDB_UPD:
5920 case ARM::t2STMIA_UPD:
5921 case ARM::t2STMDB_UPD: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005922 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
Tim Northover741e6ef2013-10-24 09:37:18 +00005923 return Error(Operands.back()->getStartLoc(),
5924 "writeback register not allowed in register list");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005925 break;
5926 }
Tim Northover8eaf1542013-11-12 21:32:41 +00005927 case ARM::sysLDMIA_UPD:
5928 case ARM::sysLDMDA_UPD:
5929 case ARM::sysLDMDB_UPD:
5930 case ARM::sysLDMIB_UPD:
5931 if (!listContainsReg(Inst, 3, ARM::PC))
5932 return Error(Operands[4]->getStartLoc(),
5933 "writeback register only allowed on system LDM "
5934 "if PC in register-list");
5935 break;
5936 case ARM::sysSTMIA_UPD:
5937 case ARM::sysSTMDA_UPD:
5938 case ARM::sysSTMDB_UPD:
5939 case ARM::sysSTMIB_UPD:
5940 return Error(Operands[2]->getStartLoc(),
5941 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005942 case ARM::tMUL: {
5943 // The second source operand must be the same register as the destination
5944 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005945 //
5946 // In this case, we must directly check the parsed operands because the
5947 // cvtThumbMultiply() function is written in such a way that it guarantees
5948 // this first statement is always true for the new Inst. Essentially, the
5949 // destination is unconditionally copied into the second source operand
5950 // without checking to see if it matches what we actually parsed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005951 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
5952 ((ARMOperand &)*Operands[5]).getReg()) &&
5953 (((ARMOperand &)*Operands[3]).getReg() !=
5954 ((ARMOperand &)*Operands[4]).getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005955 return Error(Operands[3]->getStartLoc(),
5956 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005957 }
5958 break;
5959 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005960 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5961 // so only issue a diagnostic for thumb1. The instructions will be
5962 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005963 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005964 bool ListContainsBase;
5965 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005966 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005967 return Error(Operands[2]->getStartLoc(),
5968 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005969 break;
5970 }
5971 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005972 bool ListContainsBase;
5973 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005974 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005975 return Error(Operands[2]->getStartLoc(),
5976 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005977 break;
5978 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005979 case ARM::tSTMIA_UPD: {
Tim Northover08a86602013-10-22 19:00:39 +00005980 bool ListContainsBase, InvalidLowList;
5981 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5982 0, ListContainsBase);
5983 if (InvalidLowList && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005984 return Error(Operands[4]->getStartLoc(),
5985 "registers must be in range r0-r7");
Tim Northover08a86602013-10-22 19:00:39 +00005986
5987 // This would be converted to a 32-bit stm, but that's not valid if the
5988 // writeback register is in the list.
5989 if (InvalidLowList && ListContainsBase)
5990 return Error(Operands[4]->getStartLoc(),
5991 "writeback operator '!' not allowed when base register "
5992 "in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00005993 break;
5994 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005995 case ARM::tADDrSP: {
5996 // If the non-SP source operand and the destination operand are not the
5997 // same, we need thumb2 (for the wide encoding), or we have an error.
5998 if (!isThumbTwo() &&
5999 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
6000 return Error(Operands[4]->getStartLoc(),
6001 "source register must be the same as destination");
6002 }
6003 break;
6004 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006005 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006006 case ARM::tB:
David Blaikie960ea3f2014-06-08 16:18:35 +00006007 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006008 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006009 break;
6010 case ARM::t2B: {
6011 int op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006012 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006013 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006014 break;
6015 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006016 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006017 case ARM::tBcc:
David Blaikie960ea3f2014-06-08 16:18:35 +00006018 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006019 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006020 break;
6021 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006022 int Op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006023 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006024 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006025 break;
6026 }
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006027 case ARM::MOVi16:
6028 case ARM::t2MOVi16:
6029 case ARM::t2MOVTi16:
6030 {
6031 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
6032 // especially when we turn it into a movw and the expression <symbol> does
6033 // not have a :lower16: or :upper16 as part of the expression. We don't
6034 // want the behavior of silently truncating, which can be unexpected and
6035 // lead to bugs that are difficult to find since this is an easy mistake
6036 // to make.
6037 int i = (Operands[3]->isImm()) ? 3 : 4;
David Blaikie960ea3f2014-06-08 16:18:35 +00006038 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
6039 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006040 if (CE) break;
David Blaikie960ea3f2014-06-08 16:18:35 +00006041 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006042 if (!E) break;
6043 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
6044 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006045 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
6046 return Error(
6047 Op.getStartLoc(),
6048 "immediate expression for mov requires :lower16: or :upper16");
6049 break;
6050 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006051 }
6052
6053 return false;
6054}
6055
Jim Grosbach1a747242012-01-23 23:45:44 +00006056static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00006057 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006058 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006059 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006060 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6061 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6062 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6063 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6064 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6065 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6066 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
6067 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
6068 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006069
6070 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006071 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6072 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6073 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6074 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6075 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006076
Jim Grosbach1e946a42012-01-24 00:43:12 +00006077 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6078 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6079 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6080 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6081 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006082
Jim Grosbach1e946a42012-01-24 00:43:12 +00006083 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
6084 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
6085 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
6086 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
6087 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00006088
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006089 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006090 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6091 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6092 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6093 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
6094 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6095 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6096 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6097 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6098 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
6099 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6100 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
6101 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
6102 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
6103 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
6104 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006105
Jim Grosbach1a747242012-01-23 23:45:44 +00006106 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006107 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6108 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6109 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6110 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6111 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6112 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6113 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6114 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6115 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6116 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6117 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6118 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6119 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
6120 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
6121 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
6122 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
6123 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
6124 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00006125
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006126 // VST4LN
6127 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6128 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6129 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6130 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
6131 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6132 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6133 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6134 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6135 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
6136 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6137 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
6138 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
6139 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
6140 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
6141 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
6142
Jim Grosbachda70eac2012-01-24 00:58:13 +00006143 // VST4
6144 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6145 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6146 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6147 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6148 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6149 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6150 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6151 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6152 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6153 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6154 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6155 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6156 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6157 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6158 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6159 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6160 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6161 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00006162 }
6163}
6164
Jim Grosbach1a747242012-01-23 23:45:44 +00006165static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00006166 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006167 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006168 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006169 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6170 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6171 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6172 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6173 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6174 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6175 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6176 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6177 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006178
6179 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006180 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6181 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6182 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6183 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6184 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6185 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6186 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6187 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6188 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6189 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6190 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6191 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6192 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6193 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6194 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006195
Jim Grosbachb78403c2012-01-24 23:47:04 +00006196 // VLD3DUP
6197 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6198 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6199 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6200 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
Kevin Enderbyd88fec32014-04-08 18:00:52 +00006201 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
Jim Grosbachb78403c2012-01-24 23:47:04 +00006202 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6203 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6204 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6205 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6206 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6207 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6208 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6209 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6210 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6211 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6212 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6213 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6214 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6215
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006216 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006217 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6218 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6219 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6220 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6221 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6222 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6223 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6224 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6225 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6226 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6227 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6228 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6229 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6230 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6231 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006232
6233 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006234 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6235 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6236 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6237 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6238 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6239 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6240 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6241 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6242 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6243 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6244 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6245 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6246 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6247 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6248 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6249 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6250 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6251 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00006252
Jim Grosbach14952a02012-01-24 18:37:25 +00006253 // VLD4LN
6254 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6255 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6256 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00006257 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00006258 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6259 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6260 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6261 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6262 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6263 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6264 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6265 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6266 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6267 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6268 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6269
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006270 // VLD4DUP
6271 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6272 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6273 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6274 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6275 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6276 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6277 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6278 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6279 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6280 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6281 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6282 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6283 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6284 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6285 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6286 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6287 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6288 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6289
Jim Grosbached561fc2012-01-24 00:43:17 +00006290 // VLD4
6291 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6292 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6293 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6294 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6295 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6296 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6297 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6298 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6299 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6300 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6301 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6302 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6303 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6304 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6305 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6306 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6307 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6308 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006309 }
6310}
6311
David Blaikie960ea3f2014-06-08 16:18:35 +00006312bool ARMAsmParser::processInstruction(MCInst &Inst,
6313 const OperandVector &Operands) {
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006314 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006315 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6316 case ARM::LDRT_POST:
6317 case ARM::LDRBT_POST: {
6318 const unsigned Opcode =
6319 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6320 : ARM::LDRBT_POST_IMM;
6321 MCInst TmpInst;
6322 TmpInst.setOpcode(Opcode);
6323 TmpInst.addOperand(Inst.getOperand(0));
6324 TmpInst.addOperand(Inst.getOperand(1));
6325 TmpInst.addOperand(Inst.getOperand(1));
6326 TmpInst.addOperand(MCOperand::CreateReg(0));
6327 TmpInst.addOperand(MCOperand::CreateImm(0));
6328 TmpInst.addOperand(Inst.getOperand(2));
6329 TmpInst.addOperand(Inst.getOperand(3));
6330 Inst = TmpInst;
6331 return true;
6332 }
6333 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6334 case ARM::STRT_POST:
6335 case ARM::STRBT_POST: {
6336 const unsigned Opcode =
6337 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6338 : ARM::STRBT_POST_IMM;
6339 MCInst TmpInst;
6340 TmpInst.setOpcode(Opcode);
6341 TmpInst.addOperand(Inst.getOperand(1));
6342 TmpInst.addOperand(Inst.getOperand(0));
6343 TmpInst.addOperand(Inst.getOperand(1));
6344 TmpInst.addOperand(MCOperand::CreateReg(0));
6345 TmpInst.addOperand(MCOperand::CreateImm(0));
6346 TmpInst.addOperand(Inst.getOperand(2));
6347 TmpInst.addOperand(Inst.getOperand(3));
6348 Inst = TmpInst;
6349 return true;
6350 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006351 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6352 case ARM::ADDri: {
6353 if (Inst.getOperand(1).getReg() != ARM::PC ||
6354 Inst.getOperand(5).getReg() != 0)
6355 return false;
6356 MCInst TmpInst;
6357 TmpInst.setOpcode(ARM::ADR);
6358 TmpInst.addOperand(Inst.getOperand(0));
6359 TmpInst.addOperand(Inst.getOperand(2));
6360 TmpInst.addOperand(Inst.getOperand(3));
6361 TmpInst.addOperand(Inst.getOperand(4));
6362 Inst = TmpInst;
6363 return true;
6364 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006365 // Aliases for alternate PC+imm syntax of LDR instructions.
6366 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006367 // Select the narrow version if the immediate will fit.
6368 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006369 Inst.getOperand(1).getImm() <= 0xff &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006370 !(static_cast<ARMOperand &>(*Operands[2]).isToken() &&
6371 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006372 Inst.setOpcode(ARM::tLDRpci);
6373 else
6374 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006375 return true;
6376 case ARM::t2LDRBpcrel:
6377 Inst.setOpcode(ARM::t2LDRBpci);
6378 return true;
6379 case ARM::t2LDRHpcrel:
6380 Inst.setOpcode(ARM::t2LDRHpci);
6381 return true;
6382 case ARM::t2LDRSBpcrel:
6383 Inst.setOpcode(ARM::t2LDRSBpci);
6384 return true;
6385 case ARM::t2LDRSHpcrel:
6386 Inst.setOpcode(ARM::t2LDRSHpci);
6387 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006388 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006389 case ARM::VST1LNdWB_register_Asm_8:
6390 case ARM::VST1LNdWB_register_Asm_16:
6391 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006392 MCInst TmpInst;
6393 // Shuffle the operands around so the lane index operand is in the
6394 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006395 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006396 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006397 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6398 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6399 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6400 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6401 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6402 TmpInst.addOperand(Inst.getOperand(1)); // lane
6403 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6404 TmpInst.addOperand(Inst.getOperand(6));
6405 Inst = TmpInst;
6406 return true;
6407 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006408
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006409 case ARM::VST2LNdWB_register_Asm_8:
6410 case ARM::VST2LNdWB_register_Asm_16:
6411 case ARM::VST2LNdWB_register_Asm_32:
6412 case ARM::VST2LNqWB_register_Asm_16:
6413 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006414 MCInst TmpInst;
6415 // Shuffle the operands around so the lane index operand is in the
6416 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006417 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006418 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006419 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6420 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6421 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6422 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6423 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006424 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6425 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006426 TmpInst.addOperand(Inst.getOperand(1)); // lane
6427 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6428 TmpInst.addOperand(Inst.getOperand(6));
6429 Inst = TmpInst;
6430 return true;
6431 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006432
6433 case ARM::VST3LNdWB_register_Asm_8:
6434 case ARM::VST3LNdWB_register_Asm_16:
6435 case ARM::VST3LNdWB_register_Asm_32:
6436 case ARM::VST3LNqWB_register_Asm_16:
6437 case ARM::VST3LNqWB_register_Asm_32: {
6438 MCInst TmpInst;
6439 // Shuffle the operands around so the lane index operand is in the
6440 // right place.
6441 unsigned Spacing;
6442 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6443 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6444 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6445 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6446 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6447 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6448 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6449 Spacing));
6450 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6451 Spacing * 2));
6452 TmpInst.addOperand(Inst.getOperand(1)); // lane
6453 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6454 TmpInst.addOperand(Inst.getOperand(6));
6455 Inst = TmpInst;
6456 return true;
6457 }
6458
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006459 case ARM::VST4LNdWB_register_Asm_8:
6460 case ARM::VST4LNdWB_register_Asm_16:
6461 case ARM::VST4LNdWB_register_Asm_32:
6462 case ARM::VST4LNqWB_register_Asm_16:
6463 case ARM::VST4LNqWB_register_Asm_32: {
6464 MCInst TmpInst;
6465 // Shuffle the operands around so the lane index operand is in the
6466 // right place.
6467 unsigned Spacing;
6468 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6469 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6470 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6471 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6472 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6473 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6474 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6475 Spacing));
6476 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6477 Spacing * 2));
6478 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6479 Spacing * 3));
6480 TmpInst.addOperand(Inst.getOperand(1)); // lane
6481 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6482 TmpInst.addOperand(Inst.getOperand(6));
6483 Inst = TmpInst;
6484 return true;
6485 }
6486
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006487 case ARM::VST1LNdWB_fixed_Asm_8:
6488 case ARM::VST1LNdWB_fixed_Asm_16:
6489 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006490 MCInst TmpInst;
6491 // Shuffle the operands around so the lane index operand is in the
6492 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006493 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006494 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006495 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6496 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6497 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6498 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6499 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6500 TmpInst.addOperand(Inst.getOperand(1)); // lane
6501 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6502 TmpInst.addOperand(Inst.getOperand(5));
6503 Inst = TmpInst;
6504 return true;
6505 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006506
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006507 case ARM::VST2LNdWB_fixed_Asm_8:
6508 case ARM::VST2LNdWB_fixed_Asm_16:
6509 case ARM::VST2LNdWB_fixed_Asm_32:
6510 case ARM::VST2LNqWB_fixed_Asm_16:
6511 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006512 MCInst TmpInst;
6513 // Shuffle the operands around so the lane index operand is in the
6514 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006515 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006516 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006517 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6518 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6519 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6520 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6521 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006522 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6523 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006524 TmpInst.addOperand(Inst.getOperand(1)); // lane
6525 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6526 TmpInst.addOperand(Inst.getOperand(5));
6527 Inst = TmpInst;
6528 return true;
6529 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006530
6531 case ARM::VST3LNdWB_fixed_Asm_8:
6532 case ARM::VST3LNdWB_fixed_Asm_16:
6533 case ARM::VST3LNdWB_fixed_Asm_32:
6534 case ARM::VST3LNqWB_fixed_Asm_16:
6535 case ARM::VST3LNqWB_fixed_Asm_32: {
6536 MCInst TmpInst;
6537 // Shuffle the operands around so the lane index operand is in the
6538 // right place.
6539 unsigned Spacing;
6540 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6541 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6542 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6543 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6544 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6545 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6547 Spacing));
6548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6549 Spacing * 2));
6550 TmpInst.addOperand(Inst.getOperand(1)); // lane
6551 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6552 TmpInst.addOperand(Inst.getOperand(5));
6553 Inst = TmpInst;
6554 return true;
6555 }
6556
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006557 case ARM::VST4LNdWB_fixed_Asm_8:
6558 case ARM::VST4LNdWB_fixed_Asm_16:
6559 case ARM::VST4LNdWB_fixed_Asm_32:
6560 case ARM::VST4LNqWB_fixed_Asm_16:
6561 case ARM::VST4LNqWB_fixed_Asm_32: {
6562 MCInst TmpInst;
6563 // Shuffle the operands around so the lane index operand is in the
6564 // right place.
6565 unsigned Spacing;
6566 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6567 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6568 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6569 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6570 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6571 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6573 Spacing));
6574 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6575 Spacing * 2));
6576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6577 Spacing * 3));
6578 TmpInst.addOperand(Inst.getOperand(1)); // lane
6579 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6580 TmpInst.addOperand(Inst.getOperand(5));
6581 Inst = TmpInst;
6582 return true;
6583 }
6584
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006585 case ARM::VST1LNdAsm_8:
6586 case ARM::VST1LNdAsm_16:
6587 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006588 MCInst TmpInst;
6589 // Shuffle the operands around so the lane index operand is in the
6590 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006591 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006592 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006593 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6594 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6595 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6596 TmpInst.addOperand(Inst.getOperand(1)); // lane
6597 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6598 TmpInst.addOperand(Inst.getOperand(5));
6599 Inst = TmpInst;
6600 return true;
6601 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006602
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006603 case ARM::VST2LNdAsm_8:
6604 case ARM::VST2LNdAsm_16:
6605 case ARM::VST2LNdAsm_32:
6606 case ARM::VST2LNqAsm_16:
6607 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006608 MCInst TmpInst;
6609 // Shuffle the operands around so the lane index operand is in the
6610 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006611 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006612 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006613 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6614 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6615 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006616 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6617 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006618 TmpInst.addOperand(Inst.getOperand(1)); // lane
6619 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6620 TmpInst.addOperand(Inst.getOperand(5));
6621 Inst = TmpInst;
6622 return true;
6623 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006624
6625 case ARM::VST3LNdAsm_8:
6626 case ARM::VST3LNdAsm_16:
6627 case ARM::VST3LNdAsm_32:
6628 case ARM::VST3LNqAsm_16:
6629 case ARM::VST3LNqAsm_32: {
6630 MCInst TmpInst;
6631 // Shuffle the operands around so the lane index operand is in the
6632 // right place.
6633 unsigned Spacing;
6634 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6635 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6636 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6637 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6638 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6639 Spacing));
6640 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6641 Spacing * 2));
6642 TmpInst.addOperand(Inst.getOperand(1)); // lane
6643 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6644 TmpInst.addOperand(Inst.getOperand(5));
6645 Inst = TmpInst;
6646 return true;
6647 }
6648
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006649 case ARM::VST4LNdAsm_8:
6650 case ARM::VST4LNdAsm_16:
6651 case ARM::VST4LNdAsm_32:
6652 case ARM::VST4LNqAsm_16:
6653 case ARM::VST4LNqAsm_32: {
6654 MCInst TmpInst;
6655 // Shuffle the operands around so the lane index operand is in the
6656 // right place.
6657 unsigned Spacing;
6658 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6659 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6660 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6661 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6662 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6663 Spacing));
6664 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6665 Spacing * 2));
6666 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6667 Spacing * 3));
6668 TmpInst.addOperand(Inst.getOperand(1)); // lane
6669 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6670 TmpInst.addOperand(Inst.getOperand(5));
6671 Inst = TmpInst;
6672 return true;
6673 }
6674
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006675 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006676 case ARM::VLD1LNdWB_register_Asm_8:
6677 case ARM::VLD1LNdWB_register_Asm_16:
6678 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006679 MCInst TmpInst;
6680 // Shuffle the operands around so the lane index operand is in the
6681 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006682 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006683 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006684 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6685 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6686 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6687 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6688 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6689 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6690 TmpInst.addOperand(Inst.getOperand(1)); // lane
6691 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6692 TmpInst.addOperand(Inst.getOperand(6));
6693 Inst = TmpInst;
6694 return true;
6695 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006696
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006697 case ARM::VLD2LNdWB_register_Asm_8:
6698 case ARM::VLD2LNdWB_register_Asm_16:
6699 case ARM::VLD2LNdWB_register_Asm_32:
6700 case ARM::VLD2LNqWB_register_Asm_16:
6701 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006702 MCInst TmpInst;
6703 // Shuffle the operands around so the lane index operand is in the
6704 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006705 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006706 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006707 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006708 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6709 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006710 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6711 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6712 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6713 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6714 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006715 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6716 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006717 TmpInst.addOperand(Inst.getOperand(1)); // lane
6718 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6719 TmpInst.addOperand(Inst.getOperand(6));
6720 Inst = TmpInst;
6721 return true;
6722 }
6723
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006724 case ARM::VLD3LNdWB_register_Asm_8:
6725 case ARM::VLD3LNdWB_register_Asm_16:
6726 case ARM::VLD3LNdWB_register_Asm_32:
6727 case ARM::VLD3LNqWB_register_Asm_16:
6728 case ARM::VLD3LNqWB_register_Asm_32: {
6729 MCInst TmpInst;
6730 // Shuffle the operands around so the lane index operand is in the
6731 // right place.
6732 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006733 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006734 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6735 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6736 Spacing));
6737 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006738 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006739 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6740 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6741 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6742 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6743 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6744 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6745 Spacing));
6746 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006747 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006748 TmpInst.addOperand(Inst.getOperand(1)); // lane
6749 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6750 TmpInst.addOperand(Inst.getOperand(6));
6751 Inst = TmpInst;
6752 return true;
6753 }
6754
Jim Grosbach14952a02012-01-24 18:37:25 +00006755 case ARM::VLD4LNdWB_register_Asm_8:
6756 case ARM::VLD4LNdWB_register_Asm_16:
6757 case ARM::VLD4LNdWB_register_Asm_32:
6758 case ARM::VLD4LNqWB_register_Asm_16:
6759 case ARM::VLD4LNqWB_register_Asm_32: {
6760 MCInst TmpInst;
6761 // Shuffle the operands around so the lane index operand is in the
6762 // right place.
6763 unsigned Spacing;
6764 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6765 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6766 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6767 Spacing));
6768 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6769 Spacing * 2));
6770 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6771 Spacing * 3));
6772 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6773 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6774 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6775 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6776 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== 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(1)); // lane
6784 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6785 TmpInst.addOperand(Inst.getOperand(6));
6786 Inst = TmpInst;
6787 return true;
6788 }
6789
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006790 case ARM::VLD1LNdWB_fixed_Asm_8:
6791 case ARM::VLD1LNdWB_fixed_Asm_16:
6792 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006793 MCInst TmpInst;
6794 // Shuffle the operands around so the lane index operand is in the
6795 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006796 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006797 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006798 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6799 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6800 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6801 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6802 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6803 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6804 TmpInst.addOperand(Inst.getOperand(1)); // lane
6805 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6806 TmpInst.addOperand(Inst.getOperand(5));
6807 Inst = TmpInst;
6808 return true;
6809 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006810
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006811 case ARM::VLD2LNdWB_fixed_Asm_8:
6812 case ARM::VLD2LNdWB_fixed_Asm_16:
6813 case ARM::VLD2LNdWB_fixed_Asm_32:
6814 case ARM::VLD2LNqWB_fixed_Asm_16:
6815 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006816 MCInst TmpInst;
6817 // Shuffle the operands around so the lane index operand is in the
6818 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006819 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006820 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006821 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006822 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6823 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006824 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6825 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6826 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6827 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6828 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006829 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6830 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006831 TmpInst.addOperand(Inst.getOperand(1)); // lane
6832 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6833 TmpInst.addOperand(Inst.getOperand(5));
6834 Inst = TmpInst;
6835 return true;
6836 }
6837
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006838 case ARM::VLD3LNdWB_fixed_Asm_8:
6839 case ARM::VLD3LNdWB_fixed_Asm_16:
6840 case ARM::VLD3LNdWB_fixed_Asm_32:
6841 case ARM::VLD3LNqWB_fixed_Asm_16:
6842 case ARM::VLD3LNqWB_fixed_Asm_32: {
6843 MCInst TmpInst;
6844 // Shuffle the operands around so the lane index operand is in the
6845 // right place.
6846 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006847 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006848 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6849 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6850 Spacing));
6851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006852 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006853 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6854 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6855 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6856 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6857 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6859 Spacing));
6860 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006861 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006862 TmpInst.addOperand(Inst.getOperand(1)); // lane
6863 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6864 TmpInst.addOperand(Inst.getOperand(5));
6865 Inst = TmpInst;
6866 return true;
6867 }
6868
Jim Grosbach14952a02012-01-24 18:37:25 +00006869 case ARM::VLD4LNdWB_fixed_Asm_8:
6870 case ARM::VLD4LNdWB_fixed_Asm_16:
6871 case ARM::VLD4LNdWB_fixed_Asm_32:
6872 case ARM::VLD4LNqWB_fixed_Asm_16:
6873 case ARM::VLD4LNqWB_fixed_Asm_32: {
6874 MCInst TmpInst;
6875 // Shuffle the operands around so the lane index operand is in the
6876 // right place.
6877 unsigned Spacing;
6878 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6879 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6880 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6881 Spacing));
6882 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6883 Spacing * 2));
6884 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6885 Spacing * 3));
6886 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6887 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6888 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6889 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6890 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6891 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6892 Spacing));
6893 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6894 Spacing * 2));
6895 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6896 Spacing * 3));
6897 TmpInst.addOperand(Inst.getOperand(1)); // lane
6898 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6899 TmpInst.addOperand(Inst.getOperand(5));
6900 Inst = TmpInst;
6901 return true;
6902 }
6903
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006904 case ARM::VLD1LNdAsm_8:
6905 case ARM::VLD1LNdAsm_16:
6906 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006907 MCInst TmpInst;
6908 // Shuffle the operands around so the lane index operand is in the
6909 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006910 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006911 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006912 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6913 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6914 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6915 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6916 TmpInst.addOperand(Inst.getOperand(1)); // lane
6917 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6918 TmpInst.addOperand(Inst.getOperand(5));
6919 Inst = TmpInst;
6920 return true;
6921 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006922
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006923 case ARM::VLD2LNdAsm_8:
6924 case ARM::VLD2LNdAsm_16:
6925 case ARM::VLD2LNdAsm_32:
6926 case ARM::VLD2LNqAsm_16:
6927 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006928 MCInst TmpInst;
6929 // Shuffle the operands around so the lane index operand is in the
6930 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006931 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006932 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006933 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006934 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6935 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006936 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6937 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6938 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006939 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6940 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006941 TmpInst.addOperand(Inst.getOperand(1)); // lane
6942 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6943 TmpInst.addOperand(Inst.getOperand(5));
6944 Inst = TmpInst;
6945 return true;
6946 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006947
6948 case ARM::VLD3LNdAsm_8:
6949 case ARM::VLD3LNdAsm_16:
6950 case ARM::VLD3LNdAsm_32:
6951 case ARM::VLD3LNqAsm_16:
6952 case ARM::VLD3LNqAsm_32: {
6953 MCInst TmpInst;
6954 // Shuffle the operands around so the lane index operand is in the
6955 // right place.
6956 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006957 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006958 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6959 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6960 Spacing));
6961 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006962 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006963 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6964 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6965 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6966 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6967 Spacing));
6968 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006969 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006970 TmpInst.addOperand(Inst.getOperand(1)); // lane
6971 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6972 TmpInst.addOperand(Inst.getOperand(5));
6973 Inst = TmpInst;
6974 return true;
6975 }
6976
Jim Grosbach14952a02012-01-24 18:37:25 +00006977 case ARM::VLD4LNdAsm_8:
6978 case ARM::VLD4LNdAsm_16:
6979 case ARM::VLD4LNdAsm_32:
6980 case ARM::VLD4LNqAsm_16:
6981 case ARM::VLD4LNqAsm_32: {
6982 MCInst TmpInst;
6983 // Shuffle the operands around so the lane index operand is in the
6984 // right place.
6985 unsigned Spacing;
6986 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6987 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6988 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6989 Spacing));
6990 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6991 Spacing * 2));
6992 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6993 Spacing * 3));
6994 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6995 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6996 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6997 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6998 Spacing));
6999 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7000 Spacing * 2));
7001 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7002 Spacing * 3));
7003 TmpInst.addOperand(Inst.getOperand(1)); // lane
7004 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7005 TmpInst.addOperand(Inst.getOperand(5));
7006 Inst = TmpInst;
7007 return true;
7008 }
7009
Jim Grosbachb78403c2012-01-24 23:47:04 +00007010 // VLD3DUP single 3-element structure to all lanes instructions.
7011 case ARM::VLD3DUPdAsm_8:
7012 case ARM::VLD3DUPdAsm_16:
7013 case ARM::VLD3DUPdAsm_32:
7014 case ARM::VLD3DUPqAsm_8:
7015 case ARM::VLD3DUPqAsm_16:
7016 case ARM::VLD3DUPqAsm_32: {
7017 MCInst TmpInst;
7018 unsigned Spacing;
7019 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7020 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7021 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7022 Spacing));
7023 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7024 Spacing * 2));
7025 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7026 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7027 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7028 TmpInst.addOperand(Inst.getOperand(4));
7029 Inst = TmpInst;
7030 return true;
7031 }
7032
7033 case ARM::VLD3DUPdWB_fixed_Asm_8:
7034 case ARM::VLD3DUPdWB_fixed_Asm_16:
7035 case ARM::VLD3DUPdWB_fixed_Asm_32:
7036 case ARM::VLD3DUPqWB_fixed_Asm_8:
7037 case ARM::VLD3DUPqWB_fixed_Asm_16:
7038 case ARM::VLD3DUPqWB_fixed_Asm_32: {
7039 MCInst TmpInst;
7040 unsigned Spacing;
7041 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7042 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7043 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7044 Spacing));
7045 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7046 Spacing * 2));
7047 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7048 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7049 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7050 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7051 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7052 TmpInst.addOperand(Inst.getOperand(4));
7053 Inst = TmpInst;
7054 return true;
7055 }
7056
7057 case ARM::VLD3DUPdWB_register_Asm_8:
7058 case ARM::VLD3DUPdWB_register_Asm_16:
7059 case ARM::VLD3DUPdWB_register_Asm_32:
7060 case ARM::VLD3DUPqWB_register_Asm_8:
7061 case ARM::VLD3DUPqWB_register_Asm_16:
7062 case ARM::VLD3DUPqWB_register_Asm_32: {
7063 MCInst TmpInst;
7064 unsigned Spacing;
7065 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7066 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7067 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7068 Spacing));
7069 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7070 Spacing * 2));
7071 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7072 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7073 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7074 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7075 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7076 TmpInst.addOperand(Inst.getOperand(5));
7077 Inst = TmpInst;
7078 return true;
7079 }
7080
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007081 // VLD3 multiple 3-element structure instructions.
7082 case ARM::VLD3dAsm_8:
7083 case ARM::VLD3dAsm_16:
7084 case ARM::VLD3dAsm_32:
7085 case ARM::VLD3qAsm_8:
7086 case ARM::VLD3qAsm_16:
7087 case ARM::VLD3qAsm_32: {
7088 MCInst TmpInst;
7089 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007090 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007091 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7092 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7093 Spacing));
7094 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7095 Spacing * 2));
7096 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7097 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7098 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7099 TmpInst.addOperand(Inst.getOperand(4));
7100 Inst = TmpInst;
7101 return true;
7102 }
7103
7104 case ARM::VLD3dWB_fixed_Asm_8:
7105 case ARM::VLD3dWB_fixed_Asm_16:
7106 case ARM::VLD3dWB_fixed_Asm_32:
7107 case ARM::VLD3qWB_fixed_Asm_8:
7108 case ARM::VLD3qWB_fixed_Asm_16:
7109 case ARM::VLD3qWB_fixed_Asm_32: {
7110 MCInst TmpInst;
7111 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007112 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007113 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7114 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7115 Spacing));
7116 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7117 Spacing * 2));
7118 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7119 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7120 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7121 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7122 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7123 TmpInst.addOperand(Inst.getOperand(4));
7124 Inst = TmpInst;
7125 return true;
7126 }
7127
7128 case ARM::VLD3dWB_register_Asm_8:
7129 case ARM::VLD3dWB_register_Asm_16:
7130 case ARM::VLD3dWB_register_Asm_32:
7131 case ARM::VLD3qWB_register_Asm_8:
7132 case ARM::VLD3qWB_register_Asm_16:
7133 case ARM::VLD3qWB_register_Asm_32: {
7134 MCInst TmpInst;
7135 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007136 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007137 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7138 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7139 Spacing));
7140 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7141 Spacing * 2));
7142 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7143 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7144 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7145 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7146 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7147 TmpInst.addOperand(Inst.getOperand(5));
7148 Inst = TmpInst;
7149 return true;
7150 }
7151
Jim Grosbach086cbfa2012-01-25 00:01:08 +00007152 // VLD4DUP single 3-element structure to all lanes instructions.
7153 case ARM::VLD4DUPdAsm_8:
7154 case ARM::VLD4DUPdAsm_16:
7155 case ARM::VLD4DUPdAsm_32:
7156 case ARM::VLD4DUPqAsm_8:
7157 case ARM::VLD4DUPqAsm_16:
7158 case ARM::VLD4DUPqAsm_32: {
7159 MCInst TmpInst;
7160 unsigned Spacing;
7161 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7162 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7163 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7164 Spacing));
7165 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7166 Spacing * 2));
7167 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7168 Spacing * 3));
7169 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7170 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7171 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7172 TmpInst.addOperand(Inst.getOperand(4));
7173 Inst = TmpInst;
7174 return true;
7175 }
7176
7177 case ARM::VLD4DUPdWB_fixed_Asm_8:
7178 case ARM::VLD4DUPdWB_fixed_Asm_16:
7179 case ARM::VLD4DUPdWB_fixed_Asm_32:
7180 case ARM::VLD4DUPqWB_fixed_Asm_8:
7181 case ARM::VLD4DUPqWB_fixed_Asm_16:
7182 case ARM::VLD4DUPqWB_fixed_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(MCOperand::CreateReg(0)); // Rm
7197 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7198 TmpInst.addOperand(Inst.getOperand(4));
7199 Inst = TmpInst;
7200 return true;
7201 }
7202
7203 case ARM::VLD4DUPdWB_register_Asm_8:
7204 case ARM::VLD4DUPdWB_register_Asm_16:
7205 case ARM::VLD4DUPdWB_register_Asm_32:
7206 case ARM::VLD4DUPqWB_register_Asm_8:
7207 case ARM::VLD4DUPqWB_register_Asm_16:
7208 case ARM::VLD4DUPqWB_register_Asm_32: {
7209 MCInst TmpInst;
7210 unsigned Spacing;
7211 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7212 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7213 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7214 Spacing));
7215 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7216 Spacing * 2));
7217 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7218 Spacing * 3));
7219 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7220 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7221 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7222 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7223 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7224 TmpInst.addOperand(Inst.getOperand(5));
7225 Inst = TmpInst;
7226 return true;
7227 }
7228
7229 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00007230 case ARM::VLD4dAsm_8:
7231 case ARM::VLD4dAsm_16:
7232 case ARM::VLD4dAsm_32:
7233 case ARM::VLD4qAsm_8:
7234 case ARM::VLD4qAsm_16:
7235 case ARM::VLD4qAsm_32: {
7236 MCInst TmpInst;
7237 unsigned Spacing;
7238 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
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(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7245 Spacing * 3));
7246 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7247 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7248 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7249 TmpInst.addOperand(Inst.getOperand(4));
7250 Inst = TmpInst;
7251 return true;
7252 }
7253
7254 case ARM::VLD4dWB_fixed_Asm_8:
7255 case ARM::VLD4dWB_fixed_Asm_16:
7256 case ARM::VLD4dWB_fixed_Asm_32:
7257 case ARM::VLD4qWB_fixed_Asm_8:
7258 case ARM::VLD4qWB_fixed_Asm_16:
7259 case ARM::VLD4qWB_fixed_Asm_32: {
7260 MCInst TmpInst;
7261 unsigned Spacing;
7262 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
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(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7269 Spacing * 3));
7270 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7271 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7272 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7273 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7274 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7275 TmpInst.addOperand(Inst.getOperand(4));
7276 Inst = TmpInst;
7277 return true;
7278 }
7279
7280 case ARM::VLD4dWB_register_Asm_8:
7281 case ARM::VLD4dWB_register_Asm_16:
7282 case ARM::VLD4dWB_register_Asm_32:
7283 case ARM::VLD4qWB_register_Asm_8:
7284 case ARM::VLD4qWB_register_Asm_16:
7285 case ARM::VLD4qWB_register_Asm_32: {
7286 MCInst TmpInst;
7287 unsigned Spacing;
7288 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7289 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7290 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7291 Spacing));
7292 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7293 Spacing * 2));
7294 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7295 Spacing * 3));
7296 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7297 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7298 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7299 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7300 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7301 TmpInst.addOperand(Inst.getOperand(5));
7302 Inst = TmpInst;
7303 return true;
7304 }
7305
Jim Grosbach1a747242012-01-23 23:45:44 +00007306 // VST3 multiple 3-element structure instructions.
7307 case ARM::VST3dAsm_8:
7308 case ARM::VST3dAsm_16:
7309 case ARM::VST3dAsm_32:
7310 case ARM::VST3qAsm_8:
7311 case ARM::VST3qAsm_16:
7312 case ARM::VST3qAsm_32: {
7313 MCInst TmpInst;
7314 unsigned Spacing;
7315 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7316 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7317 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7318 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7319 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7320 Spacing));
7321 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7322 Spacing * 2));
7323 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7324 TmpInst.addOperand(Inst.getOperand(4));
7325 Inst = TmpInst;
7326 return true;
7327 }
7328
7329 case ARM::VST3dWB_fixed_Asm_8:
7330 case ARM::VST3dWB_fixed_Asm_16:
7331 case ARM::VST3dWB_fixed_Asm_32:
7332 case ARM::VST3qWB_fixed_Asm_8:
7333 case ARM::VST3qWB_fixed_Asm_16:
7334 case ARM::VST3qWB_fixed_Asm_32: {
7335 MCInst TmpInst;
7336 unsigned Spacing;
7337 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7338 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7339 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7340 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7341 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7342 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7343 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7344 Spacing));
7345 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7346 Spacing * 2));
7347 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7348 TmpInst.addOperand(Inst.getOperand(4));
7349 Inst = TmpInst;
7350 return true;
7351 }
7352
7353 case ARM::VST3dWB_register_Asm_8:
7354 case ARM::VST3dWB_register_Asm_16:
7355 case ARM::VST3dWB_register_Asm_32:
7356 case ARM::VST3qWB_register_Asm_8:
7357 case ARM::VST3qWB_register_Asm_16:
7358 case ARM::VST3qWB_register_Asm_32: {
7359 MCInst TmpInst;
7360 unsigned Spacing;
7361 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7362 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7363 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7364 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7365 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7366 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7367 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7368 Spacing));
7369 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7370 Spacing * 2));
7371 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7372 TmpInst.addOperand(Inst.getOperand(5));
7373 Inst = TmpInst;
7374 return true;
7375 }
7376
Jim Grosbachda70eac2012-01-24 00:58:13 +00007377 // VST4 multiple 3-element structure instructions.
7378 case ARM::VST4dAsm_8:
7379 case ARM::VST4dAsm_16:
7380 case ARM::VST4dAsm_32:
7381 case ARM::VST4qAsm_8:
7382 case ARM::VST4qAsm_16:
7383 case ARM::VST4qAsm_32: {
7384 MCInst TmpInst;
7385 unsigned Spacing;
7386 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7387 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7388 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7389 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7390 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7391 Spacing));
7392 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7393 Spacing * 2));
7394 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7395 Spacing * 3));
7396 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7397 TmpInst.addOperand(Inst.getOperand(4));
7398 Inst = TmpInst;
7399 return true;
7400 }
7401
7402 case ARM::VST4dWB_fixed_Asm_8:
7403 case ARM::VST4dWB_fixed_Asm_16:
7404 case ARM::VST4dWB_fixed_Asm_32:
7405 case ARM::VST4qWB_fixed_Asm_8:
7406 case ARM::VST4qWB_fixed_Asm_16:
7407 case ARM::VST4qWB_fixed_Asm_32: {
7408 MCInst TmpInst;
7409 unsigned Spacing;
7410 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7411 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7412 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7413 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7414 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7415 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7416 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7417 Spacing));
7418 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7419 Spacing * 2));
7420 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7421 Spacing * 3));
7422 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7423 TmpInst.addOperand(Inst.getOperand(4));
7424 Inst = TmpInst;
7425 return true;
7426 }
7427
7428 case ARM::VST4dWB_register_Asm_8:
7429 case ARM::VST4dWB_register_Asm_16:
7430 case ARM::VST4dWB_register_Asm_32:
7431 case ARM::VST4qWB_register_Asm_8:
7432 case ARM::VST4qWB_register_Asm_16:
7433 case ARM::VST4qWB_register_Asm_32: {
7434 MCInst TmpInst;
7435 unsigned Spacing;
7436 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7437 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7438 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7439 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7440 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7441 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7442 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7443 Spacing));
7444 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7445 Spacing * 2));
7446 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7447 Spacing * 3));
7448 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7449 TmpInst.addOperand(Inst.getOperand(5));
7450 Inst = TmpInst;
7451 return true;
7452 }
7453
Jim Grosbachad66de12012-04-11 00:15:16 +00007454 // Handle encoding choice for the shift-immediate instructions.
7455 case ARM::t2LSLri:
7456 case ARM::t2LSRri:
7457 case ARM::t2ASRri: {
7458 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7459 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7460 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007461 !(static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7462 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) {
Jim Grosbachad66de12012-04-11 00:15:16 +00007463 unsigned NewOpc;
7464 switch (Inst.getOpcode()) {
7465 default: llvm_unreachable("unexpected opcode");
7466 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7467 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7468 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7469 }
7470 // The Thumb1 operands aren't in the same order. Awesome, eh?
7471 MCInst TmpInst;
7472 TmpInst.setOpcode(NewOpc);
7473 TmpInst.addOperand(Inst.getOperand(0));
7474 TmpInst.addOperand(Inst.getOperand(5));
7475 TmpInst.addOperand(Inst.getOperand(1));
7476 TmpInst.addOperand(Inst.getOperand(2));
7477 TmpInst.addOperand(Inst.getOperand(3));
7478 TmpInst.addOperand(Inst.getOperand(4));
7479 Inst = TmpInst;
7480 return true;
7481 }
7482 return false;
7483 }
7484
Jim Grosbach485e5622011-12-13 22:45:11 +00007485 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007486 case ARM::t2MOVsr:
7487 case ARM::t2MOVSsr: {
7488 // Which instruction to expand to depends on the CCOut operand and
7489 // whether we're in an IT block if the register operands are low
7490 // registers.
7491 bool isNarrow = false;
7492 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7493 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7494 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7495 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7496 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7497 isNarrow = true;
7498 MCInst TmpInst;
7499 unsigned newOpc;
7500 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7501 default: llvm_unreachable("unexpected opcode!");
7502 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7503 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7504 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7505 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7506 }
7507 TmpInst.setOpcode(newOpc);
7508 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7509 if (isNarrow)
7510 TmpInst.addOperand(MCOperand::CreateReg(
7511 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7512 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7513 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7514 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7515 TmpInst.addOperand(Inst.getOperand(5));
7516 if (!isNarrow)
7517 TmpInst.addOperand(MCOperand::CreateReg(
7518 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7519 Inst = TmpInst;
7520 return true;
7521 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007522 case ARM::t2MOVsi:
7523 case ARM::t2MOVSsi: {
7524 // Which instruction to expand to depends on the CCOut operand and
7525 // whether we're in an IT block if the register operands are low
7526 // registers.
7527 bool isNarrow = false;
7528 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7529 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7530 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7531 isNarrow = true;
7532 MCInst TmpInst;
7533 unsigned newOpc;
7534 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7535 default: llvm_unreachable("unexpected opcode!");
7536 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7537 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7538 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7539 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007540 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007541 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007542 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7543 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007544 TmpInst.setOpcode(newOpc);
7545 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7546 if (isNarrow)
7547 TmpInst.addOperand(MCOperand::CreateReg(
7548 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7549 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007550 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007551 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007552 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7553 TmpInst.addOperand(Inst.getOperand(4));
7554 if (!isNarrow)
7555 TmpInst.addOperand(MCOperand::CreateReg(
7556 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7557 Inst = TmpInst;
7558 return true;
7559 }
7560 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007561 case ARM::ASRr:
7562 case ARM::LSRr:
7563 case ARM::LSLr:
7564 case ARM::RORr: {
7565 ARM_AM::ShiftOpc ShiftTy;
7566 switch(Inst.getOpcode()) {
7567 default: llvm_unreachable("unexpected opcode!");
7568 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7569 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7570 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7571 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7572 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007573 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7574 MCInst TmpInst;
7575 TmpInst.setOpcode(ARM::MOVsr);
7576 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7577 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7578 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7579 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7580 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7581 TmpInst.addOperand(Inst.getOperand(4));
7582 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7583 Inst = TmpInst;
7584 return true;
7585 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007586 case ARM::ASRi:
7587 case ARM::LSRi:
7588 case ARM::LSLi:
7589 case ARM::RORi: {
7590 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007591 switch(Inst.getOpcode()) {
7592 default: llvm_unreachable("unexpected opcode!");
7593 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7594 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7595 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7596 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7597 }
7598 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007599 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007600 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007601 // A shift by 32 should be encoded as 0 when permitted
7602 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7603 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007604 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007605 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007606 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007607 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7608 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007609 if (Opc == ARM::MOVsi)
7610 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007611 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7612 TmpInst.addOperand(Inst.getOperand(4));
7613 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7614 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007615 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007616 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007617 case ARM::RRXi: {
7618 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7619 MCInst TmpInst;
7620 TmpInst.setOpcode(ARM::MOVsi);
7621 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7622 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7623 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7624 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7625 TmpInst.addOperand(Inst.getOperand(3));
7626 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7627 Inst = TmpInst;
7628 return true;
7629 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007630 case ARM::t2LDMIA_UPD: {
7631 // If this is a load of a single register, then we should use
7632 // a post-indexed LDR instruction instead, per the ARM ARM.
7633 if (Inst.getNumOperands() != 5)
7634 return false;
7635 MCInst TmpInst;
7636 TmpInst.setOpcode(ARM::t2LDR_POST);
7637 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7638 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7639 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7640 TmpInst.addOperand(MCOperand::CreateImm(4));
7641 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7642 TmpInst.addOperand(Inst.getOperand(3));
7643 Inst = TmpInst;
7644 return true;
7645 }
7646 case ARM::t2STMDB_UPD: {
7647 // If this is a store of a single register, then we should use
7648 // a pre-indexed STR instruction instead, per the ARM ARM.
7649 if (Inst.getNumOperands() != 5)
7650 return false;
7651 MCInst TmpInst;
7652 TmpInst.setOpcode(ARM::t2STR_PRE);
7653 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7654 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7655 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7656 TmpInst.addOperand(MCOperand::CreateImm(-4));
7657 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7658 TmpInst.addOperand(Inst.getOperand(3));
7659 Inst = TmpInst;
7660 return true;
7661 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007662 case ARM::LDMIA_UPD:
7663 // If this is a load of a single register via a 'pop', then we should use
7664 // a post-indexed LDR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00007665 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007666 Inst.getNumOperands() == 5) {
7667 MCInst TmpInst;
7668 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7669 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7670 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7671 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7672 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7673 TmpInst.addOperand(MCOperand::CreateImm(4));
7674 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7675 TmpInst.addOperand(Inst.getOperand(3));
7676 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007677 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007678 }
7679 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007680 case ARM::STMDB_UPD:
7681 // If this is a store of a single register via a 'push', then we should use
7682 // a pre-indexed STR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00007683 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007684 Inst.getNumOperands() == 5) {
7685 MCInst TmpInst;
7686 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7687 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7688 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7689 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7690 TmpInst.addOperand(MCOperand::CreateImm(-4));
7691 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7692 TmpInst.addOperand(Inst.getOperand(3));
7693 Inst = TmpInst;
7694 }
7695 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007696 case ARM::t2ADDri12:
7697 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7698 // mnemonic was used (not "addw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00007699 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00007700 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7701 break;
7702 Inst.setOpcode(ARM::t2ADDri);
7703 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7704 break;
7705 case ARM::t2SUBri12:
7706 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7707 // mnemonic was used (not "subw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00007708 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00007709 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7710 break;
7711 Inst.setOpcode(ARM::t2SUBri);
7712 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7713 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007714 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007715 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007716 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7717 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7718 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007719 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007720 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007721 return true;
7722 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007723 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007724 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007725 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007726 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7727 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7728 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007729 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007730 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007731 return true;
7732 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007733 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007734 case ARM::t2ADDri:
7735 case ARM::t2SUBri: {
7736 // If the destination and first source operand are the same, and
7737 // the flags are compatible with the current IT status, use encoding T2
7738 // instead of T3. For compatibility with the system 'as'. Make sure the
7739 // wide encoding wasn't explicit.
7740 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007741 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007742 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7743 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00007744 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7745 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7746 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbachdef5e342012-03-30 17:20:40 +00007747 break;
7748 MCInst TmpInst;
7749 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7750 ARM::tADDi8 : ARM::tSUBi8);
7751 TmpInst.addOperand(Inst.getOperand(0));
7752 TmpInst.addOperand(Inst.getOperand(5));
7753 TmpInst.addOperand(Inst.getOperand(0));
7754 TmpInst.addOperand(Inst.getOperand(2));
7755 TmpInst.addOperand(Inst.getOperand(3));
7756 TmpInst.addOperand(Inst.getOperand(4));
7757 Inst = TmpInst;
7758 return true;
7759 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007760 case ARM::t2ADDrr: {
7761 // If the destination and first source operand are the same, and
7762 // there's no setting of the flags, use encoding T2 instead of T3.
7763 // Note that this is only for ADD, not SUB. This mirrors the system
7764 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7765 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7766 Inst.getOperand(5).getReg() != 0 ||
David Blaikie960ea3f2014-06-08 16:18:35 +00007767 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7768 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007769 break;
7770 MCInst TmpInst;
7771 TmpInst.setOpcode(ARM::tADDhirr);
7772 TmpInst.addOperand(Inst.getOperand(0));
7773 TmpInst.addOperand(Inst.getOperand(0));
7774 TmpInst.addOperand(Inst.getOperand(2));
7775 TmpInst.addOperand(Inst.getOperand(3));
7776 TmpInst.addOperand(Inst.getOperand(4));
7777 Inst = TmpInst;
7778 return true;
7779 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007780 case ARM::tADDrSP: {
7781 // If the non-SP source operand and the destination operand are not the
7782 // same, we need to use the 32-bit encoding if it's available.
7783 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7784 Inst.setOpcode(ARM::t2ADDrr);
7785 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7786 return true;
7787 }
7788 break;
7789 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007790 case ARM::tB:
7791 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007792 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007793 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007794 return true;
7795 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007796 break;
7797 case ARM::t2B:
7798 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007799 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007800 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007801 return true;
7802 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007803 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007804 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007805 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007806 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007807 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007808 return true;
7809 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007810 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007811 case ARM::tBcc:
7812 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007813 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007814 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007815 return true;
7816 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007817 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007818 case ARM::tLDMIA: {
7819 // If the register list contains any high registers, or if the writeback
7820 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7821 // instead if we're in Thumb2. Otherwise, this should have generated
7822 // an error in validateInstruction().
7823 unsigned Rn = Inst.getOperand(0).getReg();
7824 bool hasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00007825 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7826 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Jim Grosbacha31f2232011-09-07 18:05:34 +00007827 bool listContainsBase;
7828 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7829 (!listContainsBase && !hasWritebackToken) ||
7830 (listContainsBase && hasWritebackToken)) {
7831 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7832 assert (isThumbTwo());
7833 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7834 // If we're switching to the updating version, we need to insert
7835 // the writeback tied operand.
7836 if (hasWritebackToken)
7837 Inst.insert(Inst.begin(),
7838 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007839 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007840 }
7841 break;
7842 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007843 case ARM::tSTMIA_UPD: {
7844 // If the register list contains any high registers, we need to use
7845 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7846 // should have generated an error in validateInstruction().
7847 unsigned Rn = Inst.getOperand(0).getReg();
7848 bool listContainsBase;
7849 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7850 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7851 assert (isThumbTwo());
7852 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007853 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007854 }
7855 break;
7856 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007857 case ARM::tPOP: {
7858 bool listContainsBase;
7859 // If the register list contains any high registers, we need to use
7860 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7861 // should have generated an error in validateInstruction().
7862 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007863 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007864 assert (isThumbTwo());
7865 Inst.setOpcode(ARM::t2LDMIA_UPD);
7866 // Add the base register and writeback operands.
7867 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7868 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007869 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007870 }
7871 case ARM::tPUSH: {
7872 bool listContainsBase;
7873 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007874 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007875 assert (isThumbTwo());
7876 Inst.setOpcode(ARM::t2STMDB_UPD);
7877 // Add the base register and writeback operands.
7878 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7879 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007880 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007881 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007882 case ARM::t2MOVi: {
7883 // If we can use the 16-bit encoding and the user didn't explicitly
7884 // request the 32-bit variant, transform it here.
7885 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007886 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007887 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007888 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7889 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7890 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
7891 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007892 // The operands aren't in the same order for tMOVi8...
7893 MCInst TmpInst;
7894 TmpInst.setOpcode(ARM::tMOVi8);
7895 TmpInst.addOperand(Inst.getOperand(0));
7896 TmpInst.addOperand(Inst.getOperand(4));
7897 TmpInst.addOperand(Inst.getOperand(1));
7898 TmpInst.addOperand(Inst.getOperand(2));
7899 TmpInst.addOperand(Inst.getOperand(3));
7900 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007901 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007902 }
7903 break;
7904 }
7905 case ARM::t2MOVr: {
7906 // If we can use the 16-bit encoding and the user didn't explicitly
7907 // request the 32-bit variant, transform it here.
7908 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7909 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7910 Inst.getOperand(2).getImm() == ARMCC::AL &&
7911 Inst.getOperand(4).getReg() == ARM::CPSR &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007912 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
7913 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007914 // The operands aren't the same for tMOV[S]r... (no cc_out)
7915 MCInst TmpInst;
7916 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7917 TmpInst.addOperand(Inst.getOperand(0));
7918 TmpInst.addOperand(Inst.getOperand(1));
7919 TmpInst.addOperand(Inst.getOperand(2));
7920 TmpInst.addOperand(Inst.getOperand(3));
7921 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007922 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007923 }
7924 break;
7925 }
Jim Grosbach82213192011-09-19 20:29:33 +00007926 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007927 case ARM::t2SXTB:
7928 case ARM::t2UXTH:
7929 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007930 // If we can use the 16-bit encoding and the user didn't explicitly
7931 // request the 32-bit variant, transform it here.
7932 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7933 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7934 Inst.getOperand(2).getImm() == 0 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007935 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
7936 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007937 unsigned NewOpc;
7938 switch (Inst.getOpcode()) {
7939 default: llvm_unreachable("Illegal opcode!");
7940 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7941 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7942 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7943 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7944 }
Jim Grosbach82213192011-09-19 20:29:33 +00007945 // The operands aren't the same for thumb1 (no rotate operand).
7946 MCInst TmpInst;
7947 TmpInst.setOpcode(NewOpc);
7948 TmpInst.addOperand(Inst.getOperand(0));
7949 TmpInst.addOperand(Inst.getOperand(1));
7950 TmpInst.addOperand(Inst.getOperand(3));
7951 TmpInst.addOperand(Inst.getOperand(4));
7952 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007953 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007954 }
7955 break;
7956 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007957 case ARM::MOVsi: {
7958 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007959 // rrx shifts and asr/lsr of #32 is encoded as 0
7960 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7961 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007962 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7963 // Shifting by zero is accepted as a vanilla 'MOVr'
7964 MCInst TmpInst;
7965 TmpInst.setOpcode(ARM::MOVr);
7966 TmpInst.addOperand(Inst.getOperand(0));
7967 TmpInst.addOperand(Inst.getOperand(1));
7968 TmpInst.addOperand(Inst.getOperand(3));
7969 TmpInst.addOperand(Inst.getOperand(4));
7970 TmpInst.addOperand(Inst.getOperand(5));
7971 Inst = TmpInst;
7972 return true;
7973 }
7974 return false;
7975 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007976 case ARM::ANDrsi:
7977 case ARM::ORRrsi:
7978 case ARM::EORrsi:
7979 case ARM::BICrsi:
7980 case ARM::SUBrsi:
7981 case ARM::ADDrsi: {
7982 unsigned newOpc;
7983 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7984 if (SOpc == ARM_AM::rrx) return false;
7985 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007986 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007987 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7988 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7989 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7990 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7991 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7992 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7993 }
7994 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007995 // The exception is for right shifts, where 0 == 32
7996 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7997 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007998 MCInst TmpInst;
7999 TmpInst.setOpcode(newOpc);
8000 TmpInst.addOperand(Inst.getOperand(0));
8001 TmpInst.addOperand(Inst.getOperand(1));
8002 TmpInst.addOperand(Inst.getOperand(2));
8003 TmpInst.addOperand(Inst.getOperand(4));
8004 TmpInst.addOperand(Inst.getOperand(5));
8005 TmpInst.addOperand(Inst.getOperand(6));
8006 Inst = TmpInst;
8007 return true;
8008 }
8009 return false;
8010 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00008011 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008012 case ARM::t2IT: {
8013 // The mask bits for all but the first condition are represented as
8014 // the low bit of the condition code value implies 't'. We currently
8015 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00008016 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008017 MCOperand &MO = Inst.getOperand(1);
8018 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00008019 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00008020 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008021 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008022 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00008023 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00008024 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008025 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00008026
8027 // Set up the IT block state according to the IT instruction we just
8028 // matched.
8029 assert(!inITBlock() && "nested IT blocks?!");
8030 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
8031 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
8032 ITState.CurPosition = 0;
8033 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008034 break;
8035 }
Richard Bartona39625e2012-07-09 16:12:24 +00008036 case ARM::t2LSLrr:
8037 case ARM::t2LSRrr:
8038 case ARM::t2ASRrr:
8039 case ARM::t2SBCrr:
8040 case ARM::t2RORrr:
8041 case ARM::t2BICrr:
8042 {
Richard Bartond5660372012-07-09 16:14:28 +00008043 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008044 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8045 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8046 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008047 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008048 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8049 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8050 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8051 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008052 unsigned NewOpc;
8053 switch (Inst.getOpcode()) {
8054 default: llvm_unreachable("unexpected opcode");
8055 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
8056 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
8057 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
8058 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
8059 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
8060 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
8061 }
8062 MCInst TmpInst;
8063 TmpInst.setOpcode(NewOpc);
8064 TmpInst.addOperand(Inst.getOperand(0));
8065 TmpInst.addOperand(Inst.getOperand(5));
8066 TmpInst.addOperand(Inst.getOperand(1));
8067 TmpInst.addOperand(Inst.getOperand(2));
8068 TmpInst.addOperand(Inst.getOperand(3));
8069 TmpInst.addOperand(Inst.getOperand(4));
8070 Inst = TmpInst;
8071 return true;
8072 }
8073 return false;
8074 }
8075 case ARM::t2ANDrr:
8076 case ARM::t2EORrr:
8077 case ARM::t2ADCrr:
8078 case ARM::t2ORRrr:
8079 {
Richard Bartond5660372012-07-09 16:14:28 +00008080 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008081 // These instructions are special in that they are commutable, so shorter encodings
8082 // are available more often.
8083 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8084 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8085 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
8086 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008087 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008088 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8089 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8090 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8091 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008092 unsigned NewOpc;
8093 switch (Inst.getOpcode()) {
8094 default: llvm_unreachable("unexpected opcode");
8095 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
8096 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
8097 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
8098 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
8099 }
8100 MCInst TmpInst;
8101 TmpInst.setOpcode(NewOpc);
8102 TmpInst.addOperand(Inst.getOperand(0));
8103 TmpInst.addOperand(Inst.getOperand(5));
8104 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
8105 TmpInst.addOperand(Inst.getOperand(1));
8106 TmpInst.addOperand(Inst.getOperand(2));
8107 } else {
8108 TmpInst.addOperand(Inst.getOperand(2));
8109 TmpInst.addOperand(Inst.getOperand(1));
8110 }
8111 TmpInst.addOperand(Inst.getOperand(3));
8112 TmpInst.addOperand(Inst.getOperand(4));
8113 Inst = TmpInst;
8114 return true;
8115 }
8116 return false;
8117 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008118 }
Jim Grosbachafad0532011-11-10 23:42:14 +00008119 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008120}
8121
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008122unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
8123 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
8124 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008125 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00008126 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008127 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
8128 assert(MCID.hasOptionalDef() &&
8129 "optionally flag setting instruction missing optional def operand");
8130 assert(MCID.NumOperands == Inst.getNumOperands() &&
8131 "operand count mismatch!");
8132 // Find the optional-def operand (cc_out).
8133 unsigned OpNo;
8134 for (OpNo = 0;
8135 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
8136 ++OpNo)
8137 ;
8138 // If we're parsing Thumb1, reject it completely.
8139 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
8140 return Match_MnemonicFail;
8141 // If we're parsing Thumb2, which form is legal depends on whether we're
8142 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00008143 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
8144 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008145 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00008146 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8147 inITBlock())
8148 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008149 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008150 // Some high-register supporting Thumb1 encodings only allow both registers
8151 // to be from r0-r7 when in Thumb2.
8152 else if (Opc == ARM::tADDhirr && isThumbOne() &&
8153 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8154 isARMLowRegister(Inst.getOperand(2).getReg()))
8155 return Match_RequiresThumb2;
8156 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00008157 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008158 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8159 isARMLowRegister(Inst.getOperand(1).getReg()))
8160 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008161 return Match_Success;
8162}
8163
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008164namespace llvm {
8165template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008166 return true; // In an assembly source, no need to second-guess
8167}
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008168}
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008169
Tim Northover26bb14e2014-08-18 11:49:42 +00008170static const char *getSubtargetFeatureName(uint64_t Val);
David Blaikie960ea3f2014-06-08 16:18:35 +00008171bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
8172 OperandVector &Operands,
Tim Northover26bb14e2014-08-18 11:49:42 +00008173 MCStreamer &Out, uint64_t &ErrorInfo,
David Blaikie960ea3f2014-06-08 16:18:35 +00008174 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00008175 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00008176 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00008177
Chad Rosier2f480a82012-10-12 22:53:36 +00008178 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00008179 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00008180 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00008181 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008182 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008183 // Context sensitive operand constraints aren't handled by the matcher,
8184 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008185 if (validateInstruction(Inst, Operands)) {
8186 // Still progress the IT block, otherwise one wrong condition causes
8187 // nasty cascading errors.
8188 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008189 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008190 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008191
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008192 { // processInstruction() updates inITBlock state, we need to save it away
8193 bool wasInITBlock = inITBlock();
8194
8195 // Some instructions need post-processing to, for example, tweak which
8196 // encoding is selected. Loop on it while changes happen so the
8197 // individual transformations can chain off each other. E.g.,
8198 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
8199 while (processInstruction(Inst, Operands))
8200 ;
8201
8202 // Only after the instruction is fully processed, we can validate it
8203 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00008204 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008205 Warning(IDLoc, "deprecated instruction in IT block");
8206 }
8207 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008208
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008209 // Only move forward at the very end so that everything in validate
8210 // and process gets a consistent answer about whether we're in an IT
8211 // block.
8212 forwardITPosition();
8213
Jim Grosbach82f76d12012-01-25 19:52:01 +00008214 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8215 // doesn't actually encode.
8216 if (Inst.getOpcode() == ARM::ITasm)
8217 return false;
8218
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00008219 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00008220 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00008221 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008222 case Match_MissingFeature: {
8223 assert(ErrorInfo && "Unknown missing feature!");
8224 // Special case the error message for the very common case where only
8225 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8226 std::string Msg = "instruction requires:";
Tim Northover26bb14e2014-08-18 11:49:42 +00008227 uint64_t Mask = 1;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008228 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8229 if (ErrorInfo & Mask) {
8230 Msg += " ";
8231 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8232 }
8233 Mask <<= 1;
8234 }
8235 return Error(IDLoc, Msg);
8236 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008237 case Match_InvalidOperand: {
8238 SMLoc ErrorLoc = IDLoc;
Tim Northover26bb14e2014-08-18 11:49:42 +00008239 if (ErrorInfo != ~0ULL) {
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008240 if (ErrorInfo >= Operands.size())
8241 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00008242
David Blaikie960ea3f2014-06-08 16:18:35 +00008243 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008244 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8245 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008246
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008247 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00008248 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008249 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00008250 return Error(IDLoc, "invalid instruction",
David Blaikie960ea3f2014-06-08 16:18:35 +00008251 ((ARMOperand &)*Operands[0]).getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00008252 case Match_RequiresNotITBlock:
8253 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008254 case Match_RequiresITBlock:
8255 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008256 case Match_RequiresV6:
8257 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8258 case Match_RequiresThumb2:
8259 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00008260 case Match_ImmRange0_15: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008261 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Jim Grosbach087affe2012-06-22 23:56:48 +00008262 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8263 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8264 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008265 case Match_ImmRange0_239: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008266 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008267 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8268 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8269 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00008270 case Match_AlignedMemoryRequiresNone:
8271 case Match_DupAlignedMemoryRequiresNone:
8272 case Match_AlignedMemoryRequires16:
8273 case Match_DupAlignedMemoryRequires16:
8274 case Match_AlignedMemoryRequires32:
8275 case Match_DupAlignedMemoryRequires32:
8276 case Match_AlignedMemoryRequires64:
8277 case Match_DupAlignedMemoryRequires64:
8278 case Match_AlignedMemoryRequires64or128:
8279 case Match_DupAlignedMemoryRequires64or128:
8280 case Match_AlignedMemoryRequires64or128or256:
8281 {
David Blaikie960ea3f2014-06-08 16:18:35 +00008282 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00008283 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8284 switch (MatchResult) {
8285 default:
8286 llvm_unreachable("Missing Match_Aligned type");
8287 case Match_AlignedMemoryRequiresNone:
8288 case Match_DupAlignedMemoryRequiresNone:
8289 return Error(ErrorLoc, "alignment must be omitted");
8290 case Match_AlignedMemoryRequires16:
8291 case Match_DupAlignedMemoryRequires16:
8292 return Error(ErrorLoc, "alignment must be 16 or omitted");
8293 case Match_AlignedMemoryRequires32:
8294 case Match_DupAlignedMemoryRequires32:
8295 return Error(ErrorLoc, "alignment must be 32 or omitted");
8296 case Match_AlignedMemoryRequires64:
8297 case Match_DupAlignedMemoryRequires64:
8298 return Error(ErrorLoc, "alignment must be 64 or omitted");
8299 case Match_AlignedMemoryRequires64or128:
8300 case Match_DupAlignedMemoryRequires64or128:
8301 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8302 case Match_AlignedMemoryRequires64or128or256:
8303 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8304 }
8305 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008306 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008307
Eric Christopher91d7b902010-10-29 09:26:59 +00008308 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00008309}
8310
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008311/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00008312bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008313 const MCObjectFileInfo::Environment Format =
8314 getContext().getObjectFileInfo()->getObjectFileType();
8315 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
8316
Kevin Enderbyccab3172009-09-15 00:27:25 +00008317 StringRef IDVal = DirectiveID.getIdentifier();
8318 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008319 return parseLiteralValues(4, DirectiveID.getLoc());
8320 else if (IDVal == ".short" || IDVal == ".hword")
8321 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008322 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008323 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00008324 else if (IDVal == ".arm")
8325 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008326 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008327 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008328 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008329 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008330 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008331 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008332 else if (IDVal == ".unreq")
8333 return parseDirectiveUnreq(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00008334 else if (IDVal == ".fnend")
8335 return parseDirectiveFnEnd(DirectiveID.getLoc());
8336 else if (IDVal == ".cantunwind")
8337 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8338 else if (IDVal == ".personality")
8339 return parseDirectivePersonality(DirectiveID.getLoc());
8340 else if (IDVal == ".handlerdata")
8341 return parseDirectiveHandlerData(DirectiveID.getLoc());
8342 else if (IDVal == ".setfp")
8343 return parseDirectiveSetFP(DirectiveID.getLoc());
8344 else if (IDVal == ".pad")
8345 return parseDirectivePad(DirectiveID.getLoc());
8346 else if (IDVal == ".save")
8347 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8348 else if (IDVal == ".vsave")
8349 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008350 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008351 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008352 else if (IDVal == ".even")
8353 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008354 else if (IDVal == ".personalityindex")
8355 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008356 else if (IDVal == ".unwind_raw")
8357 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008358 else if (IDVal == ".movsp")
8359 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008360 else if (IDVal == ".arch_extension")
8361 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008362 else if (IDVal == ".align")
8363 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008364 else if (IDVal == ".thumb_set")
8365 return parseDirectiveThumbSet(DirectiveID.getLoc());
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008366
8367 if (!IsMachO) {
8368 if (IDVal == ".arch")
8369 return parseDirectiveArch(DirectiveID.getLoc());
8370 else if (IDVal == ".cpu")
8371 return parseDirectiveCPU(DirectiveID.getLoc());
8372 else if (IDVal == ".eabi_attribute")
8373 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8374 else if (IDVal == ".fpu")
8375 return parseDirectiveFPU(DirectiveID.getLoc());
8376 else if (IDVal == ".fnstart")
8377 return parseDirectiveFnStart(DirectiveID.getLoc());
8378 else if (IDVal == ".inst")
8379 return parseDirectiveInst(DirectiveID.getLoc());
8380 else if (IDVal == ".inst.n")
8381 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8382 else if (IDVal == ".inst.w")
8383 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8384 else if (IDVal == ".object_arch")
8385 return parseDirectiveObjectArch(DirectiveID.getLoc());
8386 else if (IDVal == ".tlsdescseq")
8387 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8388 }
8389
Kevin Enderbyccab3172009-09-15 00:27:25 +00008390 return true;
8391}
8392
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008393/// parseLiteralValues
8394/// ::= .hword expression [, expression]*
8395/// ::= .short expression [, expression]*
8396/// ::= .word expression [, expression]*
8397bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00008398 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8399 for (;;) {
8400 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008401 if (getParser().parseExpression(Value)) {
8402 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008403 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008404 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008405
Eric Christopherbf7bc492013-01-09 03:52:05 +00008406 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008407
8408 if (getLexer().is(AsmToken::EndOfStatement))
8409 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008410
Kevin Enderbyccab3172009-09-15 00:27:25 +00008411 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008412 if (getLexer().isNot(AsmToken::Comma)) {
8413 Error(L, "unexpected token in directive");
8414 return false;
8415 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008416 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008417 }
8418 }
8419
Sean Callanana83fd7d2010-01-19 20:27:46 +00008420 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008421 return false;
8422}
8423
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008424/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008425/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008426bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008427 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8428 Error(L, "unexpected token in directive");
8429 return false;
8430 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008431 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008432
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008433 if (!hasThumb()) {
8434 Error(L, "target does not support Thumb mode");
8435 return false;
8436 }
Tim Northovera2292d02013-06-10 23:20:58 +00008437
Jim Grosbach7f882392011-12-07 18:04:19 +00008438 if (!isThumb())
8439 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008440
Jim Grosbach7f882392011-12-07 18:04:19 +00008441 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8442 return false;
8443}
8444
8445/// parseDirectiveARM
8446/// ::= .arm
8447bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008448 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8449 Error(L, "unexpected token in directive");
8450 return false;
8451 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008452 Parser.Lex();
8453
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008454 if (!hasARM()) {
8455 Error(L, "target does not support ARM mode");
8456 return false;
8457 }
Tim Northovera2292d02013-06-10 23:20:58 +00008458
Jim Grosbach7f882392011-12-07 18:04:19 +00008459 if (isThumb())
8460 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008461
Jim Grosbach7f882392011-12-07 18:04:19 +00008462 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008463 return false;
8464}
8465
Tim Northover1744d0a2013-10-25 12:49:50 +00008466void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8467 if (NextSymbolIsThumb) {
8468 getParser().getStreamer().EmitThumbFunc(Symbol);
8469 NextSymbolIsThumb = false;
8470 }
8471}
8472
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008473/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008474/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008475bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00008476 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8477 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008478
Jim Grosbach1152cc02011-12-21 22:30:16 +00008479 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008480 // ELF doesn't
8481 if (isMachO) {
8482 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008483 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008484 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8485 Error(L, "unexpected token in .thumb_func directive");
8486 return false;
8487 }
8488
Tim Northover1744d0a2013-10-25 12:49:50 +00008489 MCSymbol *Func =
8490 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8491 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008492 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008493 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008494 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008495 }
8496
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008497 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8498 Error(L, "unexpected token in directive");
8499 return false;
8500 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008501
Tim Northover1744d0a2013-10-25 12:49:50 +00008502 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008503 return false;
8504}
8505
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008506/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008507/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008508bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008509 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008510 if (Tok.isNot(AsmToken::Identifier)) {
8511 Error(L, "unexpected token in .syntax directive");
8512 return false;
8513 }
8514
Benjamin Kramer92d89982010-07-14 22:38:02 +00008515 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008516 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008517 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008518 } else if (Mode == "divided" || Mode == "DIVIDED") {
8519 Error(L, "'.syntax divided' arm asssembly not supported");
8520 return false;
8521 } else {
8522 Error(L, "unrecognized syntax mode in .syntax directive");
8523 return false;
8524 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008525
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008526 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8527 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8528 return false;
8529 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008530 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008531
8532 // TODO tell the MC streamer the mode
8533 // getParser().getStreamer().Emit???();
8534 return false;
8535}
8536
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008537/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008538/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008539bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008540 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008541 if (Tok.isNot(AsmToken::Integer)) {
8542 Error(L, "unexpected token in .code directive");
8543 return false;
8544 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008545 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008546 if (Val != 16 && Val != 32) {
8547 Error(L, "invalid operand to .code directive");
8548 return false;
8549 }
8550 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008551
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008552 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8553 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8554 return false;
8555 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008556 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008557
Evan Cheng284b4672011-07-08 22:36:29 +00008558 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008559 if (!hasThumb()) {
8560 Error(L, "target does not support Thumb mode");
8561 return false;
8562 }
Tim Northovera2292d02013-06-10 23:20:58 +00008563
Jim Grosbachf471ac32011-09-06 18:46:23 +00008564 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008565 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008566 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008567 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008568 if (!hasARM()) {
8569 Error(L, "target does not support ARM mode");
8570 return false;
8571 }
Tim Northovera2292d02013-06-10 23:20:58 +00008572
Jim Grosbachf471ac32011-09-06 18:46:23 +00008573 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008574 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008575 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008576 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008577
Kevin Enderby146dcf22009-10-15 20:48:48 +00008578 return false;
8579}
8580
Jim Grosbachab5830e2011-12-14 02:16:11 +00008581/// parseDirectiveReq
8582/// ::= name .req registername
8583bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8584 Parser.Lex(); // Eat the '.req' token.
8585 unsigned Reg;
8586 SMLoc SRegLoc, ERegLoc;
8587 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008588 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008589 Error(SRegLoc, "register name expected");
8590 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008591 }
8592
8593 // Shouldn't be anything else.
8594 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008595 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008596 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8597 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008598 }
8599
8600 Parser.Lex(); // Consume the EndOfStatement
8601
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008602 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) {
8603 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8604 return false;
8605 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00008606
8607 return false;
8608}
8609
8610/// parseDirectiveUneq
8611/// ::= .unreq registername
8612bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8613 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008614 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008615 Error(L, "unexpected input in .unreq directive.");
8616 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008617 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00008618 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008619 Parser.Lex(); // Eat the identifier.
8620 return false;
8621}
8622
Jason W Kim135d2442011-12-20 17:38:12 +00008623/// parseDirectiveArch
8624/// ::= .arch token
8625bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00008626 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8627
8628 unsigned ID = StringSwitch<unsigned>(Arch)
8629#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8630 .Case(NAME, ARM::ID)
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +00008631#define ARM_ARCH_ALIAS(NAME, ID) \
8632 .Case(NAME, ARM::ID)
Logan Chien439e8f92013-12-11 17:16:25 +00008633#include "MCTargetDesc/ARMArchName.def"
8634 .Default(ARM::INVALID_ARCH);
8635
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008636 if (ID == ARM::INVALID_ARCH) {
8637 Error(L, "Unknown arch name");
8638 return false;
8639 }
Logan Chien439e8f92013-12-11 17:16:25 +00008640
8641 getTargetStreamer().emitArch(ID);
8642 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008643}
8644
8645/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008646/// ::= .eabi_attribute int, int [, "str"]
8647/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00008648bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008649 int64_t Tag;
8650 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008651 TagLoc = Parser.getTok().getLoc();
8652 if (Parser.getTok().is(AsmToken::Identifier)) {
8653 StringRef Name = Parser.getTok().getIdentifier();
8654 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
8655 if (Tag == -1) {
8656 Error(TagLoc, "attribute name not recognised: " + Name);
8657 Parser.eatToEndOfStatement();
8658 return false;
8659 }
8660 Parser.Lex();
8661 } else {
8662 const MCExpr *AttrExpr;
8663
8664 TagLoc = Parser.getTok().getLoc();
8665 if (Parser.parseExpression(AttrExpr)) {
8666 Parser.eatToEndOfStatement();
8667 return false;
8668 }
8669
8670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
8671 if (!CE) {
8672 Error(TagLoc, "expected numeric constant");
8673 Parser.eatToEndOfStatement();
8674 return false;
8675 }
8676
8677 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008678 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008679
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008680 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008681 Error(Parser.getTok().getLoc(), "comma expected");
8682 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008683 return false;
8684 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008685 Parser.Lex(); // skip comma
8686
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008687 StringRef StringValue = "";
8688 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00008689
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008690 int64_t IntegerValue = 0;
8691 bool IsIntegerValue = false;
8692
8693 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
8694 IsStringValue = true;
8695 else if (Tag == ARMBuildAttrs::compatibility) {
8696 IsStringValue = true;
8697 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00008698 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008699 IsIntegerValue = true;
8700 else if (Tag % 2 == 1)
8701 IsStringValue = true;
8702 else
8703 llvm_unreachable("invalid tag type");
8704
8705 if (IsIntegerValue) {
8706 const MCExpr *ValueExpr;
8707 SMLoc ValueExprLoc = Parser.getTok().getLoc();
8708 if (Parser.parseExpression(ValueExpr)) {
8709 Parser.eatToEndOfStatement();
8710 return false;
8711 }
8712
8713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
8714 if (!CE) {
8715 Error(ValueExprLoc, "expected numeric constant");
8716 Parser.eatToEndOfStatement();
8717 return false;
8718 }
8719
8720 IntegerValue = CE->getValue();
8721 }
8722
8723 if (Tag == ARMBuildAttrs::compatibility) {
8724 if (Parser.getTok().isNot(AsmToken::Comma))
8725 IsStringValue = false;
8726 else
8727 Parser.Lex();
8728 }
8729
8730 if (IsStringValue) {
8731 if (Parser.getTok().isNot(AsmToken::String)) {
8732 Error(Parser.getTok().getLoc(), "bad string constant");
8733 Parser.eatToEndOfStatement();
8734 return false;
8735 }
8736
8737 StringValue = Parser.getTok().getStringContents();
8738 Parser.Lex();
8739 }
8740
8741 if (IsIntegerValue && IsStringValue) {
8742 assert(Tag == ARMBuildAttrs::compatibility);
8743 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
8744 } else if (IsIntegerValue)
8745 getTargetStreamer().emitAttribute(Tag, IntegerValue);
8746 else if (IsStringValue)
8747 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00008748 return false;
8749}
8750
8751/// parseDirectiveCPU
8752/// ::= .cpu str
8753bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8754 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8755 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8756 return false;
8757}
8758
Nico Weberae050bb2014-08-16 05:37:51 +00008759// FIXME: This is duplicated in getARMFPUFeatures() in
8760// tools/clang/lib/Driver/Tools.cpp
8761static const struct {
8762 const unsigned Fpu;
8763 const uint64_t Enabled;
8764 const uint64_t Disabled;
8765} Fpus[] = {
8766 {ARM::VFP, ARM::FeatureVFP2, ARM::FeatureNEON},
8767 {ARM::VFPV2, ARM::FeatureVFP2, ARM::FeatureNEON},
8768 {ARM::VFPV3, ARM::FeatureVFP3, ARM::FeatureNEON},
8769 {ARM::VFPV3_D16, ARM::FeatureVFP3 | ARM::FeatureD16, ARM::FeatureNEON},
8770 {ARM::VFPV4, ARM::FeatureVFP4, ARM::FeatureNEON},
8771 {ARM::VFPV4_D16, ARM::FeatureVFP4 | ARM::FeatureD16, ARM::FeatureNEON},
8772 {ARM::FP_ARMV8, ARM::FeatureFPARMv8,
8773 ARM::FeatureNEON | ARM::FeatureCrypto},
8774 {ARM::NEON, ARM::FeatureNEON, 0},
8775 {ARM::NEON_VFPV4, ARM::FeatureVFP4 | ARM::FeatureNEON, 0},
8776 {ARM::NEON_FP_ARMV8, ARM::FeatureFPARMv8 | ARM::FeatureNEON,
8777 ARM::FeatureCrypto},
8778 {ARM::CRYPTO_NEON_FP_ARMV8,
8779 ARM::FeatureFPARMv8 | ARM::FeatureNEON | ARM::FeatureCrypto, 0},
8780 {ARM::SOFTVFP, 0, 0},
8781};
8782
Logan Chien8cbb80d2013-10-28 17:51:12 +00008783/// parseDirectiveFPU
8784/// ::= .fpu str
8785bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8786 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8787
8788 unsigned ID = StringSwitch<unsigned>(FPU)
8789#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8790#include "ARMFPUName.def"
8791 .Default(ARM::INVALID_FPU);
8792
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008793 if (ID == ARM::INVALID_FPU) {
8794 Error(L, "Unknown FPU name");
8795 return false;
8796 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008797
Nico Weberae050bb2014-08-16 05:37:51 +00008798 for (const auto &Fpu : Fpus) {
8799 if (Fpu.Fpu != ID)
8800 continue;
8801
8802 // Need to toggle features that should be on but are off and that
8803 // should off but are on.
Tim Northover26bb14e2014-08-18 11:49:42 +00008804 uint64_t Toggle = (Fpu.Enabled & ~STI.getFeatureBits()) |
Nico Weberae050bb2014-08-16 05:37:51 +00008805 (Fpu.Disabled & STI.getFeatureBits());
8806 setAvailableFeatures(ComputeAvailableFeatures(STI.ToggleFeature(Toggle)));
8807 break;
8808 }
8809
Logan Chien8cbb80d2013-10-28 17:51:12 +00008810 getTargetStreamer().emitFPU(ID);
8811 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008812}
8813
Logan Chien4ea23b52013-05-10 16:17:24 +00008814/// parseDirectiveFnStart
8815/// ::= .fnstart
8816bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008817 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008818 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008819 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008820 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008821 }
8822
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008823 // Reset the unwind directives parser state
8824 UC.reset();
8825
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008826 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008827
8828 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00008829 return false;
8830}
8831
8832/// parseDirectiveFnEnd
8833/// ::= .fnend
8834bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8835 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008836 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008837 Error(L, ".fnstart must precede .fnend directive");
8838 return false;
8839 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008840
8841 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008842 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008843
8844 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00008845 return false;
8846}
8847
8848/// parseDirectiveCantUnwind
8849/// ::= .cantunwind
8850bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008851 UC.recordCantUnwind(L);
8852
Logan Chien4ea23b52013-05-10 16:17:24 +00008853 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008854 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008855 Error(L, ".fnstart must precede .cantunwind directive");
8856 return false;
8857 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008858 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008859 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008860 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008861 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008862 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008863 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008864 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008865 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008866 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008867 }
8868
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008869 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00008870 return false;
8871}
8872
8873/// parseDirectivePersonality
8874/// ::= .personality name
8875bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008876 bool HasExistingPersonality = UC.hasPersonality();
8877
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008878 UC.recordPersonality(L);
8879
Logan Chien4ea23b52013-05-10 16:17:24 +00008880 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008881 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008882 Error(L, ".fnstart must precede .personality directive");
8883 return false;
8884 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008885 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008886 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008887 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008888 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008889 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008890 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008891 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008892 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008893 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008894 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008895 if (HasExistingPersonality) {
8896 Parser.eatToEndOfStatement();
8897 Error(L, "multiple personality directives");
8898 UC.emitPersonalityLocNotes();
8899 return false;
8900 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008901
8902 // Parse the name of the personality routine
8903 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8904 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008905 Error(L, "unexpected input in .personality directive.");
8906 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008907 }
8908 StringRef Name(Parser.getTok().getIdentifier());
8909 Parser.Lex();
8910
8911 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008912 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00008913 return false;
8914}
8915
8916/// parseDirectiveHandlerData
8917/// ::= .handlerdata
8918bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008919 UC.recordHandlerData(L);
8920
Logan Chien4ea23b52013-05-10 16:17:24 +00008921 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008922 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008923 Error(L, ".fnstart must precede .personality directive");
8924 return false;
8925 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008926 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008927 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008928 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008929 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008930 }
8931
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008932 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00008933 return false;
8934}
8935
8936/// parseDirectiveSetFP
8937/// ::= .setfp fpreg, spreg [, offset]
8938bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8939 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008940 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008941 Error(L, ".fnstart must precede .setfp directive");
8942 return false;
8943 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008944 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008945 Error(L, ".setfp must precede .handlerdata directive");
8946 return false;
8947 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008948
8949 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008950 SMLoc FPRegLoc = Parser.getTok().getLoc();
8951 int FPReg = tryParseRegister();
8952 if (FPReg == -1) {
8953 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008954 return false;
8955 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008956
8957 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008958 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008959 Error(Parser.getTok().getLoc(), "comma expected");
8960 return false;
8961 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008962 Parser.Lex(); // skip comma
8963
8964 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008965 SMLoc SPRegLoc = Parser.getTok().getLoc();
8966 int SPReg = tryParseRegister();
8967 if (SPReg == -1) {
8968 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008969 return false;
8970 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008971
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008972 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
8973 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008974 return false;
8975 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008976
8977 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008978 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00008979
8980 // Parse offset
8981 int64_t Offset = 0;
8982 if (Parser.getTok().is(AsmToken::Comma)) {
8983 Parser.Lex(); // skip comma
8984
8985 if (Parser.getTok().isNot(AsmToken::Hash) &&
8986 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008987 Error(Parser.getTok().getLoc(), "'#' expected");
8988 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008989 }
8990 Parser.Lex(); // skip hash token.
8991
8992 const MCExpr *OffsetExpr;
8993 SMLoc ExLoc = Parser.getTok().getLoc();
8994 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008995 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8996 Error(ExLoc, "malformed setfp offset");
8997 return false;
8998 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008999 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009000 if (!CE) {
9001 Error(ExLoc, "setfp offset must be an immediate");
9002 return false;
9003 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009004
9005 Offset = CE->getValue();
9006 }
9007
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009008 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
9009 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00009010 return false;
9011}
9012
9013/// parseDirective
9014/// ::= .pad offset
9015bool ARMAsmParser::parseDirectivePad(SMLoc L) {
9016 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009017 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009018 Error(L, ".fnstart must precede .pad directive");
9019 return false;
9020 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009021 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009022 Error(L, ".pad must precede .handlerdata directive");
9023 return false;
9024 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009025
9026 // Parse the offset
9027 if (Parser.getTok().isNot(AsmToken::Hash) &&
9028 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009029 Error(Parser.getTok().getLoc(), "'#' expected");
9030 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009031 }
9032 Parser.Lex(); // skip hash token.
9033
9034 const MCExpr *OffsetExpr;
9035 SMLoc ExLoc = Parser.getTok().getLoc();
9036 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009037 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9038 Error(ExLoc, "malformed pad offset");
9039 return false;
9040 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009041 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009042 if (!CE) {
9043 Error(ExLoc, "pad offset must be an immediate");
9044 return false;
9045 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009046
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009047 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00009048 return false;
9049}
9050
9051/// parseDirectiveRegSave
9052/// ::= .save { registers }
9053/// ::= .vsave { registers }
9054bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
9055 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009056 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009057 Error(L, ".fnstart must precede .save or .vsave directives");
9058 return false;
9059 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009060 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009061 Error(L, ".save or .vsave must precede .handlerdata directive");
9062 return false;
9063 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009064
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009065 // RAII object to make sure parsed operands are deleted.
David Blaikie960ea3f2014-06-08 16:18:35 +00009066 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009067
Logan Chien4ea23b52013-05-10 16:17:24 +00009068 // Parse the register list
David Blaikie960ea3f2014-06-08 16:18:35 +00009069 if (parseRegisterList(Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00009070 return false;
David Blaikie960ea3f2014-06-08 16:18:35 +00009071 ARMOperand &Op = (ARMOperand &)*Operands[0];
9072 if (!IsVector && !Op.isRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009073 Error(L, ".save expects GPR registers");
9074 return false;
9075 }
David Blaikie960ea3f2014-06-08 16:18:35 +00009076 if (IsVector && !Op.isDPRRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009077 Error(L, ".vsave expects DPR registers");
9078 return false;
9079 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009080
David Blaikie960ea3f2014-06-08 16:18:35 +00009081 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00009082 return false;
9083}
9084
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009085/// parseDirectiveInst
9086/// ::= .inst opcode [, ...]
9087/// ::= .inst.n opcode [, ...]
9088/// ::= .inst.w opcode [, ...]
9089bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
9090 int Width;
9091
9092 if (isThumb()) {
9093 switch (Suffix) {
9094 case 'n':
9095 Width = 2;
9096 break;
9097 case 'w':
9098 Width = 4;
9099 break;
9100 default:
9101 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009102 Error(Loc, "cannot determine Thumb instruction size, "
9103 "use inst.n/inst.w instead");
9104 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009105 }
9106 } else {
9107 if (Suffix) {
9108 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009109 Error(Loc, "width suffixes are invalid in ARM mode");
9110 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009111 }
9112 Width = 4;
9113 }
9114
9115 if (getLexer().is(AsmToken::EndOfStatement)) {
9116 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009117 Error(Loc, "expected expression following directive");
9118 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009119 }
9120
9121 for (;;) {
9122 const MCExpr *Expr;
9123
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009124 if (getParser().parseExpression(Expr)) {
9125 Error(Loc, "expected expression");
9126 return false;
9127 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009128
9129 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009130 if (!Value) {
9131 Error(Loc, "expected constant expression");
9132 return false;
9133 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009134
9135 switch (Width) {
9136 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009137 if (Value->getValue() > 0xffff) {
9138 Error(Loc, "inst.n operand is too big, use inst.w instead");
9139 return false;
9140 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009141 break;
9142 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009143 if (Value->getValue() > 0xffffffff) {
9144 Error(Loc,
9145 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
9146 return false;
9147 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009148 break;
9149 default:
9150 llvm_unreachable("only supported widths are 2 and 4");
9151 }
9152
9153 getTargetStreamer().emitInst(Value->getValue(), Suffix);
9154
9155 if (getLexer().is(AsmToken::EndOfStatement))
9156 break;
9157
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009158 if (getLexer().isNot(AsmToken::Comma)) {
9159 Error(Loc, "unexpected token in directive");
9160 return false;
9161 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009162
9163 Parser.Lex();
9164 }
9165
9166 Parser.Lex();
9167 return false;
9168}
9169
David Peixotto80c083a2013-12-19 18:26:07 +00009170/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00009171/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00009172bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00009173 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00009174 return false;
9175}
9176
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009177bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9178 const MCSection *Section = getStreamer().getCurrentSection().first;
9179
9180 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9181 TokError("unexpected token in directive");
9182 return false;
9183 }
9184
9185 if (!Section) {
Rafael Espindolaf1440342014-01-23 23:14:14 +00009186 getStreamer().InitSections();
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009187 Section = getStreamer().getCurrentSection().first;
9188 }
9189
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00009190 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009191 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00009192 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009193 else
Rafael Espindola7b514962014-02-04 18:34:04 +00009194 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009195
9196 return false;
9197}
9198
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009199/// parseDirectivePersonalityIndex
9200/// ::= .personalityindex index
9201bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
9202 bool HasExistingPersonality = UC.hasPersonality();
9203
9204 UC.recordPersonalityIndex(L);
9205
9206 if (!UC.hasFnStart()) {
9207 Parser.eatToEndOfStatement();
9208 Error(L, ".fnstart must precede .personalityindex directive");
9209 return false;
9210 }
9211 if (UC.cantUnwind()) {
9212 Parser.eatToEndOfStatement();
9213 Error(L, ".personalityindex cannot be used with .cantunwind");
9214 UC.emitCantUnwindLocNotes();
9215 return false;
9216 }
9217 if (UC.hasHandlerData()) {
9218 Parser.eatToEndOfStatement();
9219 Error(L, ".personalityindex must precede .handlerdata directive");
9220 UC.emitHandlerDataLocNotes();
9221 return false;
9222 }
9223 if (HasExistingPersonality) {
9224 Parser.eatToEndOfStatement();
9225 Error(L, "multiple personality directives");
9226 UC.emitPersonalityLocNotes();
9227 return false;
9228 }
9229
9230 const MCExpr *IndexExpression;
9231 SMLoc IndexLoc = Parser.getTok().getLoc();
9232 if (Parser.parseExpression(IndexExpression)) {
9233 Parser.eatToEndOfStatement();
9234 return false;
9235 }
9236
9237 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9238 if (!CE) {
9239 Parser.eatToEndOfStatement();
9240 Error(IndexLoc, "index must be a constant number");
9241 return false;
9242 }
9243 if (CE->getValue() < 0 ||
9244 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9245 Parser.eatToEndOfStatement();
9246 Error(IndexLoc, "personality routine index should be in range [0-3]");
9247 return false;
9248 }
9249
9250 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9251 return false;
9252}
9253
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009254/// parseDirectiveUnwindRaw
9255/// ::= .unwind_raw offset, opcode [, opcode...]
9256bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
9257 if (!UC.hasFnStart()) {
9258 Parser.eatToEndOfStatement();
9259 Error(L, ".fnstart must precede .unwind_raw directives");
9260 return false;
9261 }
9262
9263 int64_t StackOffset;
9264
9265 const MCExpr *OffsetExpr;
9266 SMLoc OffsetLoc = getLexer().getLoc();
9267 if (getLexer().is(AsmToken::EndOfStatement) ||
9268 getParser().parseExpression(OffsetExpr)) {
9269 Error(OffsetLoc, "expected expression");
9270 Parser.eatToEndOfStatement();
9271 return false;
9272 }
9273
9274 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9275 if (!CE) {
9276 Error(OffsetLoc, "offset must be a constant");
9277 Parser.eatToEndOfStatement();
9278 return false;
9279 }
9280
9281 StackOffset = CE->getValue();
9282
9283 if (getLexer().isNot(AsmToken::Comma)) {
9284 Error(getLexer().getLoc(), "expected comma");
9285 Parser.eatToEndOfStatement();
9286 return false;
9287 }
9288 Parser.Lex();
9289
9290 SmallVector<uint8_t, 16> Opcodes;
9291 for (;;) {
9292 const MCExpr *OE;
9293
9294 SMLoc OpcodeLoc = getLexer().getLoc();
9295 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9296 Error(OpcodeLoc, "expected opcode expression");
9297 Parser.eatToEndOfStatement();
9298 return false;
9299 }
9300
9301 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9302 if (!OC) {
9303 Error(OpcodeLoc, "opcode value must be a constant");
9304 Parser.eatToEndOfStatement();
9305 return false;
9306 }
9307
9308 const int64_t Opcode = OC->getValue();
9309 if (Opcode & ~0xff) {
9310 Error(OpcodeLoc, "invalid opcode");
9311 Parser.eatToEndOfStatement();
9312 return false;
9313 }
9314
9315 Opcodes.push_back(uint8_t(Opcode));
9316
9317 if (getLexer().is(AsmToken::EndOfStatement))
9318 break;
9319
9320 if (getLexer().isNot(AsmToken::Comma)) {
9321 Error(getLexer().getLoc(), "unexpected token in directive");
9322 Parser.eatToEndOfStatement();
9323 return false;
9324 }
9325
9326 Parser.Lex();
9327 }
9328
9329 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9330
9331 Parser.Lex();
9332 return false;
9333}
9334
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009335/// parseDirectiveTLSDescSeq
9336/// ::= .tlsdescseq tls-variable
9337bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
9338 if (getLexer().isNot(AsmToken::Identifier)) {
9339 TokError("expected variable after '.tlsdescseq' directive");
9340 Parser.eatToEndOfStatement();
9341 return false;
9342 }
9343
9344 const MCSymbolRefExpr *SRE =
9345 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9346 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9347 Lex();
9348
9349 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9350 Error(Parser.getTok().getLoc(), "unexpected token");
9351 Parser.eatToEndOfStatement();
9352 return false;
9353 }
9354
9355 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9356 return false;
9357}
9358
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009359/// parseDirectiveMovSP
9360/// ::= .movsp reg [, #offset]
9361bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
9362 if (!UC.hasFnStart()) {
9363 Parser.eatToEndOfStatement();
9364 Error(L, ".fnstart must precede .movsp directives");
9365 return false;
9366 }
9367 if (UC.getFPReg() != ARM::SP) {
9368 Parser.eatToEndOfStatement();
9369 Error(L, "unexpected .movsp directive");
9370 return false;
9371 }
9372
9373 SMLoc SPRegLoc = Parser.getTok().getLoc();
9374 int SPReg = tryParseRegister();
9375 if (SPReg == -1) {
9376 Parser.eatToEndOfStatement();
9377 Error(SPRegLoc, "register expected");
9378 return false;
9379 }
9380
9381 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9382 Parser.eatToEndOfStatement();
9383 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9384 return false;
9385 }
9386
9387 int64_t Offset = 0;
9388 if (Parser.getTok().is(AsmToken::Comma)) {
9389 Parser.Lex();
9390
9391 if (Parser.getTok().isNot(AsmToken::Hash)) {
9392 Error(Parser.getTok().getLoc(), "expected #constant");
9393 Parser.eatToEndOfStatement();
9394 return false;
9395 }
9396 Parser.Lex();
9397
9398 const MCExpr *OffsetExpr;
9399 SMLoc OffsetLoc = Parser.getTok().getLoc();
9400 if (Parser.parseExpression(OffsetExpr)) {
9401 Parser.eatToEndOfStatement();
9402 Error(OffsetLoc, "malformed offset expression");
9403 return false;
9404 }
9405
9406 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9407 if (!CE) {
9408 Parser.eatToEndOfStatement();
9409 Error(OffsetLoc, "offset must be an immediate constant");
9410 return false;
9411 }
9412
9413 Offset = CE->getValue();
9414 }
9415
9416 getTargetStreamer().emitMovSP(SPReg, Offset);
9417 UC.saveFPReg(SPReg);
9418
9419 return false;
9420}
9421
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009422/// parseDirectiveObjectArch
9423/// ::= .object_arch name
9424bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
9425 if (getLexer().isNot(AsmToken::Identifier)) {
9426 Error(getLexer().getLoc(), "unexpected token");
9427 Parser.eatToEndOfStatement();
9428 return false;
9429 }
9430
9431 StringRef Arch = Parser.getTok().getString();
9432 SMLoc ArchLoc = Parser.getTok().getLoc();
9433 getLexer().Lex();
9434
9435 unsigned ID = StringSwitch<unsigned>(Arch)
9436#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9437 .Case(NAME, ARM::ID)
9438#define ARM_ARCH_ALIAS(NAME, ID) \
9439 .Case(NAME, ARM::ID)
9440#include "MCTargetDesc/ARMArchName.def"
9441#undef ARM_ARCH_NAME
9442#undef ARM_ARCH_ALIAS
9443 .Default(ARM::INVALID_ARCH);
9444
9445 if (ID == ARM::INVALID_ARCH) {
9446 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9447 Parser.eatToEndOfStatement();
9448 return false;
9449 }
9450
9451 getTargetStreamer().emitObjectArch(ID);
9452
9453 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9454 Error(getLexer().getLoc(), "unexpected token");
9455 Parser.eatToEndOfStatement();
9456 }
9457
9458 return false;
9459}
9460
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009461/// parseDirectiveAlign
9462/// ::= .align
9463bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9464 // NOTE: if this is not the end of the statement, fall back to the target
9465 // agnostic handling for this directive which will correctly handle this.
9466 if (getLexer().isNot(AsmToken::EndOfStatement))
9467 return true;
9468
9469 // '.align' is target specifically handled to mean 2**2 byte alignment.
9470 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9471 getStreamer().EmitCodeAlignment(4, 0);
9472 else
9473 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9474
9475 return false;
9476}
9477
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009478/// parseDirectiveThumbSet
9479/// ::= .thumb_set name, value
9480bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
9481 StringRef Name;
9482 if (Parser.parseIdentifier(Name)) {
9483 TokError("expected identifier after '.thumb_set'");
9484 Parser.eatToEndOfStatement();
9485 return false;
9486 }
9487
9488 if (getLexer().isNot(AsmToken::Comma)) {
9489 TokError("expected comma after name '" + Name + "'");
9490 Parser.eatToEndOfStatement();
9491 return false;
9492 }
9493 Lex();
9494
9495 const MCExpr *Value;
9496 if (Parser.parseExpression(Value)) {
9497 TokError("missing expression");
9498 Parser.eatToEndOfStatement();
9499 return false;
9500 }
9501
9502 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9503 TokError("unexpected token");
9504 Parser.eatToEndOfStatement();
9505 return false;
9506 }
9507 Lex();
9508
9509 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
Rafael Espindola466d6632014-04-27 20:23:58 +00009510 getTargetStreamer().emitThumbSet(Alias, Value);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009511 return false;
9512}
9513
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009514/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009515extern "C" void LLVMInitializeARMAsmParser() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00009516 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9517 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9518 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9519 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009520}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009521
Chris Lattner3e4582a2010-09-06 19:11:01 +00009522#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009523#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009524#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009525#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009526
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009527static const struct {
9528 const char *Name;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009529 const unsigned ArchCheck;
9530 const uint64_t Features;
9531} Extensions[] = {
9532 { "crc", Feature_HasV8, ARM::FeatureCRC },
9533 { "crypto", Feature_HasV8,
9534 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9535 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
9536 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
9537 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
9538 // FIXME: iWMMXT not supported
9539 { "iwmmxt", Feature_None, 0 },
9540 // FIXME: iWMMXT2 not supported
9541 { "iwmmxt2", Feature_None, 0 },
9542 // FIXME: Maverick not supported
9543 { "maverick", Feature_None, 0 },
9544 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
9545 // FIXME: ARMv6-m OS Extensions feature not checked
9546 { "os", Feature_None, 0 },
9547 // FIXME: Also available in ARMv6-K
9548 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
9549 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9550 // FIXME: Only available in A-class, isel not predicated
9551 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
9552 // FIXME: xscale not supported
9553 { "xscale", Feature_None, 0 },
9554};
9555
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009556/// parseDirectiveArchExtension
9557/// ::= .arch_extension [no]feature
9558bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
9559 if (getLexer().isNot(AsmToken::Identifier)) {
9560 Error(getLexer().getLoc(), "unexpected token");
9561 Parser.eatToEndOfStatement();
9562 return false;
9563 }
9564
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009565 StringRef Name = Parser.getTok().getString();
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009566 SMLoc ExtLoc = Parser.getTok().getLoc();
9567 getLexer().Lex();
9568
9569 bool EnableFeature = true;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009570 if (Name.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009571 EnableFeature = false;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009572 Name = Name.substr(2);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009573 }
9574
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009575 for (const auto &Extension : Extensions) {
9576 if (Extension.Name != Name)
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009577 continue;
9578
Saleem Abdulrasool8988c2a2014-07-27 19:07:09 +00009579 if (!Extension.Features)
9580 report_fatal_error("unsupported architectural extension: " + Name);
9581
9582 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) {
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009583 Error(ExtLoc, "architectural extension '" + Name + "' is not "
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009584 "allowed for the current base architecture");
9585 return false;
9586 }
9587
Tim Northover26bb14e2014-08-18 11:49:42 +00009588 uint64_t ToggleFeatures = EnableFeature
Saleem Abdulrasool78c44722014-08-17 19:20:38 +00009589 ? (~STI.getFeatureBits() & Extension.Features)
9590 : ( STI.getFeatureBits() & Extension.Features);
Tim Northover26bb14e2014-08-18 11:49:42 +00009591 uint64_t Features =
Saleem Abdulrasool78c44722014-08-17 19:20:38 +00009592 ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
9593 setAvailableFeatures(Features);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009594 return false;
9595 }
9596
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009597 Error(ExtLoc, "unknown architectural extension: " + Name);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009598 Parser.eatToEndOfStatement();
9599 return false;
9600}
9601
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009602// Define this matcher function after the auto-generated include so we
9603// have the match class enum definitions.
David Blaikie960ea3f2014-06-08 16:18:35 +00009604unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009605 unsigned Kind) {
David Blaikie960ea3f2014-06-08 16:18:35 +00009606 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009607 // If the kind is a token for a literal immediate, check if our asm
9608 // operand matches. This is for InstAliases which have a fixed-value
9609 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009610 switch (Kind) {
9611 default: break;
9612 case MCK__35_0:
David Blaikie960ea3f2014-06-08 16:18:35 +00009613 if (Op.isImm())
9614 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009615 if (CE->getValue() == 0)
9616 return Match_Success;
9617 break;
9618 case MCK_ARMSOImm:
David Blaikie960ea3f2014-06-08 16:18:35 +00009619 if (Op.isImm()) {
9620 const MCExpr *SOExpr = Op.getImm();
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009621 int64_t Value;
9622 if (!SOExpr->EvaluateAsAbsolute(Value))
Stepan Dyatkovskiydf657cc2014-03-29 13:12:40 +00009623 return Match_Success;
Richard Barton3db1d582014-05-01 11:37:44 +00009624 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
9625 "expression value must be representable in 32 bits");
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009626 }
9627 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00009628 case MCK_GPRPair:
David Blaikie960ea3f2014-06-08 16:18:35 +00009629 if (Op.isReg() &&
9630 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00009631 return Match_Success;
9632 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009633 }
9634 return Match_InvalidOperand;
9635}