blob: 4ccadf915cc74ae9ef37a81092271367a5a3502e [file] [log] [blame]
Kevin Enderbyccab3172009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Logan Chien8cbb80d2013-10-28 17:51:12 +000010#include "ARMFPUName.h"
Amara Emerson52cfb6a2013-10-03 09:31:51 +000011#include "ARMFeatures.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000012#include "MCTargetDesc/ARMAddressingModes.h"
Logan Chien439e8f92013-12-11 17:16:25 +000013#include "MCTargetDesc/ARMArchName.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000014#include "MCTargetDesc/ARMBaseInfo.h"
15#include "MCTargetDesc/ARMMCExpr.h"
Evan Cheng11424442011-07-26 00:24:13 +000016#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000017#include "llvm/ADT/SmallVector.h"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000018#include "llvm/ADT/StringExtras.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000019#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000020#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000021#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000022#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000023#include "llvm/MC/MCContext.h"
Tim Northoverd6a729b2014-01-06 14:28:05 +000024#include "llvm/MC/MCDisassembler.h"
Jack Carter718da0b2013-01-30 02:24:33 +000025#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000026#include "llvm/MC/MCExpr.h"
27#include "llvm/MC/MCInst.h"
28#include "llvm/MC/MCInstrDesc.h"
Joey Gouly0e76fa72013-09-12 10:28:05 +000029#include "llvm/MC/MCInstrInfo.h"
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +000030#include "llvm/MC/MCObjectFileInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000031#include "llvm/MC/MCParser/MCAsmLexer.h"
32#include "llvm/MC/MCParser/MCAsmParser.h"
33#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
34#include "llvm/MC/MCRegisterInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000035#include "llvm/MC/MCSection.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000036#include "llvm/MC/MCStreamer.h"
37#include "llvm/MC/MCSubtargetInfo.h"
David Peixottoe407d092013-12-19 18:12:36 +000038#include "llvm/MC/MCSymbol.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000039#include "llvm/MC/MCTargetAsmParser.h"
Saleem Abdulrasool278a9f42014-01-19 08:25:27 +000040#include "llvm/Support/ARMBuildAttributes.h"
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000041#include "llvm/Support/ARMEHABI.h"
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +000042#include "llvm/Support/COFF.h"
Tim Northoverd6a729b2014-01-06 14:28:05 +000043#include "llvm/Support/Debug.h"
Jack Carter718da0b2013-01-30 02:24:33 +000044#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000045#include "llvm/Support/MathExtras.h"
46#include "llvm/Support/SourceMgr.h"
47#include "llvm/Support/TargetRegistry.h"
48#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000049
Kevin Enderbyccab3172009-09-15 00:27:25 +000050using namespace llvm;
51
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000052namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000053
54class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000055
Jim Grosbach04945c42011-12-02 00:35:16 +000056enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000057
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000058class UnwindContext {
59 MCAsmParser &Parser;
60
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000061 typedef SmallVector<SMLoc, 4> Locs;
62
63 Locs FnStartLocs;
64 Locs CantUnwindLocs;
65 Locs PersonalityLocs;
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000066 Locs PersonalityIndexLocs;
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000067 Locs HandlerDataLocs;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000068 int FPReg;
69
70public:
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +000071 UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {}
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000072
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000073 bool hasFnStart() const { return !FnStartLocs.empty(); }
74 bool cantUnwind() const { return !CantUnwindLocs.empty(); }
75 bool hasHandlerData() const { return !HandlerDataLocs.empty(); }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000076 bool hasPersonality() const {
77 return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty());
78 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000079
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000080 void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); }
81 void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); }
82 void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); }
83 void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000084 void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000085
86 void saveFPReg(int Reg) { FPReg = Reg; }
87 int getFPReg() const { return FPReg; }
88
89 void emitFnStartLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000090 for (Locs::const_iterator FI = FnStartLocs.begin(), FE = FnStartLocs.end();
91 FI != FE; ++FI)
92 Parser.Note(*FI, ".fnstart was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000093 }
94 void emitCantUnwindLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000095 for (Locs::const_iterator UI = CantUnwindLocs.begin(),
96 UE = CantUnwindLocs.end(); UI != UE; ++UI)
97 Parser.Note(*UI, ".cantunwind was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000098 }
99 void emitHandlerDataLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000100 for (Locs::const_iterator HI = HandlerDataLocs.begin(),
101 HE = HandlerDataLocs.end(); HI != HE; ++HI)
102 Parser.Note(*HI, ".handlerdata was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000103 }
104 void emitPersonalityLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000105 for (Locs::const_iterator PI = PersonalityLocs.begin(),
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000106 PE = PersonalityLocs.end(),
107 PII = PersonalityIndexLocs.begin(),
108 PIE = PersonalityIndexLocs.end();
109 PI != PE || PII != PIE;) {
110 if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer()))
111 Parser.Note(*PI++, ".personality was specified here");
112 else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer()))
113 Parser.Note(*PII++, ".personalityindex was specified here");
114 else
115 llvm_unreachable(".personality and .personalityindex cannot be "
116 "at the same location");
117 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000118 }
119
120 void reset() {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000121 FnStartLocs = Locs();
122 CantUnwindLocs = Locs();
123 PersonalityLocs = Locs();
124 HandlerDataLocs = Locs();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000125 PersonalityIndexLocs = Locs();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000126 FPReg = ARM::SP;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000127 }
128};
129
Evan Cheng11424442011-07-26 00:24:13 +0000130class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +0000131 MCSubtargetInfo &STI;
Joey Gouly0e76fa72013-09-12 10:28:05 +0000132 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000133 const MCRegisterInfo *MRI;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000134 UnwindContext UC;
David Peixottoe407d092013-12-19 18:12:36 +0000135
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000136 ARMTargetStreamer &getTargetStreamer() {
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +0000137 assert(getParser().getStreamer().getTargetStreamer() &&
138 "do not have a target streamer");
Rafael Espindola4a1a3602014-01-14 01:21:46 +0000139 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000140 return static_cast<ARMTargetStreamer &>(TS);
141 }
142
Jim Grosbachab5830e2011-12-14 02:16:11 +0000143 // Map of register aliases registers via the .req directive.
144 StringMap<unsigned> RegisterReqs;
145
Tim Northover1744d0a2013-10-25 12:49:50 +0000146 bool NextSymbolIsThumb;
147
Jim Grosbached16ec42011-08-29 22:24:09 +0000148 struct {
149 ARMCC::CondCodes Cond; // Condition for IT block.
150 unsigned Mask:4; // Condition mask for instructions.
151 // Starting at first 1 (from lsb).
152 // '1' condition as indicated in IT.
153 // '0' inverse of condition (else).
154 // Count of instructions in IT block is
155 // 4 - trailingzeroes(mask)
156
157 bool FirstCond; // Explicit flag for when we're parsing the
158 // First instruction in the IT block. It's
159 // implied in the mask, so needs special
160 // handling.
161
162 unsigned CurPosition; // Current position in parsing of IT
163 // block. In range [0,3]. Initialized
164 // according to count of instructions in block.
165 // ~0U if no active IT block.
166 } ITState;
167 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000168 void forwardITPosition() {
169 if (!inITBlock()) return;
170 // Move to the next instruction in the IT block, if there is one. If not,
171 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000172 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000173 if (++ITState.CurPosition == 5 - TZ)
174 ITState.CurPosition = ~0U; // Done with the IT block after this.
175 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000176
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000177 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000178 return getParser().Note(L, Msg, Ranges);
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000179 }
Benjamin Kramer673824b2012-04-15 17:04:27 +0000180 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000181 ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000182 return getParser().Warning(L, Msg, Ranges);
Benjamin Kramer673824b2012-04-15 17:04:27 +0000183 }
184 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000185 ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000186 return getParser().Error(L, Msg, Ranges);
Benjamin Kramer673824b2012-04-15 17:04:27 +0000187 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000188
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000189 int tryParseRegister();
David Blaikie960ea3f2014-06-08 16:18:35 +0000190 bool tryParseRegisterWithWriteBack(OperandVector &);
191 int tryParseShiftRegister(OperandVector &);
192 bool parseRegisterList(OperandVector &);
193 bool parseMemory(OperandVector &);
194 bool parseOperand(OperandVector &, StringRef Mnemonic);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000195 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000196 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
197 unsigned &ShiftAmount);
Saleem Abdulrasool38976512014-02-23 06:22:09 +0000198 bool parseLiteralValues(unsigned Size, SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000199 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000200 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000201 bool parseDirectiveThumbFunc(SMLoc L);
202 bool parseDirectiveCode(SMLoc L);
203 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000204 bool parseDirectiveReq(StringRef Name, SMLoc L);
205 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000206 bool parseDirectiveArch(SMLoc L);
207 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000208 bool parseDirectiveCPU(SMLoc L);
209 bool parseDirectiveFPU(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000210 bool parseDirectiveFnStart(SMLoc L);
211 bool parseDirectiveFnEnd(SMLoc L);
212 bool parseDirectiveCantUnwind(SMLoc L);
213 bool parseDirectivePersonality(SMLoc L);
214 bool parseDirectiveHandlerData(SMLoc L);
215 bool parseDirectiveSetFP(SMLoc L);
216 bool parseDirectivePad(SMLoc L);
217 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000218 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
David Peixotto80c083a2013-12-19 18:26:07 +0000219 bool parseDirectiveLtorg(SMLoc L);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +0000220 bool parseDirectiveEven(SMLoc L);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000221 bool parseDirectivePersonalityIndex(SMLoc L);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000222 bool parseDirectiveUnwindRaw(SMLoc L);
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000223 bool parseDirectiveTLSDescSeq(SMLoc L);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000224 bool parseDirectiveMovSP(SMLoc L);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000225 bool parseDirectiveObjectArch(SMLoc L);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +0000226 bool parseDirectiveArchExtension(SMLoc L);
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +0000227 bool parseDirectiveAlign(SMLoc L);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +0000228 bool parseDirectiveThumbSet(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000229
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000230 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000231 bool &CarrySetting, unsigned &ProcessorIMod,
232 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000233 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
234 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000235 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000236
Evan Cheng4d1ca962011-07-08 01:53:10 +0000237 bool isThumb() const {
238 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000239 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000240 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000241 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000242 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000243 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000244 bool isThumbTwo() const {
245 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
246 }
Tim Northovera2292d02013-06-10 23:20:58 +0000247 bool hasThumb() const {
248 return STI.getFeatureBits() & ARM::HasV4TOps;
249 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000250 bool hasV6Ops() const {
251 return STI.getFeatureBits() & ARM::HasV6Ops;
252 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000253 bool hasV6MOps() const {
254 return STI.getFeatureBits() & ARM::HasV6MOps;
255 }
James Molloy21efa7d2011-09-28 14:21:38 +0000256 bool hasV7Ops() const {
257 return STI.getFeatureBits() & ARM::HasV7Ops;
258 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000259 bool hasV8Ops() const {
260 return STI.getFeatureBits() & ARM::HasV8Ops;
261 }
Tim Northovera2292d02013-06-10 23:20:58 +0000262 bool hasARM() const {
263 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
264 }
Renato Golin92c816c2014-09-01 11:25:07 +0000265 bool hasThumb2DSP() const {
266 return STI.getFeatureBits() & ARM::FeatureDSPThumb2;
267 }
Oliver Stannard9e89d8c2014-11-05 12:06:39 +0000268 bool hasD16() const {
269 return STI.getFeatureBits() & ARM::FeatureD16;
270 }
Tim Northovera2292d02013-06-10 23:20:58 +0000271
Evan Cheng284b4672011-07-08 22:36:29 +0000272 void SwitchMode() {
Tim Northover26bb14e2014-08-18 11:49:42 +0000273 uint64_t FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
Evan Cheng91111d22011-07-09 05:47:46 +0000274 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000275 }
James Molloy21efa7d2011-09-28 14:21:38 +0000276 bool isMClass() const {
277 return STI.getFeatureBits() & ARM::FeatureMClass;
278 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000279
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000280 /// @name Auto-generated Match Functions
281 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000282
Chris Lattner3e4582a2010-09-06 19:11:01 +0000283#define GET_ASSEMBLER_HEADER
284#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000285
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000286 /// }
287
David Blaikie960ea3f2014-06-08 16:18:35 +0000288 OperandMatchResultTy parseITCondCode(OperandVector &);
289 OperandMatchResultTy parseCoprocNumOperand(OperandVector &);
290 OperandMatchResultTy parseCoprocRegOperand(OperandVector &);
291 OperandMatchResultTy parseCoprocOptionOperand(OperandVector &);
292 OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &);
293 OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &);
294 OperandMatchResultTy parseProcIFlagsOperand(OperandVector &);
295 OperandMatchResultTy parseMSRMaskOperand(OperandVector &);
Tim Northoveree843ef2014-08-15 10:47:12 +0000296 OperandMatchResultTy parseBankedRegOperand(OperandVector &);
David Blaikie960ea3f2014-06-08 16:18:35 +0000297 OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low,
298 int High);
299 OperandMatchResultTy parsePKHLSLImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000300 return parsePKHImm(O, "lsl", 0, 31);
301 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000302 OperandMatchResultTy parsePKHASRImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000303 return parsePKHImm(O, "asr", 1, 32);
304 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000305 OperandMatchResultTy parseSetEndImm(OperandVector &);
306 OperandMatchResultTy parseShifterImm(OperandVector &);
307 OperandMatchResultTy parseRotImm(OperandVector &);
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000308 OperandMatchResultTy parseModImm(OperandVector &);
David Blaikie960ea3f2014-06-08 16:18:35 +0000309 OperandMatchResultTy parseBitfield(OperandVector &);
310 OperandMatchResultTy parsePostIdxReg(OperandVector &);
311 OperandMatchResultTy parseAM3Offset(OperandVector &);
312 OperandMatchResultTy parseFPImm(OperandVector &);
313 OperandMatchResultTy parseVectorList(OperandVector &);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000314 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
315 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000316
317 // Asm Match Converter Methods
David Blaikie960ea3f2014-06-08 16:18:35 +0000318 void cvtThumbMultiply(MCInst &Inst, const OperandVector &);
319 void cvtThumbBranches(MCInst &Inst, const OperandVector &);
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +0000320
David Blaikie960ea3f2014-06-08 16:18:35 +0000321 bool validateInstruction(MCInst &Inst, const OperandVector &Ops);
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +0000322 bool processInstruction(MCInst &Inst, const OperandVector &Ops, MCStreamer &Out);
David Blaikie960ea3f2014-06-08 16:18:35 +0000323 bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands);
324 bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands);
325
Kevin Enderbyccab3172009-09-15 00:27:25 +0000326public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000327 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000328 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000329 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000330 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000331 Match_RequiresThumb2,
332#define GET_OPERAND_DIAGNOSTIC_TYPES
333#include "ARMGenAsmMatcher.inc"
334
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000335 };
336
Rafael Espindola961d4692014-11-11 05:18:41 +0000337 ARMAsmParser(MCSubtargetInfo & _STI, MCAsmParser & _Parser,
338 const MCInstrInfo &MII, const MCTargetOptions &Options)
339 : MCTargetAsmParser(), STI(_STI), MII(MII), UC(_Parser) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000340 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000341
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000342 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000343 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000344
Evan Cheng4d1ca962011-07-08 01:53:10 +0000345 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000346 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000347
348 // Not in an ITBlock to start with.
349 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000350
351 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000352 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000353
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000354 // Implementation of the MCTargetAsmParser interface:
Craig Topperca7e3e52014-03-10 03:19:03 +0000355 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
David Blaikie960ea3f2014-06-08 16:18:35 +0000356 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
357 SMLoc NameLoc, OperandVector &Operands) override;
Craig Topperca7e3e52014-03-10 03:19:03 +0000358 bool ParseDirective(AsmToken DirectiveID) override;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000359
David Blaikie960ea3f2014-06-08 16:18:35 +0000360 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
Craig Topperca7e3e52014-03-10 03:19:03 +0000361 unsigned Kind) override;
362 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000363
Chad Rosier49963552012-10-13 00:26:04 +0000364 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
David Blaikie960ea3f2014-06-08 16:18:35 +0000365 OperandVector &Operands, MCStreamer &Out,
Tim Northover26bb14e2014-08-18 11:49:42 +0000366 uint64_t &ErrorInfo,
Craig Topperca7e3e52014-03-10 03:19:03 +0000367 bool MatchingInlineAsm) override;
368 void onLabelParsed(MCSymbol *Symbol) override;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000369};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000370} // end anonymous namespace
371
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000372namespace {
373
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000374/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000375/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000376class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000377 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000378 k_CondCode,
379 k_CCOut,
380 k_ITCondMask,
381 k_CoprocNum,
382 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000383 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000384 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000385 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000386 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000387 k_Memory,
388 k_PostIndexRegister,
389 k_MSRMask,
Tim Northoveree843ef2014-08-15 10:47:12 +0000390 k_BankedReg,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000391 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000392 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000393 k_Register,
394 k_RegisterList,
395 k_DPRRegisterList,
396 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000397 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000398 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000399 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000400 k_ShiftedRegister,
401 k_ShiftedImmediate,
402 k_ShifterImmediate,
403 k_RotateImmediate,
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000404 k_ModifiedImmediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000405 k_BitfieldDescriptor,
406 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000407 } Kind;
408
Kevin Enderby488f20b2014-04-10 20:18:58 +0000409 SMLoc StartLoc, EndLoc, AlignmentLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000410 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000411
Eric Christopher8996c5d2013-03-15 00:42:55 +0000412 struct CCOp {
413 ARMCC::CondCodes Val;
414 };
415
416 struct CopOp {
417 unsigned Val;
418 };
419
420 struct CoprocOptionOp {
421 unsigned Val;
422 };
423
424 struct ITMaskOp {
425 unsigned Mask:4;
426 };
427
428 struct MBOptOp {
429 ARM_MB::MemBOpt Val;
430 };
431
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000432 struct ISBOptOp {
433 ARM_ISB::InstSyncBOpt Val;
434 };
435
Eric Christopher8996c5d2013-03-15 00:42:55 +0000436 struct IFlagsOp {
437 ARM_PROC::IFlags Val;
438 };
439
440 struct MMaskOp {
441 unsigned Val;
442 };
443
Tim Northoveree843ef2014-08-15 10:47:12 +0000444 struct BankedRegOp {
445 unsigned Val;
446 };
447
Eric Christopher8996c5d2013-03-15 00:42:55 +0000448 struct TokOp {
449 const char *Data;
450 unsigned Length;
451 };
452
453 struct RegOp {
454 unsigned RegNum;
455 };
456
457 // A vector register list is a sequential list of 1 to 4 registers.
458 struct VectorListOp {
459 unsigned RegNum;
460 unsigned Count;
461 unsigned LaneIndex;
462 bool isDoubleSpaced;
463 };
464
465 struct VectorIndexOp {
466 unsigned Val;
467 };
468
469 struct ImmOp {
470 const MCExpr *Val;
471 };
472
473 /// Combined record for all forms of ARM address expressions.
474 struct MemoryOp {
475 unsigned BaseRegNum;
476 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
477 // was specified.
478 const MCConstantExpr *OffsetImm; // Offset immediate value
479 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
480 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
481 unsigned ShiftImm; // shift for OffsetReg.
482 unsigned Alignment; // 0 = no alignment specified
483 // n = alignment in bytes (2, 4, 8, 16, or 32)
484 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
485 };
486
487 struct PostIdxRegOp {
488 unsigned RegNum;
489 bool isAdd;
490 ARM_AM::ShiftOpc ShiftTy;
491 unsigned ShiftImm;
492 };
493
494 struct ShifterImmOp {
495 bool isASR;
496 unsigned Imm;
497 };
498
499 struct RegShiftedRegOp {
500 ARM_AM::ShiftOpc ShiftTy;
501 unsigned SrcReg;
502 unsigned ShiftReg;
503 unsigned ShiftImm;
504 };
505
506 struct RegShiftedImmOp {
507 ARM_AM::ShiftOpc ShiftTy;
508 unsigned SrcReg;
509 unsigned ShiftImm;
510 };
511
512 struct RotImmOp {
513 unsigned Imm;
514 };
515
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000516 struct ModImmOp {
517 unsigned Bits;
518 unsigned Rot;
519 };
520
Eric Christopher8996c5d2013-03-15 00:42:55 +0000521 struct BitfieldOp {
522 unsigned LSB;
523 unsigned Width;
524 };
525
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000526 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000527 struct CCOp CC;
528 struct CopOp Cop;
529 struct CoprocOptionOp CoprocOption;
530 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000531 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000532 struct ITMaskOp ITMask;
533 struct IFlagsOp IFlags;
534 struct MMaskOp MMask;
Tim Northoveree843ef2014-08-15 10:47:12 +0000535 struct BankedRegOp BankedReg;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000536 struct TokOp Tok;
537 struct RegOp Reg;
538 struct VectorListOp VectorList;
539 struct VectorIndexOp VectorIndex;
540 struct ImmOp Imm;
541 struct MemoryOp Memory;
542 struct PostIdxRegOp PostIdxReg;
543 struct ShifterImmOp ShifterImm;
544 struct RegShiftedRegOp RegShiftedReg;
545 struct RegShiftedImmOp RegShiftedImm;
546 struct RotImmOp RotImm;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000547 struct ModImmOp ModImm;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000548 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000549 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000550
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000551public:
David Blaikie960ea3f2014-06-08 16:18:35 +0000552 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000553 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
554 Kind = o.Kind;
555 StartLoc = o.StartLoc;
556 EndLoc = o.EndLoc;
557 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000558 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000559 CC = o.CC;
560 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000561 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000562 ITMask = o.ITMask;
563 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000564 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000565 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000566 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000567 case k_CCOut:
568 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000569 Reg = o.Reg;
570 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000571 case k_RegisterList:
572 case k_DPRRegisterList:
573 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000574 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000575 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000576 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000577 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000578 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000579 VectorList = o.VectorList;
580 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000581 case k_CoprocNum:
582 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000583 Cop = o.Cop;
584 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000585 case k_CoprocOption:
586 CoprocOption = o.CoprocOption;
587 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000588 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000589 Imm = o.Imm;
590 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000591 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000592 MBOpt = o.MBOpt;
593 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000594 case k_InstSyncBarrierOpt:
595 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000596 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000597 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000598 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000599 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000600 PostIdxReg = o.PostIdxReg;
601 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000602 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000603 MMask = o.MMask;
604 break;
Tim Northoveree843ef2014-08-15 10:47:12 +0000605 case k_BankedReg:
606 BankedReg = o.BankedReg;
607 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000608 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000609 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000610 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000611 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000612 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000613 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000614 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000615 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000616 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000617 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000618 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000619 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000620 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000621 RotImm = o.RotImm;
622 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000623 case k_ModifiedImmediate:
624 ModImm = o.ModImm;
625 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000626 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000627 Bitfield = o.Bitfield;
628 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000629 case k_VectorIndex:
630 VectorIndex = o.VectorIndex;
631 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000632 }
633 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000634
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000635 /// getStartLoc - Get the location of the first token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000636 SMLoc getStartLoc() const override { return StartLoc; }
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000637 /// getEndLoc - Get the location of the last token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000638 SMLoc getEndLoc() const override { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000639 /// getLocRange - Get the range between the first and last token of this
640 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000641 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
642
Kevin Enderby488f20b2014-04-10 20:18:58 +0000643 /// getAlignmentLoc - Get the location of the Alignment token of this operand.
644 SMLoc getAlignmentLoc() const {
645 assert(Kind == k_Memory && "Invalid access!");
646 return AlignmentLoc;
647 }
648
Daniel Dunbard8042b72010-08-11 06:36:53 +0000649 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000650 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000651 return CC.Val;
652 }
653
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000654 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000655 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000656 return Cop.Val;
657 }
658
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000659 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000660 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000661 return StringRef(Tok.Data, Tok.Length);
662 }
663
Craig Topperca7e3e52014-03-10 03:19:03 +0000664 unsigned getReg() const override {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000665 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000666 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000667 }
668
Bill Wendlingbed94652010-11-09 23:28:44 +0000669 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000670 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
671 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000672 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000673 }
674
Kevin Enderbyf5079942009-10-13 22:19:02 +0000675 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000676 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000677 return Imm.Val;
678 }
679
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000680 unsigned getVectorIndex() const {
681 assert(Kind == k_VectorIndex && "Invalid access!");
682 return VectorIndex.Val;
683 }
684
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000685 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000686 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000687 return MBOpt.Val;
688 }
689
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000690 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
691 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
692 return ISBOpt.Val;
693 }
694
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000695 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000696 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000697 return IFlags.Val;
698 }
699
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000700 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000701 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000702 return MMask.Val;
703 }
704
Tim Northoveree843ef2014-08-15 10:47:12 +0000705 unsigned getBankedReg() const {
706 assert(Kind == k_BankedReg && "Invalid access!");
707 return BankedReg.Val;
708 }
709
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000710 bool isCoprocNum() const { return Kind == k_CoprocNum; }
711 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000712 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000713 bool isCondCode() const { return Kind == k_CondCode; }
714 bool isCCOut() const { return Kind == k_CCOut; }
715 bool isITMask() const { return Kind == k_ITCondMask; }
716 bool isITCondCode() const { return Kind == k_CondCode; }
Craig Topperca7e3e52014-03-10 03:19:03 +0000717 bool isImm() const override { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000718 // checks whether this operand is an unsigned offset which fits is a field
719 // of specified width and scaled by a specific number of bits
720 template<unsigned width, unsigned scale>
721 bool isUnsignedOffset() const {
722 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000723 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000724 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
725 int64_t Val = CE->getValue();
726 int64_t Align = 1LL << scale;
727 int64_t Max = Align * ((1LL << width) - 1);
728 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
729 }
730 return false;
731 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000732 // checks whether this operand is an signed offset which fits is a field
733 // of specified width and scaled by a specific number of bits
734 template<unsigned width, unsigned scale>
735 bool isSignedOffset() const {
736 if (!isImm()) return false;
737 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
738 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
739 int64_t Val = CE->getValue();
740 int64_t Align = 1LL << scale;
741 int64_t Max = Align * ((1LL << (width-1)) - 1);
742 int64_t Min = -Align * (1LL << (width-1));
743 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
744 }
745 return false;
746 }
747
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000748 // checks whether this operand is a memory operand computed as an offset
749 // applied to PC. the offset may have 8 bits of magnitude and is represented
750 // with two bits of shift. textually it may be either [pc, #imm], #imm or
751 // relocable expression...
752 bool isThumbMemPC() const {
753 int64_t Val = 0;
754 if (isImm()) {
755 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
757 if (!CE) return false;
758 Val = CE->getValue();
759 }
760 else if (isMem()) {
761 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
762 if(Memory.BaseRegNum != ARM::PC) return false;
763 Val = Memory.OffsetImm->getValue();
764 }
765 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000766 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000767 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000768 bool isFPImm() const {
769 if (!isImm()) return false;
770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
771 if (!CE) return false;
772 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
773 return Val != -1;
774 }
Jim Grosbachea231912011-12-22 22:19:05 +0000775 bool isFBits16() const {
776 if (!isImm()) return false;
777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
778 if (!CE) return false;
779 int64_t Value = CE->getValue();
780 return Value >= 0 && Value <= 16;
781 }
782 bool isFBits32() const {
783 if (!isImm()) return false;
784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
785 if (!CE) return false;
786 int64_t Value = CE->getValue();
787 return Value >= 1 && Value <= 32;
788 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000789 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000790 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000791 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
792 if (!CE) return false;
793 int64_t Value = CE->getValue();
794 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
795 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000796 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000797 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000798 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
799 if (!CE) return false;
800 int64_t Value = CE->getValue();
801 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
802 }
803 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000804 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000805 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
806 if (!CE) return false;
807 int64_t Value = CE->getValue();
808 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
809 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000810 bool isImm0_508s4Neg() const {
811 if (!isImm()) return false;
812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
813 if (!CE) return false;
814 int64_t Value = -CE->getValue();
815 // explicitly exclude zero. we want that to use the normal 0_508 version.
816 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
817 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000818 bool isImm0_239() const {
819 if (!isImm()) return false;
820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
821 if (!CE) return false;
822 int64_t Value = CE->getValue();
823 return Value >= 0 && Value < 240;
824 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000825 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000826 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
828 if (!CE) return false;
829 int64_t Value = CE->getValue();
830 return Value >= 0 && Value < 256;
831 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000832 bool isImm0_4095() const {
833 if (!isImm()) return false;
834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
835 if (!CE) return false;
836 int64_t Value = CE->getValue();
837 return Value >= 0 && Value < 4096;
838 }
839 bool isImm0_4095Neg() const {
840 if (!isImm()) return false;
841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
842 if (!CE) return false;
843 int64_t Value = -CE->getValue();
844 return Value > 0 && Value < 4096;
845 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000846 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000847 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
849 if (!CE) return false;
850 int64_t Value = CE->getValue();
851 return Value >= 0 && Value < 2;
852 }
853 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000854 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
856 if (!CE) return false;
857 int64_t Value = CE->getValue();
858 return Value >= 0 && Value < 4;
859 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000860 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000861 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
863 if (!CE) return false;
864 int64_t Value = CE->getValue();
865 return Value >= 0 && Value < 8;
866 }
867 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000868 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
870 if (!CE) return false;
871 int64_t Value = CE->getValue();
872 return Value >= 0 && Value < 16;
873 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000874 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000875 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
877 if (!CE) return false;
878 int64_t Value = CE->getValue();
879 return Value >= 0 && Value < 32;
880 }
Jim Grosbach00326402011-12-08 01:30:04 +0000881 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000882 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
884 if (!CE) return false;
885 int64_t Value = CE->getValue();
886 return Value >= 0 && Value < 64;
887 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000888 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000889 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000890 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
891 if (!CE) return false;
892 int64_t Value = CE->getValue();
893 return Value == 8;
894 }
895 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000896 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000897 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
898 if (!CE) return false;
899 int64_t Value = CE->getValue();
900 return Value == 16;
901 }
902 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000903 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000904 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
905 if (!CE) return false;
906 int64_t Value = CE->getValue();
907 return Value == 32;
908 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000909 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000910 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000911 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
912 if (!CE) return false;
913 int64_t Value = CE->getValue();
914 return Value > 0 && Value <= 8;
915 }
916 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000917 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
919 if (!CE) return false;
920 int64_t Value = CE->getValue();
921 return Value > 0 && Value <= 16;
922 }
923 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000924 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000925 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
926 if (!CE) return false;
927 int64_t Value = CE->getValue();
928 return Value > 0 && Value <= 32;
929 }
930 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000931 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000932 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
933 if (!CE) return false;
934 int64_t Value = CE->getValue();
935 return Value > 0 && Value <= 64;
936 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000937 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000938 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000939 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
940 if (!CE) return false;
941 int64_t Value = CE->getValue();
942 return Value > 0 && Value < 8;
943 }
944 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000945 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000946 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
947 if (!CE) return false;
948 int64_t Value = CE->getValue();
949 return Value > 0 && Value < 16;
950 }
951 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000952 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
954 if (!CE) return false;
955 int64_t Value = CE->getValue();
956 return Value > 0 && Value < 32;
957 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000958 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000959 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000960 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
961 if (!CE) return false;
962 int64_t Value = CE->getValue();
963 return Value > 0 && Value < 17;
964 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000965 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000966 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000967 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
968 if (!CE) return false;
969 int64_t Value = CE->getValue();
970 return Value > 0 && Value < 33;
971 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000972 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000973 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000974 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
975 if (!CE) return false;
976 int64_t Value = CE->getValue();
977 return Value >= 0 && Value < 33;
978 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000979 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000980 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000981 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
982 if (!CE) return false;
983 int64_t Value = CE->getValue();
984 return Value >= 0 && Value < 65536;
985 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000986 bool isImm256_65535Expr() const {
987 if (!isImm()) return false;
988 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
989 // If it's not a constant expression, it'll generate a fixup and be
990 // handled later.
991 if (!CE) return true;
992 int64_t Value = CE->getValue();
993 return Value >= 256 && Value < 65536;
994 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000995 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000996 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000997 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
998 // If it's not a constant expression, it'll generate a fixup and be
999 // handled later.
1000 if (!CE) return true;
1001 int64_t Value = CE->getValue();
1002 return Value >= 0 && Value < 65536;
1003 }
Jim Grosbachf1637842011-07-26 16:24:27 +00001004 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001005 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +00001006 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1007 if (!CE) return false;
1008 int64_t Value = CE->getValue();
1009 return Value >= 0 && Value <= 0xffffff;
1010 }
Jim Grosbach46dd4132011-08-17 21:51:27 +00001011 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001012 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +00001013 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1014 if (!CE) return false;
1015 int64_t Value = CE->getValue();
1016 return Value > 0 && Value < 33;
1017 }
Jim Grosbach27c1e252011-07-21 17:23:04 +00001018 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001019 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001020 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1021 if (!CE) return false;
1022 int64_t Value = CE->getValue();
1023 return Value >= 0 && Value < 32;
1024 }
1025 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001026 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001027 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1028 if (!CE) return false;
1029 int64_t Value = CE->getValue();
1030 return Value > 0 && Value <= 32;
1031 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001032 bool isAdrLabel() const {
1033 // If we have an immediate that's not a constant, treat it as a label
1034 // reference needing a fixup. If it is a constant, but it can't fit
1035 // into shift immediate encoding, we reject it.
1036 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1037 else return (isARMSOImm() || isARMSOImmNeg());
1038 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001039 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001040 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001041 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1042 if (!CE) return false;
1043 int64_t Value = CE->getValue();
1044 return ARM_AM::getSOImmVal(Value) != -1;
1045 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001046 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001047 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1049 if (!CE) return false;
1050 int64_t Value = CE->getValue();
1051 return ARM_AM::getSOImmVal(~Value) != -1;
1052 }
Jim Grosbach30506252011-12-08 00:31:07 +00001053 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001054 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001055 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1056 if (!CE) return false;
1057 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001058 // Only use this when not representable as a plain so_imm.
1059 return ARM_AM::getSOImmVal(Value) == -1 &&
1060 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001061 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001062 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001063 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001064 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1065 if (!CE) return false;
1066 int64_t Value = CE->getValue();
1067 return ARM_AM::getT2SOImmVal(Value) != -1;
1068 }
Jim Grosbachb009a872011-10-28 22:36:30 +00001069 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001070 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +00001071 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1072 if (!CE) return false;
1073 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +00001074 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1075 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +00001076 }
Jim Grosbach30506252011-12-08 00:31:07 +00001077 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001078 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001079 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1080 if (!CE) return false;
1081 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001082 // Only use this when not representable as a plain so_imm.
1083 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1084 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001085 }
Jim Grosbach0a547702011-07-22 17:44:50 +00001086 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001087 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +00001088 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1089 if (!CE) return false;
1090 int64_t Value = CE->getValue();
1091 return Value == 1 || Value == 0;
1092 }
Craig Topperca7e3e52014-03-10 03:19:03 +00001093 bool isReg() const override { return Kind == k_Register; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001094 bool isRegList() const { return Kind == k_RegisterList; }
1095 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1096 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001097 bool isToken() const override { return Kind == k_Token; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001098 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001099 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001100 bool isMem() const override { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001101 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1102 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1103 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1104 bool isRotImm() const { return Kind == k_RotateImmediate; }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001105 bool isModImm() const { return Kind == k_ModifiedImmediate; }
1106 bool isModImmNot() const {
1107 if (!isImm()) return false;
1108 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1109 if (!CE) return false;
1110 int64_t Value = CE->getValue();
1111 return ARM_AM::getSOImmVal(~Value) != -1;
1112 }
1113 bool isModImmNeg() const {
1114 if (!isImm()) return false;
1115 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1116 if (!CE) return false;
1117 int64_t Value = CE->getValue();
1118 return ARM_AM::getSOImmVal(Value) == -1 &&
1119 ARM_AM::getSOImmVal(-Value) != -1;
1120 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001121 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1122 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001123 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001124 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001125 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001126 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const {
Chad Rosier41099832012-09-11 23:02:35 +00001127 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001128 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001129 // No offset of any kind.
Craig Topper062a2ba2014-04-25 05:30:21 +00001130 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
Kevin Enderby488f20b2014-04-10 20:18:58 +00001131 (alignOK || Memory.Alignment == Alignment);
Jim Grosbacha95ec992011-10-11 17:29:55 +00001132 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001133 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001134 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001135 return false;
1136 // Base register must be PC.
1137 if (Memory.BaseRegNum != ARM::PC)
1138 return false;
1139 // Immediate offset in range [-4095, 4095].
1140 if (!Memory.OffsetImm) return true;
1141 int64_t Val = Memory.OffsetImm->getValue();
1142 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1143 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001144 bool isAlignedMemory() const {
1145 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001146 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001147 bool isAlignedMemoryNone() const {
1148 return isMemNoOffset(false, 0);
1149 }
1150 bool isDupAlignedMemoryNone() const {
1151 return isMemNoOffset(false, 0);
1152 }
1153 bool isAlignedMemory16() const {
1154 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1155 return true;
1156 return isMemNoOffset(false, 0);
1157 }
1158 bool isDupAlignedMemory16() const {
1159 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1160 return true;
1161 return isMemNoOffset(false, 0);
1162 }
1163 bool isAlignedMemory32() const {
1164 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1165 return true;
1166 return isMemNoOffset(false, 0);
1167 }
1168 bool isDupAlignedMemory32() const {
1169 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1170 return true;
1171 return isMemNoOffset(false, 0);
1172 }
1173 bool isAlignedMemory64() const {
1174 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1175 return true;
1176 return isMemNoOffset(false, 0);
1177 }
1178 bool isDupAlignedMemory64() const {
1179 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1180 return true;
1181 return isMemNoOffset(false, 0);
1182 }
1183 bool isAlignedMemory64or128() const {
1184 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1185 return true;
1186 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1187 return true;
1188 return isMemNoOffset(false, 0);
1189 }
1190 bool isDupAlignedMemory64or128() const {
1191 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1192 return true;
1193 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1194 return true;
1195 return isMemNoOffset(false, 0);
1196 }
1197 bool isAlignedMemory64or128or256() const {
1198 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1199 return true;
1200 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1201 return true;
1202 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
1203 return true;
1204 return isMemNoOffset(false, 0);
1205 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001206 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001207 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001208 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001209 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001210 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001211 if (!Memory.OffsetImm) return true;
1212 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001213 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001214 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001215 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001216 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001217 // Immediate offset in range [-4095, 4095].
1218 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1219 if (!CE) return false;
1220 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001221 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001222 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001223 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001224 // If we have an immediate that's not a constant, treat it as a label
1225 // reference needing a fixup. If it is a constant, it's something else
1226 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001227 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001228 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001229 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001230 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001231 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001232 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001233 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001234 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001235 if (!Memory.OffsetImm) return true;
1236 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001237 // The #-0 offset is encoded as INT32_MIN, and we have to check
1238 // for this too.
1239 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001240 }
1241 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001242 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001243 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001244 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001245 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1246 // Immediate offset in range [-255, 255].
1247 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1248 if (!CE) return false;
1249 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001250 // Special case, #-0 is INT32_MIN.
1251 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001252 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001253 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001254 // If we have an immediate that's not a constant, treat it as a label
1255 // reference needing a fixup. If it is a constant, it's something else
1256 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001257 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001258 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001259 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001260 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001261 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001262 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001263 if (!Memory.OffsetImm) return true;
1264 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001265 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001266 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001267 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001268 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001269 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001270 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001271 return false;
1272 return true;
1273 }
1274 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001275 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001276 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1277 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001278 return false;
1279 return true;
1280 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001281 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001282 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001283 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001284 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001285 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001286 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001287 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001288 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001289 return false;
1290 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001291 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001292 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001293 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001294 return false;
1295 return true;
1296 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001297 bool isMemThumbRR() const {
1298 // Thumb reg+reg addressing is simple. Just two registers, a base and
1299 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001300 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001301 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001302 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001303 return isARMLowRegister(Memory.BaseRegNum) &&
1304 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001305 }
1306 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001307 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001308 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001309 return false;
1310 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001311 if (!Memory.OffsetImm) return true;
1312 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001313 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1314 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001315 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001316 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001317 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001318 return false;
1319 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001320 if (!Memory.OffsetImm) return true;
1321 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001322 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1323 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001324 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001325 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001326 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001327 return false;
1328 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001329 if (!Memory.OffsetImm) return true;
1330 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001331 return Val >= 0 && Val <= 31;
1332 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001333 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001334 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001335 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001336 return false;
1337 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001338 if (!Memory.OffsetImm) return true;
1339 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001340 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001341 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001342 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001343 // If we have an immediate that's not a constant, treat it as a label
1344 // reference needing a fixup. If it is a constant, it's something else
1345 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001346 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001347 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001348 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001349 return false;
1350 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001351 if (!Memory.OffsetImm) return true;
1352 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001353 // Special case, #-0 is INT32_MIN.
1354 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001355 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001356 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001357 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001358 return false;
1359 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001360 if (!Memory.OffsetImm) return true;
1361 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001362 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1363 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001364 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001365 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001366 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001367 // Base reg of PC isn't allowed for these encodings.
1368 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001369 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001370 if (!Memory.OffsetImm) return true;
1371 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001372 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001373 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001374 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001375 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001376 return false;
1377 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001378 if (!Memory.OffsetImm) return true;
1379 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001380 return Val >= 0 && Val < 256;
1381 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001382 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001383 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001384 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001385 // Base reg of PC isn't allowed for these encodings.
1386 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001387 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001388 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001389 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001390 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001391 }
1392 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001393 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001394 return false;
1395 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001396 if (!Memory.OffsetImm) return true;
1397 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001398 return (Val >= 0 && Val < 4096);
1399 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001400 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001401 // If we have an immediate that's not a constant, treat it as a label
1402 // reference needing a fixup. If it is a constant, it's something else
1403 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001404 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001405 return true;
1406
Chad Rosier41099832012-09-11 23:02:35 +00001407 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001408 return false;
1409 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001410 if (!Memory.OffsetImm) return true;
1411 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001412 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001413 }
1414 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001415 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001416 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1417 if (!CE) return false;
1418 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001419 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001420 }
Jim Grosbach93981412011-10-11 21:55:36 +00001421 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001422 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001423 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1424 if (!CE) return false;
1425 int64_t Val = CE->getValue();
1426 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1427 (Val == INT32_MIN);
1428 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001429
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001430 bool isMSRMask() const { return Kind == k_MSRMask; }
Tim Northoveree843ef2014-08-15 10:47:12 +00001431 bool isBankedReg() const { return Kind == k_BankedReg; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001432 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001433
Jim Grosbach741cd732011-10-17 22:26:03 +00001434 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001435 bool isSingleSpacedVectorList() const {
1436 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1437 }
1438 bool isDoubleSpacedVectorList() const {
1439 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1440 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001441 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001442 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001443 return VectorList.Count == 1;
1444 }
1445
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001446 bool isVecListDPair() const {
1447 if (!isSingleSpacedVectorList()) return false;
1448 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1449 .contains(VectorList.RegNum));
1450 }
1451
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001452 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001453 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001454 return VectorList.Count == 3;
1455 }
1456
Jim Grosbach846bcff2011-10-21 20:35:01 +00001457 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001458 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001459 return VectorList.Count == 4;
1460 }
1461
Jim Grosbache5307f92012-03-05 21:43:40 +00001462 bool isVecListDPairSpaced() const {
Kevin Enderby56113982014-03-26 21:54:11 +00001463 if (Kind != k_VectorList) return false;
Kevin Enderby816ca272012-03-20 17:41:51 +00001464 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001465 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1466 .contains(VectorList.RegNum));
1467 }
1468
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001469 bool isVecListThreeQ() const {
1470 if (!isDoubleSpacedVectorList()) return false;
1471 return VectorList.Count == 3;
1472 }
1473
Jim Grosbach1e946a42012-01-24 00:43:12 +00001474 bool isVecListFourQ() const {
1475 if (!isDoubleSpacedVectorList()) return false;
1476 return VectorList.Count == 4;
1477 }
1478
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001479 bool isSingleSpacedVectorAllLanes() const {
1480 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1481 }
1482 bool isDoubleSpacedVectorAllLanes() const {
1483 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1484 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001485 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001486 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001487 return VectorList.Count == 1;
1488 }
1489
Jim Grosbach13a292c2012-03-06 22:01:44 +00001490 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001491 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001492 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1493 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001494 }
1495
Jim Grosbached428bc2012-03-06 23:10:38 +00001496 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001497 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001498 return VectorList.Count == 2;
1499 }
1500
Jim Grosbachb78403c2012-01-24 23:47:04 +00001501 bool isVecListThreeDAllLanes() const {
1502 if (!isSingleSpacedVectorAllLanes()) return false;
1503 return VectorList.Count == 3;
1504 }
1505
1506 bool isVecListThreeQAllLanes() const {
1507 if (!isDoubleSpacedVectorAllLanes()) return false;
1508 return VectorList.Count == 3;
1509 }
1510
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001511 bool isVecListFourDAllLanes() const {
1512 if (!isSingleSpacedVectorAllLanes()) return false;
1513 return VectorList.Count == 4;
1514 }
1515
1516 bool isVecListFourQAllLanes() const {
1517 if (!isDoubleSpacedVectorAllLanes()) return false;
1518 return VectorList.Count == 4;
1519 }
1520
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001521 bool isSingleSpacedVectorIndexed() const {
1522 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1523 }
1524 bool isDoubleSpacedVectorIndexed() const {
1525 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1526 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001527 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001528 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001529 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1530 }
1531
Jim Grosbachda511042011-12-14 23:35:06 +00001532 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001533 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001534 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1535 }
1536
1537 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001538 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001539 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1540 }
1541
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001542 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001543 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001544 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1545 }
1546
Jim Grosbachda511042011-12-14 23:35:06 +00001547 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001548 if (!isSingleSpacedVectorIndexed()) return false;
1549 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1550 }
1551
1552 bool isVecListTwoQWordIndexed() const {
1553 if (!isDoubleSpacedVectorIndexed()) return false;
1554 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1555 }
1556
1557 bool isVecListTwoQHWordIndexed() const {
1558 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001559 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1560 }
1561
1562 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001563 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001564 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1565 }
1566
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001567 bool isVecListThreeDByteIndexed() const {
1568 if (!isSingleSpacedVectorIndexed()) return false;
1569 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1570 }
1571
1572 bool isVecListThreeDHWordIndexed() const {
1573 if (!isSingleSpacedVectorIndexed()) return false;
1574 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1575 }
1576
1577 bool isVecListThreeQWordIndexed() const {
1578 if (!isDoubleSpacedVectorIndexed()) return false;
1579 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1580 }
1581
1582 bool isVecListThreeQHWordIndexed() const {
1583 if (!isDoubleSpacedVectorIndexed()) return false;
1584 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1585 }
1586
1587 bool isVecListThreeDWordIndexed() const {
1588 if (!isSingleSpacedVectorIndexed()) return false;
1589 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1590 }
1591
Jim Grosbach14952a02012-01-24 18:37:25 +00001592 bool isVecListFourDByteIndexed() const {
1593 if (!isSingleSpacedVectorIndexed()) return false;
1594 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1595 }
1596
1597 bool isVecListFourDHWordIndexed() const {
1598 if (!isSingleSpacedVectorIndexed()) return false;
1599 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1600 }
1601
1602 bool isVecListFourQWordIndexed() const {
1603 if (!isDoubleSpacedVectorIndexed()) return false;
1604 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1605 }
1606
1607 bool isVecListFourQHWordIndexed() const {
1608 if (!isDoubleSpacedVectorIndexed()) return false;
1609 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1610 }
1611
1612 bool isVecListFourDWordIndexed() const {
1613 if (!isSingleSpacedVectorIndexed()) return false;
1614 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1615 }
1616
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001617 bool isVectorIndex8() const {
1618 if (Kind != k_VectorIndex) return false;
1619 return VectorIndex.Val < 8;
1620 }
1621 bool isVectorIndex16() const {
1622 if (Kind != k_VectorIndex) return false;
1623 return VectorIndex.Val < 4;
1624 }
1625 bool isVectorIndex32() const {
1626 if (Kind != k_VectorIndex) return false;
1627 return VectorIndex.Val < 2;
1628 }
1629
Jim Grosbach741cd732011-10-17 22:26:03 +00001630 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001631 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001632 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1633 // Must be a constant.
1634 if (!CE) return false;
1635 int64_t Value = CE->getValue();
1636 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1637 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001638 return Value >= 0 && Value < 256;
1639 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001640
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001641 bool isNEONi16splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001642 if (isNEONByteReplicate(2))
1643 return false; // Leave that for bytes replication and forbid by default.
1644 if (!isImm())
1645 return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001646 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1647 // Must be a constant.
1648 if (!CE) return false;
Renato Golinf5dd1da2014-09-25 11:31:24 +00001649 unsigned Value = CE->getValue();
1650 return ARM_AM::isNEONi16splat(Value);
1651 }
1652
1653 bool isNEONi16splatNot() const {
1654 if (!isImm())
1655 return false;
1656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1657 // Must be a constant.
1658 if (!CE) return false;
1659 unsigned Value = CE->getValue();
1660 return ARM_AM::isNEONi16splat(~Value & 0xffff);
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001661 }
1662
Jim Grosbach8211c052011-10-18 00:22:00 +00001663 bool isNEONi32splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001664 if (isNEONByteReplicate(4))
1665 return false; // Leave that for bytes replication and forbid by default.
1666 if (!isImm())
1667 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1669 // Must be a constant.
1670 if (!CE) return false;
Renato Golinf5dd1da2014-09-25 11:31:24 +00001671 unsigned Value = CE->getValue();
1672 return ARM_AM::isNEONi32splat(Value);
1673 }
1674
1675 bool isNEONi32splatNot() const {
1676 if (!isImm())
1677 return false;
1678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1679 // Must be a constant.
1680 if (!CE) return false;
1681 unsigned Value = CE->getValue();
1682 return ARM_AM::isNEONi32splat(~Value);
Jim Grosbach8211c052011-10-18 00:22:00 +00001683 }
1684
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001685 bool isNEONByteReplicate(unsigned NumBytes) const {
1686 if (!isImm())
1687 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001688 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1689 // Must be a constant.
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001690 if (!CE)
1691 return false;
1692 int64_t Value = CE->getValue();
1693 if (!Value)
1694 return false; // Don't bother with zero.
1695
1696 unsigned char B = Value & 0xff;
1697 for (unsigned i = 1; i < NumBytes; ++i) {
1698 Value >>= 8;
1699 if ((Value & 0xff) != B)
1700 return false;
1701 }
1702 return true;
1703 }
1704 bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); }
1705 bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); }
1706 bool isNEONi32vmov() const {
1707 if (isNEONByteReplicate(4))
1708 return false; // Let it to be classified as byte-replicate case.
1709 if (!isImm())
1710 return false;
1711 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1712 // Must be a constant.
1713 if (!CE)
1714 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001715 int64_t Value = CE->getValue();
1716 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1717 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
Renato Golinf5dd1da2014-09-25 11:31:24 +00001718 // FIXME: This is probably wrong and a copy and paste from previous example
Jim Grosbach8211c052011-10-18 00:22:00 +00001719 return (Value >= 0 && Value < 256) ||
1720 (Value >= 0x0100 && Value <= 0xff00) ||
1721 (Value >= 0x010000 && Value <= 0xff0000) ||
1722 (Value >= 0x01000000 && Value <= 0xff000000) ||
1723 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1724 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1725 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001726 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001727 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1729 // Must be a constant.
1730 if (!CE) return false;
1731 int64_t Value = ~CE->getValue();
1732 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1733 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
Renato Golinf5dd1da2014-09-25 11:31:24 +00001734 // FIXME: This is probably wrong and a copy and paste from previous example
Jim Grosbach045b6c72011-12-19 23:51:07 +00001735 return (Value >= 0 && Value < 256) ||
1736 (Value >= 0x0100 && Value <= 0xff00) ||
1737 (Value >= 0x010000 && Value <= 0xff0000) ||
1738 (Value >= 0x01000000 && Value <= 0xff000000) ||
1739 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1740 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1741 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001742
Jim Grosbache4454e02011-10-18 16:18:11 +00001743 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001744 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001745 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1746 // Must be a constant.
1747 if (!CE) return false;
1748 uint64_t Value = CE->getValue();
1749 // i64 value with each byte being either 0 or 0xff.
1750 for (unsigned i = 0; i < 8; ++i)
1751 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1752 return true;
1753 }
1754
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001755 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001756 // Add as immediates when possible. Null MCExpr = 0.
Craig Topper062a2ba2014-04-25 05:30:21 +00001757 if (!Expr)
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001758 Inst.addOperand(MCOperand::CreateImm(0));
1759 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001760 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1761 else
1762 Inst.addOperand(MCOperand::CreateExpr(Expr));
1763 }
1764
Daniel Dunbard8042b72010-08-11 06:36:53 +00001765 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001766 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001767 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001768 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1769 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001770 }
1771
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001772 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1773 assert(N == 1 && "Invalid number of operands!");
1774 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1775 }
1776
Jim Grosbach48399582011-10-12 17:34:41 +00001777 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1778 assert(N == 1 && "Invalid number of operands!");
1779 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1780 }
1781
1782 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1783 assert(N == 1 && "Invalid number of operands!");
1784 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1785 }
1786
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001787 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1788 assert(N == 1 && "Invalid number of operands!");
1789 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1790 }
1791
1792 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1793 assert(N == 1 && "Invalid number of operands!");
1794 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1795 }
1796
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001797 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1798 assert(N == 1 && "Invalid number of operands!");
1799 Inst.addOperand(MCOperand::CreateReg(getReg()));
1800 }
1801
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001802 void addRegOperands(MCInst &Inst, unsigned N) const {
1803 assert(N == 1 && "Invalid number of operands!");
1804 Inst.addOperand(MCOperand::CreateReg(getReg()));
1805 }
1806
Jim Grosbachac798e12011-07-25 20:49:51 +00001807 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001808 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001809 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001810 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001811 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1812 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001813 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001814 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001815 }
1816
Jim Grosbachac798e12011-07-25 20:49:51 +00001817 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001818 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001819 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001820 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001821 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001822 // Shift of #32 is encoded as 0 where permitted
1823 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001824 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001825 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001826 }
1827
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001828 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001829 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001830 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1831 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001832 }
1833
Bill Wendling8d2aa032010-11-08 23:49:57 +00001834 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001835 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001836 const SmallVectorImpl<unsigned> &RegList = getRegList();
1837 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001838 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1839 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001840 }
1841
Bill Wendling9898ac92010-11-17 04:32:08 +00001842 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1843 addRegListOperands(Inst, N);
1844 }
1845
1846 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1847 addRegListOperands(Inst, N);
1848 }
1849
Jim Grosbach833b9d32011-07-27 20:15:40 +00001850 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1851 assert(N == 1 && "Invalid number of operands!");
1852 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1853 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1854 }
1855
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001856 void addModImmOperands(MCInst &Inst, unsigned N) const {
1857 assert(N == 1 && "Invalid number of operands!");
1858
1859 // Support for fixups (MCFixup)
1860 if (isImm())
1861 return addImmOperands(Inst, N);
1862
1863 if (Inst.getOpcode() == ARM::ADDri &&
1864 Inst.getOperand(1).getReg() == ARM::PC) {
1865 // Instructions of the form [ADD <rd>, pc, #imm] are manually aliased
1866 // in processInstruction() to use ADR. We must keep the immediate in
1867 // its unencoded form in order to not clash with this aliasing.
1868 Inst.addOperand(MCOperand::CreateImm(ARM_AM::rotr32(ModImm.Bits,
1869 ModImm.Rot)));
1870 } else {
1871 Inst.addOperand(MCOperand::CreateImm(ModImm.Bits | (ModImm.Rot << 7)));
1872 }
1873 }
1874
1875 void addModImmNotOperands(MCInst &Inst, unsigned N) const {
1876 assert(N == 1 && "Invalid number of operands!");
1877 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1878 uint32_t Enc = ARM_AM::getSOImmVal(~CE->getValue());
1879 Inst.addOperand(MCOperand::CreateImm(Enc));
1880 }
1881
1882 void addModImmNegOperands(MCInst &Inst, unsigned N) const {
1883 assert(N == 1 && "Invalid number of operands!");
1884 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1885 uint32_t Enc = ARM_AM::getSOImmVal(-CE->getValue());
1886 Inst.addOperand(MCOperand::CreateImm(Enc));
1887 }
1888
Jim Grosbach864b6092011-07-28 21:34:26 +00001889 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1890 assert(N == 1 && "Invalid number of operands!");
1891 // Munge the lsb/width into a bitfield mask.
1892 unsigned lsb = Bitfield.LSB;
1893 unsigned width = Bitfield.Width;
1894 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1895 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1896 (32 - (lsb + width)));
1897 Inst.addOperand(MCOperand::CreateImm(Mask));
1898 }
1899
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001900 void addImmOperands(MCInst &Inst, unsigned N) const {
1901 assert(N == 1 && "Invalid number of operands!");
1902 addExpr(Inst, getImm());
1903 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001904
Jim Grosbachea231912011-12-22 22:19:05 +00001905 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1906 assert(N == 1 && "Invalid number of operands!");
1907 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1908 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1909 }
1910
1911 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1912 assert(N == 1 && "Invalid number of operands!");
1913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1914 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1915 }
1916
Jim Grosbache7fbce72011-10-03 23:38:36 +00001917 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1918 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001919 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1920 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1921 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001922 }
1923
Jim Grosbach7db8d692011-09-08 22:07:06 +00001924 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1925 assert(N == 1 && "Invalid number of operands!");
1926 // FIXME: We really want to scale the value here, but the LDRD/STRD
1927 // instruction don't encode operands that way yet.
1928 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1929 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1930 }
1931
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001932 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1933 assert(N == 1 && "Invalid number of operands!");
1934 // The immediate is scaled by four in the encoding and is stored
1935 // in the MCInst as such. Lop off the low two bits here.
1936 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1937 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1938 }
1939
Jim Grosbach930f2f62012-04-05 20:57:13 +00001940 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1941 assert(N == 1 && "Invalid number of operands!");
1942 // The immediate is scaled by four in the encoding and is stored
1943 // in the MCInst as such. Lop off the low two bits here.
1944 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1945 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1946 }
1947
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001948 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1949 assert(N == 1 && "Invalid number of operands!");
1950 // The immediate is scaled by four in the encoding and is stored
1951 // in the MCInst as such. Lop off the low two bits here.
1952 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1953 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1954 }
1955
Jim Grosbach475c6db2011-07-25 23:09:14 +00001956 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1957 assert(N == 1 && "Invalid number of operands!");
1958 // The constant encodes as the immediate-1, and we store in the instruction
1959 // the bits as encoded, so subtract off one here.
1960 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1961 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1962 }
1963
Jim Grosbach801e0a32011-07-22 23:16:18 +00001964 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1965 assert(N == 1 && "Invalid number of operands!");
1966 // The constant encodes as the immediate-1, and we store in the instruction
1967 // the bits as encoded, so subtract off one here.
1968 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1969 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1970 }
1971
Jim Grosbach46dd4132011-08-17 21:51:27 +00001972 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1973 assert(N == 1 && "Invalid number of operands!");
1974 // The constant encodes as the immediate, except for 32, which encodes as
1975 // zero.
1976 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1977 unsigned Imm = CE->getValue();
1978 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1979 }
1980
Jim Grosbach27c1e252011-07-21 17:23:04 +00001981 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1982 assert(N == 1 && "Invalid number of operands!");
1983 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1984 // the instruction as well.
1985 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1986 int Val = CE->getValue();
1987 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1988 }
1989
Jim Grosbachb009a872011-10-28 22:36:30 +00001990 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1991 assert(N == 1 && "Invalid number of operands!");
1992 // The operand is actually a t2_so_imm, but we have its bitwise
1993 // negation in the assembly source, so twiddle it here.
1994 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1995 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1996 }
1997
Jim Grosbach30506252011-12-08 00:31:07 +00001998 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1999 assert(N == 1 && "Invalid number of operands!");
2000 // The operand is actually a t2_so_imm, but we have its
2001 // negation in the assembly source, so twiddle it here.
2002 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2003 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
2004 }
2005
Jim Grosbach930f2f62012-04-05 20:57:13 +00002006 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
2007 assert(N == 1 && "Invalid number of operands!");
2008 // The operand is actually an imm0_4095, but we have its
2009 // negation in the assembly source, so twiddle it here.
2010 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2011 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
2012 }
2013
Mihai Popad36cbaa2013-07-03 09:21:44 +00002014 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
2015 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
2016 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
2017 return;
2018 }
2019
2020 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
2021 assert(SR && "Unknown value type!");
2022 Inst.addOperand(MCOperand::CreateExpr(SR));
2023 }
2024
Mihai Popa8a9da5b2013-07-22 15:49:36 +00002025 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
2026 assert(N == 1 && "Invalid number of operands!");
2027 if (isImm()) {
2028 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2029 if (CE) {
2030 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
2031 return;
2032 }
2033
2034 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
2035 assert(SR && "Unknown value type!");
2036 Inst.addOperand(MCOperand::CreateExpr(SR));
2037 return;
2038 }
2039
2040 assert(isMem() && "Unknown value type!");
2041 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
2042 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
2043 }
2044
Jim Grosbach3d785ed2011-10-28 22:50:54 +00002045 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
2046 assert(N == 1 && "Invalid number of operands!");
2047 // The operand is actually a so_imm, but we have its bitwise
2048 // negation in the assembly source, so twiddle it here.
2049 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2050 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
2051 }
2052
Jim Grosbach30506252011-12-08 00:31:07 +00002053 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
2054 assert(N == 1 && "Invalid number of operands!");
2055 // The operand is actually a so_imm, but we have its
2056 // negation in the assembly source, so twiddle it here.
2057 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2058 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
2059 }
2060
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002061 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
2062 assert(N == 1 && "Invalid number of operands!");
2063 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
2064 }
2065
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002066 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
2067 assert(N == 1 && "Invalid number of operands!");
2068 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
2069 }
2070
Jim Grosbachd3595712011-08-03 23:50:40 +00002071 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
2072 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002073 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00002074 }
2075
Jim Grosbach94298a92012-01-18 22:46:46 +00002076 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
2077 assert(N == 1 && "Invalid number of operands!");
2078 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00002079 Inst.addOperand(MCOperand::CreateImm(Imm));
2080 }
2081
Jiangning Liu10dd40e2012-08-02 08:13:13 +00002082 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
2083 assert(N == 1 && "Invalid number of operands!");
2084 assert(isImm() && "Not an immediate!");
2085
2086 // If we have an immediate that's not a constant, treat it as a label
2087 // reference needing a fixup.
2088 if (!isa<MCConstantExpr>(getImm())) {
2089 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2090 return;
2091 }
2092
2093 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2094 int Val = CE->getValue();
2095 Inst.addOperand(MCOperand::CreateImm(Val));
2096 }
2097
Jim Grosbacha95ec992011-10-11 17:29:55 +00002098 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
2099 assert(N == 2 && "Invalid number of operands!");
2100 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2101 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
2102 }
2103
Kevin Enderby488f20b2014-04-10 20:18:58 +00002104 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2105 addAlignedMemoryOperands(Inst, N);
2106 }
2107
2108 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2109 addAlignedMemoryOperands(Inst, N);
2110 }
2111
2112 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2113 addAlignedMemoryOperands(Inst, N);
2114 }
2115
2116 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2117 addAlignedMemoryOperands(Inst, N);
2118 }
2119
2120 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2121 addAlignedMemoryOperands(Inst, N);
2122 }
2123
2124 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2125 addAlignedMemoryOperands(Inst, N);
2126 }
2127
2128 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2129 addAlignedMemoryOperands(Inst, N);
2130 }
2131
2132 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2133 addAlignedMemoryOperands(Inst, N);
2134 }
2135
2136 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2137 addAlignedMemoryOperands(Inst, N);
2138 }
2139
2140 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2141 addAlignedMemoryOperands(Inst, N);
2142 }
2143
2144 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
2145 addAlignedMemoryOperands(Inst, N);
2146 }
2147
Jim Grosbachd3595712011-08-03 23:50:40 +00002148 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
2149 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002150 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2151 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00002152 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2153 // Special case for #-0
2154 if (Val == INT32_MIN) Val = 0;
2155 if (Val < 0) Val = -Val;
2156 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2157 } else {
2158 // For register offset, we encode the shift type and negation flag
2159 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002160 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2161 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002162 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002163 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2164 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002165 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002166 }
2167
Jim Grosbachcd17c122011-08-04 23:01:30 +00002168 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
2169 assert(N == 2 && "Invalid number of operands!");
2170 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2171 assert(CE && "non-constant AM2OffsetImm operand!");
2172 int32_t Val = CE->getValue();
2173 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2174 // Special case for #-0
2175 if (Val == INT32_MIN) Val = 0;
2176 if (Val < 0) Val = -Val;
2177 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2178 Inst.addOperand(MCOperand::CreateReg(0));
2179 Inst.addOperand(MCOperand::CreateImm(Val));
2180 }
2181
Jim Grosbach5b96b802011-08-10 20:29:19 +00002182 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
2183 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002184 // If we have an immediate that's not a constant, treat it as a label
2185 // reference needing a fixup. If it is a constant, it's something else
2186 // and we reject it.
2187 if (isImm()) {
2188 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2189 Inst.addOperand(MCOperand::CreateReg(0));
2190 Inst.addOperand(MCOperand::CreateImm(0));
2191 return;
2192 }
2193
Jim Grosbach871dff72011-10-11 15:59:20 +00002194 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2195 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002196 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2197 // Special case for #-0
2198 if (Val == INT32_MIN) Val = 0;
2199 if (Val < 0) Val = -Val;
2200 Val = ARM_AM::getAM3Opc(AddSub, Val);
2201 } else {
2202 // For register offset, we encode the shift type and negation flag
2203 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002204 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002205 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002206 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2207 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00002208 Inst.addOperand(MCOperand::CreateImm(Val));
2209 }
2210
2211 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
2212 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002213 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002214 int32_t Val =
2215 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
2216 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2217 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002218 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00002219 }
2220
2221 // Constant offset.
2222 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2223 int32_t Val = CE->getValue();
2224 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2225 // Special case for #-0
2226 if (Val == INT32_MIN) Val = 0;
2227 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002228 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002229 Inst.addOperand(MCOperand::CreateReg(0));
2230 Inst.addOperand(MCOperand::CreateImm(Val));
2231 }
2232
Jim Grosbachd3595712011-08-03 23:50:40 +00002233 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2234 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00002235 // If we have an immediate that's not a constant, treat it as a label
2236 // reference needing a fixup. If it is a constant, it's something else
2237 // and we reject it.
2238 if (isImm()) {
2239 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2240 Inst.addOperand(MCOperand::CreateImm(0));
2241 return;
2242 }
2243
Jim Grosbachd3595712011-08-03 23:50:40 +00002244 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002245 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002246 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2247 // Special case for #-0
2248 if (Val == INT32_MIN) Val = 0;
2249 if (Val < 0) Val = -Val;
2250 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002251 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002252 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002253 }
2254
Jim Grosbach7db8d692011-09-08 22:07:06 +00002255 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2256 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002257 // If we have an immediate that's not a constant, treat it as a label
2258 // reference needing a fixup. If it is a constant, it's something else
2259 // and we reject it.
2260 if (isImm()) {
2261 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2262 Inst.addOperand(MCOperand::CreateImm(0));
2263 return;
2264 }
2265
Jim Grosbach871dff72011-10-11 15:59:20 +00002266 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2267 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002268 Inst.addOperand(MCOperand::CreateImm(Val));
2269 }
2270
Jim Grosbacha05627e2011-09-09 18:37:27 +00002271 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2272 assert(N == 2 && "Invalid number of operands!");
2273 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002274 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2275 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002276 Inst.addOperand(MCOperand::CreateImm(Val));
2277 }
2278
Jim Grosbachd3595712011-08-03 23:50:40 +00002279 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2280 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002281 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2282 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002283 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002284 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002285
Jim Grosbach2392c532011-09-07 23:39:14 +00002286 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2287 addMemImm8OffsetOperands(Inst, N);
2288 }
2289
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002290 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002291 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002292 }
2293
2294 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2295 assert(N == 2 && "Invalid number of operands!");
2296 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002297 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002298 addExpr(Inst, getImm());
2299 Inst.addOperand(MCOperand::CreateImm(0));
2300 return;
2301 }
2302
2303 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002304 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2305 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002306 Inst.addOperand(MCOperand::CreateImm(Val));
2307 }
2308
Jim Grosbachd3595712011-08-03 23:50:40 +00002309 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2310 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002311 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002312 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002313 addExpr(Inst, getImm());
2314 Inst.addOperand(MCOperand::CreateImm(0));
2315 return;
2316 }
2317
2318 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002319 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2320 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002321 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002322 }
Bill Wendling811c9362010-11-30 07:44:32 +00002323
Jim Grosbach05541f42011-09-19 22:21:13 +00002324 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2325 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002326 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2327 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002328 }
2329
2330 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2331 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002332 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2333 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002334 }
2335
Jim Grosbachd3595712011-08-03 23:50:40 +00002336 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2337 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002338 unsigned Val =
2339 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2340 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002341 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2342 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002343 Inst.addOperand(MCOperand::CreateImm(Val));
2344 }
2345
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002346 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2347 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002348 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2349 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2350 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002351 }
2352
Jim Grosbachd3595712011-08-03 23:50:40 +00002353 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2354 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002355 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2356 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002357 }
2358
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002359 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2360 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002361 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2362 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002363 Inst.addOperand(MCOperand::CreateImm(Val));
2364 }
2365
Jim Grosbach26d35872011-08-19 18:55:51 +00002366 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2367 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002368 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2369 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002370 Inst.addOperand(MCOperand::CreateImm(Val));
2371 }
2372
Jim Grosbacha32c7532011-08-19 18:49:59 +00002373 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2374 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002375 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2376 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002377 Inst.addOperand(MCOperand::CreateImm(Val));
2378 }
2379
Jim Grosbach23983d62011-08-19 18:13:48 +00002380 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2381 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002382 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2383 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002384 Inst.addOperand(MCOperand::CreateImm(Val));
2385 }
2386
Jim Grosbachd3595712011-08-03 23:50:40 +00002387 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2388 assert(N == 1 && "Invalid number of operands!");
2389 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2390 assert(CE && "non-constant post-idx-imm8 operand!");
2391 int Imm = CE->getValue();
2392 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002393 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002394 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2395 Inst.addOperand(MCOperand::CreateImm(Imm));
2396 }
2397
Jim Grosbach93981412011-10-11 21:55:36 +00002398 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2399 assert(N == 1 && "Invalid number of operands!");
2400 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2401 assert(CE && "non-constant post-idx-imm8s4 operand!");
2402 int Imm = CE->getValue();
2403 bool isAdd = Imm >= 0;
2404 if (Imm == INT32_MIN) Imm = 0;
2405 // Immediate is scaled by 4.
2406 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2407 Inst.addOperand(MCOperand::CreateImm(Imm));
2408 }
2409
Jim Grosbachd3595712011-08-03 23:50:40 +00002410 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2411 assert(N == 2 && "Invalid number of operands!");
2412 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002413 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2414 }
2415
2416 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2417 assert(N == 2 && "Invalid number of operands!");
2418 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2419 // The sign, shift type, and shift amount are encoded in a single operand
2420 // using the AM2 encoding helpers.
2421 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2422 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2423 PostIdxReg.ShiftTy);
2424 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002425 }
2426
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002427 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2428 assert(N == 1 && "Invalid number of operands!");
2429 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2430 }
2431
Tim Northoveree843ef2014-08-15 10:47:12 +00002432 void addBankedRegOperands(MCInst &Inst, unsigned N) const {
2433 assert(N == 1 && "Invalid number of operands!");
2434 Inst.addOperand(MCOperand::CreateImm(unsigned(getBankedReg())));
2435 }
2436
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002437 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2438 assert(N == 1 && "Invalid number of operands!");
2439 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2440 }
2441
Jim Grosbach182b6a02011-11-29 23:51:09 +00002442 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002443 assert(N == 1 && "Invalid number of operands!");
2444 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2445 }
2446
Jim Grosbach04945c42011-12-02 00:35:16 +00002447 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2448 assert(N == 2 && "Invalid number of operands!");
2449 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2450 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2451 }
2452
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002453 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2454 assert(N == 1 && "Invalid number of operands!");
2455 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2456 }
2457
2458 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2459 assert(N == 1 && "Invalid number of operands!");
2460 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2461 }
2462
2463 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2464 assert(N == 1 && "Invalid number of operands!");
2465 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2466 }
2467
Jim Grosbach741cd732011-10-17 22:26:03 +00002468 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2469 assert(N == 1 && "Invalid number of operands!");
2470 // The immediate encodes the type of constant as well as the value.
2471 // Mask in that this is an i8 splat.
2472 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2473 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2474 }
2475
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002476 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2477 assert(N == 1 && "Invalid number of operands!");
2478 // The immediate encodes the type of constant as well as the value.
2479 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2480 unsigned Value = CE->getValue();
Renato Golinf5dd1da2014-09-25 11:31:24 +00002481 Value = ARM_AM::encodeNEONi16splat(Value);
2482 Inst.addOperand(MCOperand::CreateImm(Value));
2483 }
2484
2485 void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const {
2486 assert(N == 1 && "Invalid number of operands!");
2487 // The immediate encodes the type of constant as well as the value.
2488 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2489 unsigned Value = CE->getValue();
2490 Value = ARM_AM::encodeNEONi16splat(~Value & 0xffff);
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002491 Inst.addOperand(MCOperand::CreateImm(Value));
2492 }
2493
Jim Grosbach8211c052011-10-18 00:22:00 +00002494 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2495 assert(N == 1 && "Invalid number of operands!");
2496 // The immediate encodes the type of constant as well as the value.
2497 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2498 unsigned Value = CE->getValue();
Renato Golinf5dd1da2014-09-25 11:31:24 +00002499 Value = ARM_AM::encodeNEONi32splat(Value);
2500 Inst.addOperand(MCOperand::CreateImm(Value));
2501 }
2502
2503 void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const {
2504 assert(N == 1 && "Invalid number of operands!");
2505 // The immediate encodes the type of constant as well as the value.
2506 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2507 unsigned Value = CE->getValue();
2508 Value = ARM_AM::encodeNEONi32splat(~Value);
Jim Grosbach8211c052011-10-18 00:22:00 +00002509 Inst.addOperand(MCOperand::CreateImm(Value));
2510 }
2511
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002512 void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const {
2513 assert(N == 1 && "Invalid number of operands!");
2514 // The immediate encodes the type of constant as well as the value.
2515 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2516 unsigned Value = CE->getValue();
2517 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2518 Inst.getOpcode() == ARM::VMOVv16i8) &&
2519 "All vmvn instructions that wants to replicate non-zero byte "
2520 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2521 unsigned B = ((~Value) & 0xff);
2522 B |= 0xe00; // cmode = 0b1110
2523 Inst.addOperand(MCOperand::CreateImm(B));
2524 }
Jim Grosbach8211c052011-10-18 00:22:00 +00002525 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2526 assert(N == 1 && "Invalid number of operands!");
2527 // The immediate encodes the type of constant as well as the value.
2528 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2529 unsigned Value = CE->getValue();
2530 if (Value >= 256 && Value <= 0xffff)
2531 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2532 else if (Value > 0xffff && Value <= 0xffffff)
2533 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2534 else if (Value > 0xffffff)
2535 Value = (Value >> 24) | 0x600;
2536 Inst.addOperand(MCOperand::CreateImm(Value));
2537 }
2538
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002539 void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const {
2540 assert(N == 1 && "Invalid number of operands!");
2541 // The immediate encodes the type of constant as well as the value.
2542 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2543 unsigned Value = CE->getValue();
2544 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2545 Inst.getOpcode() == ARM::VMOVv16i8) &&
2546 "All instructions that wants to replicate non-zero byte "
2547 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2548 unsigned B = Value & 0xff;
2549 B |= 0xe00; // cmode = 0b1110
2550 Inst.addOperand(MCOperand::CreateImm(B));
2551 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00002552 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2553 assert(N == 1 && "Invalid number of operands!");
2554 // The immediate encodes the type of constant as well as the value.
2555 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2556 unsigned Value = ~CE->getValue();
2557 if (Value >= 256 && Value <= 0xffff)
2558 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2559 else if (Value > 0xffff && Value <= 0xffffff)
2560 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2561 else if (Value > 0xffffff)
2562 Value = (Value >> 24) | 0x600;
2563 Inst.addOperand(MCOperand::CreateImm(Value));
2564 }
2565
Jim Grosbache4454e02011-10-18 16:18:11 +00002566 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2567 assert(N == 1 && "Invalid number of operands!");
2568 // The immediate encodes the type of constant as well as the value.
2569 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2570 uint64_t Value = CE->getValue();
2571 unsigned Imm = 0;
2572 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2573 Imm |= (Value & 1) << i;
2574 }
2575 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2576 }
2577
Craig Topperca7e3e52014-03-10 03:19:03 +00002578 void print(raw_ostream &OS) const override;
Daniel Dunbarebace222010-08-11 06:37:04 +00002579
David Blaikie960ea3f2014-06-08 16:18:35 +00002580 static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) {
2581 auto Op = make_unique<ARMOperand>(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002582 Op->ITMask.Mask = Mask;
2583 Op->StartLoc = S;
2584 Op->EndLoc = S;
2585 return Op;
2586 }
2587
David Blaikie960ea3f2014-06-08 16:18:35 +00002588 static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC,
2589 SMLoc S) {
2590 auto Op = make_unique<ARMOperand>(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002591 Op->CC.Val = CC;
2592 Op->StartLoc = S;
2593 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002594 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002595 }
2596
David Blaikie960ea3f2014-06-08 16:18:35 +00002597 static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) {
2598 auto Op = make_unique<ARMOperand>(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002599 Op->Cop.Val = CopVal;
2600 Op->StartLoc = S;
2601 Op->EndLoc = S;
2602 return Op;
2603 }
2604
David Blaikie960ea3f2014-06-08 16:18:35 +00002605 static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) {
2606 auto Op = make_unique<ARMOperand>(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002607 Op->Cop.Val = CopVal;
2608 Op->StartLoc = S;
2609 Op->EndLoc = S;
2610 return Op;
2611 }
2612
David Blaikie960ea3f2014-06-08 16:18:35 +00002613 static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S,
2614 SMLoc E) {
2615 auto Op = make_unique<ARMOperand>(k_CoprocOption);
Jim Grosbach48399582011-10-12 17:34:41 +00002616 Op->Cop.Val = Val;
2617 Op->StartLoc = S;
2618 Op->EndLoc = E;
2619 return Op;
2620 }
2621
David Blaikie960ea3f2014-06-08 16:18:35 +00002622 static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) {
2623 auto Op = make_unique<ARMOperand>(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002624 Op->Reg.RegNum = RegNum;
2625 Op->StartLoc = S;
2626 Op->EndLoc = S;
2627 return Op;
2628 }
2629
David Blaikie960ea3f2014-06-08 16:18:35 +00002630 static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) {
2631 auto Op = make_unique<ARMOperand>(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002632 Op->Tok.Data = Str.data();
2633 Op->Tok.Length = Str.size();
2634 Op->StartLoc = S;
2635 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002636 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002637 }
2638
David Blaikie960ea3f2014-06-08 16:18:35 +00002639 static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S,
2640 SMLoc E) {
2641 auto Op = make_unique<ARMOperand>(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002642 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002643 Op->StartLoc = S;
2644 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002645 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002646 }
2647
David Blaikie960ea3f2014-06-08 16:18:35 +00002648 static std::unique_ptr<ARMOperand>
2649 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2650 unsigned ShiftReg, unsigned ShiftImm, SMLoc S,
2651 SMLoc E) {
2652 auto Op = make_unique<ARMOperand>(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002653 Op->RegShiftedReg.ShiftTy = ShTy;
2654 Op->RegShiftedReg.SrcReg = SrcReg;
2655 Op->RegShiftedReg.ShiftReg = ShiftReg;
2656 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002657 Op->StartLoc = S;
2658 Op->EndLoc = E;
2659 return Op;
2660 }
2661
David Blaikie960ea3f2014-06-08 16:18:35 +00002662 static std::unique_ptr<ARMOperand>
2663 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2664 unsigned ShiftImm, SMLoc S, SMLoc E) {
2665 auto Op = make_unique<ARMOperand>(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002666 Op->RegShiftedImm.ShiftTy = ShTy;
2667 Op->RegShiftedImm.SrcReg = SrcReg;
2668 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002669 Op->StartLoc = S;
2670 Op->EndLoc = E;
2671 return Op;
2672 }
2673
David Blaikie960ea3f2014-06-08 16:18:35 +00002674 static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm,
2675 SMLoc S, SMLoc E) {
2676 auto Op = make_unique<ARMOperand>(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002677 Op->ShifterImm.isASR = isASR;
2678 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002679 Op->StartLoc = S;
2680 Op->EndLoc = E;
2681 return Op;
2682 }
2683
David Blaikie960ea3f2014-06-08 16:18:35 +00002684 static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S,
2685 SMLoc E) {
2686 auto Op = make_unique<ARMOperand>(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002687 Op->RotImm.Imm = Imm;
2688 Op->StartLoc = S;
2689 Op->EndLoc = E;
2690 return Op;
2691 }
2692
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00002693 static std::unique_ptr<ARMOperand> CreateModImm(unsigned Bits, unsigned Rot,
2694 SMLoc S, SMLoc E) {
2695 auto Op = make_unique<ARMOperand>(k_ModifiedImmediate);
2696 Op->ModImm.Bits = Bits;
2697 Op->ModImm.Rot = Rot;
2698 Op->StartLoc = S;
2699 Op->EndLoc = E;
2700 return Op;
2701 }
2702
David Blaikie960ea3f2014-06-08 16:18:35 +00002703 static std::unique_ptr<ARMOperand>
2704 CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) {
2705 auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002706 Op->Bitfield.LSB = LSB;
2707 Op->Bitfield.Width = Width;
2708 Op->StartLoc = S;
2709 Op->EndLoc = E;
2710 return Op;
2711 }
2712
David Blaikie960ea3f2014-06-08 16:18:35 +00002713 static std::unique_ptr<ARMOperand>
2714 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002715 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002716 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002717 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002718
Chad Rosierfa705ee2013-07-01 20:49:23 +00002719 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002720 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002721 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002722 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002723 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002724
Chad Rosierfa705ee2013-07-01 20:49:23 +00002725 // Sort based on the register encoding values.
2726 array_pod_sort(Regs.begin(), Regs.end());
2727
David Blaikie960ea3f2014-06-08 16:18:35 +00002728 auto Op = make_unique<ARMOperand>(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002729 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002730 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002731 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002732 Op->StartLoc = StartLoc;
2733 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002734 return Op;
2735 }
2736
David Blaikie960ea3f2014-06-08 16:18:35 +00002737 static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum,
2738 unsigned Count,
2739 bool isDoubleSpaced,
2740 SMLoc S, SMLoc E) {
2741 auto Op = make_unique<ARMOperand>(k_VectorList);
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002742 Op->VectorList.RegNum = RegNum;
2743 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002744 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002745 Op->StartLoc = S;
2746 Op->EndLoc = E;
2747 return Op;
2748 }
2749
David Blaikie960ea3f2014-06-08 16:18:35 +00002750 static std::unique_ptr<ARMOperand>
2751 CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced,
2752 SMLoc S, SMLoc E) {
2753 auto Op = make_unique<ARMOperand>(k_VectorListAllLanes);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002754 Op->VectorList.RegNum = RegNum;
2755 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002756 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002757 Op->StartLoc = S;
2758 Op->EndLoc = E;
2759 return Op;
2760 }
2761
David Blaikie960ea3f2014-06-08 16:18:35 +00002762 static std::unique_ptr<ARMOperand>
2763 CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index,
2764 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2765 auto Op = make_unique<ARMOperand>(k_VectorListIndexed);
Jim Grosbach04945c42011-12-02 00:35:16 +00002766 Op->VectorList.RegNum = RegNum;
2767 Op->VectorList.Count = Count;
2768 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002769 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002770 Op->StartLoc = S;
2771 Op->EndLoc = E;
2772 return Op;
2773 }
2774
David Blaikie960ea3f2014-06-08 16:18:35 +00002775 static std::unique_ptr<ARMOperand>
2776 CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) {
2777 auto Op = make_unique<ARMOperand>(k_VectorIndex);
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002778 Op->VectorIndex.Val = Idx;
2779 Op->StartLoc = S;
2780 Op->EndLoc = E;
2781 return Op;
2782 }
2783
David Blaikie960ea3f2014-06-08 16:18:35 +00002784 static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S,
2785 SMLoc E) {
2786 auto Op = make_unique<ARMOperand>(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002787 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002788 Op->StartLoc = S;
2789 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002790 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002791 }
2792
David Blaikie960ea3f2014-06-08 16:18:35 +00002793 static std::unique_ptr<ARMOperand>
2794 CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm,
2795 unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType,
2796 unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S,
2797 SMLoc E, SMLoc AlignmentLoc = SMLoc()) {
2798 auto Op = make_unique<ARMOperand>(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002799 Op->Memory.BaseRegNum = BaseRegNum;
2800 Op->Memory.OffsetImm = OffsetImm;
2801 Op->Memory.OffsetRegNum = OffsetRegNum;
2802 Op->Memory.ShiftType = ShiftType;
2803 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002804 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002805 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002806 Op->StartLoc = S;
2807 Op->EndLoc = E;
Kevin Enderby488f20b2014-04-10 20:18:58 +00002808 Op->AlignmentLoc = AlignmentLoc;
Jim Grosbachd3595712011-08-03 23:50:40 +00002809 return Op;
2810 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002811
David Blaikie960ea3f2014-06-08 16:18:35 +00002812 static std::unique_ptr<ARMOperand>
2813 CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy,
2814 unsigned ShiftImm, SMLoc S, SMLoc E) {
2815 auto Op = make_unique<ARMOperand>(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002816 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002817 Op->PostIdxReg.isAdd = isAdd;
2818 Op->PostIdxReg.ShiftTy = ShiftTy;
2819 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002820 Op->StartLoc = S;
2821 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002822 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002823 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002824
David Blaikie960ea3f2014-06-08 16:18:35 +00002825 static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt,
2826 SMLoc S) {
2827 auto Op = make_unique<ARMOperand>(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002828 Op->MBOpt.Val = Opt;
2829 Op->StartLoc = S;
2830 Op->EndLoc = S;
2831 return Op;
2832 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002833
David Blaikie960ea3f2014-06-08 16:18:35 +00002834 static std::unique_ptr<ARMOperand>
2835 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) {
2836 auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002837 Op->ISBOpt.Val = Opt;
2838 Op->StartLoc = S;
2839 Op->EndLoc = S;
2840 return Op;
2841 }
2842
David Blaikie960ea3f2014-06-08 16:18:35 +00002843 static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags,
2844 SMLoc S) {
2845 auto Op = make_unique<ARMOperand>(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002846 Op->IFlags.Val = IFlags;
2847 Op->StartLoc = S;
2848 Op->EndLoc = S;
2849 return Op;
2850 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002851
David Blaikie960ea3f2014-06-08 16:18:35 +00002852 static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) {
2853 auto Op = make_unique<ARMOperand>(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002854 Op->MMask.Val = MMask;
2855 Op->StartLoc = S;
2856 Op->EndLoc = S;
2857 return Op;
2858 }
Tim Northoveree843ef2014-08-15 10:47:12 +00002859
2860 static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) {
2861 auto Op = make_unique<ARMOperand>(k_BankedReg);
2862 Op->BankedReg.Val = Reg;
2863 Op->StartLoc = S;
2864 Op->EndLoc = S;
2865 return Op;
2866 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002867};
2868
2869} // end anonymous namespace.
2870
Jim Grosbach602aa902011-07-13 15:34:57 +00002871void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002872 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002873 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002874 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002875 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002876 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002877 OS << "<ccout " << getReg() << ">";
2878 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002879 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002880 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002881 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2882 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2883 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002884 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2885 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2886 break;
2887 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002888 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002889 OS << "<coprocessor number: " << getCoproc() << ">";
2890 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002891 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002892 OS << "<coprocessor register: " << getCoproc() << ">";
2893 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002894 case k_CoprocOption:
2895 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2896 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002897 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002898 OS << "<mask: " << getMSRMask() << ">";
2899 break;
Tim Northoveree843ef2014-08-15 10:47:12 +00002900 case k_BankedReg:
2901 OS << "<banked reg: " << getBankedReg() << ">";
2902 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002903 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002904 getImm()->print(OS);
2905 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002906 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002907 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002908 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002909 case k_InstSyncBarrierOpt:
2910 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2911 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002912 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002913 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002914 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002915 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002916 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002917 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002918 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2919 << PostIdxReg.RegNum;
2920 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2921 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2922 << PostIdxReg.ShiftImm;
2923 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002924 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002925 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002926 OS << "<ARM_PROC::";
2927 unsigned IFlags = getProcIFlags();
2928 for (int i=2; i >= 0; --i)
2929 if (IFlags & (1 << i))
2930 OS << ARM_PROC::IFlagsToString(1 << i);
2931 OS << ">";
2932 break;
2933 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002934 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002935 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002936 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002937 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002938 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2939 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002940 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002941 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002942 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002943 << RegShiftedReg.SrcReg << " "
2944 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2945 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002946 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002947 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002948 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002949 << RegShiftedImm.SrcReg << " "
2950 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2951 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002952 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002953 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002954 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2955 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00002956 case k_ModifiedImmediate:
2957 OS << "<mod_imm #" << ModImm.Bits << ", #"
2958 << ModImm.Rot << ")>";
2959 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002960 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002961 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2962 << ", width: " << Bitfield.Width << ">";
2963 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002964 case k_RegisterList:
2965 case k_DPRRegisterList:
2966 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002967 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002968
Bill Wendlingbed94652010-11-09 23:28:44 +00002969 const SmallVectorImpl<unsigned> &RegList = getRegList();
2970 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002971 I = RegList.begin(), E = RegList.end(); I != E; ) {
2972 OS << *I;
2973 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002974 }
2975
2976 OS << ">";
2977 break;
2978 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002979 case k_VectorList:
2980 OS << "<vector_list " << VectorList.Count << " * "
2981 << VectorList.RegNum << ">";
2982 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002983 case k_VectorListAllLanes:
2984 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2985 << VectorList.RegNum << ">";
2986 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002987 case k_VectorListIndexed:
2988 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2989 << VectorList.Count << " * " << VectorList.RegNum << ">";
2990 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002991 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002992 OS << "'" << getToken() << "'";
2993 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002994 case k_VectorIndex:
2995 OS << "<vectorindex " << getVectorIndex() << ">";
2996 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002997 }
2998}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002999
3000/// @name Auto-generated Match Functions
3001/// {
3002
3003static unsigned MatchRegisterName(StringRef Name);
3004
3005/// }
3006
Bob Wilsonfb0bd042011-02-03 21:46:10 +00003007bool ARMAsmParser::ParseRegister(unsigned &RegNo,
3008 SMLoc &StartLoc, SMLoc &EndLoc) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003009 const AsmToken &Tok = getParser().getTok();
3010 StartLoc = Tok.getLoc();
3011 EndLoc = Tok.getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003012 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00003013
3014 return (RegNo == (unsigned)-1);
3015}
3016
Kevin Enderby8be42bd2009-10-30 22:55:57 +00003017/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00003018/// and if it is a register name the token is eaten and the register number is
3019/// returned. Otherwise return -1.
3020///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003021int ARMAsmParser::tryParseRegister() {
Rafael Espindola961d4692014-11-11 05:18:41 +00003022 MCAsmParser &Parser = getParser();
Chris Lattner44e5981c2010-10-30 04:09:10 +00003023 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00003024 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00003025
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003026 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00003027 unsigned RegNum = MatchRegisterName(lowerCase);
3028 if (!RegNum) {
3029 RegNum = StringSwitch<unsigned>(lowerCase)
3030 .Case("r13", ARM::SP)
3031 .Case("r14", ARM::LR)
3032 .Case("r15", ARM::PC)
3033 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00003034 // Additional register name aliases for 'gas' compatibility.
3035 .Case("a1", ARM::R0)
3036 .Case("a2", ARM::R1)
3037 .Case("a3", ARM::R2)
3038 .Case("a4", ARM::R3)
3039 .Case("v1", ARM::R4)
3040 .Case("v2", ARM::R5)
3041 .Case("v3", ARM::R6)
3042 .Case("v4", ARM::R7)
3043 .Case("v5", ARM::R8)
3044 .Case("v6", ARM::R9)
3045 .Case("v7", ARM::R10)
3046 .Case("v8", ARM::R11)
3047 .Case("sb", ARM::R9)
3048 .Case("sl", ARM::R10)
3049 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00003050 .Default(0);
3051 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00003052 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00003053 // Check for aliases registered via .req. Canonicalize to lower case.
3054 // That's more consistent since register names are case insensitive, and
3055 // it's how the original entry was passed in from MC/MCParser/AsmParser.
3056 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00003057 // If no match, return failure.
3058 if (Entry == RegisterReqs.end())
3059 return -1;
3060 Parser.Lex(); // Eat identifier token.
3061 return Entry->getValue();
3062 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00003063
Oliver Stannard9e89d8c2014-11-05 12:06:39 +00003064 // Some FPUs only have 16 D registers, so D16-D31 are invalid
3065 if (hasD16() && RegNum >= ARM::D16 && RegNum <= ARM::D31)
3066 return -1;
3067
Chris Lattner44e5981c2010-10-30 04:09:10 +00003068 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003069
Chris Lattner44e5981c2010-10-30 04:09:10 +00003070 return RegNum;
3071}
Jim Grosbach99710a82010-11-01 16:44:21 +00003072
Jim Grosbachbb24c592011-07-13 18:49:30 +00003073// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
3074// If a recoverable error occurs, return 1. If an irrecoverable error
3075// occurs, return -1. An irrecoverable error is one where tokens have been
3076// consumed in the process of trying to parse the shifter (i.e., when it is
3077// indeed a shifter operand, but malformed).
David Blaikie960ea3f2014-06-08 16:18:35 +00003078int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003079 MCAsmParser &Parser = getParser();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003080 SMLoc S = Parser.getTok().getLoc();
3081 const AsmToken &Tok = Parser.getTok();
Kevin Enderby62873712014-02-17 21:45:27 +00003082 if (Tok.isNot(AsmToken::Identifier))
3083 return -1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003084
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003085 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003086 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00003087 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003088 .Case("lsl", ARM_AM::lsl)
3089 .Case("lsr", ARM_AM::lsr)
3090 .Case("asr", ARM_AM::asr)
3091 .Case("ror", ARM_AM::ror)
3092 .Case("rrx", ARM_AM::rrx)
3093 .Default(ARM_AM::no_shift);
3094
3095 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00003096 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003097
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003098 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003099
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003100 // The source register for the shift has already been added to the
3101 // operand list, so we need to pop it off and combine it into the shifted
3102 // register operand instead.
David Blaikie960ea3f2014-06-08 16:18:35 +00003103 std::unique_ptr<ARMOperand> PrevOp(
3104 (ARMOperand *)Operands.pop_back_val().release());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003105 if (!PrevOp->isReg())
3106 return Error(PrevOp->getStartLoc(), "shift must be of a register");
3107 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003108
3109 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003110 int64_t Imm = 0;
3111 int ShiftReg = 0;
3112 if (ShiftTy == ARM_AM::rrx) {
3113 // RRX Doesn't have an explicit shift amount. The encoder expects
3114 // the shift register to be the same as the source register. Seems odd,
3115 // but OK.
3116 ShiftReg = SrcReg;
3117 } else {
3118 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003119 if (Parser.getTok().is(AsmToken::Hash) ||
3120 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003121 Parser.Lex(); // Eat hash.
3122 SMLoc ImmLoc = Parser.getTok().getLoc();
Craig Topper062a2ba2014-04-25 05:30:21 +00003123 const MCExpr *ShiftExpr = nullptr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003124 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003125 Error(ImmLoc, "invalid immediate shift value");
3126 return -1;
3127 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003128 // The expression must be evaluatable as an immediate.
3129 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00003130 if (!CE) {
3131 Error(ImmLoc, "invalid immediate shift value");
3132 return -1;
3133 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003134 // Range check the immediate.
3135 // lsl, ror: 0 <= imm <= 31
3136 // lsr, asr: 0 <= imm <= 32
3137 Imm = CE->getValue();
3138 if (Imm < 0 ||
3139 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
3140 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003141 Error(ImmLoc, "immediate shift value out of range");
3142 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003143 }
Jim Grosbach21488b82011-12-22 17:37:00 +00003144 // shift by zero is a nop. Always send it through as lsl.
3145 // ('as' compatibility)
3146 if (Imm == 0)
3147 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003148 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003149 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003150 EndLoc = Parser.getTok().getEndLoc();
3151 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00003152 if (ShiftReg == -1) {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003153 Error(L, "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003154 return -1;
3155 }
3156 } else {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003157 Error(Parser.getTok().getLoc(),
3158 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003159 return -1;
3160 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003161 }
3162
Owen Andersonb595ed02011-07-21 18:54:16 +00003163 if (ShiftReg && ShiftTy != ARM_AM::rrx)
3164 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00003165 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003166 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00003167 else
3168 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003169 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003170
Jim Grosbachbb24c592011-07-13 18:49:30 +00003171 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003172}
3173
3174
Bill Wendling2063b842010-11-18 23:43:05 +00003175/// Try to parse a register name. The token must be an Identifier when called.
3176/// If it's a register, an AsmOperand is created. Another AsmOperand is created
3177/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00003178///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00003179/// TODO this is likely to change to allow different register types and or to
3180/// parse for a specific register type.
David Blaikie960ea3f2014-06-08 16:18:35 +00003181bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003182 MCAsmParser &Parser = getParser();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003183 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003184 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00003185 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00003186 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00003187
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003188 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
3189 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003190
Chris Lattner44e5981c2010-10-30 04:09:10 +00003191 const AsmToken &ExclaimTok = Parser.getTok();
3192 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00003193 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
3194 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00003195 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003196 return false;
3197 }
3198
3199 // Also check for an index operand. This is only legal for vector registers,
3200 // but that'll get caught OK in operand matching, so we don't need to
3201 // explicitly filter everything else out here.
3202 if (Parser.getTok().is(AsmToken::LBrac)) {
3203 SMLoc SIdx = Parser.getTok().getLoc();
3204 Parser.Lex(); // Eat left bracket token.
3205
3206 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003207 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00003208 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003209 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003210 if (!MCE)
3211 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003212
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003213 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003214 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003215
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003216 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003217 Parser.Lex(); // Eat right bracket token.
3218
3219 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
3220 SIdx, E,
3221 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00003222 }
3223
Bill Wendling2063b842010-11-18 23:43:05 +00003224 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003225}
3226
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003227/// MatchCoprocessorOperandName - Try to parse an coprocessor related
Renato Golinac561c32014-06-26 13:10:53 +00003228/// instruction with a symbolic operand name.
3229/// We accept "crN" syntax for GAS compatibility.
3230/// <operand-name> ::= <prefix><number>
3231/// If CoprocOp is 'c', then:
3232/// <prefix> ::= c | cr
3233/// If CoprocOp is 'p', then :
3234/// <prefix> ::= p
3235/// <number> ::= integer in range [0, 15]
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003236static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003237 // Use the same layout as the tablegen'erated register name matcher. Ugly,
3238 // but efficient.
Renato Golinac561c32014-06-26 13:10:53 +00003239 if (Name.size() < 2 || Name[0] != CoprocOp)
3240 return -1;
3241 Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front();
3242
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003243 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00003244 default: return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003245 case 1:
3246 switch (Name[0]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003247 default: return -1;
3248 case '0': return 0;
3249 case '1': return 1;
3250 case '2': return 2;
3251 case '3': return 3;
3252 case '4': return 4;
3253 case '5': return 5;
3254 case '6': return 6;
3255 case '7': return 7;
3256 case '8': return 8;
3257 case '9': return 9;
3258 }
Renato Golinac561c32014-06-26 13:10:53 +00003259 case 2:
3260 if (Name[0] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003261 return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003262 switch (Name[1]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003263 default: return -1;
Renato Golinbc0b0372014-08-04 23:21:56 +00003264 // CP10 and CP11 are VFP/NEON and so vector instructions should be used.
3265 // However, old cores (v5/v6) did use them in that way.
3266 case '0': return 10;
3267 case '1': return 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003268 case '2': return 12;
3269 case '3': return 13;
3270 case '4': return 14;
3271 case '5': return 15;
3272 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003273 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003274}
3275
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003276/// parseITCondCode - Try to parse a condition code for an IT instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003277ARMAsmParser::OperandMatchResultTy
3278ARMAsmParser::parseITCondCode(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003279 MCAsmParser &Parser = getParser();
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003280 SMLoc S = Parser.getTok().getLoc();
3281 const AsmToken &Tok = Parser.getTok();
3282 if (!Tok.is(AsmToken::Identifier))
3283 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00003284 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003285 .Case("eq", ARMCC::EQ)
3286 .Case("ne", ARMCC::NE)
3287 .Case("hs", ARMCC::HS)
3288 .Case("cs", ARMCC::HS)
3289 .Case("lo", ARMCC::LO)
3290 .Case("cc", ARMCC::LO)
3291 .Case("mi", ARMCC::MI)
3292 .Case("pl", ARMCC::PL)
3293 .Case("vs", ARMCC::VS)
3294 .Case("vc", ARMCC::VC)
3295 .Case("hi", ARMCC::HI)
3296 .Case("ls", ARMCC::LS)
3297 .Case("ge", ARMCC::GE)
3298 .Case("lt", ARMCC::LT)
3299 .Case("gt", ARMCC::GT)
3300 .Case("le", ARMCC::LE)
3301 .Case("al", ARMCC::AL)
3302 .Default(~0U);
3303 if (CC == ~0U)
3304 return MatchOperand_NoMatch;
3305 Parser.Lex(); // Eat the token.
3306
3307 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3308
3309 return MatchOperand_Success;
3310}
3311
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003312/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003313/// token must be an Identifier when called, and if it is a coprocessor
3314/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003315ARMAsmParser::OperandMatchResultTy
3316ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003317 MCAsmParser &Parser = getParser();
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003318 SMLoc S = Parser.getTok().getLoc();
3319 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003320 if (Tok.isNot(AsmToken::Identifier))
3321 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003322
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003323 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003324 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003325 return MatchOperand_NoMatch;
Renato Golinbc0b0372014-08-04 23:21:56 +00003326 // ARMv7 and v8 don't allow cp10/cp11 due to VFP/NEON specific instructions
3327 if ((hasV7Ops() || hasV8Ops()) && (Num == 10 || Num == 11))
3328 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003329
3330 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003331 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003332 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003333}
3334
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003335/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003336/// token must be an Identifier when called, and if it is a coprocessor
3337/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003338ARMAsmParser::OperandMatchResultTy
3339ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003340 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003341 SMLoc S = Parser.getTok().getLoc();
3342 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003343 if (Tok.isNot(AsmToken::Identifier))
3344 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003345
3346 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3347 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003348 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003349
3350 Parser.Lex(); // Eat identifier token.
3351 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003352 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003353}
3354
Jim Grosbach48399582011-10-12 17:34:41 +00003355/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3356/// coproc_option : '{' imm0_255 '}'
David Blaikie960ea3f2014-06-08 16:18:35 +00003357ARMAsmParser::OperandMatchResultTy
3358ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003359 MCAsmParser &Parser = getParser();
Jim Grosbach48399582011-10-12 17:34:41 +00003360 SMLoc S = Parser.getTok().getLoc();
3361
3362 // If this isn't a '{', this isn't a coprocessor immediate operand.
3363 if (Parser.getTok().isNot(AsmToken::LCurly))
3364 return MatchOperand_NoMatch;
3365 Parser.Lex(); // Eat the '{'
3366
3367 const MCExpr *Expr;
3368 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003369 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003370 Error(Loc, "illegal expression");
3371 return MatchOperand_ParseFail;
3372 }
3373 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3374 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3375 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3376 return MatchOperand_ParseFail;
3377 }
3378 int Val = CE->getValue();
3379
3380 // Check for and consume the closing '}'
3381 if (Parser.getTok().isNot(AsmToken::RCurly))
3382 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003383 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003384 Parser.Lex(); // Eat the '}'
3385
3386 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3387 return MatchOperand_Success;
3388}
3389
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003390// For register list parsing, we need to map from raw GPR register numbering
3391// to the enumeration values. The enumeration values aren't sorted by
3392// register number due to our using "sp", "lr" and "pc" as canonical names.
3393static unsigned getNextRegister(unsigned Reg) {
3394 // If this is a GPR, we need to do it manually, otherwise we can rely
3395 // on the sort ordering of the enumeration since the other reg-classes
3396 // are sane.
3397 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3398 return Reg + 1;
3399 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003400 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003401 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3402 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3403 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3404 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3405 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3406 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3407 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3408 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3409 }
3410}
3411
Jim Grosbach85a23432011-11-11 21:27:40 +00003412// Return the low-subreg of a given Q register.
3413static unsigned getDRegFromQReg(unsigned QReg) {
3414 switch (QReg) {
3415 default: llvm_unreachable("expected a Q register!");
3416 case ARM::Q0: return ARM::D0;
3417 case ARM::Q1: return ARM::D2;
3418 case ARM::Q2: return ARM::D4;
3419 case ARM::Q3: return ARM::D6;
3420 case ARM::Q4: return ARM::D8;
3421 case ARM::Q5: return ARM::D10;
3422 case ARM::Q6: return ARM::D12;
3423 case ARM::Q7: return ARM::D14;
3424 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003425 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003426 case ARM::Q10: return ARM::D20;
3427 case ARM::Q11: return ARM::D22;
3428 case ARM::Q12: return ARM::D24;
3429 case ARM::Q13: return ARM::D26;
3430 case ARM::Q14: return ARM::D28;
3431 case ARM::Q15: return ARM::D30;
3432 }
3433}
3434
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003435/// Parse a register list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003436bool ARMAsmParser::parseRegisterList(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003437 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00003438 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003439 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003440 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003441 Parser.Lex(); // Eat '{' token.
3442 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003443
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003444 // Check the first register in the list to see what register class
3445 // this is a list of.
3446 int Reg = tryParseRegister();
3447 if (Reg == -1)
3448 return Error(RegLoc, "register expected");
3449
Jim Grosbach85a23432011-11-11 21:27:40 +00003450 // The reglist instructions have at most 16 registers, so reserve
3451 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003452 int EReg = 0;
3453 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003454
3455 // Allow Q regs and just interpret them as the two D sub-registers.
3456 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3457 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003458 EReg = MRI->getEncodingValue(Reg);
3459 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003460 ++Reg;
3461 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003462 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003463 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3464 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3465 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3466 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3467 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3468 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3469 else
3470 return Error(RegLoc, "invalid register in register list");
3471
Jim Grosbach85a23432011-11-11 21:27:40 +00003472 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003473 EReg = MRI->getEncodingValue(Reg);
3474 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003475
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003476 // This starts immediately after the first register token in the list,
3477 // so we can see either a comma or a minus (range separator) as a legal
3478 // next token.
3479 while (Parser.getTok().is(AsmToken::Comma) ||
3480 Parser.getTok().is(AsmToken::Minus)) {
3481 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003482 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003483 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003484 int EndReg = tryParseRegister();
3485 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003486 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003487 // Allow Q regs and just interpret them as the two D sub-registers.
3488 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3489 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003490 // If the register is the same as the start reg, there's nothing
3491 // more to do.
3492 if (Reg == EndReg)
3493 continue;
3494 // The register must be in the same register class as the first.
3495 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003496 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003497 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003498 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003499 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003500
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003501 // Add all the registers in the range to the register list.
3502 while (Reg != EndReg) {
3503 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003504 EReg = MRI->getEncodingValue(Reg);
3505 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003506 }
3507 continue;
3508 }
3509 Parser.Lex(); // Eat the comma.
3510 RegLoc = Parser.getTok().getLoc();
3511 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003512 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003513 Reg = tryParseRegister();
3514 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003515 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003516 // Allow Q regs and just interpret them as the two D sub-registers.
3517 bool isQReg = false;
3518 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3519 Reg = getDRegFromQReg(Reg);
3520 isQReg = true;
3521 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003522 // The register must be in the same register class as the first.
3523 if (!RC->contains(Reg))
3524 return Error(RegLoc, "invalid register in register list");
3525 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003526 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003527 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3528 Warning(RegLoc, "register list not in ascending order");
3529 else
3530 return Error(RegLoc, "register list not in ascending order");
3531 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003532 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003533 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3534 ") in register list");
3535 continue;
3536 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003537 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003538 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3539 Reg != OldReg + 1)
3540 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003541 EReg = MRI->getEncodingValue(Reg);
3542 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3543 if (isQReg) {
3544 EReg = MRI->getEncodingValue(++Reg);
3545 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3546 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003547 }
3548
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003549 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003550 return Error(Parser.getTok().getLoc(), "'}' expected");
3551 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003552 Parser.Lex(); // Eat '}' token.
3553
Jim Grosbach18bf3632011-12-13 21:48:29 +00003554 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003555 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003556
3557 // The ARM system instruction variants for LDM/STM have a '^' token here.
3558 if (Parser.getTok().is(AsmToken::Caret)) {
3559 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3560 Parser.Lex(); // Eat '^' token.
3561 }
3562
Bill Wendling2063b842010-11-18 23:43:05 +00003563 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003564}
3565
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003566// Helper function to parse the lane index for vector lists.
3567ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003568parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003569 MCAsmParser &Parser = getParser();
Jim Grosbach04945c42011-12-02 00:35:16 +00003570 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003571 if (Parser.getTok().is(AsmToken::LBrac)) {
3572 Parser.Lex(); // Eat the '['.
3573 if (Parser.getTok().is(AsmToken::RBrac)) {
3574 // "Dn[]" is the 'all lanes' syntax.
3575 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003576 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003577 Parser.Lex(); // Eat the ']'.
3578 return MatchOperand_Success;
3579 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003580
3581 // There's an optional '#' token here. Normally there wouldn't be, but
3582 // inline assemble puts one in, and it's friendly to accept that.
3583 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003584 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003585
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003586 const MCExpr *LaneIndex;
3587 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003588 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003589 Error(Loc, "illegal expression");
3590 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003591 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003592 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3593 if (!CE) {
3594 Error(Loc, "lane index must be empty or an integer");
3595 return MatchOperand_ParseFail;
3596 }
3597 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3598 Error(Parser.getTok().getLoc(), "']' expected");
3599 return MatchOperand_ParseFail;
3600 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003601 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003602 Parser.Lex(); // Eat the ']'.
3603 int64_t Val = CE->getValue();
3604
3605 // FIXME: Make this range check context sensitive for .8, .16, .32.
3606 if (Val < 0 || Val > 7) {
3607 Error(Parser.getTok().getLoc(), "lane index out of range");
3608 return MatchOperand_ParseFail;
3609 }
3610 Index = Val;
3611 LaneKind = IndexedLane;
3612 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003613 }
3614 LaneKind = NoLanes;
3615 return MatchOperand_Success;
3616}
3617
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003618// parse a vector register list
David Blaikie960ea3f2014-06-08 16:18:35 +00003619ARMAsmParser::OperandMatchResultTy
3620ARMAsmParser::parseVectorList(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003621 MCAsmParser &Parser = getParser();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003622 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003623 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003624 SMLoc S = Parser.getTok().getLoc();
3625 // As an extension (to match gas), support a plain D register or Q register
3626 // (without encosing curly braces) as a single or double entry list,
3627 // respectively.
3628 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003629 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003630 int Reg = tryParseRegister();
3631 if (Reg == -1)
3632 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003633 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003634 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003635 if (Res != MatchOperand_Success)
3636 return Res;
3637 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003638 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003639 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003640 break;
3641 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003642 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3643 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003644 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003645 case IndexedLane:
3646 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003647 LaneIndex,
3648 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003649 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003650 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003651 return MatchOperand_Success;
3652 }
3653 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3654 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003655 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003656 if (Res != MatchOperand_Success)
3657 return Res;
3658 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003659 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003660 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003661 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003662 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003663 break;
3664 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003665 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3666 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003667 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3668 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003669 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003670 case IndexedLane:
3671 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003672 LaneIndex,
3673 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003674 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003675 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003676 return MatchOperand_Success;
3677 }
3678 Error(S, "vector register expected");
3679 return MatchOperand_ParseFail;
3680 }
3681
3682 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003683 return MatchOperand_NoMatch;
3684
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003685 Parser.Lex(); // Eat '{' token.
3686 SMLoc RegLoc = Parser.getTok().getLoc();
3687
3688 int Reg = tryParseRegister();
3689 if (Reg == -1) {
3690 Error(RegLoc, "register expected");
3691 return MatchOperand_ParseFail;
3692 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003693 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003694 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003695 unsigned FirstReg = Reg;
3696 // The list is of D registers, but we also allow Q regs and just interpret
3697 // them as the two D sub-registers.
3698 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3699 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003700 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3701 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003702 ++Reg;
3703 ++Count;
3704 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003705
3706 SMLoc E;
3707 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003708 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003709
Jim Grosbache891fe82011-11-15 23:19:15 +00003710 while (Parser.getTok().is(AsmToken::Comma) ||
3711 Parser.getTok().is(AsmToken::Minus)) {
3712 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003713 if (!Spacing)
3714 Spacing = 1; // Register range implies a single spaced list.
3715 else if (Spacing == 2) {
3716 Error(Parser.getTok().getLoc(),
3717 "sequential registers in double spaced list");
3718 return MatchOperand_ParseFail;
3719 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003720 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003721 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003722 int EndReg = tryParseRegister();
3723 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003724 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003725 return MatchOperand_ParseFail;
3726 }
3727 // Allow Q regs and just interpret them as the two D sub-registers.
3728 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3729 EndReg = getDRegFromQReg(EndReg) + 1;
3730 // If the register is the same as the start reg, there's nothing
3731 // more to do.
3732 if (Reg == EndReg)
3733 continue;
3734 // The register must be in the same register class as the first.
3735 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003736 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003737 return MatchOperand_ParseFail;
3738 }
3739 // Ranges must go from low to high.
3740 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003741 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003742 return MatchOperand_ParseFail;
3743 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003744 // Parse the lane specifier if present.
3745 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003746 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003747 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3748 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003749 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003750 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003751 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003752 return MatchOperand_ParseFail;
3753 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003754
3755 // Add all the registers in the range to the register list.
3756 Count += EndReg - Reg;
3757 Reg = EndReg;
3758 continue;
3759 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003760 Parser.Lex(); // Eat the comma.
3761 RegLoc = Parser.getTok().getLoc();
3762 int OldReg = Reg;
3763 Reg = tryParseRegister();
3764 if (Reg == -1) {
3765 Error(RegLoc, "register expected");
3766 return MatchOperand_ParseFail;
3767 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003768 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003769 // It's OK to use the enumeration values directly here rather, as the
3770 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003771 //
3772 // The list is of D registers, but we also allow Q regs and just interpret
3773 // them as the two D sub-registers.
3774 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003775 if (!Spacing)
3776 Spacing = 1; // Register range implies a single spaced list.
3777 else if (Spacing == 2) {
3778 Error(RegLoc,
3779 "invalid register in double-spaced list (must be 'D' register')");
3780 return MatchOperand_ParseFail;
3781 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003782 Reg = getDRegFromQReg(Reg);
3783 if (Reg != OldReg + 1) {
3784 Error(RegLoc, "non-contiguous register range");
3785 return MatchOperand_ParseFail;
3786 }
3787 ++Reg;
3788 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003789 // Parse the lane specifier if present.
3790 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003791 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003792 SMLoc LaneLoc = Parser.getTok().getLoc();
3793 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3794 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003795 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003796 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003797 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003798 return MatchOperand_ParseFail;
3799 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003800 continue;
3801 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003802 // Normal D register.
3803 // Figure out the register spacing (single or double) of the list if
3804 // we don't know it already.
3805 if (!Spacing)
3806 Spacing = 1 + (Reg == OldReg + 2);
3807
3808 // Just check that it's contiguous and keep going.
3809 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003810 Error(RegLoc, "non-contiguous register range");
3811 return MatchOperand_ParseFail;
3812 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003813 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003814 // Parse the lane specifier if present.
3815 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003816 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003817 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003818 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003819 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003820 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003821 Error(EndLoc, "mismatched lane index in register list");
3822 return MatchOperand_ParseFail;
3823 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003824 }
3825
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003826 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003827 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003828 return MatchOperand_ParseFail;
3829 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003830 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003831 Parser.Lex(); // Eat '}' token.
3832
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003833 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003834 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003835 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003836 // composite register classes.
3837 if (Count == 2) {
3838 const MCRegisterClass *RC = (Spacing == 1) ?
3839 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3840 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3841 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3842 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003843
Jim Grosbach2f50e922011-12-15 21:44:33 +00003844 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3845 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003846 break;
3847 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003848 // Two-register operands have been converted to the
3849 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003850 if (Count == 2) {
3851 const MCRegisterClass *RC = (Spacing == 1) ?
3852 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3853 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003854 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3855 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003856 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003857 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003858 S, E));
3859 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003860 case IndexedLane:
3861 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003862 LaneIndex,
3863 (Spacing == 2),
3864 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003865 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003866 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003867 return MatchOperand_Success;
3868}
3869
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003870/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003871ARMAsmParser::OperandMatchResultTy
3872ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003873 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003874 SMLoc S = Parser.getTok().getLoc();
3875 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003876 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003877
Jiangning Liu288e1af2012-08-02 08:21:27 +00003878 if (Tok.is(AsmToken::Identifier)) {
3879 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003880
Jiangning Liu288e1af2012-08-02 08:21:27 +00003881 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3882 .Case("sy", ARM_MB::SY)
3883 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003884 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003885 .Case("sh", ARM_MB::ISH)
3886 .Case("ish", ARM_MB::ISH)
3887 .Case("shst", ARM_MB::ISHST)
3888 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003889 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003890 .Case("nsh", ARM_MB::NSH)
3891 .Case("un", ARM_MB::NSH)
3892 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003893 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003894 .Case("unst", ARM_MB::NSHST)
3895 .Case("osh", ARM_MB::OSH)
3896 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003897 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003898 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003899
Joey Gouly926d3f52013-09-05 15:35:24 +00003900 // ishld, oshld, nshld and ld are only available from ARMv8.
3901 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3902 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3903 Opt = ~0U;
3904
Jiangning Liu288e1af2012-08-02 08:21:27 +00003905 if (Opt == ~0U)
3906 return MatchOperand_NoMatch;
3907
3908 Parser.Lex(); // Eat identifier token.
3909 } else if (Tok.is(AsmToken::Hash) ||
3910 Tok.is(AsmToken::Dollar) ||
3911 Tok.is(AsmToken::Integer)) {
3912 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003913 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003914 SMLoc Loc = Parser.getTok().getLoc();
3915
3916 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003917 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003918 Error(Loc, "illegal expression");
3919 return MatchOperand_ParseFail;
3920 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00003921
Jiangning Liu288e1af2012-08-02 08:21:27 +00003922 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3923 if (!CE) {
3924 Error(Loc, "constant expression expected");
3925 return MatchOperand_ParseFail;
3926 }
3927
3928 int Val = CE->getValue();
3929 if (Val & ~0xf) {
3930 Error(Loc, "immediate value out of range");
3931 return MatchOperand_ParseFail;
3932 }
3933
3934 Opt = ARM_MB::RESERVED_0 + Val;
3935 } else
3936 return MatchOperand_ParseFail;
3937
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003938 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003939 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003940}
3941
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003942/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003943ARMAsmParser::OperandMatchResultTy
3944ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003945 MCAsmParser &Parser = getParser();
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003946 SMLoc S = Parser.getTok().getLoc();
3947 const AsmToken &Tok = Parser.getTok();
3948 unsigned Opt;
3949
3950 if (Tok.is(AsmToken::Identifier)) {
3951 StringRef OptStr = Tok.getString();
3952
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003953 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003954 Opt = ARM_ISB::SY;
3955 else
3956 return MatchOperand_NoMatch;
3957
3958 Parser.Lex(); // Eat identifier token.
3959 } else if (Tok.is(AsmToken::Hash) ||
3960 Tok.is(AsmToken::Dollar) ||
3961 Tok.is(AsmToken::Integer)) {
3962 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003963 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003964 SMLoc Loc = Parser.getTok().getLoc();
3965
3966 const MCExpr *ISBarrierID;
3967 if (getParser().parseExpression(ISBarrierID)) {
3968 Error(Loc, "illegal expression");
3969 return MatchOperand_ParseFail;
3970 }
3971
3972 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3973 if (!CE) {
3974 Error(Loc, "constant expression expected");
3975 return MatchOperand_ParseFail;
3976 }
3977
3978 int Val = CE->getValue();
3979 if (Val & ~0xf) {
3980 Error(Loc, "immediate value out of range");
3981 return MatchOperand_ParseFail;
3982 }
3983
3984 Opt = ARM_ISB::RESERVED_0 + Val;
3985 } else
3986 return MatchOperand_ParseFail;
3987
3988 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3989 (ARM_ISB::InstSyncBOpt)Opt, S));
3990 return MatchOperand_Success;
3991}
3992
3993
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003994/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003995ARMAsmParser::OperandMatchResultTy
3996ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003997 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003998 SMLoc S = Parser.getTok().getLoc();
3999 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00004000 if (!Tok.is(AsmToken::Identifier))
4001 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004002 StringRef IFlagsStr = Tok.getString();
4003
Owen Anderson10c5b122011-10-05 17:16:40 +00004004 // An iflags string of "none" is interpreted to mean that none of the AIF
4005 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004006 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00004007 if (IFlagsStr != "none") {
4008 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
4009 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
4010 .Case("a", ARM_PROC::A)
4011 .Case("i", ARM_PROC::I)
4012 .Case("f", ARM_PROC::F)
4013 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004014
Owen Anderson10c5b122011-10-05 17:16:40 +00004015 // If some specific iflag is already set, it means that some letter is
4016 // present more than once, this is not acceptable.
4017 if (Flag == ~0U || (IFlags & Flag))
4018 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004019
Owen Anderson10c5b122011-10-05 17:16:40 +00004020 IFlags |= Flag;
4021 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004022 }
4023
4024 Parser.Lex(); // Eat identifier token.
4025 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
4026 return MatchOperand_Success;
4027}
4028
Jim Grosbach2d6ef442011-07-25 20:14:50 +00004029/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00004030ARMAsmParser::OperandMatchResultTy
4031ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004032 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004033 SMLoc S = Parser.getTok().getLoc();
4034 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00004035 if (!Tok.is(AsmToken::Identifier))
4036 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004037 StringRef Mask = Tok.getString();
4038
James Molloy21efa7d2011-09-28 14:21:38 +00004039 if (isMClass()) {
4040 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00004041 std::string Name = Mask.lower();
4042 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00004043 // Note: in the documentation:
4044 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
4045 // for MSR APSR_nzcvq.
4046 // but we do make it an alias here. This is so to get the "mask encoding"
4047 // bits correct on MSR APSR writes.
4048 //
4049 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
4050 // should really only be allowed when writing a special register. Note
4051 // they get dropped in the MRS instruction reading a special register as
4052 // the SYSm field is only 8 bits.
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00004053 .Case("apsr", 0x800)
4054 .Case("apsr_nzcvq", 0x800)
4055 .Case("apsr_g", 0x400)
4056 .Case("apsr_nzcvqg", 0xc00)
4057 .Case("iapsr", 0x801)
4058 .Case("iapsr_nzcvq", 0x801)
4059 .Case("iapsr_g", 0x401)
4060 .Case("iapsr_nzcvqg", 0xc01)
4061 .Case("eapsr", 0x802)
4062 .Case("eapsr_nzcvq", 0x802)
4063 .Case("eapsr_g", 0x402)
4064 .Case("eapsr_nzcvqg", 0xc02)
4065 .Case("xpsr", 0x803)
4066 .Case("xpsr_nzcvq", 0x803)
4067 .Case("xpsr_g", 0x403)
4068 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00004069 .Case("ipsr", 0x805)
4070 .Case("epsr", 0x806)
4071 .Case("iepsr", 0x807)
4072 .Case("msp", 0x808)
4073 .Case("psp", 0x809)
4074 .Case("primask", 0x810)
4075 .Case("basepri", 0x811)
4076 .Case("basepri_max", 0x812)
4077 .Case("faultmask", 0x813)
4078 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00004079 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00004080
James Molloy21efa7d2011-09-28 14:21:38 +00004081 if (FlagsVal == ~0U)
4082 return MatchOperand_NoMatch;
4083
Renato Golin92c816c2014-09-01 11:25:07 +00004084 if (!hasThumb2DSP() && (FlagsVal & 0x400))
4085 // The _g and _nzcvqg versions are only valid if the DSP extension is
4086 // available.
4087 return MatchOperand_NoMatch;
4088
Kevin Enderby6c7279e2012-06-15 22:14:44 +00004089 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00004090 // basepri, basepri_max and faultmask only valid for V7m.
4091 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00004092
James Molloy21efa7d2011-09-28 14:21:38 +00004093 Parser.Lex(); // Eat identifier token.
4094 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4095 return MatchOperand_Success;
4096 }
4097
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004098 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
4099 size_t Start = 0, Next = Mask.find('_');
4100 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004101 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004102 if (Next != StringRef::npos)
4103 Flags = Mask.slice(Next+1, Mask.size());
4104
4105 // FlagsVal contains the complete mask:
4106 // 3-0: Mask
4107 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4108 unsigned FlagsVal = 0;
4109
4110 if (SpecReg == "apsr") {
4111 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00004112 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004113 .Case("g", 0x4) // same as CPSR_s
4114 .Case("nzcvqg", 0xc) // same as CPSR_fs
4115 .Default(~0U);
4116
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00004117 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004118 if (!Flags.empty())
4119 return MatchOperand_NoMatch;
4120 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00004121 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00004122 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004123 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00004124 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
4125 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00004126 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004127 for (int i = 0, e = Flags.size(); i != e; ++i) {
4128 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
4129 .Case("c", 1)
4130 .Case("x", 2)
4131 .Case("s", 4)
4132 .Case("f", 8)
4133 .Default(~0U);
4134
4135 // If some specific flag is already set, it means that some letter is
4136 // present more than once, this is not acceptable.
4137 if (FlagsVal == ~0U || (FlagsVal & Flag))
4138 return MatchOperand_NoMatch;
4139 FlagsVal |= Flag;
4140 }
4141 } else // No match for special register.
4142 return MatchOperand_NoMatch;
4143
Owen Anderson03a173e2011-10-21 18:43:28 +00004144 // Special register without flags is NOT equivalent to "fc" flags.
4145 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
4146 // two lines would enable gas compatibility at the expense of breaking
4147 // round-tripping.
4148 //
4149 // if (!FlagsVal)
4150 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004151
4152 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4153 if (SpecReg == "spsr")
4154 FlagsVal |= 16;
4155
4156 Parser.Lex(); // Eat identifier token.
4157 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4158 return MatchOperand_Success;
4159}
4160
Tim Northoveree843ef2014-08-15 10:47:12 +00004161/// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for
4162/// use in the MRS/MSR instructions added to support virtualization.
4163ARMAsmParser::OperandMatchResultTy
4164ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004165 MCAsmParser &Parser = getParser();
Tim Northoveree843ef2014-08-15 10:47:12 +00004166 SMLoc S = Parser.getTok().getLoc();
4167 const AsmToken &Tok = Parser.getTok();
4168 if (!Tok.is(AsmToken::Identifier))
4169 return MatchOperand_NoMatch;
4170 StringRef RegName = Tok.getString();
4171
4172 // The values here come from B9.2.3 of the ARM ARM, where bits 4-0 are SysM
4173 // and bit 5 is R.
4174 unsigned Encoding = StringSwitch<unsigned>(RegName.lower())
4175 .Case("r8_usr", 0x00)
4176 .Case("r9_usr", 0x01)
4177 .Case("r10_usr", 0x02)
4178 .Case("r11_usr", 0x03)
4179 .Case("r12_usr", 0x04)
4180 .Case("sp_usr", 0x05)
4181 .Case("lr_usr", 0x06)
4182 .Case("r8_fiq", 0x08)
4183 .Case("r9_fiq", 0x09)
4184 .Case("r10_fiq", 0x0a)
4185 .Case("r11_fiq", 0x0b)
4186 .Case("r12_fiq", 0x0c)
4187 .Case("sp_fiq", 0x0d)
4188 .Case("lr_fiq", 0x0e)
4189 .Case("lr_irq", 0x10)
4190 .Case("sp_irq", 0x11)
4191 .Case("lr_svc", 0x12)
4192 .Case("sp_svc", 0x13)
4193 .Case("lr_abt", 0x14)
4194 .Case("sp_abt", 0x15)
4195 .Case("lr_und", 0x16)
4196 .Case("sp_und", 0x17)
4197 .Case("lr_mon", 0x1c)
4198 .Case("sp_mon", 0x1d)
4199 .Case("elr_hyp", 0x1e)
4200 .Case("sp_hyp", 0x1f)
4201 .Case("spsr_fiq", 0x2e)
4202 .Case("spsr_irq", 0x30)
4203 .Case("spsr_svc", 0x32)
4204 .Case("spsr_abt", 0x34)
4205 .Case("spsr_und", 0x36)
4206 .Case("spsr_mon", 0x3c)
4207 .Case("spsr_hyp", 0x3e)
4208 .Default(~0U);
4209
4210 if (Encoding == ~0U)
4211 return MatchOperand_NoMatch;
4212
4213 Parser.Lex(); // Eat identifier token.
4214 Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S));
4215 return MatchOperand_Success;
4216}
4217
David Blaikie960ea3f2014-06-08 16:18:35 +00004218ARMAsmParser::OperandMatchResultTy
4219ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low,
4220 int High) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004221 MCAsmParser &Parser = getParser();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004222 const AsmToken &Tok = Parser.getTok();
4223 if (Tok.isNot(AsmToken::Identifier)) {
4224 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4225 return MatchOperand_ParseFail;
4226 }
4227 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004228 std::string LowerOp = Op.lower();
4229 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004230 if (ShiftName != LowerOp && ShiftName != UpperOp) {
4231 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4232 return MatchOperand_ParseFail;
4233 }
4234 Parser.Lex(); // Eat shift type token.
4235
4236 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004237 if (Parser.getTok().isNot(AsmToken::Hash) &&
4238 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004239 Error(Parser.getTok().getLoc(), "'#' expected");
4240 return MatchOperand_ParseFail;
4241 }
4242 Parser.Lex(); // Eat hash token.
4243
4244 const MCExpr *ShiftAmount;
4245 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004246 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004247 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004248 Error(Loc, "illegal expression");
4249 return MatchOperand_ParseFail;
4250 }
4251 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4252 if (!CE) {
4253 Error(Loc, "constant expression expected");
4254 return MatchOperand_ParseFail;
4255 }
4256 int Val = CE->getValue();
4257 if (Val < Low || Val > High) {
4258 Error(Loc, "immediate value out of range");
4259 return MatchOperand_ParseFail;
4260 }
4261
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004262 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00004263
4264 return MatchOperand_Success;
4265}
4266
David Blaikie960ea3f2014-06-08 16:18:35 +00004267ARMAsmParser::OperandMatchResultTy
4268ARMAsmParser::parseSetEndImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004269 MCAsmParser &Parser = getParser();
Jim Grosbach0a547702011-07-22 17:44:50 +00004270 const AsmToken &Tok = Parser.getTok();
4271 SMLoc S = Tok.getLoc();
4272 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004273 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004274 return MatchOperand_ParseFail;
4275 }
Tim Northover4d141442013-05-31 15:58:45 +00004276 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00004277 .Case("be", 1)
4278 .Case("le", 0)
4279 .Default(-1);
4280 Parser.Lex(); // Eat the token.
4281
4282 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004283 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004284 return MatchOperand_ParseFail;
4285 }
4286 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4287 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004288 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00004289 return MatchOperand_Success;
4290}
4291
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004292/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
4293/// instructions. Legal values are:
4294/// lsl #n 'n' in [0,31]
4295/// asr #n 'n' in [1,32]
4296/// n == 32 encoded as n == 0.
David Blaikie960ea3f2014-06-08 16:18:35 +00004297ARMAsmParser::OperandMatchResultTy
4298ARMAsmParser::parseShifterImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004299 MCAsmParser &Parser = getParser();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004300 const AsmToken &Tok = Parser.getTok();
4301 SMLoc S = Tok.getLoc();
4302 if (Tok.isNot(AsmToken::Identifier)) {
4303 Error(S, "shift operator 'asr' or 'lsl' expected");
4304 return MatchOperand_ParseFail;
4305 }
4306 StringRef ShiftName = Tok.getString();
4307 bool isASR;
4308 if (ShiftName == "lsl" || ShiftName == "LSL")
4309 isASR = false;
4310 else if (ShiftName == "asr" || ShiftName == "ASR")
4311 isASR = true;
4312 else {
4313 Error(S, "shift operator 'asr' or 'lsl' expected");
4314 return MatchOperand_ParseFail;
4315 }
4316 Parser.Lex(); // Eat the operator.
4317
4318 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004319 if (Parser.getTok().isNot(AsmToken::Hash) &&
4320 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004321 Error(Parser.getTok().getLoc(), "'#' expected");
4322 return MatchOperand_ParseFail;
4323 }
4324 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004325 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004326
4327 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004328 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004329 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004330 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004331 return MatchOperand_ParseFail;
4332 }
4333 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4334 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004335 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004336 return MatchOperand_ParseFail;
4337 }
4338
4339 int64_t Val = CE->getValue();
4340 if (isASR) {
4341 // Shift amount must be in [1,32]
4342 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004343 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004344 return MatchOperand_ParseFail;
4345 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00004346 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4347 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004348 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00004349 return MatchOperand_ParseFail;
4350 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004351 if (Val == 32) Val = 0;
4352 } else {
4353 // Shift amount must be in [1,32]
4354 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004355 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004356 return MatchOperand_ParseFail;
4357 }
4358 }
4359
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004360 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004361
4362 return MatchOperand_Success;
4363}
4364
Jim Grosbach833b9d32011-07-27 20:15:40 +00004365/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4366/// of instructions. Legal values are:
4367/// ror #n 'n' in {0, 8, 16, 24}
David Blaikie960ea3f2014-06-08 16:18:35 +00004368ARMAsmParser::OperandMatchResultTy
4369ARMAsmParser::parseRotImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004370 MCAsmParser &Parser = getParser();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004371 const AsmToken &Tok = Parser.getTok();
4372 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00004373 if (Tok.isNot(AsmToken::Identifier))
4374 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004375 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00004376 if (ShiftName != "ror" && ShiftName != "ROR")
4377 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004378 Parser.Lex(); // Eat the operator.
4379
4380 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004381 if (Parser.getTok().isNot(AsmToken::Hash) &&
4382 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004383 Error(Parser.getTok().getLoc(), "'#' expected");
4384 return MatchOperand_ParseFail;
4385 }
4386 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004387 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004388
4389 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004390 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004391 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004392 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004393 return MatchOperand_ParseFail;
4394 }
4395 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4396 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004397 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004398 return MatchOperand_ParseFail;
4399 }
4400
4401 int64_t Val = CE->getValue();
4402 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4403 // normally, zero is represented in asm by omitting the rotate operand
4404 // entirely.
4405 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004406 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004407 return MatchOperand_ParseFail;
4408 }
4409
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004410 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004411
4412 return MatchOperand_Success;
4413}
4414
David Blaikie960ea3f2014-06-08 16:18:35 +00004415ARMAsmParser::OperandMatchResultTy
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004416ARMAsmParser::parseModImm(OperandVector &Operands) {
4417 MCAsmParser &Parser = getParser();
4418 MCAsmLexer &Lexer = getLexer();
4419 int64_t Imm1, Imm2;
4420
4421 if ((Parser.getTok().isNot(AsmToken::Hash) &&
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004422 Parser.getTok().isNot(AsmToken::Dollar))
4423 || Lexer.peekTok().is(AsmToken::Colon))
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004424 return MatchOperand_NoMatch;
4425
4426 SMLoc S = Parser.getTok().getLoc();
4427
4428 // Eat the hash (or dollar)
4429 Parser.Lex();
4430
4431 SMLoc Sx1, Ex1;
4432 Sx1 = Parser.getTok().getLoc();
4433 const MCExpr *Imm1Exp;
4434 if (getParser().parseExpression(Imm1Exp, Ex1)) {
4435 Error(Sx1, "malformed expression");
4436 return MatchOperand_ParseFail;
4437 }
4438
4439 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm1Exp);
4440
4441 if (CE) {
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004442 // Immediate must fit within 32-bits
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004443 Imm1 = CE->getValue();
4444 if (Imm1 < INT32_MIN || Imm1 > UINT32_MAX) {
4445 Error(Sx1, "immediate operand must be representable with 32 bits");
4446 return MatchOperand_ParseFail;
4447 }
4448
4449 int Enc = ARM_AM::getSOImmVal(Imm1);
4450 if (Enc != -1 && Parser.getTok().is(AsmToken::EndOfStatement)) {
4451 // We have a match!
4452 Operands.push_back(ARMOperand::CreateModImm((Enc & 0xFF),
4453 (Enc & 0xF00) >> 7,
4454 Sx1, Ex1));
4455 return MatchOperand_Success;
4456 }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004457
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004458 // We have parsed an immediate which is not for us, fallback to a plain
4459 // immediate. This can happen for instruction aliases. For an example,
4460 // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform
4461 // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite
4462 // instruction with a mod_imm operand. The alias is defined such that the
4463 // parser method is shared, that's why we have to do this here.
4464 if (Parser.getTok().is(AsmToken::EndOfStatement)) {
4465 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4466 return MatchOperand_Success;
4467 }
4468 } else {
4469 // Operands like #(l1 - l2) can only be evaluated at a later stage (via an
4470 // MCFixup). Fallback to a plain immediate.
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004471 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4472 return MatchOperand_Success;
4473 }
4474
4475 // From this point onward, we expect the input to be a (#bits, #rot) pair
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004476 if (Parser.getTok().isNot(AsmToken::Comma)) {
4477 Error(Sx1, "expected modified immediate operand: #[0, 255], #even[0-30]");
4478 return MatchOperand_ParseFail;
4479 }
4480
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004481 if (Imm1 & ~0xFF) {
4482 Error(Sx1, "immediate operand must a number in the range [0, 255]");
4483 return MatchOperand_ParseFail;
4484 }
4485
4486 if (Lexer.peekTok().isNot(AsmToken::Hash) &&
4487 Lexer.peekTok().isNot(AsmToken::Dollar)) {
4488 Error(Lexer.peekTok().getLoc(), "immediate operand expected");
4489 return MatchOperand_ParseFail;
4490 }
4491
4492 // Eat the comma
4493 Parser.Lex();
4494
4495 // Repeat for #rot
4496 SMLoc Sx2, Ex2;
4497 Sx2 = Parser.getTok().getLoc();
4498
4499 // Eat the hash (or dollar)
4500 Parser.Lex();
4501
4502 const MCExpr *Imm2Exp;
4503 if (getParser().parseExpression(Imm2Exp, Ex2)) {
4504 Error(Sx2, "malformed expression");
4505 return MatchOperand_ParseFail;
4506 }
4507
4508 CE = dyn_cast<MCConstantExpr>(Imm2Exp);
4509
4510 if (CE) {
4511 Imm2 = CE->getValue();
4512 if (!(Imm2 & ~0x1E)) {
4513 // We have a match!
4514 Operands.push_back(ARMOperand::CreateModImm(Imm1, Imm2, S, Ex2));
4515 return MatchOperand_Success;
4516 }
4517 Error(Sx2, "immediate operand must an even number in the range [0, 30]");
4518 return MatchOperand_ParseFail;
4519 } else {
4520 Error(Sx2, "constant expression expected");
4521 return MatchOperand_ParseFail;
4522 }
4523}
4524
4525ARMAsmParser::OperandMatchResultTy
David Blaikie960ea3f2014-06-08 16:18:35 +00004526ARMAsmParser::parseBitfield(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004527 MCAsmParser &Parser = getParser();
Jim Grosbach864b6092011-07-28 21:34:26 +00004528 SMLoc S = Parser.getTok().getLoc();
4529 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004530 if (Parser.getTok().isNot(AsmToken::Hash) &&
4531 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004532 Error(Parser.getTok().getLoc(), "'#' expected");
4533 return MatchOperand_ParseFail;
4534 }
4535 Parser.Lex(); // Eat hash token.
4536
4537 const MCExpr *LSBExpr;
4538 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004539 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004540 Error(E, "malformed immediate expression");
4541 return MatchOperand_ParseFail;
4542 }
4543 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4544 if (!CE) {
4545 Error(E, "'lsb' operand must be an immediate");
4546 return MatchOperand_ParseFail;
4547 }
4548
4549 int64_t LSB = CE->getValue();
4550 // The LSB must be in the range [0,31]
4551 if (LSB < 0 || LSB > 31) {
4552 Error(E, "'lsb' operand must be in the range [0,31]");
4553 return MatchOperand_ParseFail;
4554 }
4555 E = Parser.getTok().getLoc();
4556
4557 // Expect another immediate operand.
4558 if (Parser.getTok().isNot(AsmToken::Comma)) {
4559 Error(Parser.getTok().getLoc(), "too few operands");
4560 return MatchOperand_ParseFail;
4561 }
4562 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004563 if (Parser.getTok().isNot(AsmToken::Hash) &&
4564 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004565 Error(Parser.getTok().getLoc(), "'#' expected");
4566 return MatchOperand_ParseFail;
4567 }
4568 Parser.Lex(); // Eat hash token.
4569
4570 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004571 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004572 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004573 Error(E, "malformed immediate expression");
4574 return MatchOperand_ParseFail;
4575 }
4576 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4577 if (!CE) {
4578 Error(E, "'width' operand must be an immediate");
4579 return MatchOperand_ParseFail;
4580 }
4581
4582 int64_t Width = CE->getValue();
4583 // The LSB must be in the range [1,32-lsb]
4584 if (Width < 1 || Width > 32 - LSB) {
4585 Error(E, "'width' operand must be in the range [1,32-lsb]");
4586 return MatchOperand_ParseFail;
4587 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004588
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004589 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004590
4591 return MatchOperand_Success;
4592}
4593
David Blaikie960ea3f2014-06-08 16:18:35 +00004594ARMAsmParser::OperandMatchResultTy
4595ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
Jim Grosbachd3595712011-08-03 23:50:40 +00004596 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004597 // postidx_reg := '+' register {, shift}
4598 // | '-' register {, shift}
4599 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004600
4601 // This method must return MatchOperand_NoMatch without consuming any tokens
4602 // in the case where there is no match, as other alternatives take other
4603 // parse methods.
Rafael Espindola961d4692014-11-11 05:18:41 +00004604 MCAsmParser &Parser = getParser();
Jim Grosbachd3595712011-08-03 23:50:40 +00004605 AsmToken Tok = Parser.getTok();
4606 SMLoc S = Tok.getLoc();
4607 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004608 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004609 if (Tok.is(AsmToken::Plus)) {
4610 Parser.Lex(); // Eat the '+' token.
4611 haveEaten = true;
4612 } else if (Tok.is(AsmToken::Minus)) {
4613 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004614 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004615 haveEaten = true;
4616 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004617
4618 SMLoc E = Parser.getTok().getEndLoc();
4619 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004620 if (Reg == -1) {
4621 if (!haveEaten)
4622 return MatchOperand_NoMatch;
4623 Error(Parser.getTok().getLoc(), "register expected");
4624 return MatchOperand_ParseFail;
4625 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004626
Jim Grosbachc320c852011-08-05 21:28:30 +00004627 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4628 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004629 if (Parser.getTok().is(AsmToken::Comma)) {
4630 Parser.Lex(); // Eat the ','.
4631 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4632 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004633
4634 // FIXME: Only approximates end...may include intervening whitespace.
4635 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004636 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004637
4638 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4639 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004640
4641 return MatchOperand_Success;
4642}
4643
David Blaikie960ea3f2014-06-08 16:18:35 +00004644ARMAsmParser::OperandMatchResultTy
4645ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004646 // Check for a post-index addressing register operand. Specifically:
4647 // am3offset := '+' register
4648 // | '-' register
4649 // | register
4650 // | # imm
4651 // | # + imm
4652 // | # - imm
4653
4654 // This method must return MatchOperand_NoMatch without consuming any tokens
4655 // in the case where there is no match, as other alternatives take other
4656 // parse methods.
Rafael Espindola961d4692014-11-11 05:18:41 +00004657 MCAsmParser &Parser = getParser();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004658 AsmToken Tok = Parser.getTok();
4659 SMLoc S = Tok.getLoc();
4660
4661 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004662 if (Parser.getTok().is(AsmToken::Hash) ||
4663 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004664 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004665 // Explicitly look for a '-', as we need to encode negative zero
4666 // differently.
4667 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4668 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004669 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004670 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004671 return MatchOperand_ParseFail;
4672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4673 if (!CE) {
4674 Error(S, "constant expression expected");
4675 return MatchOperand_ParseFail;
4676 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004677 // Negative zero is encoded as the flag value INT32_MIN.
4678 int32_t Val = CE->getValue();
4679 if (isNegative && Val == 0)
4680 Val = INT32_MIN;
4681
4682 Operands.push_back(
4683 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4684
4685 return MatchOperand_Success;
4686 }
4687
4688
4689 bool haveEaten = false;
4690 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004691 if (Tok.is(AsmToken::Plus)) {
4692 Parser.Lex(); // Eat the '+' token.
4693 haveEaten = true;
4694 } else if (Tok.is(AsmToken::Minus)) {
4695 Parser.Lex(); // Eat the '-' token.
4696 isAdd = false;
4697 haveEaten = true;
4698 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004699
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004700 Tok = Parser.getTok();
4701 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004702 if (Reg == -1) {
4703 if (!haveEaten)
4704 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004705 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004706 return MatchOperand_ParseFail;
4707 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004708
4709 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004710 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004711
4712 return MatchOperand_Success;
4713}
4714
Tim Northovereb5e4d52013-07-22 09:06:12 +00004715/// Convert parsed operands to MCInst. Needed here because this instruction
4716/// only has two register operands, but multiplication is commutative so
4717/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
David Blaikie960ea3f2014-06-08 16:18:35 +00004718void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
4719 const OperandVector &Operands) {
4720 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1);
4721 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004722 // If we have a three-operand form, make sure to set Rn to be the operand
4723 // that isn't the same as Rd.
4724 unsigned RegOp = 4;
4725 if (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00004726 ((ARMOperand &)*Operands[4]).getReg() ==
4727 ((ARMOperand &)*Operands[3]).getReg())
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004728 RegOp = 5;
David Blaikie960ea3f2014-06-08 16:18:35 +00004729 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004730 Inst.addOperand(Inst.getOperand(0));
David Blaikie960ea3f2014-06-08 16:18:35 +00004731 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004732}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004733
David Blaikie960ea3f2014-06-08 16:18:35 +00004734void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
4735 const OperandVector &Operands) {
Mihai Popaad18d3c2013-08-09 10:38:32 +00004736 int CondOp = -1, ImmOp = -1;
4737 switch(Inst.getOpcode()) {
4738 case ARM::tB:
4739 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4740
4741 case ARM::t2B:
4742 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4743
4744 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4745 }
4746 // first decide whether or not the branch should be conditional
4747 // by looking at it's location relative to an IT block
4748 if(inITBlock()) {
4749 // inside an IT block we cannot have any conditional branches. any
4750 // such instructions needs to be converted to unconditional form
4751 switch(Inst.getOpcode()) {
4752 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4753 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4754 }
4755 } else {
4756 // outside IT blocks we can only have unconditional branches with AL
4757 // condition code or conditional branches with non-AL condition code
David Blaikie960ea3f2014-06-08 16:18:35 +00004758 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode();
Mihai Popaad18d3c2013-08-09 10:38:32 +00004759 switch(Inst.getOpcode()) {
4760 case ARM::tB:
4761 case ARM::tBcc:
4762 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4763 break;
4764 case ARM::t2B:
4765 case ARM::t2Bcc:
4766 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4767 break;
4768 }
4769 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004770
Mihai Popaad18d3c2013-08-09 10:38:32 +00004771 // now decide on encoding size based on branch target range
4772 switch(Inst.getOpcode()) {
4773 // classify tB as either t2B or t1B based on range of immediate operand
4774 case ARM::tB: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004775 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4776 if (!op.isSignedOffset<11, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004777 Inst.setOpcode(ARM::t2B);
4778 break;
4779 }
4780 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4781 case ARM::tBcc: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004782 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4783 if (!op.isSignedOffset<8, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004784 Inst.setOpcode(ARM::t2Bcc);
4785 break;
4786 }
4787 }
David Blaikie960ea3f2014-06-08 16:18:35 +00004788 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1);
4789 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2);
Mihai Popaad18d3c2013-08-09 10:38:32 +00004790}
4791
Bill Wendlinge18980a2010-11-06 22:36:58 +00004792/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004793/// or an error. The first token must be a '[' when called.
David Blaikie960ea3f2014-06-08 16:18:35 +00004794bool ARMAsmParser::parseMemory(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004795 MCAsmParser &Parser = getParser();
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004796 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004797 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004798 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004799 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004800 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004801
Sean Callanan936b0d32010-01-19 21:44:56 +00004802 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004803 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004804 if (BaseRegNum == -1)
4805 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004806
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004807 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004808 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004809 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4810 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004811 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004812
Jim Grosbachd3595712011-08-03 23:50:40 +00004813 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004814 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004815 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004816
Craig Topper062a2ba2014-04-25 05:30:21 +00004817 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4818 ARM_AM::no_shift, 0, 0, false,
4819 S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004820
Jim Grosbach40700e02011-09-19 18:42:21 +00004821 // If there's a pre-indexing writeback marker, '!', just add it as a token
4822 // operand. It's rather odd, but syntactically valid.
4823 if (Parser.getTok().is(AsmToken::Exclaim)) {
4824 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4825 Parser.Lex(); // Eat the '!'.
4826 }
4827
Jim Grosbachd3595712011-08-03 23:50:40 +00004828 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004829 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004830
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004831 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4832 "Lost colon or comma in memory operand?!");
4833 if (Tok.is(AsmToken::Comma)) {
4834 Parser.Lex(); // Eat the comma.
4835 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004836
Jim Grosbacha95ec992011-10-11 17:29:55 +00004837 // If we have a ':', it's an alignment specifier.
4838 if (Parser.getTok().is(AsmToken::Colon)) {
4839 Parser.Lex(); // Eat the ':'.
4840 E = Parser.getTok().getLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00004841 SMLoc AlignmentLoc = Tok.getLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004842
4843 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004844 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004845 return true;
4846
4847 // The expression has to be a constant. Memory references with relocations
4848 // don't come through here, as they use the <label> forms of the relevant
4849 // instructions.
4850 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4851 if (!CE)
4852 return Error (E, "constant expression expected");
4853
4854 unsigned Align = 0;
4855 switch (CE->getValue()) {
4856 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004857 return Error(E,
4858 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4859 case 16: Align = 2; break;
4860 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004861 case 64: Align = 8; break;
4862 case 128: Align = 16; break;
4863 case 256: Align = 32; break;
4864 }
4865
4866 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004867 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004868 return Error(Parser.getTok().getLoc(), "']' expected");
4869 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004870 Parser.Lex(); // Eat right bracket token.
4871
4872 // Don't worry about range checking the value here. That's handled by
4873 // the is*() predicates.
Craig Topper062a2ba2014-04-25 05:30:21 +00004874 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004875 ARM_AM::no_shift, 0, Align,
Kevin Enderby488f20b2014-04-10 20:18:58 +00004876 false, S, E, AlignmentLoc));
Jim Grosbacha95ec992011-10-11 17:29:55 +00004877
4878 // If there's a pre-indexing writeback marker, '!', just add it as a token
4879 // operand.
4880 if (Parser.getTok().is(AsmToken::Exclaim)) {
4881 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4882 Parser.Lex(); // Eat the '!'.
4883 }
4884
4885 return false;
4886 }
4887
4888 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004889 // offset. Be friendly and also accept a plain integer (without a leading
4890 // hash) for gas compatibility.
4891 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004892 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004893 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004894 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004895 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004896 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004897
Owen Anderson967674d2011-08-29 19:36:44 +00004898 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004899 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004900 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004901 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004902
4903 // The expression has to be a constant. Memory references with relocations
4904 // don't come through here, as they use the <label> forms of the relevant
4905 // instructions.
4906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4907 if (!CE)
4908 return Error (E, "constant expression expected");
4909
Owen Anderson967674d2011-08-29 19:36:44 +00004910 // If the constant was #-0, represent it as INT32_MIN.
4911 int32_t Val = CE->getValue();
4912 if (isNegative && Val == 0)
4913 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4914
Jim Grosbachd3595712011-08-03 23:50:40 +00004915 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004916 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004917 return Error(Parser.getTok().getLoc(), "']' expected");
4918 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004919 Parser.Lex(); // Eat right bracket token.
4920
4921 // Don't worry about range checking the value here. That's handled by
4922 // the is*() predicates.
4923 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004924 ARM_AM::no_shift, 0, 0,
4925 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004926
4927 // If there's a pre-indexing writeback marker, '!', just add it as a token
4928 // operand.
4929 if (Parser.getTok().is(AsmToken::Exclaim)) {
4930 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4931 Parser.Lex(); // Eat the '!'.
4932 }
4933
4934 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004935 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004936
4937 // The register offset is optionally preceded by a '+' or '-'
4938 bool isNegative = false;
4939 if (Parser.getTok().is(AsmToken::Minus)) {
4940 isNegative = true;
4941 Parser.Lex(); // Eat the '-'.
4942 } else if (Parser.getTok().is(AsmToken::Plus)) {
4943 // Nothing to do.
4944 Parser.Lex(); // Eat the '+'.
4945 }
4946
4947 E = Parser.getTok().getLoc();
4948 int OffsetRegNum = tryParseRegister();
4949 if (OffsetRegNum == -1)
4950 return Error(E, "register expected");
4951
4952 // If there's a shift operator, handle it.
4953 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004954 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004955 if (Parser.getTok().is(AsmToken::Comma)) {
4956 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004957 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004958 return true;
4959 }
4960
4961 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004962 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004963 return Error(Parser.getTok().getLoc(), "']' expected");
4964 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004965 Parser.Lex(); // Eat right bracket token.
4966
Craig Topper062a2ba2014-04-25 05:30:21 +00004967 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004968 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004969 S, E));
4970
Jim Grosbachc320c852011-08-05 21:28:30 +00004971 // If there's a pre-indexing writeback marker, '!', just add it as a token
4972 // operand.
4973 if (Parser.getTok().is(AsmToken::Exclaim)) {
4974 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4975 Parser.Lex(); // Eat the '!'.
4976 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004977
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004978 return false;
4979}
4980
Jim Grosbachd3595712011-08-03 23:50:40 +00004981/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004982/// ( lsl | lsr | asr | ror ) , # shift_amount
4983/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004984/// return true if it parses a shift otherwise it returns false.
4985bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4986 unsigned &Amount) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004987 MCAsmParser &Parser = getParser();
Jim Grosbachd3595712011-08-03 23:50:40 +00004988 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004989 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004990 if (Tok.isNot(AsmToken::Identifier))
4991 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004992 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004993 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4994 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004995 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004996 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004997 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004998 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004999 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005000 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00005001 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005002 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00005003 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005004 else
Jim Grosbachd3595712011-08-03 23:50:40 +00005005 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00005006 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005007
Jim Grosbachd3595712011-08-03 23:50:40 +00005008 // rrx stands alone.
5009 Amount = 0;
5010 if (St != ARM_AM::rrx) {
5011 Loc = Parser.getTok().getLoc();
5012 // A '#' and a shift amount.
5013 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005014 if (HashTok.isNot(AsmToken::Hash) &&
5015 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00005016 return Error(HashTok.getLoc(), "'#' expected");
5017 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005018
Jim Grosbachd3595712011-08-03 23:50:40 +00005019 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005020 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00005021 return true;
5022 // Range check the immediate.
5023 // lsl, ror: 0 <= imm <= 31
5024 // lsr, asr: 0 <= imm <= 32
5025 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
5026 if (!CE)
5027 return Error(Loc, "shift amount must be an immediate");
5028 int64_t Imm = CE->getValue();
5029 if (Imm < 0 ||
5030 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
5031 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
5032 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00005033 // If <ShiftTy> #0, turn it into a no_shift.
5034 if (Imm == 0)
5035 St = ARM_AM::lsl;
5036 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
5037 if (Imm == 32)
5038 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00005039 Amount = Imm;
5040 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005041
5042 return false;
5043}
5044
Jim Grosbache7fbce72011-10-03 23:38:36 +00005045/// parseFPImm - A floating point immediate expression operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005046ARMAsmParser::OperandMatchResultTy
5047ARMAsmParser::parseFPImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005048 MCAsmParser &Parser = getParser();
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005049 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005050 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005051 // integer only.
5052 //
5053 // This routine still creates a generic Immediate operand, containing
5054 // a bitcast of the 64-bit floating point value. The various operands
5055 // that accept floats can check whether the value is valid for them
5056 // via the standard is*() predicates.
5057
Jim Grosbache7fbce72011-10-03 23:38:36 +00005058 SMLoc S = Parser.getTok().getLoc();
5059
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005060 if (Parser.getTok().isNot(AsmToken::Hash) &&
5061 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00005062 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00005063
5064 // Disambiguate the VMOV forms that can accept an FP immediate.
5065 // vmov.f32 <sreg>, #imm
5066 // vmov.f64 <dreg>, #imm
5067 // vmov.f32 <dreg>, #imm @ vector f32x2
5068 // vmov.f32 <qreg>, #imm @ vector f32x4
5069 //
5070 // There are also the NEON VMOV instructions which expect an
5071 // integer constant. Make sure we don't try to parse an FPImm
5072 // for these:
5073 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
David Blaikie960ea3f2014-06-08 16:18:35 +00005074 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]);
5075 bool isVmovf = TyOp.isToken() &&
5076 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64");
5077 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
5078 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
5079 Mnemonic.getToken() == "fconsts");
David Peixottoa872e0e2014-01-07 18:19:23 +00005080 if (!(isVmovf || isFconst))
Jim Grosbach741cd732011-10-17 22:26:03 +00005081 return MatchOperand_NoMatch;
5082
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00005083 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00005084
5085 // Handle negation, as that still comes through as a separate token.
5086 bool isNegative = false;
5087 if (Parser.getTok().is(AsmToken::Minus)) {
5088 isNegative = true;
5089 Parser.Lex();
5090 }
5091 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00005092 SMLoc Loc = Tok.getLoc();
David Peixottoa872e0e2014-01-07 18:19:23 +00005093 if (Tok.is(AsmToken::Real) && isVmovf) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005094 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00005095 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
5096 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005097 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00005098 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005099 Operands.push_back(ARMOperand::CreateImm(
5100 MCConstantExpr::Create(IntVal, getContext()),
5101 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00005102 return MatchOperand_Success;
5103 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005104 // Also handle plain integers. Instructions which allow floating point
5105 // immediates also allow a raw encoded 8-bit value.
David Peixottoa872e0e2014-01-07 18:19:23 +00005106 if (Tok.is(AsmToken::Integer) && isFconst) {
Jim Grosbache7fbce72011-10-03 23:38:36 +00005107 int64_t Val = Tok.getIntVal();
5108 Parser.Lex(); // Eat the token.
5109 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00005110 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00005111 return MatchOperand_ParseFail;
5112 }
David Peixottoa872e0e2014-01-07 18:19:23 +00005113 float RealVal = ARM_AM::getFPImmFloat(Val);
5114 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
5115
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005116 Operands.push_back(ARMOperand::CreateImm(
5117 MCConstantExpr::Create(Val, getContext()), S,
5118 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00005119 return MatchOperand_Success;
5120 }
5121
Jim Grosbach235c8d22012-01-19 02:47:30 +00005122 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00005123 return MatchOperand_ParseFail;
5124}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005125
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005126/// Parse a arm instruction operand. For now this parses the operand regardless
5127/// of the mnemonic.
David Blaikie960ea3f2014-06-08 16:18:35 +00005128bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005129 MCAsmParser &Parser = getParser();
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005130 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005131
5132 // Check if the current operand has a custom associated parser, if so, try to
5133 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00005134 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
5135 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005136 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00005137 // If there wasn't a custom match, try the generic matcher below. Otherwise,
5138 // there was a match, but an error occurred, in which case, just return that
5139 // the operand parsing failed.
5140 if (ResTy == MatchOperand_ParseFail)
5141 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005142
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005143 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005144 default:
5145 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00005146 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00005147 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00005148 // If we've seen a branch mnemonic, the next operand must be a label. This
5149 // is true even if the label is a register name. So "br r1" means branch to
5150 // label "r1".
5151 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
5152 if (!ExpectLabel) {
5153 if (!tryParseRegisterWithWriteBack(Operands))
5154 return false;
5155 int Res = tryParseShiftRegister(Operands);
5156 if (Res == 0) // success
5157 return false;
5158 else if (Res == -1) // irrecoverable error
5159 return true;
5160 // If this is VMRS, check for the apsr_nzcv operand.
5161 if (Mnemonic == "vmrs" &&
5162 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
5163 S = Parser.getTok().getLoc();
5164 Parser.Lex();
5165 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
5166 return false;
5167 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00005168 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00005169
5170 // Fall though for the Identifier case that is not a register or a
5171 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00005172 }
Jim Grosbach4e380352011-10-26 21:14:08 +00005173 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00005174 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00005175 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00005176 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00005177 // This was not a register so parse other operands that start with an
5178 // identifier (like labels) as expressions and create them as immediates.
5179 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005180 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005181 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00005182 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005183 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00005184 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
5185 return false;
5186 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005187 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005188 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00005189 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005190 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005191 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00005192 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00005193 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005194 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00005195 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00005196
5197 if (Parser.getTok().isNot(AsmToken::Colon)) {
5198 bool isNegative = Parser.getTok().is(AsmToken::Minus);
5199 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005200 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00005201 return true;
5202 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
5203 if (CE) {
5204 int32_t Val = CE->getValue();
5205 if (isNegative && Val == 0)
5206 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
5207 }
5208 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5209 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00005210
5211 // There can be a trailing '!' on operands that we want as a separate
Saleem Abdulrasool83e37702013-12-28 03:07:12 +00005212 // '!' Token operand. Handle that here. For example, the compatibility
Jim Grosbach9be2d712013-02-23 00:52:09 +00005213 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
5214 if (Parser.getTok().is(AsmToken::Exclaim)) {
5215 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
5216 Parser.getTok().getLoc()));
5217 Parser.Lex(); // Eat exclaim token
5218 }
Jim Grosbach003607f2012-04-16 21:18:46 +00005219 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00005220 }
Jim Grosbach003607f2012-04-16 21:18:46 +00005221 // w/ a ':' after the '#', it's just like a plain ':'.
5222 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00005223 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005224 case AsmToken::Colon: {
5225 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00005226 // FIXME: Check it's an expression prefix,
5227 // e.g. (FOO - :lower16:BAR) isn't legal.
5228 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005229 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00005230 return true;
5231
Evan Cheng965b3c72011-01-13 07:58:56 +00005232 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005233 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00005234 return true;
5235
Evan Cheng965b3c72011-01-13 07:58:56 +00005236 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00005237 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00005238 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00005239 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00005240 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005241 }
David Peixottoe407d092013-12-19 18:12:36 +00005242 case AsmToken::Equal: {
5243 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
5244 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
5245
David Peixottoe407d092013-12-19 18:12:36 +00005246 Parser.Lex(); // Eat '='
5247 const MCExpr *SubExprVal;
5248 if (getParser().parseExpression(SubExprVal))
5249 return true;
5250 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5251
David Peixottob9b73622014-02-04 17:22:40 +00005252 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
David Peixottoe407d092013-12-19 18:12:36 +00005253 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
5254 return false;
5255 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005256 }
5257}
5258
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005259// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00005260// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005261bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005262 MCAsmParser &Parser = getParser();
Evan Cheng965b3c72011-01-13 07:58:56 +00005263 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005264
Saleem Abdulrasool435f4562014-01-10 04:38:40 +00005265 // consume an optional '#' (GNU compatibility)
5266 if (getLexer().is(AsmToken::Hash))
5267 Parser.Lex();
5268
Jason W Kim1f7bc072011-01-11 23:53:41 +00005269 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00005270 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00005271 Parser.Lex(); // Eat ':'
5272
5273 if (getLexer().isNot(AsmToken::Identifier)) {
5274 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
5275 return true;
5276 }
5277
5278 StringRef IDVal = Parser.getTok().getIdentifier();
5279 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00005280 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005281 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00005282 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005283 } else {
5284 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
5285 return true;
5286 }
5287 Parser.Lex();
5288
5289 if (getLexer().isNot(AsmToken::Colon)) {
5290 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
5291 return true;
5292 }
5293 Parser.Lex(); // Eat the last ':'
5294 return false;
5295}
5296
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005297/// \brief Given a mnemonic, split out possible predication code and carry
5298/// setting letters to form a canonical mnemonic and flags.
5299//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005300// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005301// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005302StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005303 unsigned &PredicationCode,
5304 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005305 unsigned &ProcessorIMod,
5306 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005307 PredicationCode = ARMCC::AL;
5308 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005309 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005310
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005311 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005312 //
5313 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005314 if ((Mnemonic == "movs" && isThumb()) ||
5315 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
5316 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
5317 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
5318 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00005319 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005320 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
5321 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00005322 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00005323 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005324 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
5325 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
Charlie Turner4d88ae22014-12-01 08:33:28 +00005326 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic == "hvc" ||
5327 Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005328 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005329
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005330 // First, split out any predication code. Ignore mnemonics we know aren't
5331 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00005332 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00005333 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00005334 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00005335 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005336 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
5337 .Case("eq", ARMCC::EQ)
5338 .Case("ne", ARMCC::NE)
5339 .Case("hs", ARMCC::HS)
5340 .Case("cs", ARMCC::HS)
5341 .Case("lo", ARMCC::LO)
5342 .Case("cc", ARMCC::LO)
5343 .Case("mi", ARMCC::MI)
5344 .Case("pl", ARMCC::PL)
5345 .Case("vs", ARMCC::VS)
5346 .Case("vc", ARMCC::VC)
5347 .Case("hi", ARMCC::HI)
5348 .Case("ls", ARMCC::LS)
5349 .Case("ge", ARMCC::GE)
5350 .Case("lt", ARMCC::LT)
5351 .Case("gt", ARMCC::GT)
5352 .Case("le", ARMCC::LE)
5353 .Case("al", ARMCC::AL)
5354 .Default(~0U);
5355 if (CC != ~0U) {
5356 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
5357 PredicationCode = CC;
5358 }
Bill Wendling193961b2010-10-29 23:50:21 +00005359 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005360
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005361 // Next, determine if we have a carry setting bit. We explicitly ignore all
5362 // the instructions we know end in 's'.
5363 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00005364 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005365 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
5366 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
5367 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00005368 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00005369 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00005370 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00005371 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
David Peixottoa872e0e2014-01-07 18:19:23 +00005372 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00005373 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005374 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
5375 CarrySetting = true;
5376 }
5377
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005378 // The "cps" instruction can have a interrupt mode operand which is glued into
5379 // the mnemonic. Check if this is the case, split it and parse the imod op
5380 if (Mnemonic.startswith("cps")) {
5381 // Split out any imod code.
5382 unsigned IMod =
5383 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
5384 .Case("ie", ARM_PROC::IE)
5385 .Case("id", ARM_PROC::ID)
5386 .Default(~0U);
5387 if (IMod != ~0U) {
5388 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5389 ProcessorIMod = IMod;
5390 }
5391 }
5392
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005393 // The "it" instruction has the condition mask on the end of the mnemonic.
5394 if (Mnemonic.startswith("it")) {
5395 ITMask = Mnemonic.slice(2, Mnemonic.size());
5396 Mnemonic = Mnemonic.slice(0, 2);
5397 }
5398
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005399 return Mnemonic;
5400}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005401
5402/// \brief Given a canonical mnemonic, determine if the instruction ever allows
5403/// inclusion of carry set or predication code operands.
5404//
5405// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00005406void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00005407getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5408 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005409 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5410 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005411 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005412 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005413 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005414 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005415 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00005416 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005417 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005418 Mnemonic == "mla" || Mnemonic == "smlal" ||
5419 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005420 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00005421 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00005422 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005423
Tim Northover2c45a382013-06-26 16:52:40 +00005424 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5425 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00005426 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
5427 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
5428 Mnemonic.startswith("vsel") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00005429 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005430 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
5431 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Charlie Turner4d88ae22014-12-01 08:33:28 +00005432 Mnemonic == "vrintm" || Mnemonic.startswith("aes") || Mnemonic == "hvc" ||
Amara Emerson33089092013-09-19 11:59:01 +00005433 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5434 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00005435 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005436 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005437 } else if (!isThumb()) {
5438 // Some instructions are only predicable in Thumb mode
5439 CanAcceptPredicationCode
5440 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5441 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5442 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5443 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5444 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5445 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5446 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5447 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00005448 if (hasV6MOps())
5449 CanAcceptPredicationCode = Mnemonic != "movs";
5450 else
5451 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005452 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005453 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005454}
5455
Jim Grosbach7283da92011-08-16 21:12:37 +00005456bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
David Blaikie960ea3f2014-06-08 16:18:35 +00005457 OperandVector &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005458 // FIXME: This is all horribly hacky. We really need a better way to deal
5459 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005460
5461 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5462 // another does not. Specifically, the MOVW instruction does not. So we
5463 // special case it here and remove the defaulted (non-setting) cc_out
5464 // operand if that's the instruction we're trying to match.
5465 //
5466 // We do this as post-processing of the explicit operands rather than just
5467 // conditionally adding the cc_out in the first place because we need
5468 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005469 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005470 !static_cast<ARMOperand &>(*Operands[4]).isARMSOImm() &&
5471 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
5472 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach7283da92011-08-16 21:12:37 +00005473 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005474
5475 // Register-register 'add' for thumb does not have a cc_out operand
5476 // when there are only two register operands.
5477 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005478 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5479 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5480 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005481 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005482 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005483 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5484 // have to check the immediate range here since Thumb2 has a variant
5485 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005486 if (((isThumb() && Mnemonic == "add") ||
5487 (isThumbTwo() && Mnemonic == "sub")) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005488 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5489 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5490 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
5491 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5492 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
5493 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005494 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005495 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5496 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005497 // selecting via the generic "add" mnemonic, so to know that we
5498 // should remove the cc_out operand, we have to explicitly check that
5499 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005500 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005501 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5502 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5503 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005504 // Nest conditions rather than one big 'if' statement for readability.
5505 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005506 // If both registers are low, we're in an IT block, and the immediate is
5507 // in range, we should use encoding T1 instead, which has a cc_out.
5508 if (inITBlock() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005509 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
5510 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
5511 static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005512 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005513 // Check against T3. If the second register is the PC, this is an
5514 // alternate form of ADR, which uses encoding T4, so check for that too.
David Blaikie960ea3f2014-06-08 16:18:35 +00005515 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
5516 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm())
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005517 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005518
5519 // Otherwise, we use encoding T4, which does not have a cc_out
5520 // operand.
5521 return true;
5522 }
5523
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005524 // The thumb2 multiply instruction doesn't have a CCOut register, so
5525 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5526 // use the 16-bit encoding or not.
5527 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005528 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5529 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5530 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5531 static_cast<ARMOperand &>(*Operands[5]).isReg() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005532 // If the registers aren't low regs, the destination reg isn't the
5533 // same as one of the source regs, or the cc_out operand is zero
5534 // outside of an IT block, we have to use the 32-bit encoding, so
5535 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005536 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5537 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5538 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
5539 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5540 static_cast<ARMOperand &>(*Operands[5]).getReg() &&
5541 static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5542 static_cast<ARMOperand &>(*Operands[4]).getReg())))
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005543 return true;
5544
Jim Grosbachefa7e952011-11-15 19:55:16 +00005545 // Also check the 'mul' syntax variant that doesn't specify an explicit
5546 // destination register.
5547 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005548 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5549 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5550 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
Jim Grosbachefa7e952011-11-15 19:55:16 +00005551 // If the registers aren't low regs or the cc_out operand is zero
5552 // outside of an IT block, we have to use the 32-bit encoding, so
5553 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005554 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5555 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
Jim Grosbachefa7e952011-11-15 19:55:16 +00005556 !inITBlock()))
5557 return true;
5558
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005559
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005560
Jim Grosbach4b701af2011-08-24 21:42:27 +00005561 // Register-register 'add/sub' for thumb does not have a cc_out operand
5562 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5563 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5564 // right, this will result in better diagnostics (which operand is off)
5565 // anyway.
5566 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5567 (Operands.size() == 5 || Operands.size() == 6) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005568 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5569 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
5570 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5571 (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005572 (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005573 static_cast<ARMOperand &>(*Operands[5]).isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005574 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005575
Jim Grosbach7283da92011-08-16 21:12:37 +00005576 return false;
5577}
5578
David Blaikie960ea3f2014-06-08 16:18:35 +00005579bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
5580 OperandVector &Operands) {
Joey Goulye8602552013-07-19 16:34:16 +00005581 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5582 unsigned RegIdx = 3;
5583 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005584 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") {
5585 if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5586 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32")
Joey Goulye8602552013-07-19 16:34:16 +00005587 RegIdx = 4;
5588
David Blaikie960ea3f2014-06-08 16:18:35 +00005589 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
5590 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
5591 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
5592 ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
5593 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
Joey Goulye8602552013-07-19 16:34:16 +00005594 return true;
5595 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005596 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005597}
5598
Jim Grosbach12952fe2011-11-11 23:08:10 +00005599static bool isDataTypeToken(StringRef Tok) {
5600 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5601 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5602 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5603 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5604 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5605 Tok == ".f" || Tok == ".d";
5606}
5607
5608// FIXME: This bit should probably be handled via an explicit match class
5609// in the .td files that matches the suffix instead of having it be
5610// a literal string token the way it is now.
5611static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5612 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5613}
Tim Northover26bb14e2014-08-18 11:49:42 +00005614static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features,
Chad Rosier9f7a2212013-04-18 22:35:36 +00005615 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005616
5617static bool RequiresVFPRegListValidation(StringRef Inst,
5618 bool &AcceptSinglePrecisionOnly,
5619 bool &AcceptDoublePrecisionOnly) {
5620 if (Inst.size() < 7)
5621 return false;
5622
5623 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5624 StringRef AddressingMode = Inst.substr(4, 2);
5625 if (AddressingMode == "ia" || AddressingMode == "db" ||
5626 AddressingMode == "ea" || AddressingMode == "fd") {
5627 AcceptSinglePrecisionOnly = Inst[6] == 's';
5628 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5629 return true;
5630 }
5631 }
5632
5633 return false;
5634}
5635
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005636/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005637bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
David Blaikie960ea3f2014-06-08 16:18:35 +00005638 SMLoc NameLoc, OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005639 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005640 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005641 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005642 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005643 bool AcceptDoublePrecisionOnly;
5644 RequireVFPRegisterListCheck =
5645 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5646 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005647
Jim Grosbach8be2f652011-12-09 23:34:09 +00005648 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005649 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005650 // The generic tblgen'erated code does this later, at the start of
5651 // MatchInstructionImpl(), but that's too late for aliases that include
5652 // any sort of suffix.
Tim Northover26bb14e2014-08-18 11:49:42 +00005653 uint64_t AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005654 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5655 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005656
Jim Grosbachab5830e2011-12-14 02:16:11 +00005657 // First check for the ARM-specific .req directive.
5658 if (Parser.getTok().is(AsmToken::Identifier) &&
5659 Parser.getTok().getIdentifier() == ".req") {
5660 parseDirectiveReq(Name, NameLoc);
5661 // We always return 'error' for this, as we're done with this
5662 // statement and don't need to match the 'instruction."
5663 return true;
5664 }
5665
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005666 // Create the leading tokens for the mnemonic, split by '.' characters.
5667 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005668 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005669
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005670 // Split out the predication code and carry setting flag from the mnemonic.
5671 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005672 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005673 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005674 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005675 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005676 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005677
Jim Grosbach1c171b12011-08-25 17:23:55 +00005678 // In Thumb1, only the branch (B) instruction can be predicated.
5679 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005680 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005681 return Error(NameLoc, "conditional execution not supported in Thumb1");
5682 }
5683
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005684 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5685
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005686 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5687 // is the mask as it will be for the IT encoding if the conditional
5688 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5689 // where the conditional bit0 is zero, the instruction post-processing
5690 // will adjust the mask accordingly.
5691 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005692 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5693 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005694 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005695 return Error(Loc, "too many conditions on IT instruction");
5696 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005697 unsigned Mask = 8;
5698 for (unsigned i = ITMask.size(); i != 0; --i) {
5699 char pos = ITMask[i - 1];
5700 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005701 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005702 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005703 }
5704 Mask >>= 1;
5705 if (ITMask[i - 1] == 't')
5706 Mask |= 8;
5707 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005708 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005709 }
5710
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005711 // FIXME: This is all a pretty gross hack. We should automatically handle
5712 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005713
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005714 // Next, add the CCOut and ConditionCode operands, if needed.
5715 //
5716 // For mnemonics which can ever incorporate a carry setting bit or predication
5717 // code, our matching model involves us always generating CCOut and
5718 // ConditionCode operands to match the mnemonic "as written" and then we let
5719 // the matcher deal with finding the right instruction or generating an
5720 // appropriate error.
5721 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005722 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005723
Jim Grosbach03a8a162011-07-14 22:04:21 +00005724 // If we had a carry-set on an instruction that can't do that, issue an
5725 // error.
5726 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005727 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005728 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005729 "' can not set flags, but 's' suffix specified");
5730 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005731 // If we had a predication code on an instruction that can't do that, issue an
5732 // error.
5733 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005734 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005735 return Error(NameLoc, "instruction '" + Mnemonic +
5736 "' is not predicable, but condition code specified");
5737 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005738
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005739 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005740 if (CanAcceptCarrySet) {
5741 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005742 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005743 Loc));
5744 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005745
5746 // Add the predication code operand, if necessary.
5747 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005748 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5749 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005750 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005751 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005752 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005753
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005754 // Add the processor imod operand, if necessary.
5755 if (ProcessorIMod) {
5756 Operands.push_back(ARMOperand::CreateImm(
5757 MCConstantExpr::Create(ProcessorIMod, getContext()),
5758 NameLoc, NameLoc));
Oliver Stannard1ae8b472014-09-24 14:20:01 +00005759 } else if (Mnemonic == "cps" && isMClass()) {
5760 return Error(NameLoc, "instruction 'cps' requires effect for M-class");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005761 }
5762
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005763 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005764 while (Next != StringRef::npos) {
5765 Start = Next;
5766 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005767 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005768
Jim Grosbach12952fe2011-11-11 23:08:10 +00005769 // Some NEON instructions have an optional datatype suffix that is
5770 // completely ignored. Check for that.
5771 if (isDataTypeToken(ExtraToken) &&
5772 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5773 continue;
5774
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005775 // For for ARM mode generate an error if the .n qualifier is used.
5776 if (ExtraToken == ".n" && !isThumb()) {
5777 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005778 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005779 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5780 "arm mode");
5781 }
5782
5783 // The .n qualifier is always discarded as that is what the tables
5784 // and matcher expect. In ARM mode the .w qualifier has no effect,
5785 // so discard it to avoid errors that can be caused by the matcher.
5786 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005787 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5788 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5789 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005790 }
5791
5792 // Read the remaining operands.
5793 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005794 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005795 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005796 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005797 return true;
5798 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005799
5800 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005801 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005802
5803 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005804 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005805 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005806 return true;
5807 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005808 }
5809 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005810
Chris Lattnera2a9d162010-09-11 16:18:25 +00005811 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005812 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005813 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005814 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005815 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005816
Chris Lattner91689c12010-09-08 05:10:46 +00005817 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005818
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005819 if (RequireVFPRegisterListCheck) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005820 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back());
5821 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList())
5822 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005823 "VFP/Neon single precision register expected");
David Blaikie960ea3f2014-06-08 16:18:35 +00005824 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList())
5825 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005826 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005827 }
5828
Jim Grosbach7283da92011-08-16 21:12:37 +00005829 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5830 // do and don't have a cc_out optional-def operand. With some spot-checks
5831 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005832 // parse and adjust accordingly before actually matching. We shouldn't ever
5833 // try to remove a cc_out operand that was explicitly set on the the
5834 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5835 // table driven matcher doesn't fit well with the ARM instruction set.
David Blaikie960ea3f2014-06-08 16:18:35 +00005836 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005837 Operands.erase(Operands.begin() + 1);
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005838
Joey Goulye8602552013-07-19 16:34:16 +00005839 // Some instructions have the same mnemonic, but don't always
5840 // have a predicate. Distinguish them here and delete the
5841 // predicate if needed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005842 if (shouldOmitPredicateOperand(Mnemonic, Operands))
Joey Goulye8602552013-07-19 16:34:16 +00005843 Operands.erase(Operands.begin() + 1);
Joey Goulye8602552013-07-19 16:34:16 +00005844
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005845 // ARM mode 'blx' need special handling, as the register operand version
5846 // is predicable, but the label operand version is not. So, we can't rely
5847 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005848 // a k_CondCode operand in the list. If we're trying to match the label
5849 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005850 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005851 static_cast<ARMOperand &>(*Operands[2]).isImm())
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005852 Operands.erase(Operands.begin() + 1);
Jim Grosbach8cffa282011-08-11 23:51:13 +00005853
Weiming Zhao8f56f882012-11-16 21:55:34 +00005854 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5855 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5856 // a single GPRPair reg operand is used in the .td file to replace the two
5857 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5858 // expressed as a GPRPair, so we have to manually merge them.
5859 // FIXME: We would really like to be able to tablegen'erate this.
5860 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005861 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5862 Mnemonic == "stlexd")) {
5863 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005864 unsigned Idx = isLoad ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005865 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
5866 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005867
5868 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5869 // Adjust only if Op1 and Op2 are GPRs.
David Blaikie960ea3f2014-06-08 16:18:35 +00005870 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
5871 MRC.contains(Op2.getReg())) {
5872 unsigned Reg1 = Op1.getReg();
5873 unsigned Reg2 = Op2.getReg();
Weiming Zhao8f56f882012-11-16 21:55:34 +00005874 unsigned Rt = MRI->getEncodingValue(Reg1);
5875 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5876
5877 // Rt2 must be Rt + 1 and Rt must be even.
5878 if (Rt + 1 != Rt2 || (Rt & 1)) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005879 Error(Op2.getStartLoc(), isLoad
5880 ? "destination operands must be sequential"
5881 : "source operands must be sequential");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005882 return true;
5883 }
5884 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5885 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
David Blaikie960ea3f2014-06-08 16:18:35 +00005886 Operands[Idx] =
5887 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
5888 Operands.erase(Operands.begin() + Idx + 1);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005889 }
5890 }
5891
Renato Golin36c626e2014-09-26 16:14:29 +00005892 // If first 2 operands of a 3 operand instruction are the same
5893 // then transform to 2 operand version of the same instruction
5894 // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1'
5895 // FIXME: We would really like to be able to tablegen'erate this.
5896 if (isThumbOne() && Operands.size() == 6 &&
5897 (Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" ||
5898 Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5899 Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" ||
5900 Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic")) {
5901 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5902 ARMOperand &Op4 = static_cast<ARMOperand &>(*Operands[4]);
5903 ARMOperand &Op5 = static_cast<ARMOperand &>(*Operands[5]);
5904
5905 // If both registers are the same then remove one of them from
5906 // the operand list.
5907 if (Op3.isReg() && Op4.isReg() && Op3.getReg() == Op4.getReg()) {
5908 // If 3rd operand (variable Op5) is a register and the instruction is adds/sub
5909 // then do not transform as the backend already handles this instruction
5910 // correctly.
5911 if (!Op5.isReg() || !((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub")) {
5912 Operands.erase(Operands.begin() + 3);
5913 if (Mnemonic == "add" && !CarrySetting) {
5914 // Special case for 'add' (not 'adds') instruction must
5915 // remove the CCOut operand as well.
5916 Operands.erase(Operands.begin() + 1);
5917 }
5918 }
5919 }
5920 }
5921
5922 // If instruction is 'add' and first two register operands
5923 // use SP register, then remove one of the SP registers from
5924 // the instruction.
5925 // FIXME: We would really like to be able to tablegen'erate this.
5926 if (isThumbOne() && Operands.size() == 5 && Mnemonic == "add" && !CarrySetting) {
5927 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5928 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5929 if (Op2.isReg() && Op3.isReg() && Op2.getReg() == ARM::SP && Op3.getReg() == ARM::SP) {
5930 Operands.erase(Operands.begin() + 2);
5931 }
5932 }
5933
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005934 // GNU Assembler extension (compatibility)
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005935 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005936 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5937 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5938 if (Op3.isMem()) {
5939 assert(Op2.isReg() && "expected register argument");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005940
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005941 unsigned SuperReg = MRI->getMatchingSuperReg(
David Blaikie960ea3f2014-06-08 16:18:35 +00005942 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005943
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005944 assert(SuperReg && "expected register pair");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005945
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005946 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005947
David Blaikie960ea3f2014-06-08 16:18:35 +00005948 Operands.insert(
5949 Operands.begin() + 3,
5950 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005951 }
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005952 }
5953
Kevin Enderby78f95722013-07-31 21:05:30 +00005954 // FIXME: As said above, this is all a pretty gross hack. This instruction
5955 // does not fit with other "subs" and tblgen.
5956 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5957 // so the Mnemonic is the original name "subs" and delete the predicate
5958 // operand so it will match the table entry.
5959 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005960 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5961 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
5962 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5963 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
5964 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5965 Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
Kevin Enderby78f95722013-07-31 21:05:30 +00005966 Operands.erase(Operands.begin() + 1);
Kevin Enderby78f95722013-07-31 21:05:30 +00005967 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005968 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005969}
5970
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005971// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005972
5973// return 'true' if register list contains non-low GPR registers,
5974// 'false' otherwise. If Reg is in the register list or is HiReg, set
5975// 'containsReg' to true.
5976static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5977 unsigned HiReg, bool &containsReg) {
5978 containsReg = false;
5979 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5980 unsigned OpReg = Inst.getOperand(i).getReg();
5981 if (OpReg == Reg)
5982 containsReg = true;
5983 // Anything other than a low register isn't legal here.
5984 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5985 return true;
5986 }
5987 return false;
5988}
5989
Rafael Espindola5403da42014-12-04 14:10:20 +00005990// Check if the specified regisgter is in the register list of the inst,
Jim Grosbacha31f2232011-09-07 18:05:34 +00005991// starting at the indicated operand number.
Rafael Espindola5403da42014-12-04 14:10:20 +00005992static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005993 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5994 unsigned OpReg = Inst.getOperand(i).getReg();
Rafael Espindola5403da42014-12-04 14:10:20 +00005995 if (OpReg == Reg)
5996 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005997 }
5998 return false;
5999}
6000
Richard Barton8d519fe2013-09-05 14:14:19 +00006001// Return true if instruction has the interesting property of being
6002// allowed in IT blocks, but not being predicable.
6003static bool instIsBreakpoint(const MCInst &Inst) {
6004 return Inst.getOpcode() == ARM::tBKPT ||
6005 Inst.getOpcode() == ARM::BKPT ||
6006 Inst.getOpcode() == ARM::tHLT ||
6007 Inst.getOpcode() == ARM::HLT;
6008
6009}
6010
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006011// FIXME: We would really like to be able to tablegen'erate this.
David Blaikie960ea3f2014-06-08 16:18:35 +00006012bool ARMAsmParser::validateInstruction(MCInst &Inst,
6013 const OperandVector &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00006014 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00006015 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00006016
Jim Grosbached16ec42011-08-29 22:24:09 +00006017 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00006018 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00006019 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00006020 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006021 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006022 if (ITState.FirstCond)
6023 ITState.FirstCond = false;
6024 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00006025 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006026 // The instruction must be predicable.
6027 if (!MCID.isPredicable())
6028 return Error(Loc, "instructions in IT block must be predicable");
6029 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00006030 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00006031 ARMCC::getOppositeCondition(ITState.Cond);
6032 if (Cond != ITCond) {
6033 // Find the condition code Operand to get its SMLoc information.
6034 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00006035 for (unsigned I = 1; I < Operands.size(); ++I)
David Blaikie960ea3f2014-06-08 16:18:35 +00006036 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006037 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00006038 return Error(CondLoc, "incorrect condition in IT block; got '" +
6039 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
6040 "', but expected '" +
6041 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
6042 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00006043 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00006044 } else if (isThumbTwo() && MCID.isPredicable() &&
6045 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00006046 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
6047 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00006048 return Error(Loc, "predicated instructions must be in IT block");
6049
Tilmann Scheller255722b2013-09-30 16:11:48 +00006050 const unsigned Opcode = Inst.getOpcode();
6051 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00006052 case ARM::LDRD:
6053 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006054 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00006055 const unsigned RtReg = Inst.getOperand(0).getReg();
6056
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006057 // Rt can't be R14.
6058 if (RtReg == ARM::LR)
6059 return Error(Operands[3]->getStartLoc(),
6060 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006061
6062 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006063 // Rt must be even-numbered.
6064 if ((Rt & 1) == 1)
6065 return Error(Operands[3]->getStartLoc(),
6066 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006067
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006068 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00006069 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006070 if (Rt2 != Rt + 1)
6071 return Error(Operands[3]->getStartLoc(),
6072 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006073
6074 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
6075 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
6076 // For addressing modes with writeback, the base register needs to be
6077 // different from the destination registers.
6078 if (Rn == Rt || Rn == Rt2)
6079 return Error(Operands[3]->getStartLoc(),
6080 "base register needs to be different from destination "
6081 "registers");
6082 }
6083
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006084 return false;
6085 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006086 case ARM::t2LDRDi8:
6087 case ARM::t2LDRD_PRE:
6088 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00006089 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006090 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6091 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6092 if (Rt2 == Rt)
6093 return Error(Operands[3]->getStartLoc(),
6094 "destination operands can't be identical");
6095 return false;
6096 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00006097 case ARM::STRD: {
6098 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006099 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6100 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00006101 if (Rt2 != Rt + 1)
6102 return Error(Operands[3]->getStartLoc(),
6103 "source operands must be sequential");
6104 return false;
6105 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00006106 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006107 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006108 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006109 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6110 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006111 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00006112 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006113 "source operands must be sequential");
6114 return false;
6115 }
Tilmann Scheller3352a582014-07-23 12:38:17 +00006116 case ARM::STR_PRE_IMM:
6117 case ARM::STR_PRE_REG:
6118 case ARM::STR_POST_IMM:
Tilmann Scheller27272792014-07-23 13:03:47 +00006119 case ARM::STR_POST_REG:
Tilmann Scheller96ef72e2014-07-24 09:55:46 +00006120 case ARM::STRH_PRE:
6121 case ARM::STRH_POST:
Tilmann Scheller27272792014-07-23 13:03:47 +00006122 case ARM::STRB_PRE_IMM:
6123 case ARM::STRB_PRE_REG:
6124 case ARM::STRB_POST_IMM:
6125 case ARM::STRB_POST_REG: {
Tilmann Scheller3352a582014-07-23 12:38:17 +00006126 // Rt must be different from Rn.
6127 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6128 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6129
6130 if (Rt == Rn)
6131 return Error(Operands[3]->getStartLoc(),
6132 "source register and base register can't be identical");
6133 return false;
6134 }
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006135 case ARM::LDR_PRE_IMM:
6136 case ARM::LDR_PRE_REG:
6137 case ARM::LDR_POST_IMM:
Tilmann Scheller8ff079c2014-08-01 11:33:47 +00006138 case ARM::LDR_POST_REG:
6139 case ARM::LDRH_PRE:
6140 case ARM::LDRH_POST:
6141 case ARM::LDRSH_PRE:
Tilmann Scheller7cc0ed42014-08-01 12:08:04 +00006142 case ARM::LDRSH_POST:
6143 case ARM::LDRB_PRE_IMM:
6144 case ARM::LDRB_PRE_REG:
6145 case ARM::LDRB_POST_IMM:
6146 case ARM::LDRB_POST_REG:
6147 case ARM::LDRSB_PRE:
6148 case ARM::LDRSB_POST: {
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006149 // Rt must be different from Rn.
6150 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6151 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6152
6153 if (Rt == Rn)
6154 return Error(Operands[3]->getStartLoc(),
6155 "destination register and base register can't be identical");
6156 return false;
6157 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00006158 case ARM::SBFX:
6159 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006160 // Width must be in range [1, 32-lsb].
6161 unsigned LSB = Inst.getOperand(2).getImm();
6162 unsigned Widthm1 = Inst.getOperand(3).getImm();
6163 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00006164 return Error(Operands[5]->getStartLoc(),
6165 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00006166 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00006167 }
Rafael Espindola5403da42014-12-04 14:10:20 +00006168 // Notionally handles ARM::tLDMIA_UPD too.
6169 case ARM::tLDMIA: {
6170 // If we're parsing Thumb2, the .w variant is available and handles
6171 // most cases that are normally illegal for a Thumb1 LDM instruction.
6172 // We'll make the transformation in processInstruction() if necessary.
6173 //
6174 // Thumb LDM instructions are writeback iff the base register is not
6175 // in the register list.
6176 unsigned Rn = Inst.getOperand(0).getReg();
6177 bool HasWritebackToken =
6178 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
6179 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
6180 bool ListContainsBase;
6181 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
6182 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
6183 "registers must be in range r0-r7");
6184 // If we should have writeback, then there should be a '!' token.
6185 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
6186 return Error(Operands[2]->getStartLoc(),
6187 "writeback operator '!' expected");
6188 // If we should not have writeback, there must not be a '!'. This is
6189 // true even for the 32-bit wide encodings.
6190 if (ListContainsBase && HasWritebackToken)
6191 return Error(Operands[3]->getStartLoc(),
6192 "writeback operator '!' not allowed when base register "
6193 "in register list");
6194 if (listContainsReg(Inst, 3 + HasWritebackToken, ARM::SP))
6195 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
6196 "SP not allowed in register list");
6197 break;
6198 }
Tim Northover08a86602013-10-22 19:00:39 +00006199 case ARM::LDMIA_UPD:
6200 case ARM::LDMDB_UPD:
6201 case ARM::LDMIB_UPD:
6202 case ARM::LDMDA_UPD:
6203 // ARM variants loading and updating the same register are only officially
6204 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
6205 if (!hasV7Ops())
6206 break;
Rafael Espindola5403da42014-12-04 14:10:20 +00006207 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6208 return Error(Operands.back()->getStartLoc(),
6209 "writeback register not allowed in register list");
6210 break;
Jyoti Allur3b686072014-10-22 10:41:14 +00006211 case ARM::t2LDMIA:
6212 case ARM::t2LDMDB:
6213 case ARM::t2STMIA:
Rafael Espindola5403da42014-12-04 14:10:20 +00006214 case ARM::t2STMDB: {
6215 if (listContainsReg(Inst, 3, ARM::SP))
6216 return Error(Operands.back()->getStartLoc(),
6217 "SP not allowed in register list");
6218 break;
6219 }
Tim Northover08a86602013-10-22 19:00:39 +00006220 case ARM::t2LDMIA_UPD:
6221 case ARM::t2LDMDB_UPD:
6222 case ARM::t2STMIA_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006223 case ARM::t2STMDB_UPD: {
6224 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6225 return Error(Operands.back()->getStartLoc(),
6226 "writeback register not allowed in register list");
6227
6228 if (listContainsReg(Inst, 4, ARM::SP))
6229 return Error(Operands.back()->getStartLoc(),
6230 "SP not allowed in register list");
6231 break;
6232 }
Tim Northover8eaf1542013-11-12 21:32:41 +00006233 case ARM::sysLDMIA_UPD:
6234 case ARM::sysLDMDA_UPD:
6235 case ARM::sysLDMDB_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006236 case ARM::sysLDMIB_UPD:
6237 if (!listContainsReg(Inst, 3, ARM::PC))
6238 return Error(Operands[4]->getStartLoc(),
6239 "writeback register only allowed on system LDM "
6240 "if PC in register-list");
Tim Northover8eaf1542013-11-12 21:32:41 +00006241 break;
6242 case ARM::sysSTMIA_UPD:
6243 case ARM::sysSTMDA_UPD:
6244 case ARM::sysSTMDB_UPD:
6245 case ARM::sysSTMIB_UPD:
6246 return Error(Operands[2]->getStartLoc(),
6247 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006248 case ARM::tMUL: {
6249 // The second source operand must be the same register as the destination
6250 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00006251 //
6252 // In this case, we must directly check the parsed operands because the
6253 // cvtThumbMultiply() function is written in such a way that it guarantees
6254 // this first statement is always true for the new Inst. Essentially, the
6255 // destination is unconditionally copied into the second source operand
6256 // without checking to see if it matches what we actually parsed.
David Blaikie960ea3f2014-06-08 16:18:35 +00006257 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
6258 ((ARMOperand &)*Operands[5]).getReg()) &&
6259 (((ARMOperand &)*Operands[3]).getReg() !=
6260 ((ARMOperand &)*Operands[4]).getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00006261 return Error(Operands[3]->getStartLoc(),
6262 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006263 }
6264 break;
6265 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00006266 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
6267 // so only issue a diagnostic for thumb1. The instructions will be
6268 // switched to the t2 encodings in processInstruction() if necessary.
Rafael Espindola5403da42014-12-04 14:10:20 +00006269 case ARM::tPOP: {
6270 bool ListContainsBase;
6271 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
6272 !isThumbTwo())
6273 return Error(Operands[2]->getStartLoc(),
6274 "registers must be in range r0-r7 or pc");
6275 break;
6276 }
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006277 case ARM::tPUSH: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006278 bool ListContainsBase;
6279 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
6280 !isThumbTwo())
6281 return Error(Operands[2]->getStartLoc(),
6282 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006283 break;
6284 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00006285 case ARM::tSTMIA_UPD: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006286 bool ListContainsBase, InvalidLowList;
6287 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
6288 0, ListContainsBase);
6289 if (InvalidLowList && !isThumbTwo())
6290 return Error(Operands[4]->getStartLoc(),
6291 "registers must be in range r0-r7");
6292
6293 // This would be converted to a 32-bit stm, but that's not valid if the
6294 // writeback register is in the list.
6295 if (InvalidLowList && ListContainsBase)
6296 return Error(Operands[4]->getStartLoc(),
6297 "writeback operator '!' not allowed when base register "
6298 "in register list");
6299 if (listContainsReg(Inst, 4, ARM::SP) && !inITBlock())
6300 return Error(Operands.back()->getStartLoc(),
6301 "SP not allowed in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00006302 break;
6303 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00006304 case ARM::tADDrSP: {
6305 // If the non-SP source operand and the destination operand are not the
6306 // same, we need thumb2 (for the wide encoding), or we have an error.
6307 if (!isThumbTwo() &&
6308 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
6309 return Error(Operands[4]->getStartLoc(),
6310 "source register must be the same as destination");
6311 }
6312 break;
6313 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006314 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006315 case ARM::tB:
David Blaikie960ea3f2014-06-08 16:18:35 +00006316 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006317 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006318 break;
6319 case ARM::t2B: {
6320 int op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006321 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006322 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006323 break;
6324 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006325 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006326 case ARM::tBcc:
David Blaikie960ea3f2014-06-08 16:18:35 +00006327 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006328 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006329 break;
6330 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006331 int Op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006332 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006333 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006334 break;
6335 }
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006336 case ARM::MOVi16:
6337 case ARM::t2MOVi16:
6338 case ARM::t2MOVTi16:
6339 {
6340 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
6341 // especially when we turn it into a movw and the expression <symbol> does
6342 // not have a :lower16: or :upper16 as part of the expression. We don't
6343 // want the behavior of silently truncating, which can be unexpected and
6344 // lead to bugs that are difficult to find since this is an easy mistake
6345 // to make.
6346 int i = (Operands[3]->isImm()) ? 3 : 4;
David Blaikie960ea3f2014-06-08 16:18:35 +00006347 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
6348 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006349 if (CE) break;
David Blaikie960ea3f2014-06-08 16:18:35 +00006350 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006351 if (!E) break;
6352 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
6353 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006354 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
6355 return Error(
6356 Op.getStartLoc(),
6357 "immediate expression for mov requires :lower16: or :upper16");
6358 break;
6359 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006360 }
6361
6362 return false;
6363}
6364
Jim Grosbach1a747242012-01-23 23:45:44 +00006365static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00006366 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006367 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006368 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006369 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6370 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6371 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6372 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6373 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6374 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6375 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
6376 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
6377 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006378
6379 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006380 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6381 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6382 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6383 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6384 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006385
Jim Grosbach1e946a42012-01-24 00:43:12 +00006386 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6387 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6388 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6389 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6390 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006391
Jim Grosbach1e946a42012-01-24 00:43:12 +00006392 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
6393 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
6394 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
6395 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
6396 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00006397
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006398 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006399 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6400 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6401 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6402 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
6403 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6404 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6405 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6406 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6407 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
6408 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6409 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
6410 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
6411 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
6412 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
6413 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006414
Jim Grosbach1a747242012-01-23 23:45:44 +00006415 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006416 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6417 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6418 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6419 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6420 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6421 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6422 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6423 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6424 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6425 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6426 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6427 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6428 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
6429 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
6430 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
6431 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
6432 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
6433 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00006434
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006435 // VST4LN
6436 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6437 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6438 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6439 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
6440 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6441 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6442 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6443 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6444 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
6445 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6446 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
6447 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
6448 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
6449 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
6450 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
6451
Jim Grosbachda70eac2012-01-24 00:58:13 +00006452 // VST4
6453 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6454 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6455 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6456 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6457 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6458 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6459 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6460 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6461 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6462 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6463 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6464 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6465 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6466 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6467 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6468 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6469 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6470 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00006471 }
6472}
6473
Jim Grosbach1a747242012-01-23 23:45:44 +00006474static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00006475 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006476 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006477 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006478 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6479 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6480 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6481 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6482 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6483 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6484 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6485 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6486 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006487
6488 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006489 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6490 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6491 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6492 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6493 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6494 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6495 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6496 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6497 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6498 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6499 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6500 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6501 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6502 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6503 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006504
Jim Grosbachb78403c2012-01-24 23:47:04 +00006505 // VLD3DUP
6506 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6507 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6508 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6509 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
Kevin Enderbyd88fec32014-04-08 18:00:52 +00006510 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
Jim Grosbachb78403c2012-01-24 23:47:04 +00006511 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6512 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6513 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6514 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6515 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6516 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6517 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6518 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6519 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6520 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6521 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6522 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6523 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6524
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006525 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006526 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6527 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6528 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6529 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6530 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6531 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6532 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6533 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6534 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6535 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6536 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6537 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6538 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6539 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6540 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006541
6542 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006543 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6544 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6545 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6546 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6547 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6548 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6549 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6550 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6551 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6552 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6553 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6554 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6555 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6556 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6557 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6558 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6559 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6560 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00006561
Jim Grosbach14952a02012-01-24 18:37:25 +00006562 // VLD4LN
6563 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6564 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6565 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00006566 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00006567 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6568 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6569 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6570 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6571 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6572 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6573 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6574 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6575 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6576 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6577 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6578
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006579 // VLD4DUP
6580 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6581 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6582 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6583 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6584 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6585 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6586 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6587 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6588 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6589 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6590 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6591 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6592 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6593 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6594 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6595 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6596 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6597 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6598
Jim Grosbached561fc2012-01-24 00:43:17 +00006599 // VLD4
6600 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6601 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6602 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6603 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6604 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6605 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6606 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6607 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6608 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6609 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6610 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6611 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6612 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6613 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6614 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6615 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6616 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6617 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006618 }
6619}
6620
David Blaikie960ea3f2014-06-08 16:18:35 +00006621bool ARMAsmParser::processInstruction(MCInst &Inst,
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006622 const OperandVector &Operands,
6623 MCStreamer &Out) {
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006624 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006625 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6626 case ARM::LDRT_POST:
6627 case ARM::LDRBT_POST: {
6628 const unsigned Opcode =
6629 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6630 : ARM::LDRBT_POST_IMM;
6631 MCInst TmpInst;
6632 TmpInst.setOpcode(Opcode);
6633 TmpInst.addOperand(Inst.getOperand(0));
6634 TmpInst.addOperand(Inst.getOperand(1));
6635 TmpInst.addOperand(Inst.getOperand(1));
6636 TmpInst.addOperand(MCOperand::CreateReg(0));
6637 TmpInst.addOperand(MCOperand::CreateImm(0));
6638 TmpInst.addOperand(Inst.getOperand(2));
6639 TmpInst.addOperand(Inst.getOperand(3));
6640 Inst = TmpInst;
6641 return true;
6642 }
6643 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6644 case ARM::STRT_POST:
6645 case ARM::STRBT_POST: {
6646 const unsigned Opcode =
6647 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6648 : ARM::STRBT_POST_IMM;
6649 MCInst TmpInst;
6650 TmpInst.setOpcode(Opcode);
6651 TmpInst.addOperand(Inst.getOperand(1));
6652 TmpInst.addOperand(Inst.getOperand(0));
6653 TmpInst.addOperand(Inst.getOperand(1));
6654 TmpInst.addOperand(MCOperand::CreateReg(0));
6655 TmpInst.addOperand(MCOperand::CreateImm(0));
6656 TmpInst.addOperand(Inst.getOperand(2));
6657 TmpInst.addOperand(Inst.getOperand(3));
6658 Inst = TmpInst;
6659 return true;
6660 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006661 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6662 case ARM::ADDri: {
6663 if (Inst.getOperand(1).getReg() != ARM::PC ||
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006664 Inst.getOperand(5).getReg() != 0 ||
6665 !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm()))
Jim Grosbache974a6a2012-09-25 00:08:13 +00006666 return false;
6667 MCInst TmpInst;
6668 TmpInst.setOpcode(ARM::ADR);
6669 TmpInst.addOperand(Inst.getOperand(0));
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006670 if (Inst.getOperand(2).isImm()) {
6671 TmpInst.addOperand(Inst.getOperand(2));
6672 } else {
6673 // Turn PC-relative expression into absolute expression.
6674 // Reading PC provides the start of the current instruction + 8 and
6675 // the transform to adr is biased by that.
6676 MCSymbol *Dot = getContext().CreateTempSymbol();
6677 Out.EmitLabel(Dot);
6678 const MCExpr *OpExpr = Inst.getOperand(2).getExpr();
6679 const MCExpr *InstPC = MCSymbolRefExpr::Create(Dot,
6680 MCSymbolRefExpr::VK_None,
6681 getContext());
6682 const MCExpr *Const8 = MCConstantExpr::Create(8, getContext());
6683 const MCExpr *ReadPC = MCBinaryExpr::CreateAdd(InstPC, Const8,
6684 getContext());
6685 const MCExpr *FixupAddr = MCBinaryExpr::CreateAdd(ReadPC, OpExpr,
6686 getContext());
6687 TmpInst.addOperand(MCOperand::CreateExpr(FixupAddr));
6688 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006689 TmpInst.addOperand(Inst.getOperand(3));
6690 TmpInst.addOperand(Inst.getOperand(4));
6691 Inst = TmpInst;
6692 return true;
6693 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006694 // Aliases for alternate PC+imm syntax of LDR instructions.
6695 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006696 // Select the narrow version if the immediate will fit.
6697 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006698 Inst.getOperand(1).getImm() <= 0xff &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006699 !(static_cast<ARMOperand &>(*Operands[2]).isToken() &&
6700 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006701 Inst.setOpcode(ARM::tLDRpci);
6702 else
6703 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006704 return true;
6705 case ARM::t2LDRBpcrel:
6706 Inst.setOpcode(ARM::t2LDRBpci);
6707 return true;
6708 case ARM::t2LDRHpcrel:
6709 Inst.setOpcode(ARM::t2LDRHpci);
6710 return true;
6711 case ARM::t2LDRSBpcrel:
6712 Inst.setOpcode(ARM::t2LDRSBpci);
6713 return true;
6714 case ARM::t2LDRSHpcrel:
6715 Inst.setOpcode(ARM::t2LDRSHpci);
6716 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006717 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006718 case ARM::VST1LNdWB_register_Asm_8:
6719 case ARM::VST1LNdWB_register_Asm_16:
6720 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006721 MCInst TmpInst;
6722 // Shuffle the operands around so the lane index operand is in the
6723 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006724 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006725 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006726 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6727 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6728 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6729 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6730 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6731 TmpInst.addOperand(Inst.getOperand(1)); // lane
6732 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6733 TmpInst.addOperand(Inst.getOperand(6));
6734 Inst = TmpInst;
6735 return true;
6736 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006737
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006738 case ARM::VST2LNdWB_register_Asm_8:
6739 case ARM::VST2LNdWB_register_Asm_16:
6740 case ARM::VST2LNdWB_register_Asm_32:
6741 case ARM::VST2LNqWB_register_Asm_16:
6742 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006743 MCInst TmpInst;
6744 // Shuffle the operands around so the lane index operand is in the
6745 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006746 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006747 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006748 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6749 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6750 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6751 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6752 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006753 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6754 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006755 TmpInst.addOperand(Inst.getOperand(1)); // lane
6756 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6757 TmpInst.addOperand(Inst.getOperand(6));
6758 Inst = TmpInst;
6759 return true;
6760 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006761
6762 case ARM::VST3LNdWB_register_Asm_8:
6763 case ARM::VST3LNdWB_register_Asm_16:
6764 case ARM::VST3LNdWB_register_Asm_32:
6765 case ARM::VST3LNqWB_register_Asm_16:
6766 case ARM::VST3LNqWB_register_Asm_32: {
6767 MCInst TmpInst;
6768 // Shuffle the operands around so the lane index operand is in the
6769 // right place.
6770 unsigned Spacing;
6771 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
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)); // 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(Inst.getOperand(1)); // lane
6782 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6783 TmpInst.addOperand(Inst.getOperand(6));
6784 Inst = TmpInst;
6785 return true;
6786 }
6787
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006788 case ARM::VST4LNdWB_register_Asm_8:
6789 case ARM::VST4LNdWB_register_Asm_16:
6790 case ARM::VST4LNdWB_register_Asm_32:
6791 case ARM::VST4LNqWB_register_Asm_16:
6792 case ARM::VST4LNqWB_register_Asm_32: {
6793 MCInst TmpInst;
6794 // Shuffle the operands around so the lane index operand is in the
6795 // right place.
6796 unsigned Spacing;
6797 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6798 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6799 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6800 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6801 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6802 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6803 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6804 Spacing));
6805 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6806 Spacing * 2));
6807 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6808 Spacing * 3));
6809 TmpInst.addOperand(Inst.getOperand(1)); // lane
6810 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6811 TmpInst.addOperand(Inst.getOperand(6));
6812 Inst = TmpInst;
6813 return true;
6814 }
6815
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006816 case ARM::VST1LNdWB_fixed_Asm_8:
6817 case ARM::VST1LNdWB_fixed_Asm_16:
6818 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006819 MCInst TmpInst;
6820 // Shuffle the operands around so the lane index operand is in the
6821 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006822 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006823 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +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)); // Vd
6829 TmpInst.addOperand(Inst.getOperand(1)); // lane
6830 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6831 TmpInst.addOperand(Inst.getOperand(5));
6832 Inst = TmpInst;
6833 return true;
6834 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006835
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006836 case ARM::VST2LNdWB_fixed_Asm_8:
6837 case ARM::VST2LNdWB_fixed_Asm_16:
6838 case ARM::VST2LNdWB_fixed_Asm_32:
6839 case ARM::VST2LNqWB_fixed_Asm_16:
6840 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006841 MCInst TmpInst;
6842 // Shuffle the operands around so the lane index operand is in the
6843 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006844 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006845 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006846 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6847 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6848 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6849 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6850 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6852 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006853 TmpInst.addOperand(Inst.getOperand(1)); // lane
6854 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6855 TmpInst.addOperand(Inst.getOperand(5));
6856 Inst = TmpInst;
6857 return true;
6858 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006859
6860 case ARM::VST3LNdWB_fixed_Asm_8:
6861 case ARM::VST3LNdWB_fixed_Asm_16:
6862 case ARM::VST3LNdWB_fixed_Asm_32:
6863 case ARM::VST3LNqWB_fixed_Asm_16:
6864 case ARM::VST3LNqWB_fixed_Asm_32: {
6865 MCInst TmpInst;
6866 // Shuffle the operands around so the lane index operand is in the
6867 // right place.
6868 unsigned Spacing;
6869 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6870 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6871 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6872 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6873 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6874 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6875 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6876 Spacing));
6877 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6878 Spacing * 2));
6879 TmpInst.addOperand(Inst.getOperand(1)); // lane
6880 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6881 TmpInst.addOperand(Inst.getOperand(5));
6882 Inst = TmpInst;
6883 return true;
6884 }
6885
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006886 case ARM::VST4LNdWB_fixed_Asm_8:
6887 case ARM::VST4LNdWB_fixed_Asm_16:
6888 case ARM::VST4LNdWB_fixed_Asm_32:
6889 case ARM::VST4LNqWB_fixed_Asm_16:
6890 case ARM::VST4LNqWB_fixed_Asm_32: {
6891 MCInst TmpInst;
6892 // Shuffle the operands around so the lane index operand is in the
6893 // right place.
6894 unsigned Spacing;
6895 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6896 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6897 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6898 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6899 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6900 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6901 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6902 Spacing));
6903 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6904 Spacing * 2));
6905 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6906 Spacing * 3));
6907 TmpInst.addOperand(Inst.getOperand(1)); // lane
6908 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6909 TmpInst.addOperand(Inst.getOperand(5));
6910 Inst = TmpInst;
6911 return true;
6912 }
6913
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006914 case ARM::VST1LNdAsm_8:
6915 case ARM::VST1LNdAsm_16:
6916 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006917 MCInst TmpInst;
6918 // Shuffle the operands around so the lane index operand is in the
6919 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006920 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006921 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006922 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6923 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6924 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6925 TmpInst.addOperand(Inst.getOperand(1)); // lane
6926 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6927 TmpInst.addOperand(Inst.getOperand(5));
6928 Inst = TmpInst;
6929 return true;
6930 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006931
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006932 case ARM::VST2LNdAsm_8:
6933 case ARM::VST2LNdAsm_16:
6934 case ARM::VST2LNdAsm_32:
6935 case ARM::VST2LNqAsm_16:
6936 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006937 MCInst TmpInst;
6938 // Shuffle the operands around so the lane index operand is in the
6939 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006940 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006941 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006942 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6943 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6944 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006945 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6946 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006947 TmpInst.addOperand(Inst.getOperand(1)); // lane
6948 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6949 TmpInst.addOperand(Inst.getOperand(5));
6950 Inst = TmpInst;
6951 return true;
6952 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006953
6954 case ARM::VST3LNdAsm_8:
6955 case ARM::VST3LNdAsm_16:
6956 case ARM::VST3LNdAsm_32:
6957 case ARM::VST3LNqAsm_16:
6958 case ARM::VST3LNqAsm_32: {
6959 MCInst TmpInst;
6960 // Shuffle the operands around so the lane index operand is in the
6961 // right place.
6962 unsigned Spacing;
6963 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6964 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6965 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6966 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6967 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6968 Spacing));
6969 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6970 Spacing * 2));
6971 TmpInst.addOperand(Inst.getOperand(1)); // lane
6972 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6973 TmpInst.addOperand(Inst.getOperand(5));
6974 Inst = TmpInst;
6975 return true;
6976 }
6977
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006978 case ARM::VST4LNdAsm_8:
6979 case ARM::VST4LNdAsm_16:
6980 case ARM::VST4LNdAsm_32:
6981 case ARM::VST4LNqAsm_16:
6982 case ARM::VST4LNqAsm_32: {
6983 MCInst TmpInst;
6984 // Shuffle the operands around so the lane index operand is in the
6985 // right place.
6986 unsigned Spacing;
6987 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6988 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6989 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6990 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6991 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6992 Spacing));
6993 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6994 Spacing * 2));
6995 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6996 Spacing * 3));
6997 TmpInst.addOperand(Inst.getOperand(1)); // lane
6998 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6999 TmpInst.addOperand(Inst.getOperand(5));
7000 Inst = TmpInst;
7001 return true;
7002 }
7003
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007004 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007005 case ARM::VLD1LNdWB_register_Asm_8:
7006 case ARM::VLD1LNdWB_register_Asm_16:
7007 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007008 MCInst TmpInst;
7009 // Shuffle the operands around so the lane index operand is in the
7010 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007011 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007012 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007013 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7014 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7015 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7016 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7017 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7018 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7019 TmpInst.addOperand(Inst.getOperand(1)); // lane
7020 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7021 TmpInst.addOperand(Inst.getOperand(6));
7022 Inst = TmpInst;
7023 return true;
7024 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007025
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007026 case ARM::VLD2LNdWB_register_Asm_8:
7027 case ARM::VLD2LNdWB_register_Asm_16:
7028 case ARM::VLD2LNdWB_register_Asm_32:
7029 case ARM::VLD2LNqWB_register_Asm_16:
7030 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007031 MCInst TmpInst;
7032 // Shuffle the operands around so the lane index operand is in the
7033 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007034 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007035 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007036 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007037 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7038 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007039 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7040 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7041 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7042 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7043 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007044 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7045 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007046 TmpInst.addOperand(Inst.getOperand(1)); // lane
7047 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7048 TmpInst.addOperand(Inst.getOperand(6));
7049 Inst = TmpInst;
7050 return true;
7051 }
7052
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007053 case ARM::VLD3LNdWB_register_Asm_8:
7054 case ARM::VLD3LNdWB_register_Asm_16:
7055 case ARM::VLD3LNdWB_register_Asm_32:
7056 case ARM::VLD3LNqWB_register_Asm_16:
7057 case ARM::VLD3LNqWB_register_Asm_32: {
7058 MCInst TmpInst;
7059 // Shuffle the operands around so the lane index operand is in the
7060 // right place.
7061 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007062 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007063 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7064 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7065 Spacing));
7066 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007067 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007068 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7069 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7070 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7071 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7072 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7073 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7074 Spacing));
7075 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007076 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007077 TmpInst.addOperand(Inst.getOperand(1)); // lane
7078 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7079 TmpInst.addOperand(Inst.getOperand(6));
7080 Inst = TmpInst;
7081 return true;
7082 }
7083
Jim Grosbach14952a02012-01-24 18:37:25 +00007084 case ARM::VLD4LNdWB_register_Asm_8:
7085 case ARM::VLD4LNdWB_register_Asm_16:
7086 case ARM::VLD4LNdWB_register_Asm_32:
7087 case ARM::VLD4LNqWB_register_Asm_16:
7088 case ARM::VLD4LNqWB_register_Asm_32: {
7089 MCInst TmpInst;
7090 // Shuffle the operands around so the lane index operand is in the
7091 // right place.
7092 unsigned Spacing;
7093 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7094 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7095 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7096 Spacing));
7097 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7098 Spacing * 2));
7099 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7100 Spacing * 3));
7101 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7102 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7103 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7104 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7105 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7106 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7107 Spacing));
7108 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7109 Spacing * 2));
7110 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7111 Spacing * 3));
7112 TmpInst.addOperand(Inst.getOperand(1)); // lane
7113 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7114 TmpInst.addOperand(Inst.getOperand(6));
7115 Inst = TmpInst;
7116 return true;
7117 }
7118
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007119 case ARM::VLD1LNdWB_fixed_Asm_8:
7120 case ARM::VLD1LNdWB_fixed_Asm_16:
7121 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007122 MCInst TmpInst;
7123 // Shuffle the operands around so the lane index operand is in the
7124 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007125 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007126 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007127 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7128 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7129 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7130 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7131 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7132 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7133 TmpInst.addOperand(Inst.getOperand(1)); // lane
7134 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7135 TmpInst.addOperand(Inst.getOperand(5));
7136 Inst = TmpInst;
7137 return true;
7138 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007139
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007140 case ARM::VLD2LNdWB_fixed_Asm_8:
7141 case ARM::VLD2LNdWB_fixed_Asm_16:
7142 case ARM::VLD2LNdWB_fixed_Asm_32:
7143 case ARM::VLD2LNqWB_fixed_Asm_16:
7144 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007145 MCInst TmpInst;
7146 // Shuffle the operands around so the lane index operand is in the
7147 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007148 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007149 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007150 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007151 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7152 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007153 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7154 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7155 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7156 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7157 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007158 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7159 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007160 TmpInst.addOperand(Inst.getOperand(1)); // lane
7161 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7162 TmpInst.addOperand(Inst.getOperand(5));
7163 Inst = TmpInst;
7164 return true;
7165 }
7166
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007167 case ARM::VLD3LNdWB_fixed_Asm_8:
7168 case ARM::VLD3LNdWB_fixed_Asm_16:
7169 case ARM::VLD3LNdWB_fixed_Asm_32:
7170 case ARM::VLD3LNqWB_fixed_Asm_16:
7171 case ARM::VLD3LNqWB_fixed_Asm_32: {
7172 MCInst TmpInst;
7173 // Shuffle the operands around so the lane index operand is in the
7174 // right place.
7175 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007176 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007177 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7178 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7179 Spacing));
7180 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007181 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007182 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7183 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7184 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7185 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7186 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7187 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7188 Spacing));
7189 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007190 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007191 TmpInst.addOperand(Inst.getOperand(1)); // lane
7192 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7193 TmpInst.addOperand(Inst.getOperand(5));
7194 Inst = TmpInst;
7195 return true;
7196 }
7197
Jim Grosbach14952a02012-01-24 18:37:25 +00007198 case ARM::VLD4LNdWB_fixed_Asm_8:
7199 case ARM::VLD4LNdWB_fixed_Asm_16:
7200 case ARM::VLD4LNdWB_fixed_Asm_32:
7201 case ARM::VLD4LNqWB_fixed_Asm_16:
7202 case ARM::VLD4LNqWB_fixed_Asm_32: {
7203 MCInst TmpInst;
7204 // Shuffle the operands around so the lane index operand is in the
7205 // right place.
7206 unsigned Spacing;
7207 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7208 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7209 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7210 Spacing));
7211 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7212 Spacing * 2));
7213 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7214 Spacing * 3));
7215 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7216 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7217 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7218 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7219 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7220 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7221 Spacing));
7222 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7223 Spacing * 2));
7224 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7225 Spacing * 3));
7226 TmpInst.addOperand(Inst.getOperand(1)); // lane
7227 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7228 TmpInst.addOperand(Inst.getOperand(5));
7229 Inst = TmpInst;
7230 return true;
7231 }
7232
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007233 case ARM::VLD1LNdAsm_8:
7234 case ARM::VLD1LNdAsm_16:
7235 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00007236 MCInst TmpInst;
7237 // Shuffle the operands around so the lane index operand is in the
7238 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007239 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007240 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00007241 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7242 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7243 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7244 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7245 TmpInst.addOperand(Inst.getOperand(1)); // lane
7246 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7247 TmpInst.addOperand(Inst.getOperand(5));
7248 Inst = TmpInst;
7249 return true;
7250 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007251
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007252 case ARM::VLD2LNdAsm_8:
7253 case ARM::VLD2LNdAsm_16:
7254 case ARM::VLD2LNdAsm_32:
7255 case ARM::VLD2LNqAsm_16:
7256 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007257 MCInst TmpInst;
7258 // Shuffle the operands around so the lane index operand is in the
7259 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007260 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007261 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007262 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007263 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7264 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007265 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7266 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7267 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007268 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7269 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007270 TmpInst.addOperand(Inst.getOperand(1)); // lane
7271 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7272 TmpInst.addOperand(Inst.getOperand(5));
7273 Inst = TmpInst;
7274 return true;
7275 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007276
7277 case ARM::VLD3LNdAsm_8:
7278 case ARM::VLD3LNdAsm_16:
7279 case ARM::VLD3LNdAsm_32:
7280 case ARM::VLD3LNqAsm_16:
7281 case ARM::VLD3LNqAsm_32: {
7282 MCInst TmpInst;
7283 // Shuffle the operands around so the lane index operand is in the
7284 // right place.
7285 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007286 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007287 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7288 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7289 Spacing));
7290 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007291 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007292 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7293 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7294 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7295 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7296 Spacing));
7297 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007298 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007299 TmpInst.addOperand(Inst.getOperand(1)); // lane
7300 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7301 TmpInst.addOperand(Inst.getOperand(5));
7302 Inst = TmpInst;
7303 return true;
7304 }
7305
Jim Grosbach14952a02012-01-24 18:37:25 +00007306 case ARM::VLD4LNdAsm_8:
7307 case ARM::VLD4LNdAsm_16:
7308 case ARM::VLD4LNdAsm_32:
7309 case ARM::VLD4LNqAsm_16:
7310 case ARM::VLD4LNqAsm_32: {
7311 MCInst TmpInst;
7312 // Shuffle the operands around so the lane index operand is in the
7313 // right place.
7314 unsigned Spacing;
7315 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7316 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7317 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7318 Spacing));
7319 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7320 Spacing * 2));
7321 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7322 Spacing * 3));
7323 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7324 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7325 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7326 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7327 Spacing));
7328 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7329 Spacing * 2));
7330 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7331 Spacing * 3));
7332 TmpInst.addOperand(Inst.getOperand(1)); // lane
7333 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7334 TmpInst.addOperand(Inst.getOperand(5));
7335 Inst = TmpInst;
7336 return true;
7337 }
7338
Jim Grosbachb78403c2012-01-24 23:47:04 +00007339 // VLD3DUP single 3-element structure to all lanes instructions.
7340 case ARM::VLD3DUPdAsm_8:
7341 case ARM::VLD3DUPdAsm_16:
7342 case ARM::VLD3DUPdAsm_32:
7343 case ARM::VLD3DUPqAsm_8:
7344 case ARM::VLD3DUPqAsm_16:
7345 case ARM::VLD3DUPqAsm_32: {
7346 MCInst TmpInst;
7347 unsigned Spacing;
7348 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7349 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7350 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7351 Spacing));
7352 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7353 Spacing * 2));
7354 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7355 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7356 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7357 TmpInst.addOperand(Inst.getOperand(4));
7358 Inst = TmpInst;
7359 return true;
7360 }
7361
7362 case ARM::VLD3DUPdWB_fixed_Asm_8:
7363 case ARM::VLD3DUPdWB_fixed_Asm_16:
7364 case ARM::VLD3DUPdWB_fixed_Asm_32:
7365 case ARM::VLD3DUPqWB_fixed_Asm_8:
7366 case ARM::VLD3DUPqWB_fixed_Asm_16:
7367 case ARM::VLD3DUPqWB_fixed_Asm_32: {
7368 MCInst TmpInst;
7369 unsigned Spacing;
7370 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7371 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7372 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7373 Spacing));
7374 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7375 Spacing * 2));
7376 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7377 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7378 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7379 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7380 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7381 TmpInst.addOperand(Inst.getOperand(4));
7382 Inst = TmpInst;
7383 return true;
7384 }
7385
7386 case ARM::VLD3DUPdWB_register_Asm_8:
7387 case ARM::VLD3DUPdWB_register_Asm_16:
7388 case ARM::VLD3DUPdWB_register_Asm_32:
7389 case ARM::VLD3DUPqWB_register_Asm_8:
7390 case ARM::VLD3DUPqWB_register_Asm_16:
7391 case ARM::VLD3DUPqWB_register_Asm_32: {
7392 MCInst TmpInst;
7393 unsigned Spacing;
7394 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7395 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7396 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7397 Spacing));
7398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7399 Spacing * 2));
7400 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7401 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7402 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7403 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7404 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7405 TmpInst.addOperand(Inst.getOperand(5));
7406 Inst = TmpInst;
7407 return true;
7408 }
7409
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007410 // VLD3 multiple 3-element structure instructions.
7411 case ARM::VLD3dAsm_8:
7412 case ARM::VLD3dAsm_16:
7413 case ARM::VLD3dAsm_32:
7414 case ARM::VLD3qAsm_8:
7415 case ARM::VLD3qAsm_16:
7416 case ARM::VLD3qAsm_32: {
7417 MCInst TmpInst;
7418 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007419 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007420 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7421 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7422 Spacing));
7423 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7424 Spacing * 2));
7425 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7426 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7427 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7428 TmpInst.addOperand(Inst.getOperand(4));
7429 Inst = TmpInst;
7430 return true;
7431 }
7432
7433 case ARM::VLD3dWB_fixed_Asm_8:
7434 case ARM::VLD3dWB_fixed_Asm_16:
7435 case ARM::VLD3dWB_fixed_Asm_32:
7436 case ARM::VLD3qWB_fixed_Asm_8:
7437 case ARM::VLD3qWB_fixed_Asm_16:
7438 case ARM::VLD3qWB_fixed_Asm_32: {
7439 MCInst TmpInst;
7440 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007441 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007442 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7443 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7444 Spacing));
7445 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7446 Spacing * 2));
7447 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7448 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7449 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7450 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7451 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7452 TmpInst.addOperand(Inst.getOperand(4));
7453 Inst = TmpInst;
7454 return true;
7455 }
7456
7457 case ARM::VLD3dWB_register_Asm_8:
7458 case ARM::VLD3dWB_register_Asm_16:
7459 case ARM::VLD3dWB_register_Asm_32:
7460 case ARM::VLD3qWB_register_Asm_8:
7461 case ARM::VLD3qWB_register_Asm_16:
7462 case ARM::VLD3qWB_register_Asm_32: {
7463 MCInst TmpInst;
7464 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007465 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007466 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7467 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7468 Spacing));
7469 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7470 Spacing * 2));
7471 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7472 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7473 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7474 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7475 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7476 TmpInst.addOperand(Inst.getOperand(5));
7477 Inst = TmpInst;
7478 return true;
7479 }
7480
Jim Grosbach086cbfa2012-01-25 00:01:08 +00007481 // VLD4DUP single 3-element structure to all lanes instructions.
7482 case ARM::VLD4DUPdAsm_8:
7483 case ARM::VLD4DUPdAsm_16:
7484 case ARM::VLD4DUPdAsm_32:
7485 case ARM::VLD4DUPqAsm_8:
7486 case ARM::VLD4DUPqAsm_16:
7487 case ARM::VLD4DUPqAsm_32: {
7488 MCInst TmpInst;
7489 unsigned Spacing;
7490 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7491 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7492 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7493 Spacing));
7494 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7495 Spacing * 2));
7496 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7497 Spacing * 3));
7498 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7499 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7500 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7501 TmpInst.addOperand(Inst.getOperand(4));
7502 Inst = TmpInst;
7503 return true;
7504 }
7505
7506 case ARM::VLD4DUPdWB_fixed_Asm_8:
7507 case ARM::VLD4DUPdWB_fixed_Asm_16:
7508 case ARM::VLD4DUPdWB_fixed_Asm_32:
7509 case ARM::VLD4DUPqWB_fixed_Asm_8:
7510 case ARM::VLD4DUPqWB_fixed_Asm_16:
7511 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7512 MCInst TmpInst;
7513 unsigned Spacing;
7514 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7515 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7516 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7517 Spacing));
7518 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7519 Spacing * 2));
7520 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7521 Spacing * 3));
7522 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7523 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7524 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7525 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7526 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7527 TmpInst.addOperand(Inst.getOperand(4));
7528 Inst = TmpInst;
7529 return true;
7530 }
7531
7532 case ARM::VLD4DUPdWB_register_Asm_8:
7533 case ARM::VLD4DUPdWB_register_Asm_16:
7534 case ARM::VLD4DUPdWB_register_Asm_32:
7535 case ARM::VLD4DUPqWB_register_Asm_8:
7536 case ARM::VLD4DUPqWB_register_Asm_16:
7537 case ARM::VLD4DUPqWB_register_Asm_32: {
7538 MCInst TmpInst;
7539 unsigned Spacing;
7540 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7541 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7542 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7543 Spacing));
7544 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7545 Spacing * 2));
7546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7547 Spacing * 3));
7548 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7549 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7550 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7551 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7552 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7553 TmpInst.addOperand(Inst.getOperand(5));
7554 Inst = TmpInst;
7555 return true;
7556 }
7557
7558 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00007559 case ARM::VLD4dAsm_8:
7560 case ARM::VLD4dAsm_16:
7561 case ARM::VLD4dAsm_32:
7562 case ARM::VLD4qAsm_8:
7563 case ARM::VLD4qAsm_16:
7564 case ARM::VLD4qAsm_32: {
7565 MCInst TmpInst;
7566 unsigned Spacing;
7567 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7568 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7569 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7570 Spacing));
7571 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7572 Spacing * 2));
7573 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7574 Spacing * 3));
7575 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7576 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7577 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7578 TmpInst.addOperand(Inst.getOperand(4));
7579 Inst = TmpInst;
7580 return true;
7581 }
7582
7583 case ARM::VLD4dWB_fixed_Asm_8:
7584 case ARM::VLD4dWB_fixed_Asm_16:
7585 case ARM::VLD4dWB_fixed_Asm_32:
7586 case ARM::VLD4qWB_fixed_Asm_8:
7587 case ARM::VLD4qWB_fixed_Asm_16:
7588 case ARM::VLD4qWB_fixed_Asm_32: {
7589 MCInst TmpInst;
7590 unsigned Spacing;
7591 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7592 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7593 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7594 Spacing));
7595 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7596 Spacing * 2));
7597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7598 Spacing * 3));
7599 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7600 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7601 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7602 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7603 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7604 TmpInst.addOperand(Inst.getOperand(4));
7605 Inst = TmpInst;
7606 return true;
7607 }
7608
7609 case ARM::VLD4dWB_register_Asm_8:
7610 case ARM::VLD4dWB_register_Asm_16:
7611 case ARM::VLD4dWB_register_Asm_32:
7612 case ARM::VLD4qWB_register_Asm_8:
7613 case ARM::VLD4qWB_register_Asm_16:
7614 case ARM::VLD4qWB_register_Asm_32: {
7615 MCInst TmpInst;
7616 unsigned Spacing;
7617 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7618 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7620 Spacing));
7621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7622 Spacing * 2));
7623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7624 Spacing * 3));
7625 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7626 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7627 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7628 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7629 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7630 TmpInst.addOperand(Inst.getOperand(5));
7631 Inst = TmpInst;
7632 return true;
7633 }
7634
Jim Grosbach1a747242012-01-23 23:45:44 +00007635 // VST3 multiple 3-element structure instructions.
7636 case ARM::VST3dAsm_8:
7637 case ARM::VST3dAsm_16:
7638 case ARM::VST3dAsm_32:
7639 case ARM::VST3qAsm_8:
7640 case ARM::VST3qAsm_16:
7641 case ARM::VST3qAsm_32: {
7642 MCInst TmpInst;
7643 unsigned Spacing;
7644 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7645 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7646 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7647 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7648 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7649 Spacing));
7650 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7651 Spacing * 2));
7652 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7653 TmpInst.addOperand(Inst.getOperand(4));
7654 Inst = TmpInst;
7655 return true;
7656 }
7657
7658 case ARM::VST3dWB_fixed_Asm_8:
7659 case ARM::VST3dWB_fixed_Asm_16:
7660 case ARM::VST3dWB_fixed_Asm_32:
7661 case ARM::VST3qWB_fixed_Asm_8:
7662 case ARM::VST3qWB_fixed_Asm_16:
7663 case ARM::VST3qWB_fixed_Asm_32: {
7664 MCInst TmpInst;
7665 unsigned Spacing;
7666 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7667 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7668 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7669 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7670 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7671 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7672 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7673 Spacing));
7674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7675 Spacing * 2));
7676 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7677 TmpInst.addOperand(Inst.getOperand(4));
7678 Inst = TmpInst;
7679 return true;
7680 }
7681
7682 case ARM::VST3dWB_register_Asm_8:
7683 case ARM::VST3dWB_register_Asm_16:
7684 case ARM::VST3dWB_register_Asm_32:
7685 case ARM::VST3qWB_register_Asm_8:
7686 case ARM::VST3qWB_register_Asm_16:
7687 case ARM::VST3qWB_register_Asm_32: {
7688 MCInst TmpInst;
7689 unsigned Spacing;
7690 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7691 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7692 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7693 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7694 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7695 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7696 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7697 Spacing));
7698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7699 Spacing * 2));
7700 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7701 TmpInst.addOperand(Inst.getOperand(5));
7702 Inst = TmpInst;
7703 return true;
7704 }
7705
Jim Grosbachda70eac2012-01-24 00:58:13 +00007706 // VST4 multiple 3-element structure instructions.
7707 case ARM::VST4dAsm_8:
7708 case ARM::VST4dAsm_16:
7709 case ARM::VST4dAsm_32:
7710 case ARM::VST4qAsm_8:
7711 case ARM::VST4qAsm_16:
7712 case ARM::VST4qAsm_32: {
7713 MCInst TmpInst;
7714 unsigned Spacing;
7715 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7716 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7717 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7718 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7719 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7720 Spacing));
7721 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7722 Spacing * 2));
7723 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7724 Spacing * 3));
7725 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7726 TmpInst.addOperand(Inst.getOperand(4));
7727 Inst = TmpInst;
7728 return true;
7729 }
7730
7731 case ARM::VST4dWB_fixed_Asm_8:
7732 case ARM::VST4dWB_fixed_Asm_16:
7733 case ARM::VST4dWB_fixed_Asm_32:
7734 case ARM::VST4qWB_fixed_Asm_8:
7735 case ARM::VST4qWB_fixed_Asm_16:
7736 case ARM::VST4qWB_fixed_Asm_32: {
7737 MCInst TmpInst;
7738 unsigned Spacing;
7739 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7740 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7741 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7742 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7743 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7744 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7745 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7746 Spacing));
7747 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7748 Spacing * 2));
7749 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7750 Spacing * 3));
7751 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7752 TmpInst.addOperand(Inst.getOperand(4));
7753 Inst = TmpInst;
7754 return true;
7755 }
7756
7757 case ARM::VST4dWB_register_Asm_8:
7758 case ARM::VST4dWB_register_Asm_16:
7759 case ARM::VST4dWB_register_Asm_32:
7760 case ARM::VST4qWB_register_Asm_8:
7761 case ARM::VST4qWB_register_Asm_16:
7762 case ARM::VST4qWB_register_Asm_32: {
7763 MCInst TmpInst;
7764 unsigned Spacing;
7765 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7766 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7767 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7768 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7769 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7770 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7771 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7772 Spacing));
7773 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7774 Spacing * 2));
7775 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7776 Spacing * 3));
7777 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7778 TmpInst.addOperand(Inst.getOperand(5));
7779 Inst = TmpInst;
7780 return true;
7781 }
7782
Jim Grosbachad66de12012-04-11 00:15:16 +00007783 // Handle encoding choice for the shift-immediate instructions.
7784 case ARM::t2LSLri:
7785 case ARM::t2LSRri:
7786 case ARM::t2ASRri: {
7787 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7788 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7789 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007790 !(static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7791 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) {
Jim Grosbachad66de12012-04-11 00:15:16 +00007792 unsigned NewOpc;
7793 switch (Inst.getOpcode()) {
7794 default: llvm_unreachable("unexpected opcode");
7795 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7796 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7797 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7798 }
7799 // The Thumb1 operands aren't in the same order. Awesome, eh?
7800 MCInst TmpInst;
7801 TmpInst.setOpcode(NewOpc);
7802 TmpInst.addOperand(Inst.getOperand(0));
7803 TmpInst.addOperand(Inst.getOperand(5));
7804 TmpInst.addOperand(Inst.getOperand(1));
7805 TmpInst.addOperand(Inst.getOperand(2));
7806 TmpInst.addOperand(Inst.getOperand(3));
7807 TmpInst.addOperand(Inst.getOperand(4));
7808 Inst = TmpInst;
7809 return true;
7810 }
7811 return false;
7812 }
7813
Jim Grosbach485e5622011-12-13 22:45:11 +00007814 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007815 case ARM::t2MOVsr:
7816 case ARM::t2MOVSsr: {
7817 // Which instruction to expand to depends on the CCOut operand and
7818 // whether we're in an IT block if the register operands are low
7819 // registers.
7820 bool isNarrow = false;
7821 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7822 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7823 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7824 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7825 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7826 isNarrow = true;
7827 MCInst TmpInst;
7828 unsigned newOpc;
7829 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7830 default: llvm_unreachable("unexpected opcode!");
7831 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7832 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7833 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7834 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7835 }
7836 TmpInst.setOpcode(newOpc);
7837 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7838 if (isNarrow)
7839 TmpInst.addOperand(MCOperand::CreateReg(
7840 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7841 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7842 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7843 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7844 TmpInst.addOperand(Inst.getOperand(5));
7845 if (!isNarrow)
7846 TmpInst.addOperand(MCOperand::CreateReg(
7847 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7848 Inst = TmpInst;
7849 return true;
7850 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007851 case ARM::t2MOVsi:
7852 case ARM::t2MOVSsi: {
7853 // Which instruction to expand to depends on the CCOut operand and
7854 // whether we're in an IT block if the register operands are low
7855 // registers.
7856 bool isNarrow = false;
7857 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7858 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7859 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7860 isNarrow = true;
7861 MCInst TmpInst;
7862 unsigned newOpc;
7863 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7864 default: llvm_unreachable("unexpected opcode!");
7865 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7866 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7867 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7868 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007869 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007870 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007871 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7872 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007873 TmpInst.setOpcode(newOpc);
7874 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7875 if (isNarrow)
7876 TmpInst.addOperand(MCOperand::CreateReg(
7877 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7878 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007879 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007880 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007881 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7882 TmpInst.addOperand(Inst.getOperand(4));
7883 if (!isNarrow)
7884 TmpInst.addOperand(MCOperand::CreateReg(
7885 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7886 Inst = TmpInst;
7887 return true;
7888 }
7889 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007890 case ARM::ASRr:
7891 case ARM::LSRr:
7892 case ARM::LSLr:
7893 case ARM::RORr: {
7894 ARM_AM::ShiftOpc ShiftTy;
7895 switch(Inst.getOpcode()) {
7896 default: llvm_unreachable("unexpected opcode!");
7897 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7898 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7899 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7900 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7901 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007902 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7903 MCInst TmpInst;
7904 TmpInst.setOpcode(ARM::MOVsr);
7905 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7906 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7907 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7908 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7909 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7910 TmpInst.addOperand(Inst.getOperand(4));
7911 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7912 Inst = TmpInst;
7913 return true;
7914 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007915 case ARM::ASRi:
7916 case ARM::LSRi:
7917 case ARM::LSLi:
7918 case ARM::RORi: {
7919 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007920 switch(Inst.getOpcode()) {
7921 default: llvm_unreachable("unexpected opcode!");
7922 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7923 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7924 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7925 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7926 }
7927 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007928 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007929 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007930 // A shift by 32 should be encoded as 0 when permitted
7931 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7932 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007933 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007934 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007935 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007936 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7937 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007938 if (Opc == ARM::MOVsi)
7939 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007940 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7941 TmpInst.addOperand(Inst.getOperand(4));
7942 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7943 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007944 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007945 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007946 case ARM::RRXi: {
7947 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7948 MCInst TmpInst;
7949 TmpInst.setOpcode(ARM::MOVsi);
7950 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7951 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7952 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7953 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7954 TmpInst.addOperand(Inst.getOperand(3));
7955 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7956 Inst = TmpInst;
7957 return true;
7958 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007959 case ARM::t2LDMIA_UPD: {
7960 // If this is a load of a single register, then we should use
7961 // a post-indexed LDR instruction instead, per the ARM ARM.
7962 if (Inst.getNumOperands() != 5)
7963 return false;
7964 MCInst TmpInst;
7965 TmpInst.setOpcode(ARM::t2LDR_POST);
7966 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7967 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7968 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7969 TmpInst.addOperand(MCOperand::CreateImm(4));
7970 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7971 TmpInst.addOperand(Inst.getOperand(3));
7972 Inst = TmpInst;
7973 return true;
7974 }
7975 case ARM::t2STMDB_UPD: {
7976 // If this is a store of a single register, then we should use
7977 // a pre-indexed STR instruction instead, per the ARM ARM.
7978 if (Inst.getNumOperands() != 5)
7979 return false;
7980 MCInst TmpInst;
7981 TmpInst.setOpcode(ARM::t2STR_PRE);
7982 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7983 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7984 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7985 TmpInst.addOperand(MCOperand::CreateImm(-4));
7986 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7987 TmpInst.addOperand(Inst.getOperand(3));
7988 Inst = TmpInst;
7989 return true;
7990 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007991 case ARM::LDMIA_UPD:
7992 // If this is a load of a single register via a 'pop', then we should use
7993 // a post-indexed LDR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00007994 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007995 Inst.getNumOperands() == 5) {
7996 MCInst TmpInst;
7997 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7998 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7999 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8000 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8001 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
8002 TmpInst.addOperand(MCOperand::CreateImm(4));
8003 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8004 TmpInst.addOperand(Inst.getOperand(3));
8005 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008006 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008007 }
8008 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008009 case ARM::STMDB_UPD:
8010 // If this is a store of a single register via a 'push', then we should use
8011 // a pre-indexed STR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008012 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008013 Inst.getNumOperands() == 5) {
8014 MCInst TmpInst;
8015 TmpInst.setOpcode(ARM::STR_PRE_IMM);
8016 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8017 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8018 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
8019 TmpInst.addOperand(MCOperand::CreateImm(-4));
8020 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8021 TmpInst.addOperand(Inst.getOperand(3));
8022 Inst = TmpInst;
8023 }
8024 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00008025 case ARM::t2ADDri12:
8026 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
8027 // mnemonic was used (not "addw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008028 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008029 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8030 break;
8031 Inst.setOpcode(ARM::t2ADDri);
8032 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8033 break;
8034 case ARM::t2SUBri12:
8035 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
8036 // mnemonic was used (not "subw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008037 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008038 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8039 break;
8040 Inst.setOpcode(ARM::t2SUBri);
8041 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8042 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008043 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008044 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00008045 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8046 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8047 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008048 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008049 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008050 return true;
8051 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008052 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008053 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008054 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008055 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8056 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8057 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008058 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008059 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008060 return true;
8061 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008062 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00008063 case ARM::t2ADDri:
8064 case ARM::t2SUBri: {
8065 // If the destination and first source operand are the same, and
8066 // the flags are compatible with the current IT status, use encoding T2
8067 // instead of T3. For compatibility with the system 'as'. Make sure the
8068 // wide encoding wasn't explicit.
8069 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00008070 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00008071 (unsigned)Inst.getOperand(2).getImm() > 255 ||
8072 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008073 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
8074 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8075 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbachdef5e342012-03-30 17:20:40 +00008076 break;
8077 MCInst TmpInst;
8078 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
8079 ARM::tADDi8 : ARM::tSUBi8);
8080 TmpInst.addOperand(Inst.getOperand(0));
8081 TmpInst.addOperand(Inst.getOperand(5));
8082 TmpInst.addOperand(Inst.getOperand(0));
8083 TmpInst.addOperand(Inst.getOperand(2));
8084 TmpInst.addOperand(Inst.getOperand(3));
8085 TmpInst.addOperand(Inst.getOperand(4));
8086 Inst = TmpInst;
8087 return true;
8088 }
Jim Grosbache489bab2011-12-05 22:16:39 +00008089 case ARM::t2ADDrr: {
8090 // If the destination and first source operand are the same, and
8091 // there's no setting of the flags, use encoding T2 instead of T3.
8092 // Note that this is only for ADD, not SUB. This mirrors the system
8093 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
8094 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
8095 Inst.getOperand(5).getReg() != 0 ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008096 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8097 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00008098 break;
8099 MCInst TmpInst;
8100 TmpInst.setOpcode(ARM::tADDhirr);
8101 TmpInst.addOperand(Inst.getOperand(0));
8102 TmpInst.addOperand(Inst.getOperand(0));
8103 TmpInst.addOperand(Inst.getOperand(2));
8104 TmpInst.addOperand(Inst.getOperand(3));
8105 TmpInst.addOperand(Inst.getOperand(4));
8106 Inst = TmpInst;
8107 return true;
8108 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00008109 case ARM::tADDrSP: {
8110 // If the non-SP source operand and the destination operand are not the
8111 // same, we need to use the 32-bit encoding if it's available.
8112 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
8113 Inst.setOpcode(ARM::t2ADDrr);
8114 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8115 return true;
8116 }
8117 break;
8118 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008119 case ARM::tB:
8120 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008121 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008122 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008123 return true;
8124 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008125 break;
8126 case ARM::t2B:
8127 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008128 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008129 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008130 return true;
8131 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008132 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00008133 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008134 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00008135 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00008136 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00008137 return true;
8138 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00008139 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008140 case ARM::tBcc:
8141 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00008142 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008143 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00008144 return true;
8145 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00008146 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008147 case ARM::tLDMIA: {
8148 // If the register list contains any high registers, or if the writeback
8149 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
8150 // instead if we're in Thumb2. Otherwise, this should have generated
8151 // an error in validateInstruction().
8152 unsigned Rn = Inst.getOperand(0).getReg();
8153 bool hasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00008154 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8155 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Jim Grosbacha31f2232011-09-07 18:05:34 +00008156 bool listContainsBase;
8157 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
8158 (!listContainsBase && !hasWritebackToken) ||
8159 (listContainsBase && hasWritebackToken)) {
8160 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8161 assert (isThumbTwo());
8162 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
8163 // If we're switching to the updating version, we need to insert
8164 // the writeback tied operand.
8165 if (hasWritebackToken)
8166 Inst.insert(Inst.begin(),
8167 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00008168 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008169 }
8170 break;
8171 }
Jim Grosbach099c9762011-09-16 20:50:13 +00008172 case ARM::tSTMIA_UPD: {
8173 // If the register list contains any high registers, we need to use
8174 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8175 // should have generated an error in validateInstruction().
8176 unsigned Rn = Inst.getOperand(0).getReg();
8177 bool listContainsBase;
8178 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
8179 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8180 assert (isThumbTwo());
8181 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00008182 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00008183 }
8184 break;
8185 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008186 case ARM::tPOP: {
8187 bool listContainsBase;
8188 // If the register list contains any high registers, we need to use
8189 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8190 // should have generated an error in validateInstruction().
8191 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008192 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008193 assert (isThumbTwo());
8194 Inst.setOpcode(ARM::t2LDMIA_UPD);
8195 // Add the base register and writeback operands.
8196 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8197 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008198 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008199 }
8200 case ARM::tPUSH: {
8201 bool listContainsBase;
8202 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008203 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008204 assert (isThumbTwo());
8205 Inst.setOpcode(ARM::t2STMDB_UPD);
8206 // Add the base register and writeback operands.
8207 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8208 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008209 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008210 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008211 case ARM::t2MOVi: {
8212 // If we can use the 16-bit encoding and the user didn't explicitly
8213 // request the 32-bit variant, transform it here.
8214 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00008215 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00008216 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008217 Inst.getOperand(4).getReg() == ARM::CPSR) ||
8218 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
8219 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8220 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008221 // The operands aren't in the same order for tMOVi8...
8222 MCInst TmpInst;
8223 TmpInst.setOpcode(ARM::tMOVi8);
8224 TmpInst.addOperand(Inst.getOperand(0));
8225 TmpInst.addOperand(Inst.getOperand(4));
8226 TmpInst.addOperand(Inst.getOperand(1));
8227 TmpInst.addOperand(Inst.getOperand(2));
8228 TmpInst.addOperand(Inst.getOperand(3));
8229 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008230 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008231 }
8232 break;
8233 }
8234 case ARM::t2MOVr: {
8235 // If we can use the 16-bit encoding and the user didn't explicitly
8236 // request the 32-bit variant, transform it here.
8237 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8238 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8239 Inst.getOperand(2).getImm() == ARMCC::AL &&
8240 Inst.getOperand(4).getReg() == ARM::CPSR &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008241 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8242 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008243 // The operands aren't the same for tMOV[S]r... (no cc_out)
8244 MCInst TmpInst;
8245 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
8246 TmpInst.addOperand(Inst.getOperand(0));
8247 TmpInst.addOperand(Inst.getOperand(1));
8248 TmpInst.addOperand(Inst.getOperand(2));
8249 TmpInst.addOperand(Inst.getOperand(3));
8250 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008251 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008252 }
8253 break;
8254 }
Jim Grosbach82213192011-09-19 20:29:33 +00008255 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00008256 case ARM::t2SXTB:
8257 case ARM::t2UXTH:
8258 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00008259 // If we can use the 16-bit encoding and the user didn't explicitly
8260 // request the 32-bit variant, transform it here.
8261 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8262 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8263 Inst.getOperand(2).getImm() == 0 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008264 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8265 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00008266 unsigned NewOpc;
8267 switch (Inst.getOpcode()) {
8268 default: llvm_unreachable("Illegal opcode!");
8269 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
8270 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
8271 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
8272 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
8273 }
Jim Grosbach82213192011-09-19 20:29:33 +00008274 // The operands aren't the same for thumb1 (no rotate operand).
8275 MCInst TmpInst;
8276 TmpInst.setOpcode(NewOpc);
8277 TmpInst.addOperand(Inst.getOperand(0));
8278 TmpInst.addOperand(Inst.getOperand(1));
8279 TmpInst.addOperand(Inst.getOperand(3));
8280 TmpInst.addOperand(Inst.getOperand(4));
8281 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008282 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00008283 }
8284 break;
8285 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008286 case ARM::MOVsi: {
8287 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00008288 // rrx shifts and asr/lsr of #32 is encoded as 0
8289 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
8290 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008291 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
8292 // Shifting by zero is accepted as a vanilla 'MOVr'
8293 MCInst TmpInst;
8294 TmpInst.setOpcode(ARM::MOVr);
8295 TmpInst.addOperand(Inst.getOperand(0));
8296 TmpInst.addOperand(Inst.getOperand(1));
8297 TmpInst.addOperand(Inst.getOperand(3));
8298 TmpInst.addOperand(Inst.getOperand(4));
8299 TmpInst.addOperand(Inst.getOperand(5));
8300 Inst = TmpInst;
8301 return true;
8302 }
8303 return false;
8304 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00008305 case ARM::ANDrsi:
8306 case ARM::ORRrsi:
8307 case ARM::EORrsi:
8308 case ARM::BICrsi:
8309 case ARM::SUBrsi:
8310 case ARM::ADDrsi: {
8311 unsigned newOpc;
8312 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
8313 if (SOpc == ARM_AM::rrx) return false;
8314 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00008315 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00008316 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
8317 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
8318 case ARM::EORrsi: newOpc = ARM::EORrr; break;
8319 case ARM::BICrsi: newOpc = ARM::BICrr; break;
8320 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
8321 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
8322 }
8323 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00008324 // The exception is for right shifts, where 0 == 32
8325 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
8326 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00008327 MCInst TmpInst;
8328 TmpInst.setOpcode(newOpc);
8329 TmpInst.addOperand(Inst.getOperand(0));
8330 TmpInst.addOperand(Inst.getOperand(1));
8331 TmpInst.addOperand(Inst.getOperand(2));
8332 TmpInst.addOperand(Inst.getOperand(4));
8333 TmpInst.addOperand(Inst.getOperand(5));
8334 TmpInst.addOperand(Inst.getOperand(6));
8335 Inst = TmpInst;
8336 return true;
8337 }
8338 return false;
8339 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00008340 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008341 case ARM::t2IT: {
8342 // The mask bits for all but the first condition are represented as
8343 // the low bit of the condition code value implies 't'. We currently
8344 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00008345 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008346 MCOperand &MO = Inst.getOperand(1);
8347 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00008348 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00008349 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008350 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008351 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00008352 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00008353 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008354 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00008355
8356 // Set up the IT block state according to the IT instruction we just
8357 // matched.
8358 assert(!inITBlock() && "nested IT blocks?!");
8359 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
8360 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
8361 ITState.CurPosition = 0;
8362 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008363 break;
8364 }
Richard Bartona39625e2012-07-09 16:12:24 +00008365 case ARM::t2LSLrr:
8366 case ARM::t2LSRrr:
8367 case ARM::t2ASRrr:
8368 case ARM::t2SBCrr:
8369 case ARM::t2RORrr:
8370 case ARM::t2BICrr:
8371 {
Richard Bartond5660372012-07-09 16:14:28 +00008372 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008373 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8374 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8375 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008376 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008377 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8378 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8379 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8380 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008381 unsigned NewOpc;
8382 switch (Inst.getOpcode()) {
8383 default: llvm_unreachable("unexpected opcode");
8384 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
8385 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
8386 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
8387 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
8388 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
8389 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
8390 }
8391 MCInst TmpInst;
8392 TmpInst.setOpcode(NewOpc);
8393 TmpInst.addOperand(Inst.getOperand(0));
8394 TmpInst.addOperand(Inst.getOperand(5));
8395 TmpInst.addOperand(Inst.getOperand(1));
8396 TmpInst.addOperand(Inst.getOperand(2));
8397 TmpInst.addOperand(Inst.getOperand(3));
8398 TmpInst.addOperand(Inst.getOperand(4));
8399 Inst = TmpInst;
8400 return true;
8401 }
8402 return false;
8403 }
8404 case ARM::t2ANDrr:
8405 case ARM::t2EORrr:
8406 case ARM::t2ADCrr:
8407 case ARM::t2ORRrr:
8408 {
Richard Bartond5660372012-07-09 16:14:28 +00008409 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008410 // These instructions are special in that they are commutable, so shorter encodings
8411 // are available more often.
8412 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8413 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8414 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
8415 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008416 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008417 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8418 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8419 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8420 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008421 unsigned NewOpc;
8422 switch (Inst.getOpcode()) {
8423 default: llvm_unreachable("unexpected opcode");
8424 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
8425 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
8426 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
8427 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
8428 }
8429 MCInst TmpInst;
8430 TmpInst.setOpcode(NewOpc);
8431 TmpInst.addOperand(Inst.getOperand(0));
8432 TmpInst.addOperand(Inst.getOperand(5));
8433 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
8434 TmpInst.addOperand(Inst.getOperand(1));
8435 TmpInst.addOperand(Inst.getOperand(2));
8436 } else {
8437 TmpInst.addOperand(Inst.getOperand(2));
8438 TmpInst.addOperand(Inst.getOperand(1));
8439 }
8440 TmpInst.addOperand(Inst.getOperand(3));
8441 TmpInst.addOperand(Inst.getOperand(4));
8442 Inst = TmpInst;
8443 return true;
8444 }
8445 return false;
8446 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008447 }
Jim Grosbachafad0532011-11-10 23:42:14 +00008448 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008449}
8450
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008451unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
8452 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
8453 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008454 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00008455 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008456 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
8457 assert(MCID.hasOptionalDef() &&
8458 "optionally flag setting instruction missing optional def operand");
8459 assert(MCID.NumOperands == Inst.getNumOperands() &&
8460 "operand count mismatch!");
8461 // Find the optional-def operand (cc_out).
8462 unsigned OpNo;
8463 for (OpNo = 0;
8464 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
8465 ++OpNo)
8466 ;
8467 // If we're parsing Thumb1, reject it completely.
8468 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
8469 return Match_MnemonicFail;
8470 // If we're parsing Thumb2, which form is legal depends on whether we're
8471 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00008472 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
8473 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008474 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00008475 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8476 inITBlock())
8477 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008478 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008479 // Some high-register supporting Thumb1 encodings only allow both registers
8480 // to be from r0-r7 when in Thumb2.
Renato Golin36c626e2014-09-26 16:14:29 +00008481 else if (Opc == ARM::tADDhirr && isThumbOne() && !hasV6MOps() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008482 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8483 isARMLowRegister(Inst.getOperand(2).getReg()))
8484 return Match_RequiresThumb2;
8485 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00008486 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008487 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8488 isARMLowRegister(Inst.getOperand(1).getReg()))
8489 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008490 return Match_Success;
8491}
8492
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008493namespace llvm {
8494template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008495 return true; // In an assembly source, no need to second-guess
8496}
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008497}
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008498
Tim Northover26bb14e2014-08-18 11:49:42 +00008499static const char *getSubtargetFeatureName(uint64_t Val);
David Blaikie960ea3f2014-06-08 16:18:35 +00008500bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
8501 OperandVector &Operands,
Tim Northover26bb14e2014-08-18 11:49:42 +00008502 MCStreamer &Out, uint64_t &ErrorInfo,
David Blaikie960ea3f2014-06-08 16:18:35 +00008503 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00008504 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00008505 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00008506
Chad Rosier2f480a82012-10-12 22:53:36 +00008507 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00008508 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00008509 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00008510 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008511 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008512 // Context sensitive operand constraints aren't handled by the matcher,
8513 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008514 if (validateInstruction(Inst, Operands)) {
8515 // Still progress the IT block, otherwise one wrong condition causes
8516 // nasty cascading errors.
8517 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008518 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008519 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008520
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008521 { // processInstruction() updates inITBlock state, we need to save it away
8522 bool wasInITBlock = inITBlock();
8523
8524 // Some instructions need post-processing to, for example, tweak which
8525 // encoding is selected. Loop on it while changes happen so the
8526 // individual transformations can chain off each other. E.g.,
8527 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00008528 while (processInstruction(Inst, Operands, Out))
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008529 ;
8530
8531 // Only after the instruction is fully processed, we can validate it
8532 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00008533 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008534 Warning(IDLoc, "deprecated instruction in IT block");
8535 }
8536 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008537
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008538 // Only move forward at the very end so that everything in validate
8539 // and process gets a consistent answer about whether we're in an IT
8540 // block.
8541 forwardITPosition();
8542
Jim Grosbach82f76d12012-01-25 19:52:01 +00008543 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8544 // doesn't actually encode.
8545 if (Inst.getOpcode() == ARM::ITasm)
8546 return false;
8547
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00008548 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00008549 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00008550 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008551 case Match_MissingFeature: {
8552 assert(ErrorInfo && "Unknown missing feature!");
8553 // Special case the error message for the very common case where only
8554 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8555 std::string Msg = "instruction requires:";
Tim Northover26bb14e2014-08-18 11:49:42 +00008556 uint64_t Mask = 1;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008557 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8558 if (ErrorInfo & Mask) {
8559 Msg += " ";
8560 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8561 }
8562 Mask <<= 1;
8563 }
8564 return Error(IDLoc, Msg);
8565 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008566 case Match_InvalidOperand: {
8567 SMLoc ErrorLoc = IDLoc;
Tim Northover26bb14e2014-08-18 11:49:42 +00008568 if (ErrorInfo != ~0ULL) {
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008569 if (ErrorInfo >= Operands.size())
8570 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00008571
David Blaikie960ea3f2014-06-08 16:18:35 +00008572 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008573 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8574 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008575
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008576 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00008577 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008578 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00008579 return Error(IDLoc, "invalid instruction",
David Blaikie960ea3f2014-06-08 16:18:35 +00008580 ((ARMOperand &)*Operands[0]).getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00008581 case Match_RequiresNotITBlock:
8582 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008583 case Match_RequiresITBlock:
8584 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008585 case Match_RequiresV6:
8586 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8587 case Match_RequiresThumb2:
8588 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00008589 case Match_ImmRange0_15: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008590 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Jim Grosbach087affe2012-06-22 23:56:48 +00008591 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8592 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8593 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008594 case Match_ImmRange0_239: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008595 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008596 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8597 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8598 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00008599 case Match_AlignedMemoryRequiresNone:
8600 case Match_DupAlignedMemoryRequiresNone:
8601 case Match_AlignedMemoryRequires16:
8602 case Match_DupAlignedMemoryRequires16:
8603 case Match_AlignedMemoryRequires32:
8604 case Match_DupAlignedMemoryRequires32:
8605 case Match_AlignedMemoryRequires64:
8606 case Match_DupAlignedMemoryRequires64:
8607 case Match_AlignedMemoryRequires64or128:
8608 case Match_DupAlignedMemoryRequires64or128:
8609 case Match_AlignedMemoryRequires64or128or256:
8610 {
David Blaikie960ea3f2014-06-08 16:18:35 +00008611 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00008612 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8613 switch (MatchResult) {
8614 default:
8615 llvm_unreachable("Missing Match_Aligned type");
8616 case Match_AlignedMemoryRequiresNone:
8617 case Match_DupAlignedMemoryRequiresNone:
8618 return Error(ErrorLoc, "alignment must be omitted");
8619 case Match_AlignedMemoryRequires16:
8620 case Match_DupAlignedMemoryRequires16:
8621 return Error(ErrorLoc, "alignment must be 16 or omitted");
8622 case Match_AlignedMemoryRequires32:
8623 case Match_DupAlignedMemoryRequires32:
8624 return Error(ErrorLoc, "alignment must be 32 or omitted");
8625 case Match_AlignedMemoryRequires64:
8626 case Match_DupAlignedMemoryRequires64:
8627 return Error(ErrorLoc, "alignment must be 64 or omitted");
8628 case Match_AlignedMemoryRequires64or128:
8629 case Match_DupAlignedMemoryRequires64or128:
8630 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8631 case Match_AlignedMemoryRequires64or128or256:
8632 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8633 }
8634 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008635 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008636
Eric Christopher91d7b902010-10-29 09:26:59 +00008637 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00008638}
8639
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008640/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00008641bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008642 const MCObjectFileInfo::Environment Format =
8643 getContext().getObjectFileInfo()->getObjectFileType();
8644 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008645 bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008646
Kevin Enderbyccab3172009-09-15 00:27:25 +00008647 StringRef IDVal = DirectiveID.getIdentifier();
8648 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008649 return parseLiteralValues(4, DirectiveID.getLoc());
8650 else if (IDVal == ".short" || IDVal == ".hword")
8651 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008652 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008653 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00008654 else if (IDVal == ".arm")
8655 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008656 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008657 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008658 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008659 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008660 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008661 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008662 else if (IDVal == ".unreq")
8663 return parseDirectiveUnreq(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00008664 else if (IDVal == ".fnend")
8665 return parseDirectiveFnEnd(DirectiveID.getLoc());
8666 else if (IDVal == ".cantunwind")
8667 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8668 else if (IDVal == ".personality")
8669 return parseDirectivePersonality(DirectiveID.getLoc());
8670 else if (IDVal == ".handlerdata")
8671 return parseDirectiveHandlerData(DirectiveID.getLoc());
8672 else if (IDVal == ".setfp")
8673 return parseDirectiveSetFP(DirectiveID.getLoc());
8674 else if (IDVal == ".pad")
8675 return parseDirectivePad(DirectiveID.getLoc());
8676 else if (IDVal == ".save")
8677 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8678 else if (IDVal == ".vsave")
8679 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008680 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008681 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008682 else if (IDVal == ".even")
8683 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008684 else if (IDVal == ".personalityindex")
8685 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008686 else if (IDVal == ".unwind_raw")
8687 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008688 else if (IDVal == ".movsp")
8689 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008690 else if (IDVal == ".arch_extension")
8691 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008692 else if (IDVal == ".align")
8693 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008694 else if (IDVal == ".thumb_set")
8695 return parseDirectiveThumbSet(DirectiveID.getLoc());
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008696
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008697 if (!IsMachO && !IsCOFF) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008698 if (IDVal == ".arch")
8699 return parseDirectiveArch(DirectiveID.getLoc());
8700 else if (IDVal == ".cpu")
8701 return parseDirectiveCPU(DirectiveID.getLoc());
8702 else if (IDVal == ".eabi_attribute")
8703 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8704 else if (IDVal == ".fpu")
8705 return parseDirectiveFPU(DirectiveID.getLoc());
8706 else if (IDVal == ".fnstart")
8707 return parseDirectiveFnStart(DirectiveID.getLoc());
8708 else if (IDVal == ".inst")
8709 return parseDirectiveInst(DirectiveID.getLoc());
8710 else if (IDVal == ".inst.n")
8711 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8712 else if (IDVal == ".inst.w")
8713 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8714 else if (IDVal == ".object_arch")
8715 return parseDirectiveObjectArch(DirectiveID.getLoc());
8716 else if (IDVal == ".tlsdescseq")
8717 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8718 }
8719
Kevin Enderbyccab3172009-09-15 00:27:25 +00008720 return true;
8721}
8722
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008723/// parseLiteralValues
8724/// ::= .hword expression [, expression]*
8725/// ::= .short expression [, expression]*
8726/// ::= .word expression [, expression]*
8727bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008728 MCAsmParser &Parser = getParser();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008729 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8730 for (;;) {
8731 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008732 if (getParser().parseExpression(Value)) {
8733 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008734 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008735 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008736
Eric Christopherbf7bc492013-01-09 03:52:05 +00008737 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008738
8739 if (getLexer().is(AsmToken::EndOfStatement))
8740 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008741
Kevin Enderbyccab3172009-09-15 00:27:25 +00008742 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008743 if (getLexer().isNot(AsmToken::Comma)) {
8744 Error(L, "unexpected token in directive");
8745 return false;
8746 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008747 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008748 }
8749 }
8750
Sean Callanana83fd7d2010-01-19 20:27:46 +00008751 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008752 return false;
8753}
8754
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008755/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008756/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008757bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008758 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008759 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8760 Error(L, "unexpected token in directive");
8761 return false;
8762 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008763 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008764
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008765 if (!hasThumb()) {
8766 Error(L, "target does not support Thumb mode");
8767 return false;
8768 }
Tim Northovera2292d02013-06-10 23:20:58 +00008769
Jim Grosbach7f882392011-12-07 18:04:19 +00008770 if (!isThumb())
8771 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008772
Jim Grosbach7f882392011-12-07 18:04:19 +00008773 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8774 return false;
8775}
8776
8777/// parseDirectiveARM
8778/// ::= .arm
8779bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008780 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008781 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8782 Error(L, "unexpected token in directive");
8783 return false;
8784 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008785 Parser.Lex();
8786
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008787 if (!hasARM()) {
8788 Error(L, "target does not support ARM mode");
8789 return false;
8790 }
Tim Northovera2292d02013-06-10 23:20:58 +00008791
Jim Grosbach7f882392011-12-07 18:04:19 +00008792 if (isThumb())
8793 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008794
Jim Grosbach7f882392011-12-07 18:04:19 +00008795 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008796 return false;
8797}
8798
Tim Northover1744d0a2013-10-25 12:49:50 +00008799void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8800 if (NextSymbolIsThumb) {
8801 getParser().getStreamer().EmitThumbFunc(Symbol);
8802 NextSymbolIsThumb = false;
8803 }
8804}
8805
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008806/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008807/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008808bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008809 MCAsmParser &Parser = getParser();
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008810 const auto Format = getContext().getObjectFileInfo()->getObjectFileType();
8811 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008812
Jim Grosbach1152cc02011-12-21 22:30:16 +00008813 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008814 // ELF doesn't
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008815 if (IsMachO) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008816 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008817 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008818 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8819 Error(L, "unexpected token in .thumb_func directive");
8820 return false;
8821 }
8822
Tim Northover1744d0a2013-10-25 12:49:50 +00008823 MCSymbol *Func =
8824 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8825 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008826 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008827 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008828 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008829 }
8830
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008831 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008832 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8833 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008834 return false;
8835 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008836
Tim Northover1744d0a2013-10-25 12:49:50 +00008837 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008838 return false;
8839}
8840
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008841/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008842/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008843bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008844 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008845 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008846 if (Tok.isNot(AsmToken::Identifier)) {
8847 Error(L, "unexpected token in .syntax directive");
8848 return false;
8849 }
8850
Benjamin Kramer92d89982010-07-14 22:38:02 +00008851 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008852 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008853 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008854 } else if (Mode == "divided" || Mode == "DIVIDED") {
8855 Error(L, "'.syntax divided' arm asssembly not supported");
8856 return false;
8857 } else {
8858 Error(L, "unrecognized syntax mode in .syntax directive");
8859 return false;
8860 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008861
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008862 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8863 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8864 return false;
8865 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008866 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008867
8868 // TODO tell the MC streamer the mode
8869 // getParser().getStreamer().Emit???();
8870 return false;
8871}
8872
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008873/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008874/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008875bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008876 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008877 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008878 if (Tok.isNot(AsmToken::Integer)) {
8879 Error(L, "unexpected token in .code directive");
8880 return false;
8881 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008882 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008883 if (Val != 16 && Val != 32) {
8884 Error(L, "invalid operand to .code directive");
8885 return false;
8886 }
8887 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008888
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008889 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8890 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8891 return false;
8892 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008893 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008894
Evan Cheng284b4672011-07-08 22:36:29 +00008895 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008896 if (!hasThumb()) {
8897 Error(L, "target does not support Thumb mode");
8898 return false;
8899 }
Tim Northovera2292d02013-06-10 23:20:58 +00008900
Jim Grosbachf471ac32011-09-06 18:46:23 +00008901 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008902 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008903 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008904 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008905 if (!hasARM()) {
8906 Error(L, "target does not support ARM mode");
8907 return false;
8908 }
Tim Northovera2292d02013-06-10 23:20:58 +00008909
Jim Grosbachf471ac32011-09-06 18:46:23 +00008910 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008911 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008912 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008913 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008914
Kevin Enderby146dcf22009-10-15 20:48:48 +00008915 return false;
8916}
8917
Jim Grosbachab5830e2011-12-14 02:16:11 +00008918/// parseDirectiveReq
8919/// ::= name .req registername
8920bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008921 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008922 Parser.Lex(); // Eat the '.req' token.
8923 unsigned Reg;
8924 SMLoc SRegLoc, ERegLoc;
8925 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008926 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008927 Error(SRegLoc, "register name expected");
8928 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008929 }
8930
8931 // Shouldn't be anything else.
8932 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008933 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008934 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8935 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008936 }
8937
8938 Parser.Lex(); // Consume the EndOfStatement
8939
David Blaikie5106ce72014-11-19 05:49:42 +00008940 if (!RegisterReqs.insert(std::make_pair(Name, Reg)).second) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008941 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8942 return false;
8943 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00008944
8945 return false;
8946}
8947
8948/// parseDirectiveUneq
8949/// ::= .unreq registername
8950bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008951 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008952 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008953 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008954 Error(L, "unexpected input in .unreq directive.");
8955 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008956 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00008957 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008958 Parser.Lex(); // Eat the identifier.
8959 return false;
8960}
8961
Jason W Kim135d2442011-12-20 17:38:12 +00008962/// parseDirectiveArch
8963/// ::= .arch token
8964bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00008965 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8966
8967 unsigned ID = StringSwitch<unsigned>(Arch)
8968#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8969 .Case(NAME, ARM::ID)
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +00008970#define ARM_ARCH_ALIAS(NAME, ID) \
8971 .Case(NAME, ARM::ID)
Logan Chien439e8f92013-12-11 17:16:25 +00008972#include "MCTargetDesc/ARMArchName.def"
8973 .Default(ARM::INVALID_ARCH);
8974
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008975 if (ID == ARM::INVALID_ARCH) {
8976 Error(L, "Unknown arch name");
8977 return false;
8978 }
Logan Chien439e8f92013-12-11 17:16:25 +00008979
8980 getTargetStreamer().emitArch(ID);
8981 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008982}
8983
8984/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008985/// ::= .eabi_attribute int, int [, "str"]
8986/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00008987bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008988 MCAsmParser &Parser = getParser();
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008989 int64_t Tag;
8990 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008991 TagLoc = Parser.getTok().getLoc();
8992 if (Parser.getTok().is(AsmToken::Identifier)) {
8993 StringRef Name = Parser.getTok().getIdentifier();
8994 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
8995 if (Tag == -1) {
8996 Error(TagLoc, "attribute name not recognised: " + Name);
8997 Parser.eatToEndOfStatement();
8998 return false;
8999 }
9000 Parser.Lex();
9001 } else {
9002 const MCExpr *AttrExpr;
9003
9004 TagLoc = Parser.getTok().getLoc();
9005 if (Parser.parseExpression(AttrExpr)) {
9006 Parser.eatToEndOfStatement();
9007 return false;
9008 }
9009
9010 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
9011 if (!CE) {
9012 Error(TagLoc, "expected numeric constant");
9013 Parser.eatToEndOfStatement();
9014 return false;
9015 }
9016
9017 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009018 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009019
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009020 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009021 Error(Parser.getTok().getLoc(), "comma expected");
9022 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009023 return false;
9024 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009025 Parser.Lex(); // skip comma
9026
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009027 StringRef StringValue = "";
9028 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00009029
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009030 int64_t IntegerValue = 0;
9031 bool IsIntegerValue = false;
9032
9033 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
9034 IsStringValue = true;
9035 else if (Tag == ARMBuildAttrs::compatibility) {
9036 IsStringValue = true;
9037 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00009038 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009039 IsIntegerValue = true;
9040 else if (Tag % 2 == 1)
9041 IsStringValue = true;
9042 else
9043 llvm_unreachable("invalid tag type");
9044
9045 if (IsIntegerValue) {
9046 const MCExpr *ValueExpr;
9047 SMLoc ValueExprLoc = Parser.getTok().getLoc();
9048 if (Parser.parseExpression(ValueExpr)) {
9049 Parser.eatToEndOfStatement();
9050 return false;
9051 }
9052
9053 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
9054 if (!CE) {
9055 Error(ValueExprLoc, "expected numeric constant");
9056 Parser.eatToEndOfStatement();
9057 return false;
9058 }
9059
9060 IntegerValue = CE->getValue();
9061 }
9062
9063 if (Tag == ARMBuildAttrs::compatibility) {
9064 if (Parser.getTok().isNot(AsmToken::Comma))
9065 IsStringValue = false;
9066 else
9067 Parser.Lex();
9068 }
9069
9070 if (IsStringValue) {
9071 if (Parser.getTok().isNot(AsmToken::String)) {
9072 Error(Parser.getTok().getLoc(), "bad string constant");
9073 Parser.eatToEndOfStatement();
9074 return false;
9075 }
9076
9077 StringValue = Parser.getTok().getStringContents();
9078 Parser.Lex();
9079 }
9080
9081 if (IsIntegerValue && IsStringValue) {
9082 assert(Tag == ARMBuildAttrs::compatibility);
9083 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
9084 } else if (IsIntegerValue)
9085 getTargetStreamer().emitAttribute(Tag, IntegerValue);
9086 else if (IsStringValue)
9087 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00009088 return false;
9089}
9090
9091/// parseDirectiveCPU
9092/// ::= .cpu str
9093bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
9094 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
9095 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
Roman Divacky7e6b5952014-12-02 20:03:22 +00009096
Roman Divackyfdf05602014-12-03 18:39:44 +00009097 if (!STI.isCPUStringValid(CPU)) {
Roman Divacky7e6b5952014-12-02 20:03:22 +00009098 Error(L, "Unknown CPU name");
9099 return false;
9100 }
9101
9102 STI.InitMCProcessorInfo(CPU, "");
9103 STI.InitCPUSchedModel(CPU);
9104 unsigned FB = ComputeAvailableFeatures(STI.getFeatureBits());
9105 setAvailableFeatures(FB);
9106
Logan Chien8cbb80d2013-10-28 17:51:12 +00009107 return false;
9108}
9109
Nico Weberae050bb2014-08-16 05:37:51 +00009110// FIXME: This is duplicated in getARMFPUFeatures() in
9111// tools/clang/lib/Driver/Tools.cpp
9112static const struct {
9113 const unsigned Fpu;
9114 const uint64_t Enabled;
9115 const uint64_t Disabled;
9116} Fpus[] = {
9117 {ARM::VFP, ARM::FeatureVFP2, ARM::FeatureNEON},
9118 {ARM::VFPV2, ARM::FeatureVFP2, ARM::FeatureNEON},
9119 {ARM::VFPV3, ARM::FeatureVFP3, ARM::FeatureNEON},
9120 {ARM::VFPV3_D16, ARM::FeatureVFP3 | ARM::FeatureD16, ARM::FeatureNEON},
9121 {ARM::VFPV4, ARM::FeatureVFP4, ARM::FeatureNEON},
9122 {ARM::VFPV4_D16, ARM::FeatureVFP4 | ARM::FeatureD16, ARM::FeatureNEON},
Oliver Stannard37e4daa2014-10-01 09:02:17 +00009123 {ARM::FPV5_D16, ARM::FeatureFPARMv8 | ARM::FeatureD16,
9124 ARM::FeatureNEON | ARM::FeatureCrypto},
Nico Weberae050bb2014-08-16 05:37:51 +00009125 {ARM::FP_ARMV8, ARM::FeatureFPARMv8,
9126 ARM::FeatureNEON | ARM::FeatureCrypto},
9127 {ARM::NEON, ARM::FeatureNEON, 0},
9128 {ARM::NEON_VFPV4, ARM::FeatureVFP4 | ARM::FeatureNEON, 0},
9129 {ARM::NEON_FP_ARMV8, ARM::FeatureFPARMv8 | ARM::FeatureNEON,
9130 ARM::FeatureCrypto},
9131 {ARM::CRYPTO_NEON_FP_ARMV8,
9132 ARM::FeatureFPARMv8 | ARM::FeatureNEON | ARM::FeatureCrypto, 0},
9133 {ARM::SOFTVFP, 0, 0},
9134};
9135
Logan Chien8cbb80d2013-10-28 17:51:12 +00009136/// parseDirectiveFPU
9137/// ::= .fpu str
9138bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
9139 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
9140
9141 unsigned ID = StringSwitch<unsigned>(FPU)
9142#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
9143#include "ARMFPUName.def"
9144 .Default(ARM::INVALID_FPU);
9145
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009146 if (ID == ARM::INVALID_FPU) {
9147 Error(L, "Unknown FPU name");
9148 return false;
9149 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009150
Nico Weberae050bb2014-08-16 05:37:51 +00009151 for (const auto &Fpu : Fpus) {
9152 if (Fpu.Fpu != ID)
9153 continue;
9154
9155 // Need to toggle features that should be on but are off and that
9156 // should off but are on.
Tim Northover26bb14e2014-08-18 11:49:42 +00009157 uint64_t Toggle = (Fpu.Enabled & ~STI.getFeatureBits()) |
Nico Weberae050bb2014-08-16 05:37:51 +00009158 (Fpu.Disabled & STI.getFeatureBits());
9159 setAvailableFeatures(ComputeAvailableFeatures(STI.ToggleFeature(Toggle)));
9160 break;
9161 }
9162
Logan Chien8cbb80d2013-10-28 17:51:12 +00009163 getTargetStreamer().emitFPU(ID);
9164 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00009165}
9166
Logan Chien4ea23b52013-05-10 16:17:24 +00009167/// parseDirectiveFnStart
9168/// ::= .fnstart
9169bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009170 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009171 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009172 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009173 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009174 }
9175
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009176 // Reset the unwind directives parser state
9177 UC.reset();
9178
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009179 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009180
9181 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00009182 return false;
9183}
9184
9185/// parseDirectiveFnEnd
9186/// ::= .fnend
9187bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
9188 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009189 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009190 Error(L, ".fnstart must precede .fnend directive");
9191 return false;
9192 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009193
9194 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009195 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009196
9197 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00009198 return false;
9199}
9200
9201/// parseDirectiveCantUnwind
9202/// ::= .cantunwind
9203bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009204 UC.recordCantUnwind(L);
9205
Logan Chien4ea23b52013-05-10 16:17:24 +00009206 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009207 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009208 Error(L, ".fnstart must precede .cantunwind directive");
9209 return false;
9210 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009211 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009212 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009213 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009214 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009215 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009216 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009217 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009218 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009219 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009220 }
9221
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009222 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00009223 return false;
9224}
9225
9226/// parseDirectivePersonality
9227/// ::= .personality name
9228bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009229 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009230 bool HasExistingPersonality = UC.hasPersonality();
9231
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009232 UC.recordPersonality(L);
9233
Logan Chien4ea23b52013-05-10 16:17:24 +00009234 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009235 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009236 Error(L, ".fnstart must precede .personality directive");
9237 return false;
9238 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009239 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009240 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009241 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009242 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009243 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009244 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009245 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009246 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009247 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009248 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009249 if (HasExistingPersonality) {
9250 Parser.eatToEndOfStatement();
9251 Error(L, "multiple personality directives");
9252 UC.emitPersonalityLocNotes();
9253 return false;
9254 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009255
9256 // Parse the name of the personality routine
9257 if (Parser.getTok().isNot(AsmToken::Identifier)) {
9258 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009259 Error(L, "unexpected input in .personality directive.");
9260 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009261 }
9262 StringRef Name(Parser.getTok().getIdentifier());
9263 Parser.Lex();
9264
9265 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009266 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00009267 return false;
9268}
9269
9270/// parseDirectiveHandlerData
9271/// ::= .handlerdata
9272bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009273 UC.recordHandlerData(L);
9274
Logan Chien4ea23b52013-05-10 16:17:24 +00009275 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009276 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009277 Error(L, ".fnstart must precede .personality directive");
9278 return false;
9279 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009280 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009281 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009282 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009283 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009284 }
9285
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009286 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00009287 return false;
9288}
9289
9290/// parseDirectiveSetFP
9291/// ::= .setfp fpreg, spreg [, offset]
9292bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009293 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009294 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009295 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009296 Error(L, ".fnstart must precede .setfp directive");
9297 return false;
9298 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009299 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009300 Error(L, ".setfp must precede .handlerdata directive");
9301 return false;
9302 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009303
9304 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009305 SMLoc FPRegLoc = Parser.getTok().getLoc();
9306 int FPReg = tryParseRegister();
9307 if (FPReg == -1) {
9308 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009309 return false;
9310 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009311
9312 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009313 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009314 Error(Parser.getTok().getLoc(), "comma expected");
9315 return false;
9316 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009317 Parser.Lex(); // skip comma
9318
9319 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009320 SMLoc SPRegLoc = Parser.getTok().getLoc();
9321 int SPReg = tryParseRegister();
9322 if (SPReg == -1) {
9323 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009324 return false;
9325 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009326
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009327 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
9328 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009329 return false;
9330 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009331
9332 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009333 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00009334
9335 // Parse offset
9336 int64_t Offset = 0;
9337 if (Parser.getTok().is(AsmToken::Comma)) {
9338 Parser.Lex(); // skip comma
9339
9340 if (Parser.getTok().isNot(AsmToken::Hash) &&
9341 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009342 Error(Parser.getTok().getLoc(), "'#' expected");
9343 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009344 }
9345 Parser.Lex(); // skip hash token.
9346
9347 const MCExpr *OffsetExpr;
9348 SMLoc ExLoc = Parser.getTok().getLoc();
9349 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009350 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9351 Error(ExLoc, "malformed setfp offset");
9352 return false;
9353 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009354 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009355 if (!CE) {
9356 Error(ExLoc, "setfp offset must be an immediate");
9357 return false;
9358 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009359
9360 Offset = CE->getValue();
9361 }
9362
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009363 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
9364 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00009365 return false;
9366}
9367
9368/// parseDirective
9369/// ::= .pad offset
9370bool ARMAsmParser::parseDirectivePad(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009371 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009372 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009373 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009374 Error(L, ".fnstart must precede .pad directive");
9375 return false;
9376 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009377 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009378 Error(L, ".pad must precede .handlerdata directive");
9379 return false;
9380 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009381
9382 // Parse the offset
9383 if (Parser.getTok().isNot(AsmToken::Hash) &&
9384 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009385 Error(Parser.getTok().getLoc(), "'#' expected");
9386 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009387 }
9388 Parser.Lex(); // skip hash token.
9389
9390 const MCExpr *OffsetExpr;
9391 SMLoc ExLoc = Parser.getTok().getLoc();
9392 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009393 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9394 Error(ExLoc, "malformed pad offset");
9395 return false;
9396 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009397 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009398 if (!CE) {
9399 Error(ExLoc, "pad offset must be an immediate");
9400 return false;
9401 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009402
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009403 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00009404 return false;
9405}
9406
9407/// parseDirectiveRegSave
9408/// ::= .save { registers }
9409/// ::= .vsave { registers }
9410bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
9411 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009412 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009413 Error(L, ".fnstart must precede .save or .vsave directives");
9414 return false;
9415 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009416 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009417 Error(L, ".save or .vsave must precede .handlerdata directive");
9418 return false;
9419 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009420
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009421 // RAII object to make sure parsed operands are deleted.
David Blaikie960ea3f2014-06-08 16:18:35 +00009422 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009423
Logan Chien4ea23b52013-05-10 16:17:24 +00009424 // Parse the register list
David Blaikie960ea3f2014-06-08 16:18:35 +00009425 if (parseRegisterList(Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00009426 return false;
David Blaikie960ea3f2014-06-08 16:18:35 +00009427 ARMOperand &Op = (ARMOperand &)*Operands[0];
9428 if (!IsVector && !Op.isRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009429 Error(L, ".save expects GPR registers");
9430 return false;
9431 }
David Blaikie960ea3f2014-06-08 16:18:35 +00009432 if (IsVector && !Op.isDPRRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009433 Error(L, ".vsave expects DPR registers");
9434 return false;
9435 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009436
David Blaikie960ea3f2014-06-08 16:18:35 +00009437 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00009438 return false;
9439}
9440
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009441/// parseDirectiveInst
9442/// ::= .inst opcode [, ...]
9443/// ::= .inst.n opcode [, ...]
9444/// ::= .inst.w opcode [, ...]
9445bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009446 MCAsmParser &Parser = getParser();
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009447 int Width;
9448
9449 if (isThumb()) {
9450 switch (Suffix) {
9451 case 'n':
9452 Width = 2;
9453 break;
9454 case 'w':
9455 Width = 4;
9456 break;
9457 default:
9458 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009459 Error(Loc, "cannot determine Thumb instruction size, "
9460 "use inst.n/inst.w instead");
9461 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009462 }
9463 } else {
9464 if (Suffix) {
9465 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009466 Error(Loc, "width suffixes are invalid in ARM mode");
9467 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009468 }
9469 Width = 4;
9470 }
9471
9472 if (getLexer().is(AsmToken::EndOfStatement)) {
9473 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009474 Error(Loc, "expected expression following directive");
9475 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009476 }
9477
9478 for (;;) {
9479 const MCExpr *Expr;
9480
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009481 if (getParser().parseExpression(Expr)) {
9482 Error(Loc, "expected expression");
9483 return false;
9484 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009485
9486 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009487 if (!Value) {
9488 Error(Loc, "expected constant expression");
9489 return false;
9490 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009491
9492 switch (Width) {
9493 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009494 if (Value->getValue() > 0xffff) {
9495 Error(Loc, "inst.n operand is too big, use inst.w instead");
9496 return false;
9497 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009498 break;
9499 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009500 if (Value->getValue() > 0xffffffff) {
9501 Error(Loc,
9502 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
9503 return false;
9504 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009505 break;
9506 default:
9507 llvm_unreachable("only supported widths are 2 and 4");
9508 }
9509
9510 getTargetStreamer().emitInst(Value->getValue(), Suffix);
9511
9512 if (getLexer().is(AsmToken::EndOfStatement))
9513 break;
9514
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009515 if (getLexer().isNot(AsmToken::Comma)) {
9516 Error(Loc, "unexpected token in directive");
9517 return false;
9518 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009519
9520 Parser.Lex();
9521 }
9522
9523 Parser.Lex();
9524 return false;
9525}
9526
David Peixotto80c083a2013-12-19 18:26:07 +00009527/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00009528/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00009529bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00009530 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00009531 return false;
9532}
9533
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009534bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9535 const MCSection *Section = getStreamer().getCurrentSection().first;
9536
9537 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9538 TokError("unexpected token in directive");
9539 return false;
9540 }
9541
9542 if (!Section) {
Rafael Espindola7b61ddf2014-10-15 16:12:52 +00009543 getStreamer().InitSections(false);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009544 Section = getStreamer().getCurrentSection().first;
9545 }
9546
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00009547 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009548 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00009549 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009550 else
Rafael Espindola7b514962014-02-04 18:34:04 +00009551 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009552
9553 return false;
9554}
9555
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009556/// parseDirectivePersonalityIndex
9557/// ::= .personalityindex index
9558bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009559 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009560 bool HasExistingPersonality = UC.hasPersonality();
9561
9562 UC.recordPersonalityIndex(L);
9563
9564 if (!UC.hasFnStart()) {
9565 Parser.eatToEndOfStatement();
9566 Error(L, ".fnstart must precede .personalityindex directive");
9567 return false;
9568 }
9569 if (UC.cantUnwind()) {
9570 Parser.eatToEndOfStatement();
9571 Error(L, ".personalityindex cannot be used with .cantunwind");
9572 UC.emitCantUnwindLocNotes();
9573 return false;
9574 }
9575 if (UC.hasHandlerData()) {
9576 Parser.eatToEndOfStatement();
9577 Error(L, ".personalityindex must precede .handlerdata directive");
9578 UC.emitHandlerDataLocNotes();
9579 return false;
9580 }
9581 if (HasExistingPersonality) {
9582 Parser.eatToEndOfStatement();
9583 Error(L, "multiple personality directives");
9584 UC.emitPersonalityLocNotes();
9585 return false;
9586 }
9587
9588 const MCExpr *IndexExpression;
9589 SMLoc IndexLoc = Parser.getTok().getLoc();
9590 if (Parser.parseExpression(IndexExpression)) {
9591 Parser.eatToEndOfStatement();
9592 return false;
9593 }
9594
9595 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9596 if (!CE) {
9597 Parser.eatToEndOfStatement();
9598 Error(IndexLoc, "index must be a constant number");
9599 return false;
9600 }
9601 if (CE->getValue() < 0 ||
9602 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9603 Parser.eatToEndOfStatement();
9604 Error(IndexLoc, "personality routine index should be in range [0-3]");
9605 return false;
9606 }
9607
9608 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9609 return false;
9610}
9611
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009612/// parseDirectiveUnwindRaw
9613/// ::= .unwind_raw offset, opcode [, opcode...]
9614bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009615 MCAsmParser &Parser = getParser();
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009616 if (!UC.hasFnStart()) {
9617 Parser.eatToEndOfStatement();
9618 Error(L, ".fnstart must precede .unwind_raw directives");
9619 return false;
9620 }
9621
9622 int64_t StackOffset;
9623
9624 const MCExpr *OffsetExpr;
9625 SMLoc OffsetLoc = getLexer().getLoc();
9626 if (getLexer().is(AsmToken::EndOfStatement) ||
9627 getParser().parseExpression(OffsetExpr)) {
9628 Error(OffsetLoc, "expected expression");
9629 Parser.eatToEndOfStatement();
9630 return false;
9631 }
9632
9633 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9634 if (!CE) {
9635 Error(OffsetLoc, "offset must be a constant");
9636 Parser.eatToEndOfStatement();
9637 return false;
9638 }
9639
9640 StackOffset = CE->getValue();
9641
9642 if (getLexer().isNot(AsmToken::Comma)) {
9643 Error(getLexer().getLoc(), "expected comma");
9644 Parser.eatToEndOfStatement();
9645 return false;
9646 }
9647 Parser.Lex();
9648
9649 SmallVector<uint8_t, 16> Opcodes;
9650 for (;;) {
9651 const MCExpr *OE;
9652
9653 SMLoc OpcodeLoc = getLexer().getLoc();
9654 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9655 Error(OpcodeLoc, "expected opcode expression");
9656 Parser.eatToEndOfStatement();
9657 return false;
9658 }
9659
9660 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9661 if (!OC) {
9662 Error(OpcodeLoc, "opcode value must be a constant");
9663 Parser.eatToEndOfStatement();
9664 return false;
9665 }
9666
9667 const int64_t Opcode = OC->getValue();
9668 if (Opcode & ~0xff) {
9669 Error(OpcodeLoc, "invalid opcode");
9670 Parser.eatToEndOfStatement();
9671 return false;
9672 }
9673
9674 Opcodes.push_back(uint8_t(Opcode));
9675
9676 if (getLexer().is(AsmToken::EndOfStatement))
9677 break;
9678
9679 if (getLexer().isNot(AsmToken::Comma)) {
9680 Error(getLexer().getLoc(), "unexpected token in directive");
9681 Parser.eatToEndOfStatement();
9682 return false;
9683 }
9684
9685 Parser.Lex();
9686 }
9687
9688 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9689
9690 Parser.Lex();
9691 return false;
9692}
9693
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009694/// parseDirectiveTLSDescSeq
9695/// ::= .tlsdescseq tls-variable
9696bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009697 MCAsmParser &Parser = getParser();
9698
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009699 if (getLexer().isNot(AsmToken::Identifier)) {
9700 TokError("expected variable after '.tlsdescseq' directive");
9701 Parser.eatToEndOfStatement();
9702 return false;
9703 }
9704
9705 const MCSymbolRefExpr *SRE =
9706 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9707 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9708 Lex();
9709
9710 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9711 Error(Parser.getTok().getLoc(), "unexpected token");
9712 Parser.eatToEndOfStatement();
9713 return false;
9714 }
9715
9716 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9717 return false;
9718}
9719
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009720/// parseDirectiveMovSP
9721/// ::= .movsp reg [, #offset]
9722bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009723 MCAsmParser &Parser = getParser();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009724 if (!UC.hasFnStart()) {
9725 Parser.eatToEndOfStatement();
9726 Error(L, ".fnstart must precede .movsp directives");
9727 return false;
9728 }
9729 if (UC.getFPReg() != ARM::SP) {
9730 Parser.eatToEndOfStatement();
9731 Error(L, "unexpected .movsp directive");
9732 return false;
9733 }
9734
9735 SMLoc SPRegLoc = Parser.getTok().getLoc();
9736 int SPReg = tryParseRegister();
9737 if (SPReg == -1) {
9738 Parser.eatToEndOfStatement();
9739 Error(SPRegLoc, "register expected");
9740 return false;
9741 }
9742
9743 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9744 Parser.eatToEndOfStatement();
9745 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9746 return false;
9747 }
9748
9749 int64_t Offset = 0;
9750 if (Parser.getTok().is(AsmToken::Comma)) {
9751 Parser.Lex();
9752
9753 if (Parser.getTok().isNot(AsmToken::Hash)) {
9754 Error(Parser.getTok().getLoc(), "expected #constant");
9755 Parser.eatToEndOfStatement();
9756 return false;
9757 }
9758 Parser.Lex();
9759
9760 const MCExpr *OffsetExpr;
9761 SMLoc OffsetLoc = Parser.getTok().getLoc();
9762 if (Parser.parseExpression(OffsetExpr)) {
9763 Parser.eatToEndOfStatement();
9764 Error(OffsetLoc, "malformed offset expression");
9765 return false;
9766 }
9767
9768 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9769 if (!CE) {
9770 Parser.eatToEndOfStatement();
9771 Error(OffsetLoc, "offset must be an immediate constant");
9772 return false;
9773 }
9774
9775 Offset = CE->getValue();
9776 }
9777
9778 getTargetStreamer().emitMovSP(SPReg, Offset);
9779 UC.saveFPReg(SPReg);
9780
9781 return false;
9782}
9783
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009784/// parseDirectiveObjectArch
9785/// ::= .object_arch name
9786bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009787 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009788 if (getLexer().isNot(AsmToken::Identifier)) {
9789 Error(getLexer().getLoc(), "unexpected token");
9790 Parser.eatToEndOfStatement();
9791 return false;
9792 }
9793
9794 StringRef Arch = Parser.getTok().getString();
9795 SMLoc ArchLoc = Parser.getTok().getLoc();
9796 getLexer().Lex();
9797
9798 unsigned ID = StringSwitch<unsigned>(Arch)
9799#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9800 .Case(NAME, ARM::ID)
9801#define ARM_ARCH_ALIAS(NAME, ID) \
9802 .Case(NAME, ARM::ID)
9803#include "MCTargetDesc/ARMArchName.def"
9804#undef ARM_ARCH_NAME
9805#undef ARM_ARCH_ALIAS
9806 .Default(ARM::INVALID_ARCH);
9807
9808 if (ID == ARM::INVALID_ARCH) {
9809 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9810 Parser.eatToEndOfStatement();
9811 return false;
9812 }
9813
9814 getTargetStreamer().emitObjectArch(ID);
9815
9816 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9817 Error(getLexer().getLoc(), "unexpected token");
9818 Parser.eatToEndOfStatement();
9819 }
9820
9821 return false;
9822}
9823
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009824/// parseDirectiveAlign
9825/// ::= .align
9826bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9827 // NOTE: if this is not the end of the statement, fall back to the target
9828 // agnostic handling for this directive which will correctly handle this.
9829 if (getLexer().isNot(AsmToken::EndOfStatement))
9830 return true;
9831
9832 // '.align' is target specifically handled to mean 2**2 byte alignment.
9833 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9834 getStreamer().EmitCodeAlignment(4, 0);
9835 else
9836 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9837
9838 return false;
9839}
9840
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009841/// parseDirectiveThumbSet
9842/// ::= .thumb_set name, value
9843bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009844 MCAsmParser &Parser = getParser();
9845
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009846 StringRef Name;
9847 if (Parser.parseIdentifier(Name)) {
9848 TokError("expected identifier after '.thumb_set'");
9849 Parser.eatToEndOfStatement();
9850 return false;
9851 }
9852
9853 if (getLexer().isNot(AsmToken::Comma)) {
9854 TokError("expected comma after name '" + Name + "'");
9855 Parser.eatToEndOfStatement();
9856 return false;
9857 }
9858 Lex();
9859
9860 const MCExpr *Value;
9861 if (Parser.parseExpression(Value)) {
9862 TokError("missing expression");
9863 Parser.eatToEndOfStatement();
9864 return false;
9865 }
9866
9867 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9868 TokError("unexpected token");
9869 Parser.eatToEndOfStatement();
9870 return false;
9871 }
9872 Lex();
9873
9874 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
Rafael Espindola466d6632014-04-27 20:23:58 +00009875 getTargetStreamer().emitThumbSet(Alias, Value);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009876 return false;
9877}
9878
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009879/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009880extern "C" void LLVMInitializeARMAsmParser() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00009881 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9882 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9883 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9884 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009885}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009886
Chris Lattner3e4582a2010-09-06 19:11:01 +00009887#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009888#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009889#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009890#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009891
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009892static const struct {
9893 const char *Name;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009894 const unsigned ArchCheck;
9895 const uint64_t Features;
9896} Extensions[] = {
9897 { "crc", Feature_HasV8, ARM::FeatureCRC },
9898 { "crypto", Feature_HasV8,
9899 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9900 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
9901 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
9902 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
9903 // FIXME: iWMMXT not supported
9904 { "iwmmxt", Feature_None, 0 },
9905 // FIXME: iWMMXT2 not supported
9906 { "iwmmxt2", Feature_None, 0 },
9907 // FIXME: Maverick not supported
9908 { "maverick", Feature_None, 0 },
9909 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
9910 // FIXME: ARMv6-m OS Extensions feature not checked
9911 { "os", Feature_None, 0 },
9912 // FIXME: Also available in ARMv6-K
9913 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
9914 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9915 // FIXME: Only available in A-class, isel not predicated
9916 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
9917 // FIXME: xscale not supported
9918 { "xscale", Feature_None, 0 },
9919};
9920
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009921/// parseDirectiveArchExtension
9922/// ::= .arch_extension [no]feature
9923bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009924 MCAsmParser &Parser = getParser();
9925
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009926 if (getLexer().isNot(AsmToken::Identifier)) {
9927 Error(getLexer().getLoc(), "unexpected token");
9928 Parser.eatToEndOfStatement();
9929 return false;
9930 }
9931
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009932 StringRef Name = Parser.getTok().getString();
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009933 SMLoc ExtLoc = Parser.getTok().getLoc();
9934 getLexer().Lex();
9935
9936 bool EnableFeature = true;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009937 if (Name.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009938 EnableFeature = false;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009939 Name = Name.substr(2);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009940 }
9941
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009942 for (const auto &Extension : Extensions) {
9943 if (Extension.Name != Name)
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009944 continue;
9945
Saleem Abdulrasool8988c2a2014-07-27 19:07:09 +00009946 if (!Extension.Features)
9947 report_fatal_error("unsupported architectural extension: " + Name);
9948
9949 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) {
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009950 Error(ExtLoc, "architectural extension '" + Name + "' is not "
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009951 "allowed for the current base architecture");
9952 return false;
9953 }
9954
Tim Northover26bb14e2014-08-18 11:49:42 +00009955 uint64_t ToggleFeatures = EnableFeature
Saleem Abdulrasool78c44722014-08-17 19:20:38 +00009956 ? (~STI.getFeatureBits() & Extension.Features)
9957 : ( STI.getFeatureBits() & Extension.Features);
Tim Northover26bb14e2014-08-18 11:49:42 +00009958 uint64_t Features =
Saleem Abdulrasool78c44722014-08-17 19:20:38 +00009959 ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
9960 setAvailableFeatures(Features);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009961 return false;
9962 }
9963
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009964 Error(ExtLoc, "unknown architectural extension: " + Name);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009965 Parser.eatToEndOfStatement();
9966 return false;
9967}
9968
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009969// Define this matcher function after the auto-generated include so we
9970// have the match class enum definitions.
David Blaikie960ea3f2014-06-08 16:18:35 +00009971unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009972 unsigned Kind) {
David Blaikie960ea3f2014-06-08 16:18:35 +00009973 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009974 // If the kind is a token for a literal immediate, check if our asm
9975 // operand matches. This is for InstAliases which have a fixed-value
9976 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009977 switch (Kind) {
9978 default: break;
9979 case MCK__35_0:
David Blaikie960ea3f2014-06-08 16:18:35 +00009980 if (Op.isImm())
9981 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009982 if (CE->getValue() == 0)
9983 return Match_Success;
9984 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00009985 case MCK_ModImm:
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009986 case MCK_ARMSOImm:
David Blaikie960ea3f2014-06-08 16:18:35 +00009987 if (Op.isImm()) {
9988 const MCExpr *SOExpr = Op.getImm();
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009989 int64_t Value;
9990 if (!SOExpr->EvaluateAsAbsolute(Value))
Stepan Dyatkovskiydf657cc2014-03-29 13:12:40 +00009991 return Match_Success;
Richard Barton3db1d582014-05-01 11:37:44 +00009992 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
9993 "expression value must be representable in 32 bits");
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009994 }
9995 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00009996 case MCK_GPRPair:
David Blaikie960ea3f2014-06-08 16:18:35 +00009997 if (Op.isReg() &&
9998 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00009999 return Match_Success;
10000 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010001 }
10002 return Match_InvalidOperand;
10003}