blob: b080c92820f452b668ffe27783d21397719195b9 [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
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004421 SMLoc S = Parser.getTok().getLoc();
4422
Asiri Rathnayake13cef352014-12-04 19:34:59 +00004423 // 1) A mod_imm operand can appear in the place of a register name:
4424 // add r0, #mod_imm
4425 // add r0, r0, #mod_imm
4426 // to correctly handle the latter, we bail out as soon as we see an
4427 // identifier.
4428 //
4429 // 2) Similarly, we do not want to parse into complex operands:
4430 // mov r0, #mod_imm
4431 // mov r0, :lower16:(_foo)
4432 if (Parser.getTok().is(AsmToken::Identifier) ||
4433 Parser.getTok().is(AsmToken::Colon))
4434 return MatchOperand_NoMatch;
4435
4436 // Hash (dollar) is optional as per the ARMARM
4437 if (Parser.getTok().is(AsmToken::Hash) ||
4438 Parser.getTok().is(AsmToken::Dollar)) {
4439 // Avoid parsing into complex operands (#:)
4440 if (Lexer.peekTok().is(AsmToken::Colon))
4441 return MatchOperand_NoMatch;
4442
4443 // Eat the hash (dollar)
4444 Parser.Lex();
4445 }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004446
4447 SMLoc Sx1, Ex1;
4448 Sx1 = Parser.getTok().getLoc();
4449 const MCExpr *Imm1Exp;
4450 if (getParser().parseExpression(Imm1Exp, Ex1)) {
4451 Error(Sx1, "malformed expression");
4452 return MatchOperand_ParseFail;
4453 }
4454
4455 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm1Exp);
4456
4457 if (CE) {
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004458 // Immediate must fit within 32-bits
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004459 Imm1 = CE->getValue();
4460 if (Imm1 < INT32_MIN || Imm1 > UINT32_MAX) {
4461 Error(Sx1, "immediate operand must be representable with 32 bits");
4462 return MatchOperand_ParseFail;
4463 }
4464
4465 int Enc = ARM_AM::getSOImmVal(Imm1);
4466 if (Enc != -1 && Parser.getTok().is(AsmToken::EndOfStatement)) {
4467 // We have a match!
4468 Operands.push_back(ARMOperand::CreateModImm((Enc & 0xFF),
4469 (Enc & 0xF00) >> 7,
4470 Sx1, Ex1));
4471 return MatchOperand_Success;
4472 }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004473
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004474 // We have parsed an immediate which is not for us, fallback to a plain
4475 // immediate. This can happen for instruction aliases. For an example,
4476 // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform
4477 // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite
4478 // instruction with a mod_imm operand. The alias is defined such that the
4479 // parser method is shared, that's why we have to do this here.
4480 if (Parser.getTok().is(AsmToken::EndOfStatement)) {
4481 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4482 return MatchOperand_Success;
4483 }
4484 } else {
4485 // Operands like #(l1 - l2) can only be evaluated at a later stage (via an
4486 // MCFixup). Fallback to a plain immediate.
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004487 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4488 return MatchOperand_Success;
4489 }
4490
4491 // From this point onward, we expect the input to be a (#bits, #rot) pair
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004492 if (Parser.getTok().isNot(AsmToken::Comma)) {
4493 Error(Sx1, "expected modified immediate operand: #[0, 255], #even[0-30]");
4494 return MatchOperand_ParseFail;
4495 }
4496
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004497 if (Imm1 & ~0xFF) {
4498 Error(Sx1, "immediate operand must a number in the range [0, 255]");
4499 return MatchOperand_ParseFail;
4500 }
4501
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004502 // Eat the comma
4503 Parser.Lex();
4504
4505 // Repeat for #rot
4506 SMLoc Sx2, Ex2;
4507 Sx2 = Parser.getTok().getLoc();
4508
Asiri Rathnayake13cef352014-12-04 19:34:59 +00004509 // Eat the optional hash (dollar)
4510 if (Parser.getTok().is(AsmToken::Hash) ||
4511 Parser.getTok().is(AsmToken::Dollar))
4512 Parser.Lex();
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004513
4514 const MCExpr *Imm2Exp;
4515 if (getParser().parseExpression(Imm2Exp, Ex2)) {
4516 Error(Sx2, "malformed expression");
4517 return MatchOperand_ParseFail;
4518 }
4519
4520 CE = dyn_cast<MCConstantExpr>(Imm2Exp);
4521
4522 if (CE) {
4523 Imm2 = CE->getValue();
4524 if (!(Imm2 & ~0x1E)) {
4525 // We have a match!
4526 Operands.push_back(ARMOperand::CreateModImm(Imm1, Imm2, S, Ex2));
4527 return MatchOperand_Success;
4528 }
4529 Error(Sx2, "immediate operand must an even number in the range [0, 30]");
4530 return MatchOperand_ParseFail;
4531 } else {
4532 Error(Sx2, "constant expression expected");
4533 return MatchOperand_ParseFail;
4534 }
4535}
4536
4537ARMAsmParser::OperandMatchResultTy
David Blaikie960ea3f2014-06-08 16:18:35 +00004538ARMAsmParser::parseBitfield(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004539 MCAsmParser &Parser = getParser();
Jim Grosbach864b6092011-07-28 21:34:26 +00004540 SMLoc S = Parser.getTok().getLoc();
4541 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004542 if (Parser.getTok().isNot(AsmToken::Hash) &&
4543 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004544 Error(Parser.getTok().getLoc(), "'#' expected");
4545 return MatchOperand_ParseFail;
4546 }
4547 Parser.Lex(); // Eat hash token.
4548
4549 const MCExpr *LSBExpr;
4550 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004551 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004552 Error(E, "malformed immediate expression");
4553 return MatchOperand_ParseFail;
4554 }
4555 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4556 if (!CE) {
4557 Error(E, "'lsb' operand must be an immediate");
4558 return MatchOperand_ParseFail;
4559 }
4560
4561 int64_t LSB = CE->getValue();
4562 // The LSB must be in the range [0,31]
4563 if (LSB < 0 || LSB > 31) {
4564 Error(E, "'lsb' operand must be in the range [0,31]");
4565 return MatchOperand_ParseFail;
4566 }
4567 E = Parser.getTok().getLoc();
4568
4569 // Expect another immediate operand.
4570 if (Parser.getTok().isNot(AsmToken::Comma)) {
4571 Error(Parser.getTok().getLoc(), "too few operands");
4572 return MatchOperand_ParseFail;
4573 }
4574 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004575 if (Parser.getTok().isNot(AsmToken::Hash) &&
4576 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004577 Error(Parser.getTok().getLoc(), "'#' expected");
4578 return MatchOperand_ParseFail;
4579 }
4580 Parser.Lex(); // Eat hash token.
4581
4582 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004583 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004584 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004585 Error(E, "malformed immediate expression");
4586 return MatchOperand_ParseFail;
4587 }
4588 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4589 if (!CE) {
4590 Error(E, "'width' operand must be an immediate");
4591 return MatchOperand_ParseFail;
4592 }
4593
4594 int64_t Width = CE->getValue();
4595 // The LSB must be in the range [1,32-lsb]
4596 if (Width < 1 || Width > 32 - LSB) {
4597 Error(E, "'width' operand must be in the range [1,32-lsb]");
4598 return MatchOperand_ParseFail;
4599 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004600
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004601 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004602
4603 return MatchOperand_Success;
4604}
4605
David Blaikie960ea3f2014-06-08 16:18:35 +00004606ARMAsmParser::OperandMatchResultTy
4607ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
Jim Grosbachd3595712011-08-03 23:50:40 +00004608 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004609 // postidx_reg := '+' register {, shift}
4610 // | '-' register {, shift}
4611 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004612
4613 // This method must return MatchOperand_NoMatch without consuming any tokens
4614 // in the case where there is no match, as other alternatives take other
4615 // parse methods.
Rafael Espindola961d4692014-11-11 05:18:41 +00004616 MCAsmParser &Parser = getParser();
Jim Grosbachd3595712011-08-03 23:50:40 +00004617 AsmToken Tok = Parser.getTok();
4618 SMLoc S = Tok.getLoc();
4619 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004620 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004621 if (Tok.is(AsmToken::Plus)) {
4622 Parser.Lex(); // Eat the '+' token.
4623 haveEaten = true;
4624 } else if (Tok.is(AsmToken::Minus)) {
4625 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004626 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004627 haveEaten = true;
4628 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004629
4630 SMLoc E = Parser.getTok().getEndLoc();
4631 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004632 if (Reg == -1) {
4633 if (!haveEaten)
4634 return MatchOperand_NoMatch;
4635 Error(Parser.getTok().getLoc(), "register expected");
4636 return MatchOperand_ParseFail;
4637 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004638
Jim Grosbachc320c852011-08-05 21:28:30 +00004639 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4640 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004641 if (Parser.getTok().is(AsmToken::Comma)) {
4642 Parser.Lex(); // Eat the ','.
4643 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4644 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004645
4646 // FIXME: Only approximates end...may include intervening whitespace.
4647 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004648 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004649
4650 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4651 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004652
4653 return MatchOperand_Success;
4654}
4655
David Blaikie960ea3f2014-06-08 16:18:35 +00004656ARMAsmParser::OperandMatchResultTy
4657ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004658 // Check for a post-index addressing register operand. Specifically:
4659 // am3offset := '+' register
4660 // | '-' register
4661 // | register
4662 // | # imm
4663 // | # + imm
4664 // | # - imm
4665
4666 // This method must return MatchOperand_NoMatch without consuming any tokens
4667 // in the case where there is no match, as other alternatives take other
4668 // parse methods.
Rafael Espindola961d4692014-11-11 05:18:41 +00004669 MCAsmParser &Parser = getParser();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004670 AsmToken Tok = Parser.getTok();
4671 SMLoc S = Tok.getLoc();
4672
4673 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004674 if (Parser.getTok().is(AsmToken::Hash) ||
4675 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004676 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004677 // Explicitly look for a '-', as we need to encode negative zero
4678 // differently.
4679 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4680 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004681 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004682 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004683 return MatchOperand_ParseFail;
4684 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4685 if (!CE) {
4686 Error(S, "constant expression expected");
4687 return MatchOperand_ParseFail;
4688 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004689 // Negative zero is encoded as the flag value INT32_MIN.
4690 int32_t Val = CE->getValue();
4691 if (isNegative && Val == 0)
4692 Val = INT32_MIN;
4693
4694 Operands.push_back(
4695 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4696
4697 return MatchOperand_Success;
4698 }
4699
4700
4701 bool haveEaten = false;
4702 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004703 if (Tok.is(AsmToken::Plus)) {
4704 Parser.Lex(); // Eat the '+' token.
4705 haveEaten = true;
4706 } else if (Tok.is(AsmToken::Minus)) {
4707 Parser.Lex(); // Eat the '-' token.
4708 isAdd = false;
4709 haveEaten = true;
4710 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004711
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004712 Tok = Parser.getTok();
4713 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004714 if (Reg == -1) {
4715 if (!haveEaten)
4716 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004717 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004718 return MatchOperand_ParseFail;
4719 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004720
4721 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004722 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004723
4724 return MatchOperand_Success;
4725}
4726
Tim Northovereb5e4d52013-07-22 09:06:12 +00004727/// Convert parsed operands to MCInst. Needed here because this instruction
4728/// only has two register operands, but multiplication is commutative so
4729/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
David Blaikie960ea3f2014-06-08 16:18:35 +00004730void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
4731 const OperandVector &Operands) {
4732 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1);
4733 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004734 // If we have a three-operand form, make sure to set Rn to be the operand
4735 // that isn't the same as Rd.
4736 unsigned RegOp = 4;
4737 if (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00004738 ((ARMOperand &)*Operands[4]).getReg() ==
4739 ((ARMOperand &)*Operands[3]).getReg())
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004740 RegOp = 5;
David Blaikie960ea3f2014-06-08 16:18:35 +00004741 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004742 Inst.addOperand(Inst.getOperand(0));
David Blaikie960ea3f2014-06-08 16:18:35 +00004743 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004744}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004745
David Blaikie960ea3f2014-06-08 16:18:35 +00004746void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
4747 const OperandVector &Operands) {
Mihai Popaad18d3c2013-08-09 10:38:32 +00004748 int CondOp = -1, ImmOp = -1;
4749 switch(Inst.getOpcode()) {
4750 case ARM::tB:
4751 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4752
4753 case ARM::t2B:
4754 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4755
4756 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4757 }
4758 // first decide whether or not the branch should be conditional
4759 // by looking at it's location relative to an IT block
4760 if(inITBlock()) {
4761 // inside an IT block we cannot have any conditional branches. any
4762 // such instructions needs to be converted to unconditional form
4763 switch(Inst.getOpcode()) {
4764 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4765 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4766 }
4767 } else {
4768 // outside IT blocks we can only have unconditional branches with AL
4769 // condition code or conditional branches with non-AL condition code
David Blaikie960ea3f2014-06-08 16:18:35 +00004770 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode();
Mihai Popaad18d3c2013-08-09 10:38:32 +00004771 switch(Inst.getOpcode()) {
4772 case ARM::tB:
4773 case ARM::tBcc:
4774 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4775 break;
4776 case ARM::t2B:
4777 case ARM::t2Bcc:
4778 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4779 break;
4780 }
4781 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004782
Mihai Popaad18d3c2013-08-09 10:38:32 +00004783 // now decide on encoding size based on branch target range
4784 switch(Inst.getOpcode()) {
4785 // classify tB as either t2B or t1B based on range of immediate operand
4786 case ARM::tB: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004787 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4788 if (!op.isSignedOffset<11, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004789 Inst.setOpcode(ARM::t2B);
4790 break;
4791 }
4792 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4793 case ARM::tBcc: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004794 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4795 if (!op.isSignedOffset<8, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004796 Inst.setOpcode(ARM::t2Bcc);
4797 break;
4798 }
4799 }
David Blaikie960ea3f2014-06-08 16:18:35 +00004800 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1);
4801 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2);
Mihai Popaad18d3c2013-08-09 10:38:32 +00004802}
4803
Bill Wendlinge18980a2010-11-06 22:36:58 +00004804/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004805/// or an error. The first token must be a '[' when called.
David Blaikie960ea3f2014-06-08 16:18:35 +00004806bool ARMAsmParser::parseMemory(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004807 MCAsmParser &Parser = getParser();
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004808 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004809 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004810 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004811 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004812 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004813
Sean Callanan936b0d32010-01-19 21:44:56 +00004814 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004815 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004816 if (BaseRegNum == -1)
4817 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004818
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004819 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004820 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004821 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4822 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004823 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004824
Jim Grosbachd3595712011-08-03 23:50:40 +00004825 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004826 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004827 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004828
Craig Topper062a2ba2014-04-25 05:30:21 +00004829 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4830 ARM_AM::no_shift, 0, 0, false,
4831 S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004832
Jim Grosbach40700e02011-09-19 18:42:21 +00004833 // If there's a pre-indexing writeback marker, '!', just add it as a token
4834 // operand. It's rather odd, but syntactically valid.
4835 if (Parser.getTok().is(AsmToken::Exclaim)) {
4836 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4837 Parser.Lex(); // Eat the '!'.
4838 }
4839
Jim Grosbachd3595712011-08-03 23:50:40 +00004840 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004841 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004842
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004843 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4844 "Lost colon or comma in memory operand?!");
4845 if (Tok.is(AsmToken::Comma)) {
4846 Parser.Lex(); // Eat the comma.
4847 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004848
Jim Grosbacha95ec992011-10-11 17:29:55 +00004849 // If we have a ':', it's an alignment specifier.
4850 if (Parser.getTok().is(AsmToken::Colon)) {
4851 Parser.Lex(); // Eat the ':'.
4852 E = Parser.getTok().getLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00004853 SMLoc AlignmentLoc = Tok.getLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004854
4855 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004856 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004857 return true;
4858
4859 // The expression has to be a constant. Memory references with relocations
4860 // don't come through here, as they use the <label> forms of the relevant
4861 // instructions.
4862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4863 if (!CE)
4864 return Error (E, "constant expression expected");
4865
4866 unsigned Align = 0;
4867 switch (CE->getValue()) {
4868 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004869 return Error(E,
4870 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4871 case 16: Align = 2; break;
4872 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004873 case 64: Align = 8; break;
4874 case 128: Align = 16; break;
4875 case 256: Align = 32; break;
4876 }
4877
4878 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004879 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004880 return Error(Parser.getTok().getLoc(), "']' expected");
4881 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004882 Parser.Lex(); // Eat right bracket token.
4883
4884 // Don't worry about range checking the value here. That's handled by
4885 // the is*() predicates.
Craig Topper062a2ba2014-04-25 05:30:21 +00004886 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004887 ARM_AM::no_shift, 0, Align,
Kevin Enderby488f20b2014-04-10 20:18:58 +00004888 false, S, E, AlignmentLoc));
Jim Grosbacha95ec992011-10-11 17:29:55 +00004889
4890 // If there's a pre-indexing writeback marker, '!', just add it as a token
4891 // operand.
4892 if (Parser.getTok().is(AsmToken::Exclaim)) {
4893 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4894 Parser.Lex(); // Eat the '!'.
4895 }
4896
4897 return false;
4898 }
4899
4900 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004901 // offset. Be friendly and also accept a plain integer (without a leading
4902 // hash) for gas compatibility.
4903 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004904 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004905 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004906 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004907 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004908 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004909
Owen Anderson967674d2011-08-29 19:36:44 +00004910 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004911 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004912 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004913 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004914
4915 // The expression has to be a constant. Memory references with relocations
4916 // don't come through here, as they use the <label> forms of the relevant
4917 // instructions.
4918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4919 if (!CE)
4920 return Error (E, "constant expression expected");
4921
Owen Anderson967674d2011-08-29 19:36:44 +00004922 // If the constant was #-0, represent it as INT32_MIN.
4923 int32_t Val = CE->getValue();
4924 if (isNegative && Val == 0)
4925 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4926
Jim Grosbachd3595712011-08-03 23:50:40 +00004927 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004928 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004929 return Error(Parser.getTok().getLoc(), "']' expected");
4930 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004931 Parser.Lex(); // Eat right bracket token.
4932
4933 // Don't worry about range checking the value here. That's handled by
4934 // the is*() predicates.
4935 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004936 ARM_AM::no_shift, 0, 0,
4937 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004938
4939 // If there's a pre-indexing writeback marker, '!', just add it as a token
4940 // operand.
4941 if (Parser.getTok().is(AsmToken::Exclaim)) {
4942 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4943 Parser.Lex(); // Eat the '!'.
4944 }
4945
4946 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004947 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004948
4949 // The register offset is optionally preceded by a '+' or '-'
4950 bool isNegative = false;
4951 if (Parser.getTok().is(AsmToken::Minus)) {
4952 isNegative = true;
4953 Parser.Lex(); // Eat the '-'.
4954 } else if (Parser.getTok().is(AsmToken::Plus)) {
4955 // Nothing to do.
4956 Parser.Lex(); // Eat the '+'.
4957 }
4958
4959 E = Parser.getTok().getLoc();
4960 int OffsetRegNum = tryParseRegister();
4961 if (OffsetRegNum == -1)
4962 return Error(E, "register expected");
4963
4964 // If there's a shift operator, handle it.
4965 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004966 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004967 if (Parser.getTok().is(AsmToken::Comma)) {
4968 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004969 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004970 return true;
4971 }
4972
4973 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004974 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004975 return Error(Parser.getTok().getLoc(), "']' expected");
4976 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004977 Parser.Lex(); // Eat right bracket token.
4978
Craig Topper062a2ba2014-04-25 05:30:21 +00004979 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004980 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004981 S, E));
4982
Jim Grosbachc320c852011-08-05 21:28:30 +00004983 // If there's a pre-indexing writeback marker, '!', just add it as a token
4984 // operand.
4985 if (Parser.getTok().is(AsmToken::Exclaim)) {
4986 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4987 Parser.Lex(); // Eat the '!'.
4988 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004989
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004990 return false;
4991}
4992
Jim Grosbachd3595712011-08-03 23:50:40 +00004993/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004994/// ( lsl | lsr | asr | ror ) , # shift_amount
4995/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004996/// return true if it parses a shift otherwise it returns false.
4997bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4998 unsigned &Amount) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004999 MCAsmParser &Parser = getParser();
Jim Grosbachd3595712011-08-03 23:50:40 +00005000 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00005001 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005002 if (Tok.isNot(AsmToken::Identifier))
5003 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00005004 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00005005 if (ShiftName == "lsl" || ShiftName == "LSL" ||
5006 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00005007 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005008 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00005009 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005010 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00005011 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005012 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00005013 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005014 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00005015 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005016 else
Jim Grosbachd3595712011-08-03 23:50:40 +00005017 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00005018 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005019
Jim Grosbachd3595712011-08-03 23:50:40 +00005020 // rrx stands alone.
5021 Amount = 0;
5022 if (St != ARM_AM::rrx) {
5023 Loc = Parser.getTok().getLoc();
5024 // A '#' and a shift amount.
5025 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005026 if (HashTok.isNot(AsmToken::Hash) &&
5027 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00005028 return Error(HashTok.getLoc(), "'#' expected");
5029 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005030
Jim Grosbachd3595712011-08-03 23:50:40 +00005031 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005032 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00005033 return true;
5034 // Range check the immediate.
5035 // lsl, ror: 0 <= imm <= 31
5036 // lsr, asr: 0 <= imm <= 32
5037 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
5038 if (!CE)
5039 return Error(Loc, "shift amount must be an immediate");
5040 int64_t Imm = CE->getValue();
5041 if (Imm < 0 ||
5042 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
5043 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
5044 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00005045 // If <ShiftTy> #0, turn it into a no_shift.
5046 if (Imm == 0)
5047 St = ARM_AM::lsl;
5048 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
5049 if (Imm == 32)
5050 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00005051 Amount = Imm;
5052 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005053
5054 return false;
5055}
5056
Jim Grosbache7fbce72011-10-03 23:38:36 +00005057/// parseFPImm - A floating point immediate expression operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005058ARMAsmParser::OperandMatchResultTy
5059ARMAsmParser::parseFPImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005060 MCAsmParser &Parser = getParser();
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005061 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005062 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005063 // integer only.
5064 //
5065 // This routine still creates a generic Immediate operand, containing
5066 // a bitcast of the 64-bit floating point value. The various operands
5067 // that accept floats can check whether the value is valid for them
5068 // via the standard is*() predicates.
5069
Jim Grosbache7fbce72011-10-03 23:38:36 +00005070 SMLoc S = Parser.getTok().getLoc();
5071
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005072 if (Parser.getTok().isNot(AsmToken::Hash) &&
5073 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00005074 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00005075
5076 // Disambiguate the VMOV forms that can accept an FP immediate.
5077 // vmov.f32 <sreg>, #imm
5078 // vmov.f64 <dreg>, #imm
5079 // vmov.f32 <dreg>, #imm @ vector f32x2
5080 // vmov.f32 <qreg>, #imm @ vector f32x4
5081 //
5082 // There are also the NEON VMOV instructions which expect an
5083 // integer constant. Make sure we don't try to parse an FPImm
5084 // for these:
5085 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
David Blaikie960ea3f2014-06-08 16:18:35 +00005086 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]);
5087 bool isVmovf = TyOp.isToken() &&
5088 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64");
5089 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
5090 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
5091 Mnemonic.getToken() == "fconsts");
David Peixottoa872e0e2014-01-07 18:19:23 +00005092 if (!(isVmovf || isFconst))
Jim Grosbach741cd732011-10-17 22:26:03 +00005093 return MatchOperand_NoMatch;
5094
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00005095 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00005096
5097 // Handle negation, as that still comes through as a separate token.
5098 bool isNegative = false;
5099 if (Parser.getTok().is(AsmToken::Minus)) {
5100 isNegative = true;
5101 Parser.Lex();
5102 }
5103 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00005104 SMLoc Loc = Tok.getLoc();
David Peixottoa872e0e2014-01-07 18:19:23 +00005105 if (Tok.is(AsmToken::Real) && isVmovf) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005106 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00005107 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
5108 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005109 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00005110 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005111 Operands.push_back(ARMOperand::CreateImm(
5112 MCConstantExpr::Create(IntVal, getContext()),
5113 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00005114 return MatchOperand_Success;
5115 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005116 // Also handle plain integers. Instructions which allow floating point
5117 // immediates also allow a raw encoded 8-bit value.
David Peixottoa872e0e2014-01-07 18:19:23 +00005118 if (Tok.is(AsmToken::Integer) && isFconst) {
Jim Grosbache7fbce72011-10-03 23:38:36 +00005119 int64_t Val = Tok.getIntVal();
5120 Parser.Lex(); // Eat the token.
5121 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00005122 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00005123 return MatchOperand_ParseFail;
5124 }
David Peixottoa872e0e2014-01-07 18:19:23 +00005125 float RealVal = ARM_AM::getFPImmFloat(Val);
5126 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
5127
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005128 Operands.push_back(ARMOperand::CreateImm(
5129 MCConstantExpr::Create(Val, getContext()), S,
5130 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00005131 return MatchOperand_Success;
5132 }
5133
Jim Grosbach235c8d22012-01-19 02:47:30 +00005134 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00005135 return MatchOperand_ParseFail;
5136}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005137
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005138/// Parse a arm instruction operand. For now this parses the operand regardless
5139/// of the mnemonic.
David Blaikie960ea3f2014-06-08 16:18:35 +00005140bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005141 MCAsmParser &Parser = getParser();
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005142 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005143
5144 // Check if the current operand has a custom associated parser, if so, try to
5145 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00005146 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
5147 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005148 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00005149 // If there wasn't a custom match, try the generic matcher below. Otherwise,
5150 // there was a match, but an error occurred, in which case, just return that
5151 // the operand parsing failed.
5152 if (ResTy == MatchOperand_ParseFail)
5153 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005154
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005155 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005156 default:
5157 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00005158 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00005159 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00005160 // If we've seen a branch mnemonic, the next operand must be a label. This
5161 // is true even if the label is a register name. So "br r1" means branch to
5162 // label "r1".
5163 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
5164 if (!ExpectLabel) {
5165 if (!tryParseRegisterWithWriteBack(Operands))
5166 return false;
5167 int Res = tryParseShiftRegister(Operands);
5168 if (Res == 0) // success
5169 return false;
5170 else if (Res == -1) // irrecoverable error
5171 return true;
5172 // If this is VMRS, check for the apsr_nzcv operand.
5173 if (Mnemonic == "vmrs" &&
5174 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
5175 S = Parser.getTok().getLoc();
5176 Parser.Lex();
5177 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
5178 return false;
5179 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00005180 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00005181
5182 // Fall though for the Identifier case that is not a register or a
5183 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00005184 }
Jim Grosbach4e380352011-10-26 21:14:08 +00005185 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00005186 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00005187 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00005188 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00005189 // This was not a register so parse other operands that start with an
5190 // identifier (like labels) as expressions and create them as immediates.
5191 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005192 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005193 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00005194 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005195 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00005196 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
5197 return false;
5198 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005199 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005200 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00005201 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005202 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005203 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00005204 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00005205 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005206 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00005207 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00005208
5209 if (Parser.getTok().isNot(AsmToken::Colon)) {
5210 bool isNegative = Parser.getTok().is(AsmToken::Minus);
5211 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005212 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00005213 return true;
5214 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
5215 if (CE) {
5216 int32_t Val = CE->getValue();
5217 if (isNegative && Val == 0)
5218 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
5219 }
5220 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5221 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00005222
5223 // There can be a trailing '!' on operands that we want as a separate
Saleem Abdulrasool83e37702013-12-28 03:07:12 +00005224 // '!' Token operand. Handle that here. For example, the compatibility
Jim Grosbach9be2d712013-02-23 00:52:09 +00005225 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
5226 if (Parser.getTok().is(AsmToken::Exclaim)) {
5227 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
5228 Parser.getTok().getLoc()));
5229 Parser.Lex(); // Eat exclaim token
5230 }
Jim Grosbach003607f2012-04-16 21:18:46 +00005231 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00005232 }
Jim Grosbach003607f2012-04-16 21:18:46 +00005233 // w/ a ':' after the '#', it's just like a plain ':'.
5234 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00005235 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005236 case AsmToken::Colon: {
5237 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00005238 // FIXME: Check it's an expression prefix,
5239 // e.g. (FOO - :lower16:BAR) isn't legal.
5240 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005241 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00005242 return true;
5243
Evan Cheng965b3c72011-01-13 07:58:56 +00005244 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005245 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00005246 return true;
5247
Evan Cheng965b3c72011-01-13 07:58:56 +00005248 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00005249 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00005250 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00005251 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00005252 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005253 }
David Peixottoe407d092013-12-19 18:12:36 +00005254 case AsmToken::Equal: {
5255 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
5256 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
5257
David Peixottoe407d092013-12-19 18:12:36 +00005258 Parser.Lex(); // Eat '='
5259 const MCExpr *SubExprVal;
5260 if (getParser().parseExpression(SubExprVal))
5261 return true;
5262 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5263
David Peixottob9b73622014-02-04 17:22:40 +00005264 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
David Peixottoe407d092013-12-19 18:12:36 +00005265 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
5266 return false;
5267 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005268 }
5269}
5270
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005271// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00005272// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005273bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005274 MCAsmParser &Parser = getParser();
Evan Cheng965b3c72011-01-13 07:58:56 +00005275 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005276
Saleem Abdulrasool435f4562014-01-10 04:38:40 +00005277 // consume an optional '#' (GNU compatibility)
5278 if (getLexer().is(AsmToken::Hash))
5279 Parser.Lex();
5280
Jason W Kim1f7bc072011-01-11 23:53:41 +00005281 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00005282 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00005283 Parser.Lex(); // Eat ':'
5284
5285 if (getLexer().isNot(AsmToken::Identifier)) {
5286 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
5287 return true;
5288 }
5289
5290 StringRef IDVal = Parser.getTok().getIdentifier();
5291 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00005292 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005293 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00005294 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005295 } else {
5296 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
5297 return true;
5298 }
5299 Parser.Lex();
5300
5301 if (getLexer().isNot(AsmToken::Colon)) {
5302 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
5303 return true;
5304 }
5305 Parser.Lex(); // Eat the last ':'
5306 return false;
5307}
5308
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005309/// \brief Given a mnemonic, split out possible predication code and carry
5310/// setting letters to form a canonical mnemonic and flags.
5311//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005312// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005313// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005314StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005315 unsigned &PredicationCode,
5316 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005317 unsigned &ProcessorIMod,
5318 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005319 PredicationCode = ARMCC::AL;
5320 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005321 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005322
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005323 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005324 //
5325 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005326 if ((Mnemonic == "movs" && isThumb()) ||
5327 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
5328 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
5329 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
5330 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00005331 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005332 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
5333 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00005334 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00005335 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005336 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
5337 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
Charlie Turner4d88ae22014-12-01 08:33:28 +00005338 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic == "hvc" ||
5339 Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005340 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005341
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005342 // First, split out any predication code. Ignore mnemonics we know aren't
5343 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00005344 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00005345 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00005346 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00005347 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005348 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
5349 .Case("eq", ARMCC::EQ)
5350 .Case("ne", ARMCC::NE)
5351 .Case("hs", ARMCC::HS)
5352 .Case("cs", ARMCC::HS)
5353 .Case("lo", ARMCC::LO)
5354 .Case("cc", ARMCC::LO)
5355 .Case("mi", ARMCC::MI)
5356 .Case("pl", ARMCC::PL)
5357 .Case("vs", ARMCC::VS)
5358 .Case("vc", ARMCC::VC)
5359 .Case("hi", ARMCC::HI)
5360 .Case("ls", ARMCC::LS)
5361 .Case("ge", ARMCC::GE)
5362 .Case("lt", ARMCC::LT)
5363 .Case("gt", ARMCC::GT)
5364 .Case("le", ARMCC::LE)
5365 .Case("al", ARMCC::AL)
5366 .Default(~0U);
5367 if (CC != ~0U) {
5368 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
5369 PredicationCode = CC;
5370 }
Bill Wendling193961b2010-10-29 23:50:21 +00005371 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005372
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005373 // Next, determine if we have a carry setting bit. We explicitly ignore all
5374 // the instructions we know end in 's'.
5375 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00005376 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005377 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
5378 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
5379 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00005380 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00005381 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00005382 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00005383 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
David Peixottoa872e0e2014-01-07 18:19:23 +00005384 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00005385 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005386 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
5387 CarrySetting = true;
5388 }
5389
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005390 // The "cps" instruction can have a interrupt mode operand which is glued into
5391 // the mnemonic. Check if this is the case, split it and parse the imod op
5392 if (Mnemonic.startswith("cps")) {
5393 // Split out any imod code.
5394 unsigned IMod =
5395 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
5396 .Case("ie", ARM_PROC::IE)
5397 .Case("id", ARM_PROC::ID)
5398 .Default(~0U);
5399 if (IMod != ~0U) {
5400 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5401 ProcessorIMod = IMod;
5402 }
5403 }
5404
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005405 // The "it" instruction has the condition mask on the end of the mnemonic.
5406 if (Mnemonic.startswith("it")) {
5407 ITMask = Mnemonic.slice(2, Mnemonic.size());
5408 Mnemonic = Mnemonic.slice(0, 2);
5409 }
5410
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005411 return Mnemonic;
5412}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005413
5414/// \brief Given a canonical mnemonic, determine if the instruction ever allows
5415/// inclusion of carry set or predication code operands.
5416//
5417// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00005418void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00005419getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5420 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005421 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5422 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005423 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005424 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005425 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005426 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005427 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00005428 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005429 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005430 Mnemonic == "mla" || Mnemonic == "smlal" ||
5431 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005432 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00005433 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00005434 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005435
Tim Northover2c45a382013-06-26 16:52:40 +00005436 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5437 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00005438 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
5439 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
5440 Mnemonic.startswith("vsel") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00005441 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005442 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
5443 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Charlie Turner4d88ae22014-12-01 08:33:28 +00005444 Mnemonic == "vrintm" || Mnemonic.startswith("aes") || Mnemonic == "hvc" ||
Amara Emerson33089092013-09-19 11:59:01 +00005445 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5446 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00005447 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005448 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005449 } else if (!isThumb()) {
5450 // Some instructions are only predicable in Thumb mode
5451 CanAcceptPredicationCode
5452 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5453 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5454 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5455 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5456 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5457 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5458 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5459 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00005460 if (hasV6MOps())
5461 CanAcceptPredicationCode = Mnemonic != "movs";
5462 else
5463 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005464 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005465 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005466}
5467
Jim Grosbach7283da92011-08-16 21:12:37 +00005468bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
David Blaikie960ea3f2014-06-08 16:18:35 +00005469 OperandVector &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005470 // FIXME: This is all horribly hacky. We really need a better way to deal
5471 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005472
5473 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5474 // another does not. Specifically, the MOVW instruction does not. So we
5475 // special case it here and remove the defaulted (non-setting) cc_out
5476 // operand if that's the instruction we're trying to match.
5477 //
5478 // We do this as post-processing of the explicit operands rather than just
5479 // conditionally adding the cc_out in the first place because we need
5480 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005481 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005482 !static_cast<ARMOperand &>(*Operands[4]).isARMSOImm() &&
5483 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
5484 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach7283da92011-08-16 21:12:37 +00005485 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005486
5487 // Register-register 'add' for thumb does not have a cc_out operand
5488 // when there are only two register operands.
5489 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005490 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5491 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5492 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005493 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005494 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005495 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5496 // have to check the immediate range here since Thumb2 has a variant
5497 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005498 if (((isThumb() && Mnemonic == "add") ||
5499 (isThumbTwo() && Mnemonic == "sub")) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005500 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5501 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5502 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
5503 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5504 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
5505 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005506 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005507 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5508 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005509 // selecting via the generic "add" mnemonic, so to know that we
5510 // should remove the cc_out operand, we have to explicitly check that
5511 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005512 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005513 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5514 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5515 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005516 // Nest conditions rather than one big 'if' statement for readability.
5517 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005518 // If both registers are low, we're in an IT block, and the immediate is
5519 // in range, we should use encoding T1 instead, which has a cc_out.
5520 if (inITBlock() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005521 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
5522 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
5523 static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005524 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005525 // Check against T3. If the second register is the PC, this is an
5526 // alternate form of ADR, which uses encoding T4, so check for that too.
David Blaikie960ea3f2014-06-08 16:18:35 +00005527 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
5528 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm())
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005529 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005530
5531 // Otherwise, we use encoding T4, which does not have a cc_out
5532 // operand.
5533 return true;
5534 }
5535
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005536 // The thumb2 multiply instruction doesn't have a CCOut register, so
5537 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5538 // use the 16-bit encoding or not.
5539 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005540 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5541 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5542 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5543 static_cast<ARMOperand &>(*Operands[5]).isReg() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005544 // If the registers aren't low regs, the destination reg isn't the
5545 // same as one of the source regs, or the cc_out operand is zero
5546 // outside of an IT block, we have to use the 32-bit encoding, so
5547 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005548 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5549 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5550 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
5551 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5552 static_cast<ARMOperand &>(*Operands[5]).getReg() &&
5553 static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5554 static_cast<ARMOperand &>(*Operands[4]).getReg())))
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005555 return true;
5556
Jim Grosbachefa7e952011-11-15 19:55:16 +00005557 // Also check the 'mul' syntax variant that doesn't specify an explicit
5558 // destination register.
5559 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005560 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5561 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5562 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
Jim Grosbachefa7e952011-11-15 19:55:16 +00005563 // If the registers aren't low regs or the cc_out operand is zero
5564 // outside of an IT block, we have to use the 32-bit encoding, so
5565 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005566 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5567 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
Jim Grosbachefa7e952011-11-15 19:55:16 +00005568 !inITBlock()))
5569 return true;
5570
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005571
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005572
Jim Grosbach4b701af2011-08-24 21:42:27 +00005573 // Register-register 'add/sub' for thumb does not have a cc_out operand
5574 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5575 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5576 // right, this will result in better diagnostics (which operand is off)
5577 // anyway.
5578 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5579 (Operands.size() == 5 || Operands.size() == 6) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005580 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5581 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
5582 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5583 (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005584 (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005585 static_cast<ARMOperand &>(*Operands[5]).isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005586 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005587
Jim Grosbach7283da92011-08-16 21:12:37 +00005588 return false;
5589}
5590
David Blaikie960ea3f2014-06-08 16:18:35 +00005591bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
5592 OperandVector &Operands) {
Joey Goulye8602552013-07-19 16:34:16 +00005593 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5594 unsigned RegIdx = 3;
5595 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005596 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") {
5597 if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5598 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32")
Joey Goulye8602552013-07-19 16:34:16 +00005599 RegIdx = 4;
5600
David Blaikie960ea3f2014-06-08 16:18:35 +00005601 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
5602 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
5603 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
5604 ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
5605 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
Joey Goulye8602552013-07-19 16:34:16 +00005606 return true;
5607 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005608 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005609}
5610
Jim Grosbach12952fe2011-11-11 23:08:10 +00005611static bool isDataTypeToken(StringRef Tok) {
5612 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5613 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5614 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5615 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5616 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5617 Tok == ".f" || Tok == ".d";
5618}
5619
5620// FIXME: This bit should probably be handled via an explicit match class
5621// in the .td files that matches the suffix instead of having it be
5622// a literal string token the way it is now.
5623static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5624 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5625}
Tim Northover26bb14e2014-08-18 11:49:42 +00005626static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features,
Chad Rosier9f7a2212013-04-18 22:35:36 +00005627 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005628
5629static bool RequiresVFPRegListValidation(StringRef Inst,
5630 bool &AcceptSinglePrecisionOnly,
5631 bool &AcceptDoublePrecisionOnly) {
5632 if (Inst.size() < 7)
5633 return false;
5634
5635 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5636 StringRef AddressingMode = Inst.substr(4, 2);
5637 if (AddressingMode == "ia" || AddressingMode == "db" ||
5638 AddressingMode == "ea" || AddressingMode == "fd") {
5639 AcceptSinglePrecisionOnly = Inst[6] == 's';
5640 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5641 return true;
5642 }
5643 }
5644
5645 return false;
5646}
5647
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005648/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005649bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
David Blaikie960ea3f2014-06-08 16:18:35 +00005650 SMLoc NameLoc, OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005651 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005652 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005653 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005654 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005655 bool AcceptDoublePrecisionOnly;
5656 RequireVFPRegisterListCheck =
5657 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5658 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005659
Jim Grosbach8be2f652011-12-09 23:34:09 +00005660 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005661 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005662 // The generic tblgen'erated code does this later, at the start of
5663 // MatchInstructionImpl(), but that's too late for aliases that include
5664 // any sort of suffix.
Tim Northover26bb14e2014-08-18 11:49:42 +00005665 uint64_t AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005666 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5667 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005668
Jim Grosbachab5830e2011-12-14 02:16:11 +00005669 // First check for the ARM-specific .req directive.
5670 if (Parser.getTok().is(AsmToken::Identifier) &&
5671 Parser.getTok().getIdentifier() == ".req") {
5672 parseDirectiveReq(Name, NameLoc);
5673 // We always return 'error' for this, as we're done with this
5674 // statement and don't need to match the 'instruction."
5675 return true;
5676 }
5677
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005678 // Create the leading tokens for the mnemonic, split by '.' characters.
5679 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005680 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005681
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005682 // Split out the predication code and carry setting flag from the mnemonic.
5683 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005684 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005685 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005686 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005687 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005688 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005689
Jim Grosbach1c171b12011-08-25 17:23:55 +00005690 // In Thumb1, only the branch (B) instruction can be predicated.
5691 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005692 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005693 return Error(NameLoc, "conditional execution not supported in Thumb1");
5694 }
5695
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005696 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5697
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005698 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5699 // is the mask as it will be for the IT encoding if the conditional
5700 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5701 // where the conditional bit0 is zero, the instruction post-processing
5702 // will adjust the mask accordingly.
5703 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005704 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5705 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005706 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005707 return Error(Loc, "too many conditions on IT instruction");
5708 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005709 unsigned Mask = 8;
5710 for (unsigned i = ITMask.size(); i != 0; --i) {
5711 char pos = ITMask[i - 1];
5712 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005713 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005714 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005715 }
5716 Mask >>= 1;
5717 if (ITMask[i - 1] == 't')
5718 Mask |= 8;
5719 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005720 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005721 }
5722
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005723 // FIXME: This is all a pretty gross hack. We should automatically handle
5724 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005725
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005726 // Next, add the CCOut and ConditionCode operands, if needed.
5727 //
5728 // For mnemonics which can ever incorporate a carry setting bit or predication
5729 // code, our matching model involves us always generating CCOut and
5730 // ConditionCode operands to match the mnemonic "as written" and then we let
5731 // the matcher deal with finding the right instruction or generating an
5732 // appropriate error.
5733 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005734 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005735
Jim Grosbach03a8a162011-07-14 22:04:21 +00005736 // If we had a carry-set on an instruction that can't do that, issue an
5737 // error.
5738 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005739 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005740 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005741 "' can not set flags, but 's' suffix specified");
5742 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005743 // If we had a predication code on an instruction that can't do that, issue an
5744 // error.
5745 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005746 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005747 return Error(NameLoc, "instruction '" + Mnemonic +
5748 "' is not predicable, but condition code specified");
5749 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005750
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005751 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005752 if (CanAcceptCarrySet) {
5753 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005754 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005755 Loc));
5756 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005757
5758 // Add the predication code operand, if necessary.
5759 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005760 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5761 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005762 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005763 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005764 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005765
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005766 // Add the processor imod operand, if necessary.
5767 if (ProcessorIMod) {
5768 Operands.push_back(ARMOperand::CreateImm(
5769 MCConstantExpr::Create(ProcessorIMod, getContext()),
5770 NameLoc, NameLoc));
Oliver Stannard1ae8b472014-09-24 14:20:01 +00005771 } else if (Mnemonic == "cps" && isMClass()) {
5772 return Error(NameLoc, "instruction 'cps' requires effect for M-class");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005773 }
5774
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005775 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005776 while (Next != StringRef::npos) {
5777 Start = Next;
5778 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005779 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005780
Jim Grosbach12952fe2011-11-11 23:08:10 +00005781 // Some NEON instructions have an optional datatype suffix that is
5782 // completely ignored. Check for that.
5783 if (isDataTypeToken(ExtraToken) &&
5784 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5785 continue;
5786
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005787 // For for ARM mode generate an error if the .n qualifier is used.
5788 if (ExtraToken == ".n" && !isThumb()) {
5789 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005790 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005791 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5792 "arm mode");
5793 }
5794
5795 // The .n qualifier is always discarded as that is what the tables
5796 // and matcher expect. In ARM mode the .w qualifier has no effect,
5797 // so discard it to avoid errors that can be caused by the matcher.
5798 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005799 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5800 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5801 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005802 }
5803
5804 // Read the remaining operands.
5805 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005806 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005807 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005808 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005809 return true;
5810 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005811
5812 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005813 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005814
5815 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005816 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005817 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005818 return true;
5819 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005820 }
5821 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005822
Chris Lattnera2a9d162010-09-11 16:18:25 +00005823 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005824 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005825 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005826 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005827 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005828
Chris Lattner91689c12010-09-08 05:10:46 +00005829 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005830
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005831 if (RequireVFPRegisterListCheck) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005832 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back());
5833 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList())
5834 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005835 "VFP/Neon single precision register expected");
David Blaikie960ea3f2014-06-08 16:18:35 +00005836 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList())
5837 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005838 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005839 }
5840
Jim Grosbach7283da92011-08-16 21:12:37 +00005841 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5842 // do and don't have a cc_out optional-def operand. With some spot-checks
5843 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005844 // parse and adjust accordingly before actually matching. We shouldn't ever
5845 // try to remove a cc_out operand that was explicitly set on the the
5846 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5847 // table driven matcher doesn't fit well with the ARM instruction set.
David Blaikie960ea3f2014-06-08 16:18:35 +00005848 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005849 Operands.erase(Operands.begin() + 1);
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005850
Joey Goulye8602552013-07-19 16:34:16 +00005851 // Some instructions have the same mnemonic, but don't always
5852 // have a predicate. Distinguish them here and delete the
5853 // predicate if needed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005854 if (shouldOmitPredicateOperand(Mnemonic, Operands))
Joey Goulye8602552013-07-19 16:34:16 +00005855 Operands.erase(Operands.begin() + 1);
Joey Goulye8602552013-07-19 16:34:16 +00005856
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005857 // ARM mode 'blx' need special handling, as the register operand version
5858 // is predicable, but the label operand version is not. So, we can't rely
5859 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005860 // a k_CondCode operand in the list. If we're trying to match the label
5861 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005862 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005863 static_cast<ARMOperand &>(*Operands[2]).isImm())
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005864 Operands.erase(Operands.begin() + 1);
Jim Grosbach8cffa282011-08-11 23:51:13 +00005865
Weiming Zhao8f56f882012-11-16 21:55:34 +00005866 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5867 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5868 // a single GPRPair reg operand is used in the .td file to replace the two
5869 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5870 // expressed as a GPRPair, so we have to manually merge them.
5871 // FIXME: We would really like to be able to tablegen'erate this.
5872 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005873 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5874 Mnemonic == "stlexd")) {
5875 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005876 unsigned Idx = isLoad ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005877 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
5878 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005879
5880 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5881 // Adjust only if Op1 and Op2 are GPRs.
David Blaikie960ea3f2014-06-08 16:18:35 +00005882 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
5883 MRC.contains(Op2.getReg())) {
5884 unsigned Reg1 = Op1.getReg();
5885 unsigned Reg2 = Op2.getReg();
Weiming Zhao8f56f882012-11-16 21:55:34 +00005886 unsigned Rt = MRI->getEncodingValue(Reg1);
5887 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5888
5889 // Rt2 must be Rt + 1 and Rt must be even.
5890 if (Rt + 1 != Rt2 || (Rt & 1)) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005891 Error(Op2.getStartLoc(), isLoad
5892 ? "destination operands must be sequential"
5893 : "source operands must be sequential");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005894 return true;
5895 }
5896 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5897 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
David Blaikie960ea3f2014-06-08 16:18:35 +00005898 Operands[Idx] =
5899 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
5900 Operands.erase(Operands.begin() + Idx + 1);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005901 }
5902 }
5903
Renato Golin36c626e2014-09-26 16:14:29 +00005904 // If first 2 operands of a 3 operand instruction are the same
5905 // then transform to 2 operand version of the same instruction
5906 // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1'
5907 // FIXME: We would really like to be able to tablegen'erate this.
5908 if (isThumbOne() && Operands.size() == 6 &&
5909 (Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" ||
5910 Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5911 Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" ||
5912 Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic")) {
5913 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5914 ARMOperand &Op4 = static_cast<ARMOperand &>(*Operands[4]);
5915 ARMOperand &Op5 = static_cast<ARMOperand &>(*Operands[5]);
5916
5917 // If both registers are the same then remove one of them from
5918 // the operand list.
5919 if (Op3.isReg() && Op4.isReg() && Op3.getReg() == Op4.getReg()) {
5920 // If 3rd operand (variable Op5) is a register and the instruction is adds/sub
5921 // then do not transform as the backend already handles this instruction
5922 // correctly.
5923 if (!Op5.isReg() || !((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub")) {
5924 Operands.erase(Operands.begin() + 3);
5925 if (Mnemonic == "add" && !CarrySetting) {
5926 // Special case for 'add' (not 'adds') instruction must
5927 // remove the CCOut operand as well.
5928 Operands.erase(Operands.begin() + 1);
5929 }
5930 }
5931 }
5932 }
5933
5934 // If instruction is 'add' and first two register operands
5935 // use SP register, then remove one of the SP registers from
5936 // the instruction.
5937 // FIXME: We would really like to be able to tablegen'erate this.
5938 if (isThumbOne() && Operands.size() == 5 && Mnemonic == "add" && !CarrySetting) {
5939 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5940 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5941 if (Op2.isReg() && Op3.isReg() && Op2.getReg() == ARM::SP && Op3.getReg() == ARM::SP) {
5942 Operands.erase(Operands.begin() + 2);
5943 }
5944 }
5945
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005946 // GNU Assembler extension (compatibility)
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005947 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005948 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5949 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5950 if (Op3.isMem()) {
5951 assert(Op2.isReg() && "expected register argument");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005952
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005953 unsigned SuperReg = MRI->getMatchingSuperReg(
David Blaikie960ea3f2014-06-08 16:18:35 +00005954 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005955
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005956 assert(SuperReg && "expected register pair");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005957
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005958 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005959
David Blaikie960ea3f2014-06-08 16:18:35 +00005960 Operands.insert(
5961 Operands.begin() + 3,
5962 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005963 }
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005964 }
5965
Kevin Enderby78f95722013-07-31 21:05:30 +00005966 // FIXME: As said above, this is all a pretty gross hack. This instruction
5967 // does not fit with other "subs" and tblgen.
5968 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5969 // so the Mnemonic is the original name "subs" and delete the predicate
5970 // operand so it will match the table entry.
5971 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005972 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5973 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
5974 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5975 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
5976 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5977 Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
Kevin Enderby78f95722013-07-31 21:05:30 +00005978 Operands.erase(Operands.begin() + 1);
Kevin Enderby78f95722013-07-31 21:05:30 +00005979 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005980 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005981}
5982
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005983// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005984
5985// return 'true' if register list contains non-low GPR registers,
5986// 'false' otherwise. If Reg is in the register list or is HiReg, set
5987// 'containsReg' to true.
5988static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5989 unsigned HiReg, bool &containsReg) {
5990 containsReg = false;
5991 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5992 unsigned OpReg = Inst.getOperand(i).getReg();
5993 if (OpReg == Reg)
5994 containsReg = true;
5995 // Anything other than a low register isn't legal here.
5996 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5997 return true;
5998 }
5999 return false;
6000}
6001
Rafael Espindola5403da42014-12-04 14:10:20 +00006002// Check if the specified regisgter is in the register list of the inst,
Jim Grosbacha31f2232011-09-07 18:05:34 +00006003// starting at the indicated operand number.
Rafael Espindola5403da42014-12-04 14:10:20 +00006004static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
Jim Grosbacha31f2232011-09-07 18:05:34 +00006005 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
6006 unsigned OpReg = Inst.getOperand(i).getReg();
Rafael Espindola5403da42014-12-04 14:10:20 +00006007 if (OpReg == Reg)
6008 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00006009 }
6010 return false;
6011}
6012
Richard Barton8d519fe2013-09-05 14:14:19 +00006013// Return true if instruction has the interesting property of being
6014// allowed in IT blocks, but not being predicable.
6015static bool instIsBreakpoint(const MCInst &Inst) {
6016 return Inst.getOpcode() == ARM::tBKPT ||
6017 Inst.getOpcode() == ARM::BKPT ||
6018 Inst.getOpcode() == ARM::tHLT ||
6019 Inst.getOpcode() == ARM::HLT;
6020
6021}
6022
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006023// FIXME: We would really like to be able to tablegen'erate this.
David Blaikie960ea3f2014-06-08 16:18:35 +00006024bool ARMAsmParser::validateInstruction(MCInst &Inst,
6025 const OperandVector &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00006026 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00006027 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00006028
Jim Grosbached16ec42011-08-29 22:24:09 +00006029 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00006030 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00006031 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00006032 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006033 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006034 if (ITState.FirstCond)
6035 ITState.FirstCond = false;
6036 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00006037 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006038 // The instruction must be predicable.
6039 if (!MCID.isPredicable())
6040 return Error(Loc, "instructions in IT block must be predicable");
6041 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00006042 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00006043 ARMCC::getOppositeCondition(ITState.Cond);
6044 if (Cond != ITCond) {
6045 // Find the condition code Operand to get its SMLoc information.
6046 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00006047 for (unsigned I = 1; I < Operands.size(); ++I)
David Blaikie960ea3f2014-06-08 16:18:35 +00006048 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006049 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00006050 return Error(CondLoc, "incorrect condition in IT block; got '" +
6051 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
6052 "', but expected '" +
6053 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
6054 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00006055 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00006056 } else if (isThumbTwo() && MCID.isPredicable() &&
6057 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00006058 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
6059 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00006060 return Error(Loc, "predicated instructions must be in IT block");
6061
Tilmann Scheller255722b2013-09-30 16:11:48 +00006062 const unsigned Opcode = Inst.getOpcode();
6063 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00006064 case ARM::LDRD:
6065 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006066 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00006067 const unsigned RtReg = Inst.getOperand(0).getReg();
6068
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006069 // Rt can't be R14.
6070 if (RtReg == ARM::LR)
6071 return Error(Operands[3]->getStartLoc(),
6072 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006073
6074 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006075 // Rt must be even-numbered.
6076 if ((Rt & 1) == 1)
6077 return Error(Operands[3]->getStartLoc(),
6078 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006079
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006080 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00006081 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006082 if (Rt2 != Rt + 1)
6083 return Error(Operands[3]->getStartLoc(),
6084 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006085
6086 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
6087 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
6088 // For addressing modes with writeback, the base register needs to be
6089 // different from the destination registers.
6090 if (Rn == Rt || Rn == Rt2)
6091 return Error(Operands[3]->getStartLoc(),
6092 "base register needs to be different from destination "
6093 "registers");
6094 }
6095
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006096 return false;
6097 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006098 case ARM::t2LDRDi8:
6099 case ARM::t2LDRD_PRE:
6100 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00006101 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006102 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6103 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6104 if (Rt2 == Rt)
6105 return Error(Operands[3]->getStartLoc(),
6106 "destination operands can't be identical");
6107 return false;
6108 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00006109 case ARM::STRD: {
6110 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006111 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6112 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00006113 if (Rt2 != Rt + 1)
6114 return Error(Operands[3]->getStartLoc(),
6115 "source operands must be sequential");
6116 return false;
6117 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00006118 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006119 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006120 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006121 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6122 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006123 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00006124 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006125 "source operands must be sequential");
6126 return false;
6127 }
Tilmann Scheller3352a582014-07-23 12:38:17 +00006128 case ARM::STR_PRE_IMM:
6129 case ARM::STR_PRE_REG:
6130 case ARM::STR_POST_IMM:
Tilmann Scheller27272792014-07-23 13:03:47 +00006131 case ARM::STR_POST_REG:
Tilmann Scheller96ef72e2014-07-24 09:55:46 +00006132 case ARM::STRH_PRE:
6133 case ARM::STRH_POST:
Tilmann Scheller27272792014-07-23 13:03:47 +00006134 case ARM::STRB_PRE_IMM:
6135 case ARM::STRB_PRE_REG:
6136 case ARM::STRB_POST_IMM:
6137 case ARM::STRB_POST_REG: {
Tilmann Scheller3352a582014-07-23 12:38:17 +00006138 // Rt must be different from Rn.
6139 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6140 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6141
6142 if (Rt == Rn)
6143 return Error(Operands[3]->getStartLoc(),
6144 "source register and base register can't be identical");
6145 return false;
6146 }
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006147 case ARM::LDR_PRE_IMM:
6148 case ARM::LDR_PRE_REG:
6149 case ARM::LDR_POST_IMM:
Tilmann Scheller8ff079c2014-08-01 11:33:47 +00006150 case ARM::LDR_POST_REG:
6151 case ARM::LDRH_PRE:
6152 case ARM::LDRH_POST:
6153 case ARM::LDRSH_PRE:
Tilmann Scheller7cc0ed42014-08-01 12:08:04 +00006154 case ARM::LDRSH_POST:
6155 case ARM::LDRB_PRE_IMM:
6156 case ARM::LDRB_PRE_REG:
6157 case ARM::LDRB_POST_IMM:
6158 case ARM::LDRB_POST_REG:
6159 case ARM::LDRSB_PRE:
6160 case ARM::LDRSB_POST: {
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006161 // Rt must be different from Rn.
6162 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6163 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6164
6165 if (Rt == Rn)
6166 return Error(Operands[3]->getStartLoc(),
6167 "destination register and base register can't be identical");
6168 return false;
6169 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00006170 case ARM::SBFX:
6171 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006172 // Width must be in range [1, 32-lsb].
6173 unsigned LSB = Inst.getOperand(2).getImm();
6174 unsigned Widthm1 = Inst.getOperand(3).getImm();
6175 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00006176 return Error(Operands[5]->getStartLoc(),
6177 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00006178 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00006179 }
Rafael Espindola5403da42014-12-04 14:10:20 +00006180 // Notionally handles ARM::tLDMIA_UPD too.
6181 case ARM::tLDMIA: {
6182 // If we're parsing Thumb2, the .w variant is available and handles
6183 // most cases that are normally illegal for a Thumb1 LDM instruction.
6184 // We'll make the transformation in processInstruction() if necessary.
6185 //
6186 // Thumb LDM instructions are writeback iff the base register is not
6187 // in the register list.
6188 unsigned Rn = Inst.getOperand(0).getReg();
6189 bool HasWritebackToken =
6190 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
6191 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
6192 bool ListContainsBase;
6193 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
6194 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
6195 "registers must be in range r0-r7");
6196 // If we should have writeback, then there should be a '!' token.
6197 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
6198 return Error(Operands[2]->getStartLoc(),
6199 "writeback operator '!' expected");
6200 // If we should not have writeback, there must not be a '!'. This is
6201 // true even for the 32-bit wide encodings.
6202 if (ListContainsBase && HasWritebackToken)
6203 return Error(Operands[3]->getStartLoc(),
6204 "writeback operator '!' not allowed when base register "
6205 "in register list");
6206 if (listContainsReg(Inst, 3 + HasWritebackToken, ARM::SP))
6207 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
6208 "SP not allowed in register list");
6209 break;
6210 }
Tim Northover08a86602013-10-22 19:00:39 +00006211 case ARM::LDMIA_UPD:
6212 case ARM::LDMDB_UPD:
6213 case ARM::LDMIB_UPD:
6214 case ARM::LDMDA_UPD:
6215 // ARM variants loading and updating the same register are only officially
6216 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
6217 if (!hasV7Ops())
6218 break;
Rafael Espindola5403da42014-12-04 14:10:20 +00006219 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6220 return Error(Operands.back()->getStartLoc(),
6221 "writeback register not allowed in register list");
6222 break;
Jyoti Allur3b686072014-10-22 10:41:14 +00006223 case ARM::t2LDMIA:
6224 case ARM::t2LDMDB:
6225 case ARM::t2STMIA:
Rafael Espindola5403da42014-12-04 14:10:20 +00006226 case ARM::t2STMDB: {
6227 if (listContainsReg(Inst, 3, ARM::SP))
6228 return Error(Operands.back()->getStartLoc(),
6229 "SP not allowed in register list");
6230 break;
6231 }
Tim Northover08a86602013-10-22 19:00:39 +00006232 case ARM::t2LDMIA_UPD:
6233 case ARM::t2LDMDB_UPD:
6234 case ARM::t2STMIA_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006235 case ARM::t2STMDB_UPD: {
6236 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6237 return Error(Operands.back()->getStartLoc(),
6238 "writeback register not allowed in register list");
6239
6240 if (listContainsReg(Inst, 4, ARM::SP))
6241 return Error(Operands.back()->getStartLoc(),
6242 "SP not allowed in register list");
6243 break;
6244 }
Tim Northover8eaf1542013-11-12 21:32:41 +00006245 case ARM::sysLDMIA_UPD:
6246 case ARM::sysLDMDA_UPD:
6247 case ARM::sysLDMDB_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006248 case ARM::sysLDMIB_UPD:
6249 if (!listContainsReg(Inst, 3, ARM::PC))
6250 return Error(Operands[4]->getStartLoc(),
6251 "writeback register only allowed on system LDM "
6252 "if PC in register-list");
Tim Northover8eaf1542013-11-12 21:32:41 +00006253 break;
6254 case ARM::sysSTMIA_UPD:
6255 case ARM::sysSTMDA_UPD:
6256 case ARM::sysSTMDB_UPD:
6257 case ARM::sysSTMIB_UPD:
6258 return Error(Operands[2]->getStartLoc(),
6259 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006260 case ARM::tMUL: {
6261 // The second source operand must be the same register as the destination
6262 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00006263 //
6264 // In this case, we must directly check the parsed operands because the
6265 // cvtThumbMultiply() function is written in such a way that it guarantees
6266 // this first statement is always true for the new Inst. Essentially, the
6267 // destination is unconditionally copied into the second source operand
6268 // without checking to see if it matches what we actually parsed.
David Blaikie960ea3f2014-06-08 16:18:35 +00006269 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
6270 ((ARMOperand &)*Operands[5]).getReg()) &&
6271 (((ARMOperand &)*Operands[3]).getReg() !=
6272 ((ARMOperand &)*Operands[4]).getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00006273 return Error(Operands[3]->getStartLoc(),
6274 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006275 }
6276 break;
6277 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00006278 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
6279 // so only issue a diagnostic for thumb1. The instructions will be
6280 // switched to the t2 encodings in processInstruction() if necessary.
Rafael Espindola5403da42014-12-04 14:10:20 +00006281 case ARM::tPOP: {
6282 bool ListContainsBase;
6283 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
6284 !isThumbTwo())
6285 return Error(Operands[2]->getStartLoc(),
6286 "registers must be in range r0-r7 or pc");
6287 break;
6288 }
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006289 case ARM::tPUSH: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006290 bool ListContainsBase;
6291 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
6292 !isThumbTwo())
6293 return Error(Operands[2]->getStartLoc(),
6294 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006295 break;
6296 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00006297 case ARM::tSTMIA_UPD: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006298 bool ListContainsBase, InvalidLowList;
6299 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
6300 0, ListContainsBase);
6301 if (InvalidLowList && !isThumbTwo())
6302 return Error(Operands[4]->getStartLoc(),
6303 "registers must be in range r0-r7");
6304
6305 // This would be converted to a 32-bit stm, but that's not valid if the
6306 // writeback register is in the list.
6307 if (InvalidLowList && ListContainsBase)
6308 return Error(Operands[4]->getStartLoc(),
6309 "writeback operator '!' not allowed when base register "
6310 "in register list");
6311 if (listContainsReg(Inst, 4, ARM::SP) && !inITBlock())
6312 return Error(Operands.back()->getStartLoc(),
6313 "SP not allowed in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00006314 break;
6315 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00006316 case ARM::tADDrSP: {
6317 // If the non-SP source operand and the destination operand are not the
6318 // same, we need thumb2 (for the wide encoding), or we have an error.
6319 if (!isThumbTwo() &&
6320 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
6321 return Error(Operands[4]->getStartLoc(),
6322 "source register must be the same as destination");
6323 }
6324 break;
6325 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006326 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006327 case ARM::tB:
David Blaikie960ea3f2014-06-08 16:18:35 +00006328 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006329 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006330 break;
6331 case ARM::t2B: {
6332 int op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006333 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006334 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006335 break;
6336 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006337 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006338 case ARM::tBcc:
David Blaikie960ea3f2014-06-08 16:18:35 +00006339 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006340 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006341 break;
6342 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006343 int Op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006344 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006345 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006346 break;
6347 }
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006348 case ARM::MOVi16:
6349 case ARM::t2MOVi16:
6350 case ARM::t2MOVTi16:
6351 {
6352 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
6353 // especially when we turn it into a movw and the expression <symbol> does
6354 // not have a :lower16: or :upper16 as part of the expression. We don't
6355 // want the behavior of silently truncating, which can be unexpected and
6356 // lead to bugs that are difficult to find since this is an easy mistake
6357 // to make.
6358 int i = (Operands[3]->isImm()) ? 3 : 4;
David Blaikie960ea3f2014-06-08 16:18:35 +00006359 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
6360 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006361 if (CE) break;
David Blaikie960ea3f2014-06-08 16:18:35 +00006362 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006363 if (!E) break;
6364 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
6365 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006366 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
6367 return Error(
6368 Op.getStartLoc(),
6369 "immediate expression for mov requires :lower16: or :upper16");
6370 break;
6371 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006372 }
6373
6374 return false;
6375}
6376
Jim Grosbach1a747242012-01-23 23:45:44 +00006377static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00006378 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006379 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006380 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006381 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6382 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6383 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6384 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6385 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6386 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6387 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
6388 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
6389 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006390
6391 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006392 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6393 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6394 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6395 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6396 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006397
Jim Grosbach1e946a42012-01-24 00:43:12 +00006398 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6399 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6400 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6401 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6402 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006403
Jim Grosbach1e946a42012-01-24 00:43:12 +00006404 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
6405 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
6406 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
6407 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
6408 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00006409
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006410 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006411 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6412 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6413 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6414 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
6415 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6416 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6417 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6418 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6419 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
6420 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6421 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
6422 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
6423 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
6424 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
6425 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006426
Jim Grosbach1a747242012-01-23 23:45:44 +00006427 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006428 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6429 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6430 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6431 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6432 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6433 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6434 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6435 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6436 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6437 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6438 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6439 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6440 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
6441 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
6442 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
6443 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
6444 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
6445 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00006446
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006447 // VST4LN
6448 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6449 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6450 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6451 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
6452 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6453 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6454 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6455 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6456 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
6457 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6458 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
6459 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
6460 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
6461 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
6462 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
6463
Jim Grosbachda70eac2012-01-24 00:58:13 +00006464 // VST4
6465 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6466 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6467 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6468 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6469 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6470 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6471 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6472 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6473 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6474 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6475 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6476 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6477 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6478 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6479 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6480 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6481 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6482 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00006483 }
6484}
6485
Jim Grosbach1a747242012-01-23 23:45:44 +00006486static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00006487 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006488 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006489 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006490 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6491 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6492 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6493 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6494 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6495 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6496 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6497 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6498 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006499
6500 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006501 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6502 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6503 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6504 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6505 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6506 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6507 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6508 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6509 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6510 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6511 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6512 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6513 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6514 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6515 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006516
Jim Grosbachb78403c2012-01-24 23:47:04 +00006517 // VLD3DUP
6518 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6519 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6520 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6521 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
Kevin Enderbyd88fec32014-04-08 18:00:52 +00006522 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
Jim Grosbachb78403c2012-01-24 23:47:04 +00006523 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6524 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6525 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6526 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6527 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6528 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6529 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6530 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6531 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6532 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6533 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6534 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6535 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6536
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006537 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006538 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6539 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6540 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6541 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6542 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6543 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6544 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6545 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6546 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6547 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6548 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6549 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6550 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6551 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6552 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006553
6554 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006555 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6556 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6557 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6558 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6559 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6560 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6561 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6562 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6563 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6564 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6565 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6566 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6567 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6568 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6569 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6570 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6571 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6572 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00006573
Jim Grosbach14952a02012-01-24 18:37:25 +00006574 // VLD4LN
6575 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6576 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6577 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00006578 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00006579 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6580 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6581 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6582 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6583 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6584 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6585 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6586 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6587 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6588 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6589 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6590
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006591 // VLD4DUP
6592 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6593 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6594 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6595 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6596 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6597 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6598 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6599 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6600 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6601 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6602 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6603 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6604 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6605 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6606 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6607 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6608 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6609 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6610
Jim Grosbached561fc2012-01-24 00:43:17 +00006611 // VLD4
6612 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6613 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6614 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6615 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6616 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6617 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6618 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6619 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6620 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6621 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6622 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6623 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6624 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6625 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6626 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6627 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6628 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6629 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006630 }
6631}
6632
David Blaikie960ea3f2014-06-08 16:18:35 +00006633bool ARMAsmParser::processInstruction(MCInst &Inst,
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006634 const OperandVector &Operands,
6635 MCStreamer &Out) {
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006636 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006637 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6638 case ARM::LDRT_POST:
6639 case ARM::LDRBT_POST: {
6640 const unsigned Opcode =
6641 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6642 : ARM::LDRBT_POST_IMM;
6643 MCInst TmpInst;
6644 TmpInst.setOpcode(Opcode);
6645 TmpInst.addOperand(Inst.getOperand(0));
6646 TmpInst.addOperand(Inst.getOperand(1));
6647 TmpInst.addOperand(Inst.getOperand(1));
6648 TmpInst.addOperand(MCOperand::CreateReg(0));
6649 TmpInst.addOperand(MCOperand::CreateImm(0));
6650 TmpInst.addOperand(Inst.getOperand(2));
6651 TmpInst.addOperand(Inst.getOperand(3));
6652 Inst = TmpInst;
6653 return true;
6654 }
6655 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6656 case ARM::STRT_POST:
6657 case ARM::STRBT_POST: {
6658 const unsigned Opcode =
6659 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6660 : ARM::STRBT_POST_IMM;
6661 MCInst TmpInst;
6662 TmpInst.setOpcode(Opcode);
6663 TmpInst.addOperand(Inst.getOperand(1));
6664 TmpInst.addOperand(Inst.getOperand(0));
6665 TmpInst.addOperand(Inst.getOperand(1));
6666 TmpInst.addOperand(MCOperand::CreateReg(0));
6667 TmpInst.addOperand(MCOperand::CreateImm(0));
6668 TmpInst.addOperand(Inst.getOperand(2));
6669 TmpInst.addOperand(Inst.getOperand(3));
6670 Inst = TmpInst;
6671 return true;
6672 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006673 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6674 case ARM::ADDri: {
6675 if (Inst.getOperand(1).getReg() != ARM::PC ||
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006676 Inst.getOperand(5).getReg() != 0 ||
6677 !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm()))
Jim Grosbache974a6a2012-09-25 00:08:13 +00006678 return false;
6679 MCInst TmpInst;
6680 TmpInst.setOpcode(ARM::ADR);
6681 TmpInst.addOperand(Inst.getOperand(0));
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006682 if (Inst.getOperand(2).isImm()) {
6683 TmpInst.addOperand(Inst.getOperand(2));
6684 } else {
6685 // Turn PC-relative expression into absolute expression.
6686 // Reading PC provides the start of the current instruction + 8 and
6687 // the transform to adr is biased by that.
6688 MCSymbol *Dot = getContext().CreateTempSymbol();
6689 Out.EmitLabel(Dot);
6690 const MCExpr *OpExpr = Inst.getOperand(2).getExpr();
6691 const MCExpr *InstPC = MCSymbolRefExpr::Create(Dot,
6692 MCSymbolRefExpr::VK_None,
6693 getContext());
6694 const MCExpr *Const8 = MCConstantExpr::Create(8, getContext());
6695 const MCExpr *ReadPC = MCBinaryExpr::CreateAdd(InstPC, Const8,
6696 getContext());
6697 const MCExpr *FixupAddr = MCBinaryExpr::CreateAdd(ReadPC, OpExpr,
6698 getContext());
6699 TmpInst.addOperand(MCOperand::CreateExpr(FixupAddr));
6700 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006701 TmpInst.addOperand(Inst.getOperand(3));
6702 TmpInst.addOperand(Inst.getOperand(4));
6703 Inst = TmpInst;
6704 return true;
6705 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006706 // Aliases for alternate PC+imm syntax of LDR instructions.
6707 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006708 // Select the narrow version if the immediate will fit.
6709 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006710 Inst.getOperand(1).getImm() <= 0xff &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006711 !(static_cast<ARMOperand &>(*Operands[2]).isToken() &&
6712 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006713 Inst.setOpcode(ARM::tLDRpci);
6714 else
6715 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006716 return true;
6717 case ARM::t2LDRBpcrel:
6718 Inst.setOpcode(ARM::t2LDRBpci);
6719 return true;
6720 case ARM::t2LDRHpcrel:
6721 Inst.setOpcode(ARM::t2LDRHpci);
6722 return true;
6723 case ARM::t2LDRSBpcrel:
6724 Inst.setOpcode(ARM::t2LDRSBpci);
6725 return true;
6726 case ARM::t2LDRSHpcrel:
6727 Inst.setOpcode(ARM::t2LDRSHpci);
6728 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006729 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006730 case ARM::VST1LNdWB_register_Asm_8:
6731 case ARM::VST1LNdWB_register_Asm_16:
6732 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006733 MCInst TmpInst;
6734 // Shuffle the operands around so the lane index operand is in the
6735 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006736 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006737 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006738 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6739 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6740 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6741 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6742 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6743 TmpInst.addOperand(Inst.getOperand(1)); // lane
6744 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6745 TmpInst.addOperand(Inst.getOperand(6));
6746 Inst = TmpInst;
6747 return true;
6748 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006749
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006750 case ARM::VST2LNdWB_register_Asm_8:
6751 case ARM::VST2LNdWB_register_Asm_16:
6752 case ARM::VST2LNdWB_register_Asm_32:
6753 case ARM::VST2LNqWB_register_Asm_16:
6754 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006755 MCInst TmpInst;
6756 // Shuffle the operands around so the lane index operand is in the
6757 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006758 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006759 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006760 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6761 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6762 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6763 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6764 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006765 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6766 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006767 TmpInst.addOperand(Inst.getOperand(1)); // lane
6768 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6769 TmpInst.addOperand(Inst.getOperand(6));
6770 Inst = TmpInst;
6771 return true;
6772 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006773
6774 case ARM::VST3LNdWB_register_Asm_8:
6775 case ARM::VST3LNdWB_register_Asm_16:
6776 case ARM::VST3LNdWB_register_Asm_32:
6777 case ARM::VST3LNqWB_register_Asm_16:
6778 case ARM::VST3LNqWB_register_Asm_32: {
6779 MCInst TmpInst;
6780 // Shuffle the operands around so the lane index operand is in the
6781 // right place.
6782 unsigned Spacing;
6783 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6784 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6785 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6786 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6787 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6788 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6789 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6790 Spacing));
6791 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6792 Spacing * 2));
6793 TmpInst.addOperand(Inst.getOperand(1)); // lane
6794 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6795 TmpInst.addOperand(Inst.getOperand(6));
6796 Inst = TmpInst;
6797 return true;
6798 }
6799
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006800 case ARM::VST4LNdWB_register_Asm_8:
6801 case ARM::VST4LNdWB_register_Asm_16:
6802 case ARM::VST4LNdWB_register_Asm_32:
6803 case ARM::VST4LNqWB_register_Asm_16:
6804 case ARM::VST4LNqWB_register_Asm_32: {
6805 MCInst TmpInst;
6806 // Shuffle the operands around so the lane index operand is in the
6807 // right place.
6808 unsigned Spacing;
6809 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6810 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6811 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6812 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6813 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6814 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6815 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6816 Spacing));
6817 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6818 Spacing * 2));
6819 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6820 Spacing * 3));
6821 TmpInst.addOperand(Inst.getOperand(1)); // lane
6822 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6823 TmpInst.addOperand(Inst.getOperand(6));
6824 Inst = TmpInst;
6825 return true;
6826 }
6827
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006828 case ARM::VST1LNdWB_fixed_Asm_8:
6829 case ARM::VST1LNdWB_fixed_Asm_16:
6830 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006831 MCInst TmpInst;
6832 // Shuffle the operands around so the lane index operand is in the
6833 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006834 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006835 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006836 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6837 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6838 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6839 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6840 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6841 TmpInst.addOperand(Inst.getOperand(1)); // lane
6842 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6843 TmpInst.addOperand(Inst.getOperand(5));
6844 Inst = TmpInst;
6845 return true;
6846 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006847
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006848 case ARM::VST2LNdWB_fixed_Asm_8:
6849 case ARM::VST2LNdWB_fixed_Asm_16:
6850 case ARM::VST2LNdWB_fixed_Asm_32:
6851 case ARM::VST2LNqWB_fixed_Asm_16:
6852 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006853 MCInst TmpInst;
6854 // Shuffle the operands around so the lane index operand is in the
6855 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006856 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006857 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006858 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6859 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6860 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6861 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6862 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006863 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6864 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006865 TmpInst.addOperand(Inst.getOperand(1)); // lane
6866 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6867 TmpInst.addOperand(Inst.getOperand(5));
6868 Inst = TmpInst;
6869 return true;
6870 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006871
6872 case ARM::VST3LNdWB_fixed_Asm_8:
6873 case ARM::VST3LNdWB_fixed_Asm_16:
6874 case ARM::VST3LNdWB_fixed_Asm_32:
6875 case ARM::VST3LNqWB_fixed_Asm_16:
6876 case ARM::VST3LNqWB_fixed_Asm_32: {
6877 MCInst TmpInst;
6878 // Shuffle the operands around so the lane index operand is in the
6879 // right place.
6880 unsigned Spacing;
6881 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6882 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6883 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6884 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6885 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6886 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6887 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6888 Spacing));
6889 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6890 Spacing * 2));
6891 TmpInst.addOperand(Inst.getOperand(1)); // lane
6892 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6893 TmpInst.addOperand(Inst.getOperand(5));
6894 Inst = TmpInst;
6895 return true;
6896 }
6897
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006898 case ARM::VST4LNdWB_fixed_Asm_8:
6899 case ARM::VST4LNdWB_fixed_Asm_16:
6900 case ARM::VST4LNdWB_fixed_Asm_32:
6901 case ARM::VST4LNqWB_fixed_Asm_16:
6902 case ARM::VST4LNqWB_fixed_Asm_32: {
6903 MCInst TmpInst;
6904 // Shuffle the operands around so the lane index operand is in the
6905 // right place.
6906 unsigned Spacing;
6907 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6908 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6909 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6910 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6911 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6912 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6913 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6914 Spacing));
6915 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6916 Spacing * 2));
6917 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6918 Spacing * 3));
6919 TmpInst.addOperand(Inst.getOperand(1)); // lane
6920 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6921 TmpInst.addOperand(Inst.getOperand(5));
6922 Inst = TmpInst;
6923 return true;
6924 }
6925
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006926 case ARM::VST1LNdAsm_8:
6927 case ARM::VST1LNdAsm_16:
6928 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006929 MCInst TmpInst;
6930 // Shuffle the operands around so the lane index operand is in the
6931 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006932 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006933 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006934 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6935 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6936 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6937 TmpInst.addOperand(Inst.getOperand(1)); // lane
6938 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6939 TmpInst.addOperand(Inst.getOperand(5));
6940 Inst = TmpInst;
6941 return true;
6942 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006943
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006944 case ARM::VST2LNdAsm_8:
6945 case ARM::VST2LNdAsm_16:
6946 case ARM::VST2LNdAsm_32:
6947 case ARM::VST2LNqAsm_16:
6948 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006949 MCInst TmpInst;
6950 // Shuffle the operands around so the lane index operand is in the
6951 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006952 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006953 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006954 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6955 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6956 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006957 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6958 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006959 TmpInst.addOperand(Inst.getOperand(1)); // lane
6960 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6961 TmpInst.addOperand(Inst.getOperand(5));
6962 Inst = TmpInst;
6963 return true;
6964 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006965
6966 case ARM::VST3LNdAsm_8:
6967 case ARM::VST3LNdAsm_16:
6968 case ARM::VST3LNdAsm_32:
6969 case ARM::VST3LNqAsm_16:
6970 case ARM::VST3LNqAsm_32: {
6971 MCInst TmpInst;
6972 // Shuffle the operands around so the lane index operand is in the
6973 // right place.
6974 unsigned Spacing;
6975 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6976 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6977 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6978 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6979 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6980 Spacing));
6981 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6982 Spacing * 2));
6983 TmpInst.addOperand(Inst.getOperand(1)); // lane
6984 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6985 TmpInst.addOperand(Inst.getOperand(5));
6986 Inst = TmpInst;
6987 return true;
6988 }
6989
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006990 case ARM::VST4LNdAsm_8:
6991 case ARM::VST4LNdAsm_16:
6992 case ARM::VST4LNdAsm_32:
6993 case ARM::VST4LNqAsm_16:
6994 case ARM::VST4LNqAsm_32: {
6995 MCInst TmpInst;
6996 // Shuffle the operands around so the lane index operand is in the
6997 // right place.
6998 unsigned Spacing;
6999 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7000 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7001 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7002 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7003 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7004 Spacing));
7005 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7006 Spacing * 2));
7007 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7008 Spacing * 3));
7009 TmpInst.addOperand(Inst.getOperand(1)); // lane
7010 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7011 TmpInst.addOperand(Inst.getOperand(5));
7012 Inst = TmpInst;
7013 return true;
7014 }
7015
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007016 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007017 case ARM::VLD1LNdWB_register_Asm_8:
7018 case ARM::VLD1LNdWB_register_Asm_16:
7019 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007020 MCInst TmpInst;
7021 // Shuffle the operands around so the lane index operand is in the
7022 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007023 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007024 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007025 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7026 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7027 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7028 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7029 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7030 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7031 TmpInst.addOperand(Inst.getOperand(1)); // lane
7032 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7033 TmpInst.addOperand(Inst.getOperand(6));
7034 Inst = TmpInst;
7035 return true;
7036 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007037
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007038 case ARM::VLD2LNdWB_register_Asm_8:
7039 case ARM::VLD2LNdWB_register_Asm_16:
7040 case ARM::VLD2LNdWB_register_Asm_32:
7041 case ARM::VLD2LNqWB_register_Asm_16:
7042 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007043 MCInst TmpInst;
7044 // Shuffle the operands around so the lane index operand is in the
7045 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007046 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007047 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007048 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007049 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7050 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007051 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7052 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7053 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7054 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7055 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007056 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7057 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007058 TmpInst.addOperand(Inst.getOperand(1)); // lane
7059 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7060 TmpInst.addOperand(Inst.getOperand(6));
7061 Inst = TmpInst;
7062 return true;
7063 }
7064
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007065 case ARM::VLD3LNdWB_register_Asm_8:
7066 case ARM::VLD3LNdWB_register_Asm_16:
7067 case ARM::VLD3LNdWB_register_Asm_32:
7068 case ARM::VLD3LNqWB_register_Asm_16:
7069 case ARM::VLD3LNqWB_register_Asm_32: {
7070 MCInst TmpInst;
7071 // Shuffle the operands around so the lane index operand is in the
7072 // right place.
7073 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007074 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007075 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7076 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7077 Spacing));
7078 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007079 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007080 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7081 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7082 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7083 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7084 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7085 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7086 Spacing));
7087 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007088 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007089 TmpInst.addOperand(Inst.getOperand(1)); // lane
7090 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7091 TmpInst.addOperand(Inst.getOperand(6));
7092 Inst = TmpInst;
7093 return true;
7094 }
7095
Jim Grosbach14952a02012-01-24 18:37:25 +00007096 case ARM::VLD4LNdWB_register_Asm_8:
7097 case ARM::VLD4LNdWB_register_Asm_16:
7098 case ARM::VLD4LNdWB_register_Asm_32:
7099 case ARM::VLD4LNqWB_register_Asm_16:
7100 case ARM::VLD4LNqWB_register_Asm_32: {
7101 MCInst TmpInst;
7102 // Shuffle the operands around so the lane index operand is in the
7103 // right place.
7104 unsigned Spacing;
7105 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7106 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7107 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7108 Spacing));
7109 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7110 Spacing * 2));
7111 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7112 Spacing * 3));
7113 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7114 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7115 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7116 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7117 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7118 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7119 Spacing));
7120 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7121 Spacing * 2));
7122 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7123 Spacing * 3));
7124 TmpInst.addOperand(Inst.getOperand(1)); // lane
7125 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7126 TmpInst.addOperand(Inst.getOperand(6));
7127 Inst = TmpInst;
7128 return true;
7129 }
7130
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007131 case ARM::VLD1LNdWB_fixed_Asm_8:
7132 case ARM::VLD1LNdWB_fixed_Asm_16:
7133 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007134 MCInst TmpInst;
7135 // Shuffle the operands around so the lane index operand is in the
7136 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007137 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007138 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007139 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7140 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7141 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7142 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7143 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7144 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7145 TmpInst.addOperand(Inst.getOperand(1)); // lane
7146 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7147 TmpInst.addOperand(Inst.getOperand(5));
7148 Inst = TmpInst;
7149 return true;
7150 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007151
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007152 case ARM::VLD2LNdWB_fixed_Asm_8:
7153 case ARM::VLD2LNdWB_fixed_Asm_16:
7154 case ARM::VLD2LNdWB_fixed_Asm_32:
7155 case ARM::VLD2LNqWB_fixed_Asm_16:
7156 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007157 MCInst TmpInst;
7158 // Shuffle the operands around so the lane index operand is in the
7159 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007160 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007161 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007162 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007163 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7164 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007165 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7166 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7167 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7168 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7169 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007170 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7171 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007172 TmpInst.addOperand(Inst.getOperand(1)); // lane
7173 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7174 TmpInst.addOperand(Inst.getOperand(5));
7175 Inst = TmpInst;
7176 return true;
7177 }
7178
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007179 case ARM::VLD3LNdWB_fixed_Asm_8:
7180 case ARM::VLD3LNdWB_fixed_Asm_16:
7181 case ARM::VLD3LNdWB_fixed_Asm_32:
7182 case ARM::VLD3LNqWB_fixed_Asm_16:
7183 case ARM::VLD3LNqWB_fixed_Asm_32: {
7184 MCInst TmpInst;
7185 // Shuffle the operands around so the lane index operand is in the
7186 // right place.
7187 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007188 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007189 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7190 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7191 Spacing));
7192 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007193 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007194 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7195 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7196 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7197 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7198 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7199 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7200 Spacing));
7201 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007202 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007203 TmpInst.addOperand(Inst.getOperand(1)); // lane
7204 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7205 TmpInst.addOperand(Inst.getOperand(5));
7206 Inst = TmpInst;
7207 return true;
7208 }
7209
Jim Grosbach14952a02012-01-24 18:37:25 +00007210 case ARM::VLD4LNdWB_fixed_Asm_8:
7211 case ARM::VLD4LNdWB_fixed_Asm_16:
7212 case ARM::VLD4LNdWB_fixed_Asm_32:
7213 case ARM::VLD4LNqWB_fixed_Asm_16:
7214 case ARM::VLD4LNqWB_fixed_Asm_32: {
7215 MCInst TmpInst;
7216 // Shuffle the operands around so the lane index operand is in the
7217 // right place.
7218 unsigned Spacing;
7219 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7220 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7221 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7222 Spacing));
7223 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7224 Spacing * 2));
7225 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7226 Spacing * 3));
7227 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7228 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7229 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7230 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7231 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7232 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7233 Spacing));
7234 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7235 Spacing * 2));
7236 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7237 Spacing * 3));
7238 TmpInst.addOperand(Inst.getOperand(1)); // lane
7239 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7240 TmpInst.addOperand(Inst.getOperand(5));
7241 Inst = TmpInst;
7242 return true;
7243 }
7244
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007245 case ARM::VLD1LNdAsm_8:
7246 case ARM::VLD1LNdAsm_16:
7247 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00007248 MCInst TmpInst;
7249 // Shuffle the operands around so the lane index operand is in the
7250 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007251 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007252 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00007253 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7254 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7255 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7256 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7257 TmpInst.addOperand(Inst.getOperand(1)); // lane
7258 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7259 TmpInst.addOperand(Inst.getOperand(5));
7260 Inst = TmpInst;
7261 return true;
7262 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007263
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007264 case ARM::VLD2LNdAsm_8:
7265 case ARM::VLD2LNdAsm_16:
7266 case ARM::VLD2LNdAsm_32:
7267 case ARM::VLD2LNqAsm_16:
7268 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007269 MCInst TmpInst;
7270 // Shuffle the operands around so the lane index operand is in the
7271 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007272 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007273 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007274 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007275 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7276 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007277 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7278 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7279 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007280 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7281 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007282 TmpInst.addOperand(Inst.getOperand(1)); // lane
7283 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7284 TmpInst.addOperand(Inst.getOperand(5));
7285 Inst = TmpInst;
7286 return true;
7287 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007288
7289 case ARM::VLD3LNdAsm_8:
7290 case ARM::VLD3LNdAsm_16:
7291 case ARM::VLD3LNdAsm_32:
7292 case ARM::VLD3LNqAsm_16:
7293 case ARM::VLD3LNqAsm_32: {
7294 MCInst TmpInst;
7295 // Shuffle the operands around so the lane index operand is in the
7296 // right place.
7297 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007298 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007299 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7301 Spacing));
7302 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007303 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007304 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7305 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7306 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7307 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7308 Spacing));
7309 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007310 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007311 TmpInst.addOperand(Inst.getOperand(1)); // lane
7312 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7313 TmpInst.addOperand(Inst.getOperand(5));
7314 Inst = TmpInst;
7315 return true;
7316 }
7317
Jim Grosbach14952a02012-01-24 18:37:25 +00007318 case ARM::VLD4LNdAsm_8:
7319 case ARM::VLD4LNdAsm_16:
7320 case ARM::VLD4LNdAsm_32:
7321 case ARM::VLD4LNqAsm_16:
7322 case ARM::VLD4LNqAsm_32: {
7323 MCInst TmpInst;
7324 // Shuffle the operands around so the lane index operand is in the
7325 // right place.
7326 unsigned Spacing;
7327 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7328 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7329 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7330 Spacing));
7331 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7332 Spacing * 2));
7333 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7334 Spacing * 3));
7335 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7336 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7337 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7338 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7339 Spacing));
7340 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7341 Spacing * 2));
7342 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7343 Spacing * 3));
7344 TmpInst.addOperand(Inst.getOperand(1)); // lane
7345 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7346 TmpInst.addOperand(Inst.getOperand(5));
7347 Inst = TmpInst;
7348 return true;
7349 }
7350
Jim Grosbachb78403c2012-01-24 23:47:04 +00007351 // VLD3DUP single 3-element structure to all lanes instructions.
7352 case ARM::VLD3DUPdAsm_8:
7353 case ARM::VLD3DUPdAsm_16:
7354 case ARM::VLD3DUPdAsm_32:
7355 case ARM::VLD3DUPqAsm_8:
7356 case ARM::VLD3DUPqAsm_16:
7357 case ARM::VLD3DUPqAsm_32: {
7358 MCInst TmpInst;
7359 unsigned Spacing;
7360 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7361 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7362 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7363 Spacing));
7364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7365 Spacing * 2));
7366 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7367 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7368 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7369 TmpInst.addOperand(Inst.getOperand(4));
7370 Inst = TmpInst;
7371 return true;
7372 }
7373
7374 case ARM::VLD3DUPdWB_fixed_Asm_8:
7375 case ARM::VLD3DUPdWB_fixed_Asm_16:
7376 case ARM::VLD3DUPdWB_fixed_Asm_32:
7377 case ARM::VLD3DUPqWB_fixed_Asm_8:
7378 case ARM::VLD3DUPqWB_fixed_Asm_16:
7379 case ARM::VLD3DUPqWB_fixed_Asm_32: {
7380 MCInst TmpInst;
7381 unsigned Spacing;
7382 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7383 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7384 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7385 Spacing));
7386 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7387 Spacing * 2));
7388 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7389 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7390 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7391 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7392 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7393 TmpInst.addOperand(Inst.getOperand(4));
7394 Inst = TmpInst;
7395 return true;
7396 }
7397
7398 case ARM::VLD3DUPdWB_register_Asm_8:
7399 case ARM::VLD3DUPdWB_register_Asm_16:
7400 case ARM::VLD3DUPdWB_register_Asm_32:
7401 case ARM::VLD3DUPqWB_register_Asm_8:
7402 case ARM::VLD3DUPqWB_register_Asm_16:
7403 case ARM::VLD3DUPqWB_register_Asm_32: {
7404 MCInst TmpInst;
7405 unsigned Spacing;
7406 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7407 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7408 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7409 Spacing));
7410 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7411 Spacing * 2));
7412 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7413 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7414 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7415 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7416 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7417 TmpInst.addOperand(Inst.getOperand(5));
7418 Inst = TmpInst;
7419 return true;
7420 }
7421
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007422 // VLD3 multiple 3-element structure instructions.
7423 case ARM::VLD3dAsm_8:
7424 case ARM::VLD3dAsm_16:
7425 case ARM::VLD3dAsm_32:
7426 case ARM::VLD3qAsm_8:
7427 case ARM::VLD3qAsm_16:
7428 case ARM::VLD3qAsm_32: {
7429 MCInst TmpInst;
7430 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007431 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007432 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7433 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7434 Spacing));
7435 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7436 Spacing * 2));
7437 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7438 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7439 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7440 TmpInst.addOperand(Inst.getOperand(4));
7441 Inst = TmpInst;
7442 return true;
7443 }
7444
7445 case ARM::VLD3dWB_fixed_Asm_8:
7446 case ARM::VLD3dWB_fixed_Asm_16:
7447 case ARM::VLD3dWB_fixed_Asm_32:
7448 case ARM::VLD3qWB_fixed_Asm_8:
7449 case ARM::VLD3qWB_fixed_Asm_16:
7450 case ARM::VLD3qWB_fixed_Asm_32: {
7451 MCInst TmpInst;
7452 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007453 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007454 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7455 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7456 Spacing));
7457 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7458 Spacing * 2));
7459 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7460 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7461 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7462 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7463 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7464 TmpInst.addOperand(Inst.getOperand(4));
7465 Inst = TmpInst;
7466 return true;
7467 }
7468
7469 case ARM::VLD3dWB_register_Asm_8:
7470 case ARM::VLD3dWB_register_Asm_16:
7471 case ARM::VLD3dWB_register_Asm_32:
7472 case ARM::VLD3qWB_register_Asm_8:
7473 case ARM::VLD3qWB_register_Asm_16:
7474 case ARM::VLD3qWB_register_Asm_32: {
7475 MCInst TmpInst;
7476 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007477 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007478 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7479 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7480 Spacing));
7481 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7482 Spacing * 2));
7483 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7484 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7485 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7486 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7487 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7488 TmpInst.addOperand(Inst.getOperand(5));
7489 Inst = TmpInst;
7490 return true;
7491 }
7492
Jim Grosbach086cbfa2012-01-25 00:01:08 +00007493 // VLD4DUP single 3-element structure to all lanes instructions.
7494 case ARM::VLD4DUPdAsm_8:
7495 case ARM::VLD4DUPdAsm_16:
7496 case ARM::VLD4DUPdAsm_32:
7497 case ARM::VLD4DUPqAsm_8:
7498 case ARM::VLD4DUPqAsm_16:
7499 case ARM::VLD4DUPqAsm_32: {
7500 MCInst TmpInst;
7501 unsigned Spacing;
7502 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7503 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7504 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7505 Spacing));
7506 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7507 Spacing * 2));
7508 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7509 Spacing * 3));
7510 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7511 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7512 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7513 TmpInst.addOperand(Inst.getOperand(4));
7514 Inst = TmpInst;
7515 return true;
7516 }
7517
7518 case ARM::VLD4DUPdWB_fixed_Asm_8:
7519 case ARM::VLD4DUPdWB_fixed_Asm_16:
7520 case ARM::VLD4DUPdWB_fixed_Asm_32:
7521 case ARM::VLD4DUPqWB_fixed_Asm_8:
7522 case ARM::VLD4DUPqWB_fixed_Asm_16:
7523 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7524 MCInst TmpInst;
7525 unsigned Spacing;
7526 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7527 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7528 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7529 Spacing));
7530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7531 Spacing * 2));
7532 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7533 Spacing * 3));
7534 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7535 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7536 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7537 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7538 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7539 TmpInst.addOperand(Inst.getOperand(4));
7540 Inst = TmpInst;
7541 return true;
7542 }
7543
7544 case ARM::VLD4DUPdWB_register_Asm_8:
7545 case ARM::VLD4DUPdWB_register_Asm_16:
7546 case ARM::VLD4DUPdWB_register_Asm_32:
7547 case ARM::VLD4DUPqWB_register_Asm_8:
7548 case ARM::VLD4DUPqWB_register_Asm_16:
7549 case ARM::VLD4DUPqWB_register_Asm_32: {
7550 MCInst TmpInst;
7551 unsigned Spacing;
7552 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7553 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7555 Spacing));
7556 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7557 Spacing * 2));
7558 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7559 Spacing * 3));
7560 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7561 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7562 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7563 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7564 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7565 TmpInst.addOperand(Inst.getOperand(5));
7566 Inst = TmpInst;
7567 return true;
7568 }
7569
7570 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00007571 case ARM::VLD4dAsm_8:
7572 case ARM::VLD4dAsm_16:
7573 case ARM::VLD4dAsm_32:
7574 case ARM::VLD4qAsm_8:
7575 case ARM::VLD4qAsm_16:
7576 case ARM::VLD4qAsm_32: {
7577 MCInst TmpInst;
7578 unsigned Spacing;
7579 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7580 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7581 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7582 Spacing));
7583 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7584 Spacing * 2));
7585 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7586 Spacing * 3));
7587 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7588 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7589 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7590 TmpInst.addOperand(Inst.getOperand(4));
7591 Inst = TmpInst;
7592 return true;
7593 }
7594
7595 case ARM::VLD4dWB_fixed_Asm_8:
7596 case ARM::VLD4dWB_fixed_Asm_16:
7597 case ARM::VLD4dWB_fixed_Asm_32:
7598 case ARM::VLD4qWB_fixed_Asm_8:
7599 case ARM::VLD4qWB_fixed_Asm_16:
7600 case ARM::VLD4qWB_fixed_Asm_32: {
7601 MCInst TmpInst;
7602 unsigned Spacing;
7603 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7604 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7605 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7606 Spacing));
7607 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7608 Spacing * 2));
7609 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7610 Spacing * 3));
7611 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7612 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7613 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7614 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7615 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7616 TmpInst.addOperand(Inst.getOperand(4));
7617 Inst = TmpInst;
7618 return true;
7619 }
7620
7621 case ARM::VLD4dWB_register_Asm_8:
7622 case ARM::VLD4dWB_register_Asm_16:
7623 case ARM::VLD4dWB_register_Asm_32:
7624 case ARM::VLD4qWB_register_Asm_8:
7625 case ARM::VLD4qWB_register_Asm_16:
7626 case ARM::VLD4qWB_register_Asm_32: {
7627 MCInst TmpInst;
7628 unsigned Spacing;
7629 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7630 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7631 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7632 Spacing));
7633 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7634 Spacing * 2));
7635 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7636 Spacing * 3));
7637 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7638 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7639 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7640 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7641 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7642 TmpInst.addOperand(Inst.getOperand(5));
7643 Inst = TmpInst;
7644 return true;
7645 }
7646
Jim Grosbach1a747242012-01-23 23:45:44 +00007647 // VST3 multiple 3-element structure instructions.
7648 case ARM::VST3dAsm_8:
7649 case ARM::VST3dAsm_16:
7650 case ARM::VST3dAsm_32:
7651 case ARM::VST3qAsm_8:
7652 case ARM::VST3qAsm_16:
7653 case ARM::VST3qAsm_32: {
7654 MCInst TmpInst;
7655 unsigned Spacing;
7656 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7657 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7658 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7659 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7660 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7661 Spacing));
7662 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7663 Spacing * 2));
7664 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7665 TmpInst.addOperand(Inst.getOperand(4));
7666 Inst = TmpInst;
7667 return true;
7668 }
7669
7670 case ARM::VST3dWB_fixed_Asm_8:
7671 case ARM::VST3dWB_fixed_Asm_16:
7672 case ARM::VST3dWB_fixed_Asm_32:
7673 case ARM::VST3qWB_fixed_Asm_8:
7674 case ARM::VST3qWB_fixed_Asm_16:
7675 case ARM::VST3qWB_fixed_Asm_32: {
7676 MCInst TmpInst;
7677 unsigned Spacing;
7678 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7679 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7680 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7681 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7682 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7683 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7684 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7685 Spacing));
7686 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7687 Spacing * 2));
7688 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7689 TmpInst.addOperand(Inst.getOperand(4));
7690 Inst = TmpInst;
7691 return true;
7692 }
7693
7694 case ARM::VST3dWB_register_Asm_8:
7695 case ARM::VST3dWB_register_Asm_16:
7696 case ARM::VST3dWB_register_Asm_32:
7697 case ARM::VST3qWB_register_Asm_8:
7698 case ARM::VST3qWB_register_Asm_16:
7699 case ARM::VST3qWB_register_Asm_32: {
7700 MCInst TmpInst;
7701 unsigned Spacing;
7702 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7703 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7704 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7705 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7706 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7707 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7708 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7709 Spacing));
7710 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7711 Spacing * 2));
7712 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7713 TmpInst.addOperand(Inst.getOperand(5));
7714 Inst = TmpInst;
7715 return true;
7716 }
7717
Jim Grosbachda70eac2012-01-24 00:58:13 +00007718 // VST4 multiple 3-element structure instructions.
7719 case ARM::VST4dAsm_8:
7720 case ARM::VST4dAsm_16:
7721 case ARM::VST4dAsm_32:
7722 case ARM::VST4qAsm_8:
7723 case ARM::VST4qAsm_16:
7724 case ARM::VST4qAsm_32: {
7725 MCInst TmpInst;
7726 unsigned Spacing;
7727 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7728 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7729 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7730 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7731 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7732 Spacing));
7733 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7734 Spacing * 2));
7735 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7736 Spacing * 3));
7737 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7738 TmpInst.addOperand(Inst.getOperand(4));
7739 Inst = TmpInst;
7740 return true;
7741 }
7742
7743 case ARM::VST4dWB_fixed_Asm_8:
7744 case ARM::VST4dWB_fixed_Asm_16:
7745 case ARM::VST4dWB_fixed_Asm_32:
7746 case ARM::VST4qWB_fixed_Asm_8:
7747 case ARM::VST4qWB_fixed_Asm_16:
7748 case ARM::VST4qWB_fixed_Asm_32: {
7749 MCInst TmpInst;
7750 unsigned Spacing;
7751 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7752 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7753 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7754 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7755 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7756 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7758 Spacing));
7759 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7760 Spacing * 2));
7761 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7762 Spacing * 3));
7763 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7764 TmpInst.addOperand(Inst.getOperand(4));
7765 Inst = TmpInst;
7766 return true;
7767 }
7768
7769 case ARM::VST4dWB_register_Asm_8:
7770 case ARM::VST4dWB_register_Asm_16:
7771 case ARM::VST4dWB_register_Asm_32:
7772 case ARM::VST4qWB_register_Asm_8:
7773 case ARM::VST4qWB_register_Asm_16:
7774 case ARM::VST4qWB_register_Asm_32: {
7775 MCInst TmpInst;
7776 unsigned Spacing;
7777 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7778 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7779 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7780 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7781 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7782 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7783 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7784 Spacing));
7785 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7786 Spacing * 2));
7787 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7788 Spacing * 3));
7789 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7790 TmpInst.addOperand(Inst.getOperand(5));
7791 Inst = TmpInst;
7792 return true;
7793 }
7794
Jim Grosbachad66de12012-04-11 00:15:16 +00007795 // Handle encoding choice for the shift-immediate instructions.
7796 case ARM::t2LSLri:
7797 case ARM::t2LSRri:
7798 case ARM::t2ASRri: {
7799 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7800 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7801 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007802 !(static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7803 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) {
Jim Grosbachad66de12012-04-11 00:15:16 +00007804 unsigned NewOpc;
7805 switch (Inst.getOpcode()) {
7806 default: llvm_unreachable("unexpected opcode");
7807 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7808 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7809 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7810 }
7811 // The Thumb1 operands aren't in the same order. Awesome, eh?
7812 MCInst TmpInst;
7813 TmpInst.setOpcode(NewOpc);
7814 TmpInst.addOperand(Inst.getOperand(0));
7815 TmpInst.addOperand(Inst.getOperand(5));
7816 TmpInst.addOperand(Inst.getOperand(1));
7817 TmpInst.addOperand(Inst.getOperand(2));
7818 TmpInst.addOperand(Inst.getOperand(3));
7819 TmpInst.addOperand(Inst.getOperand(4));
7820 Inst = TmpInst;
7821 return true;
7822 }
7823 return false;
7824 }
7825
Jim Grosbach485e5622011-12-13 22:45:11 +00007826 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007827 case ARM::t2MOVsr:
7828 case ARM::t2MOVSsr: {
7829 // Which instruction to expand to depends on the CCOut operand and
7830 // whether we're in an IT block if the register operands are low
7831 // registers.
7832 bool isNarrow = false;
7833 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7834 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7835 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7836 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7837 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7838 isNarrow = true;
7839 MCInst TmpInst;
7840 unsigned newOpc;
7841 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7842 default: llvm_unreachable("unexpected opcode!");
7843 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7844 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7845 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7846 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7847 }
7848 TmpInst.setOpcode(newOpc);
7849 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7850 if (isNarrow)
7851 TmpInst.addOperand(MCOperand::CreateReg(
7852 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7853 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7854 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7855 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7856 TmpInst.addOperand(Inst.getOperand(5));
7857 if (!isNarrow)
7858 TmpInst.addOperand(MCOperand::CreateReg(
7859 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7860 Inst = TmpInst;
7861 return true;
7862 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007863 case ARM::t2MOVsi:
7864 case ARM::t2MOVSsi: {
7865 // Which instruction to expand to depends on the CCOut operand and
7866 // whether we're in an IT block if the register operands are low
7867 // registers.
7868 bool isNarrow = false;
7869 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7870 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7871 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7872 isNarrow = true;
7873 MCInst TmpInst;
7874 unsigned newOpc;
7875 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7876 default: llvm_unreachable("unexpected opcode!");
7877 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7878 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7879 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7880 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007881 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007882 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007883 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7884 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007885 TmpInst.setOpcode(newOpc);
7886 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7887 if (isNarrow)
7888 TmpInst.addOperand(MCOperand::CreateReg(
7889 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7890 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007891 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007892 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007893 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7894 TmpInst.addOperand(Inst.getOperand(4));
7895 if (!isNarrow)
7896 TmpInst.addOperand(MCOperand::CreateReg(
7897 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7898 Inst = TmpInst;
7899 return true;
7900 }
7901 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007902 case ARM::ASRr:
7903 case ARM::LSRr:
7904 case ARM::LSLr:
7905 case ARM::RORr: {
7906 ARM_AM::ShiftOpc ShiftTy;
7907 switch(Inst.getOpcode()) {
7908 default: llvm_unreachable("unexpected opcode!");
7909 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7910 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7911 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7912 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7913 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007914 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7915 MCInst TmpInst;
7916 TmpInst.setOpcode(ARM::MOVsr);
7917 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7918 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7919 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7920 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7921 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7922 TmpInst.addOperand(Inst.getOperand(4));
7923 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7924 Inst = TmpInst;
7925 return true;
7926 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007927 case ARM::ASRi:
7928 case ARM::LSRi:
7929 case ARM::LSLi:
7930 case ARM::RORi: {
7931 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007932 switch(Inst.getOpcode()) {
7933 default: llvm_unreachable("unexpected opcode!");
7934 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7935 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7936 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7937 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7938 }
7939 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007940 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007941 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007942 // A shift by 32 should be encoded as 0 when permitted
7943 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7944 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007945 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007946 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007947 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007948 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7949 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007950 if (Opc == ARM::MOVsi)
7951 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007952 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7953 TmpInst.addOperand(Inst.getOperand(4));
7954 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7955 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007956 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007957 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007958 case ARM::RRXi: {
7959 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7960 MCInst TmpInst;
7961 TmpInst.setOpcode(ARM::MOVsi);
7962 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7963 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7964 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7965 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7966 TmpInst.addOperand(Inst.getOperand(3));
7967 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7968 Inst = TmpInst;
7969 return true;
7970 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007971 case ARM::t2LDMIA_UPD: {
7972 // If this is a load of a single register, then we should use
7973 // a post-indexed LDR instruction instead, per the ARM ARM.
7974 if (Inst.getNumOperands() != 5)
7975 return false;
7976 MCInst TmpInst;
7977 TmpInst.setOpcode(ARM::t2LDR_POST);
7978 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7979 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7980 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7981 TmpInst.addOperand(MCOperand::CreateImm(4));
7982 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7983 TmpInst.addOperand(Inst.getOperand(3));
7984 Inst = TmpInst;
7985 return true;
7986 }
7987 case ARM::t2STMDB_UPD: {
7988 // If this is a store of a single register, then we should use
7989 // a pre-indexed STR instruction instead, per the ARM ARM.
7990 if (Inst.getNumOperands() != 5)
7991 return false;
7992 MCInst TmpInst;
7993 TmpInst.setOpcode(ARM::t2STR_PRE);
7994 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7995 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7996 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7997 TmpInst.addOperand(MCOperand::CreateImm(-4));
7998 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7999 TmpInst.addOperand(Inst.getOperand(3));
8000 Inst = TmpInst;
8001 return true;
8002 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008003 case ARM::LDMIA_UPD:
8004 // If this is a load of a single register via a 'pop', then we should use
8005 // a post-indexed LDR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008006 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008007 Inst.getNumOperands() == 5) {
8008 MCInst TmpInst;
8009 TmpInst.setOpcode(ARM::LDR_POST_IMM);
8010 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8011 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8012 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8013 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
8014 TmpInst.addOperand(MCOperand::CreateImm(4));
8015 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8016 TmpInst.addOperand(Inst.getOperand(3));
8017 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008018 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008019 }
8020 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008021 case ARM::STMDB_UPD:
8022 // If this is a store of a single register via a 'push', then we should use
8023 // a pre-indexed STR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008024 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008025 Inst.getNumOperands() == 5) {
8026 MCInst TmpInst;
8027 TmpInst.setOpcode(ARM::STR_PRE_IMM);
8028 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8029 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8030 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
8031 TmpInst.addOperand(MCOperand::CreateImm(-4));
8032 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8033 TmpInst.addOperand(Inst.getOperand(3));
8034 Inst = TmpInst;
8035 }
8036 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00008037 case ARM::t2ADDri12:
8038 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
8039 // mnemonic was used (not "addw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008040 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008041 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8042 break;
8043 Inst.setOpcode(ARM::t2ADDri);
8044 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8045 break;
8046 case ARM::t2SUBri12:
8047 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
8048 // mnemonic was used (not "subw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008049 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008050 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8051 break;
8052 Inst.setOpcode(ARM::t2SUBri);
8053 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8054 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008055 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008056 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00008057 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8058 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8059 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008060 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008061 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008062 return true;
8063 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008064 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008065 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008066 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008067 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8068 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8069 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008070 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008071 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008072 return true;
8073 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008074 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00008075 case ARM::t2ADDri:
8076 case ARM::t2SUBri: {
8077 // If the destination and first source operand are the same, and
8078 // the flags are compatible with the current IT status, use encoding T2
8079 // instead of T3. For compatibility with the system 'as'. Make sure the
8080 // wide encoding wasn't explicit.
8081 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00008082 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00008083 (unsigned)Inst.getOperand(2).getImm() > 255 ||
8084 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008085 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
8086 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8087 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbachdef5e342012-03-30 17:20:40 +00008088 break;
8089 MCInst TmpInst;
8090 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
8091 ARM::tADDi8 : ARM::tSUBi8);
8092 TmpInst.addOperand(Inst.getOperand(0));
8093 TmpInst.addOperand(Inst.getOperand(5));
8094 TmpInst.addOperand(Inst.getOperand(0));
8095 TmpInst.addOperand(Inst.getOperand(2));
8096 TmpInst.addOperand(Inst.getOperand(3));
8097 TmpInst.addOperand(Inst.getOperand(4));
8098 Inst = TmpInst;
8099 return true;
8100 }
Jim Grosbache489bab2011-12-05 22:16:39 +00008101 case ARM::t2ADDrr: {
8102 // If the destination and first source operand are the same, and
8103 // there's no setting of the flags, use encoding T2 instead of T3.
8104 // Note that this is only for ADD, not SUB. This mirrors the system
8105 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
8106 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
8107 Inst.getOperand(5).getReg() != 0 ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008108 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8109 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00008110 break;
8111 MCInst TmpInst;
8112 TmpInst.setOpcode(ARM::tADDhirr);
8113 TmpInst.addOperand(Inst.getOperand(0));
8114 TmpInst.addOperand(Inst.getOperand(0));
8115 TmpInst.addOperand(Inst.getOperand(2));
8116 TmpInst.addOperand(Inst.getOperand(3));
8117 TmpInst.addOperand(Inst.getOperand(4));
8118 Inst = TmpInst;
8119 return true;
8120 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00008121 case ARM::tADDrSP: {
8122 // If the non-SP source operand and the destination operand are not the
8123 // same, we need to use the 32-bit encoding if it's available.
8124 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
8125 Inst.setOpcode(ARM::t2ADDrr);
8126 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8127 return true;
8128 }
8129 break;
8130 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008131 case ARM::tB:
8132 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008133 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008134 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008135 return true;
8136 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008137 break;
8138 case ARM::t2B:
8139 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008140 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008141 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008142 return true;
8143 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008144 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00008145 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008146 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00008147 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00008148 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00008149 return true;
8150 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00008151 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008152 case ARM::tBcc:
8153 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00008154 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008155 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00008156 return true;
8157 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00008158 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008159 case ARM::tLDMIA: {
8160 // If the register list contains any high registers, or if the writeback
8161 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
8162 // instead if we're in Thumb2. Otherwise, this should have generated
8163 // an error in validateInstruction().
8164 unsigned Rn = Inst.getOperand(0).getReg();
8165 bool hasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00008166 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8167 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Jim Grosbacha31f2232011-09-07 18:05:34 +00008168 bool listContainsBase;
8169 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
8170 (!listContainsBase && !hasWritebackToken) ||
8171 (listContainsBase && hasWritebackToken)) {
8172 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8173 assert (isThumbTwo());
8174 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
8175 // If we're switching to the updating version, we need to insert
8176 // the writeback tied operand.
8177 if (hasWritebackToken)
8178 Inst.insert(Inst.begin(),
8179 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00008180 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008181 }
8182 break;
8183 }
Jim Grosbach099c9762011-09-16 20:50:13 +00008184 case ARM::tSTMIA_UPD: {
8185 // If the register list contains any high registers, we need to use
8186 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8187 // should have generated an error in validateInstruction().
8188 unsigned Rn = Inst.getOperand(0).getReg();
8189 bool listContainsBase;
8190 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
8191 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8192 assert (isThumbTwo());
8193 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00008194 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00008195 }
8196 break;
8197 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008198 case ARM::tPOP: {
8199 bool listContainsBase;
8200 // If the register list contains any high registers, we need to use
8201 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8202 // should have generated an error in validateInstruction().
8203 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008204 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008205 assert (isThumbTwo());
8206 Inst.setOpcode(ARM::t2LDMIA_UPD);
8207 // Add the base register and writeback operands.
8208 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8209 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008210 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008211 }
8212 case ARM::tPUSH: {
8213 bool listContainsBase;
8214 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008215 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008216 assert (isThumbTwo());
8217 Inst.setOpcode(ARM::t2STMDB_UPD);
8218 // Add the base register and writeback operands.
8219 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8220 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008221 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008222 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008223 case ARM::t2MOVi: {
8224 // If we can use the 16-bit encoding and the user didn't explicitly
8225 // request the 32-bit variant, transform it here.
8226 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00008227 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00008228 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008229 Inst.getOperand(4).getReg() == ARM::CPSR) ||
8230 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
8231 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8232 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008233 // The operands aren't in the same order for tMOVi8...
8234 MCInst TmpInst;
8235 TmpInst.setOpcode(ARM::tMOVi8);
8236 TmpInst.addOperand(Inst.getOperand(0));
8237 TmpInst.addOperand(Inst.getOperand(4));
8238 TmpInst.addOperand(Inst.getOperand(1));
8239 TmpInst.addOperand(Inst.getOperand(2));
8240 TmpInst.addOperand(Inst.getOperand(3));
8241 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008242 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008243 }
8244 break;
8245 }
8246 case ARM::t2MOVr: {
8247 // If we can use the 16-bit encoding and the user didn't explicitly
8248 // request the 32-bit variant, transform it here.
8249 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8250 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8251 Inst.getOperand(2).getImm() == ARMCC::AL &&
8252 Inst.getOperand(4).getReg() == ARM::CPSR &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008253 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8254 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008255 // The operands aren't the same for tMOV[S]r... (no cc_out)
8256 MCInst TmpInst;
8257 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
8258 TmpInst.addOperand(Inst.getOperand(0));
8259 TmpInst.addOperand(Inst.getOperand(1));
8260 TmpInst.addOperand(Inst.getOperand(2));
8261 TmpInst.addOperand(Inst.getOperand(3));
8262 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008263 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008264 }
8265 break;
8266 }
Jim Grosbach82213192011-09-19 20:29:33 +00008267 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00008268 case ARM::t2SXTB:
8269 case ARM::t2UXTH:
8270 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00008271 // If we can use the 16-bit encoding and the user didn't explicitly
8272 // request the 32-bit variant, transform it here.
8273 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8274 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8275 Inst.getOperand(2).getImm() == 0 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008276 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8277 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00008278 unsigned NewOpc;
8279 switch (Inst.getOpcode()) {
8280 default: llvm_unreachable("Illegal opcode!");
8281 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
8282 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
8283 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
8284 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
8285 }
Jim Grosbach82213192011-09-19 20:29:33 +00008286 // The operands aren't the same for thumb1 (no rotate operand).
8287 MCInst TmpInst;
8288 TmpInst.setOpcode(NewOpc);
8289 TmpInst.addOperand(Inst.getOperand(0));
8290 TmpInst.addOperand(Inst.getOperand(1));
8291 TmpInst.addOperand(Inst.getOperand(3));
8292 TmpInst.addOperand(Inst.getOperand(4));
8293 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008294 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00008295 }
8296 break;
8297 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008298 case ARM::MOVsi: {
8299 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00008300 // rrx shifts and asr/lsr of #32 is encoded as 0
8301 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
8302 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008303 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
8304 // Shifting by zero is accepted as a vanilla 'MOVr'
8305 MCInst TmpInst;
8306 TmpInst.setOpcode(ARM::MOVr);
8307 TmpInst.addOperand(Inst.getOperand(0));
8308 TmpInst.addOperand(Inst.getOperand(1));
8309 TmpInst.addOperand(Inst.getOperand(3));
8310 TmpInst.addOperand(Inst.getOperand(4));
8311 TmpInst.addOperand(Inst.getOperand(5));
8312 Inst = TmpInst;
8313 return true;
8314 }
8315 return false;
8316 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00008317 case ARM::ANDrsi:
8318 case ARM::ORRrsi:
8319 case ARM::EORrsi:
8320 case ARM::BICrsi:
8321 case ARM::SUBrsi:
8322 case ARM::ADDrsi: {
8323 unsigned newOpc;
8324 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
8325 if (SOpc == ARM_AM::rrx) return false;
8326 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00008327 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00008328 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
8329 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
8330 case ARM::EORrsi: newOpc = ARM::EORrr; break;
8331 case ARM::BICrsi: newOpc = ARM::BICrr; break;
8332 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
8333 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
8334 }
8335 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00008336 // The exception is for right shifts, where 0 == 32
8337 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
8338 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00008339 MCInst TmpInst;
8340 TmpInst.setOpcode(newOpc);
8341 TmpInst.addOperand(Inst.getOperand(0));
8342 TmpInst.addOperand(Inst.getOperand(1));
8343 TmpInst.addOperand(Inst.getOperand(2));
8344 TmpInst.addOperand(Inst.getOperand(4));
8345 TmpInst.addOperand(Inst.getOperand(5));
8346 TmpInst.addOperand(Inst.getOperand(6));
8347 Inst = TmpInst;
8348 return true;
8349 }
8350 return false;
8351 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00008352 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008353 case ARM::t2IT: {
8354 // The mask bits for all but the first condition are represented as
8355 // the low bit of the condition code value implies 't'. We currently
8356 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00008357 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008358 MCOperand &MO = Inst.getOperand(1);
8359 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00008360 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00008361 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008362 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008363 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00008364 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00008365 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008366 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00008367
8368 // Set up the IT block state according to the IT instruction we just
8369 // matched.
8370 assert(!inITBlock() && "nested IT blocks?!");
8371 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
8372 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
8373 ITState.CurPosition = 0;
8374 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008375 break;
8376 }
Richard Bartona39625e2012-07-09 16:12:24 +00008377 case ARM::t2LSLrr:
8378 case ARM::t2LSRrr:
8379 case ARM::t2ASRrr:
8380 case ARM::t2SBCrr:
8381 case ARM::t2RORrr:
8382 case ARM::t2BICrr:
8383 {
Richard Bartond5660372012-07-09 16:14:28 +00008384 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008385 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8386 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8387 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008388 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008389 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8390 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8391 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8392 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008393 unsigned NewOpc;
8394 switch (Inst.getOpcode()) {
8395 default: llvm_unreachable("unexpected opcode");
8396 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
8397 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
8398 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
8399 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
8400 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
8401 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
8402 }
8403 MCInst TmpInst;
8404 TmpInst.setOpcode(NewOpc);
8405 TmpInst.addOperand(Inst.getOperand(0));
8406 TmpInst.addOperand(Inst.getOperand(5));
8407 TmpInst.addOperand(Inst.getOperand(1));
8408 TmpInst.addOperand(Inst.getOperand(2));
8409 TmpInst.addOperand(Inst.getOperand(3));
8410 TmpInst.addOperand(Inst.getOperand(4));
8411 Inst = TmpInst;
8412 return true;
8413 }
8414 return false;
8415 }
8416 case ARM::t2ANDrr:
8417 case ARM::t2EORrr:
8418 case ARM::t2ADCrr:
8419 case ARM::t2ORRrr:
8420 {
Richard Bartond5660372012-07-09 16:14:28 +00008421 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008422 // These instructions are special in that they are commutable, so shorter encodings
8423 // are available more often.
8424 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8425 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8426 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
8427 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008428 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008429 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8430 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8431 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8432 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008433 unsigned NewOpc;
8434 switch (Inst.getOpcode()) {
8435 default: llvm_unreachable("unexpected opcode");
8436 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
8437 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
8438 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
8439 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
8440 }
8441 MCInst TmpInst;
8442 TmpInst.setOpcode(NewOpc);
8443 TmpInst.addOperand(Inst.getOperand(0));
8444 TmpInst.addOperand(Inst.getOperand(5));
8445 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
8446 TmpInst.addOperand(Inst.getOperand(1));
8447 TmpInst.addOperand(Inst.getOperand(2));
8448 } else {
8449 TmpInst.addOperand(Inst.getOperand(2));
8450 TmpInst.addOperand(Inst.getOperand(1));
8451 }
8452 TmpInst.addOperand(Inst.getOperand(3));
8453 TmpInst.addOperand(Inst.getOperand(4));
8454 Inst = TmpInst;
8455 return true;
8456 }
8457 return false;
8458 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008459 }
Jim Grosbachafad0532011-11-10 23:42:14 +00008460 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008461}
8462
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008463unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
8464 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
8465 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008466 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00008467 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008468 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
8469 assert(MCID.hasOptionalDef() &&
8470 "optionally flag setting instruction missing optional def operand");
8471 assert(MCID.NumOperands == Inst.getNumOperands() &&
8472 "operand count mismatch!");
8473 // Find the optional-def operand (cc_out).
8474 unsigned OpNo;
8475 for (OpNo = 0;
8476 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
8477 ++OpNo)
8478 ;
8479 // If we're parsing Thumb1, reject it completely.
8480 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
8481 return Match_MnemonicFail;
8482 // If we're parsing Thumb2, which form is legal depends on whether we're
8483 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00008484 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
8485 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008486 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00008487 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8488 inITBlock())
8489 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008490 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008491 // Some high-register supporting Thumb1 encodings only allow both registers
8492 // to be from r0-r7 when in Thumb2.
Renato Golin36c626e2014-09-26 16:14:29 +00008493 else if (Opc == ARM::tADDhirr && isThumbOne() && !hasV6MOps() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008494 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8495 isARMLowRegister(Inst.getOperand(2).getReg()))
8496 return Match_RequiresThumb2;
8497 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00008498 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008499 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8500 isARMLowRegister(Inst.getOperand(1).getReg()))
8501 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008502 return Match_Success;
8503}
8504
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008505namespace llvm {
8506template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008507 return true; // In an assembly source, no need to second-guess
8508}
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008509}
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008510
Tim Northover26bb14e2014-08-18 11:49:42 +00008511static const char *getSubtargetFeatureName(uint64_t Val);
David Blaikie960ea3f2014-06-08 16:18:35 +00008512bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
8513 OperandVector &Operands,
Tim Northover26bb14e2014-08-18 11:49:42 +00008514 MCStreamer &Out, uint64_t &ErrorInfo,
David Blaikie960ea3f2014-06-08 16:18:35 +00008515 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00008516 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00008517 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00008518
Chad Rosier2f480a82012-10-12 22:53:36 +00008519 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00008520 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00008521 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00008522 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008523 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008524 // Context sensitive operand constraints aren't handled by the matcher,
8525 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008526 if (validateInstruction(Inst, Operands)) {
8527 // Still progress the IT block, otherwise one wrong condition causes
8528 // nasty cascading errors.
8529 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008530 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008531 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008532
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008533 { // processInstruction() updates inITBlock state, we need to save it away
8534 bool wasInITBlock = inITBlock();
8535
8536 // Some instructions need post-processing to, for example, tweak which
8537 // encoding is selected. Loop on it while changes happen so the
8538 // individual transformations can chain off each other. E.g.,
8539 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00008540 while (processInstruction(Inst, Operands, Out))
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008541 ;
8542
8543 // Only after the instruction is fully processed, we can validate it
8544 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00008545 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008546 Warning(IDLoc, "deprecated instruction in IT block");
8547 }
8548 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008549
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008550 // Only move forward at the very end so that everything in validate
8551 // and process gets a consistent answer about whether we're in an IT
8552 // block.
8553 forwardITPosition();
8554
Jim Grosbach82f76d12012-01-25 19:52:01 +00008555 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8556 // doesn't actually encode.
8557 if (Inst.getOpcode() == ARM::ITasm)
8558 return false;
8559
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00008560 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00008561 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00008562 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008563 case Match_MissingFeature: {
8564 assert(ErrorInfo && "Unknown missing feature!");
8565 // Special case the error message for the very common case where only
8566 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8567 std::string Msg = "instruction requires:";
Tim Northover26bb14e2014-08-18 11:49:42 +00008568 uint64_t Mask = 1;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008569 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8570 if (ErrorInfo & Mask) {
8571 Msg += " ";
8572 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8573 }
8574 Mask <<= 1;
8575 }
8576 return Error(IDLoc, Msg);
8577 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008578 case Match_InvalidOperand: {
8579 SMLoc ErrorLoc = IDLoc;
Tim Northover26bb14e2014-08-18 11:49:42 +00008580 if (ErrorInfo != ~0ULL) {
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008581 if (ErrorInfo >= Operands.size())
8582 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00008583
David Blaikie960ea3f2014-06-08 16:18:35 +00008584 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008585 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8586 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008587
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008588 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00008589 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008590 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00008591 return Error(IDLoc, "invalid instruction",
David Blaikie960ea3f2014-06-08 16:18:35 +00008592 ((ARMOperand &)*Operands[0]).getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00008593 case Match_RequiresNotITBlock:
8594 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008595 case Match_RequiresITBlock:
8596 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008597 case Match_RequiresV6:
8598 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8599 case Match_RequiresThumb2:
8600 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00008601 case Match_ImmRange0_15: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008602 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Jim Grosbach087affe2012-06-22 23:56:48 +00008603 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8604 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8605 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008606 case Match_ImmRange0_239: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008607 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008608 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8609 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8610 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00008611 case Match_AlignedMemoryRequiresNone:
8612 case Match_DupAlignedMemoryRequiresNone:
8613 case Match_AlignedMemoryRequires16:
8614 case Match_DupAlignedMemoryRequires16:
8615 case Match_AlignedMemoryRequires32:
8616 case Match_DupAlignedMemoryRequires32:
8617 case Match_AlignedMemoryRequires64:
8618 case Match_DupAlignedMemoryRequires64:
8619 case Match_AlignedMemoryRequires64or128:
8620 case Match_DupAlignedMemoryRequires64or128:
8621 case Match_AlignedMemoryRequires64or128or256:
8622 {
David Blaikie960ea3f2014-06-08 16:18:35 +00008623 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00008624 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8625 switch (MatchResult) {
8626 default:
8627 llvm_unreachable("Missing Match_Aligned type");
8628 case Match_AlignedMemoryRequiresNone:
8629 case Match_DupAlignedMemoryRequiresNone:
8630 return Error(ErrorLoc, "alignment must be omitted");
8631 case Match_AlignedMemoryRequires16:
8632 case Match_DupAlignedMemoryRequires16:
8633 return Error(ErrorLoc, "alignment must be 16 or omitted");
8634 case Match_AlignedMemoryRequires32:
8635 case Match_DupAlignedMemoryRequires32:
8636 return Error(ErrorLoc, "alignment must be 32 or omitted");
8637 case Match_AlignedMemoryRequires64:
8638 case Match_DupAlignedMemoryRequires64:
8639 return Error(ErrorLoc, "alignment must be 64 or omitted");
8640 case Match_AlignedMemoryRequires64or128:
8641 case Match_DupAlignedMemoryRequires64or128:
8642 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8643 case Match_AlignedMemoryRequires64or128or256:
8644 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8645 }
8646 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008647 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008648
Eric Christopher91d7b902010-10-29 09:26:59 +00008649 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00008650}
8651
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008652/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00008653bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008654 const MCObjectFileInfo::Environment Format =
8655 getContext().getObjectFileInfo()->getObjectFileType();
8656 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008657 bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008658
Kevin Enderbyccab3172009-09-15 00:27:25 +00008659 StringRef IDVal = DirectiveID.getIdentifier();
8660 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008661 return parseLiteralValues(4, DirectiveID.getLoc());
8662 else if (IDVal == ".short" || IDVal == ".hword")
8663 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008664 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008665 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00008666 else if (IDVal == ".arm")
8667 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008668 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008669 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008670 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008671 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008672 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008673 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008674 else if (IDVal == ".unreq")
8675 return parseDirectiveUnreq(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00008676 else if (IDVal == ".fnend")
8677 return parseDirectiveFnEnd(DirectiveID.getLoc());
8678 else if (IDVal == ".cantunwind")
8679 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8680 else if (IDVal == ".personality")
8681 return parseDirectivePersonality(DirectiveID.getLoc());
8682 else if (IDVal == ".handlerdata")
8683 return parseDirectiveHandlerData(DirectiveID.getLoc());
8684 else if (IDVal == ".setfp")
8685 return parseDirectiveSetFP(DirectiveID.getLoc());
8686 else if (IDVal == ".pad")
8687 return parseDirectivePad(DirectiveID.getLoc());
8688 else if (IDVal == ".save")
8689 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8690 else if (IDVal == ".vsave")
8691 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008692 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008693 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008694 else if (IDVal == ".even")
8695 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008696 else if (IDVal == ".personalityindex")
8697 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008698 else if (IDVal == ".unwind_raw")
8699 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008700 else if (IDVal == ".movsp")
8701 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008702 else if (IDVal == ".arch_extension")
8703 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008704 else if (IDVal == ".align")
8705 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008706 else if (IDVal == ".thumb_set")
8707 return parseDirectiveThumbSet(DirectiveID.getLoc());
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008708
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008709 if (!IsMachO && !IsCOFF) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008710 if (IDVal == ".arch")
8711 return parseDirectiveArch(DirectiveID.getLoc());
8712 else if (IDVal == ".cpu")
8713 return parseDirectiveCPU(DirectiveID.getLoc());
8714 else if (IDVal == ".eabi_attribute")
8715 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8716 else if (IDVal == ".fpu")
8717 return parseDirectiveFPU(DirectiveID.getLoc());
8718 else if (IDVal == ".fnstart")
8719 return parseDirectiveFnStart(DirectiveID.getLoc());
8720 else if (IDVal == ".inst")
8721 return parseDirectiveInst(DirectiveID.getLoc());
8722 else if (IDVal == ".inst.n")
8723 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8724 else if (IDVal == ".inst.w")
8725 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8726 else if (IDVal == ".object_arch")
8727 return parseDirectiveObjectArch(DirectiveID.getLoc());
8728 else if (IDVal == ".tlsdescseq")
8729 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8730 }
8731
Kevin Enderbyccab3172009-09-15 00:27:25 +00008732 return true;
8733}
8734
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008735/// parseLiteralValues
8736/// ::= .hword expression [, expression]*
8737/// ::= .short expression [, expression]*
8738/// ::= .word expression [, expression]*
8739bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008740 MCAsmParser &Parser = getParser();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008741 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8742 for (;;) {
8743 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008744 if (getParser().parseExpression(Value)) {
8745 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008746 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008747 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008748
Eric Christopherbf7bc492013-01-09 03:52:05 +00008749 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008750
8751 if (getLexer().is(AsmToken::EndOfStatement))
8752 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008753
Kevin Enderbyccab3172009-09-15 00:27:25 +00008754 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008755 if (getLexer().isNot(AsmToken::Comma)) {
8756 Error(L, "unexpected token in directive");
8757 return false;
8758 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008759 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008760 }
8761 }
8762
Sean Callanana83fd7d2010-01-19 20:27:46 +00008763 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008764 return false;
8765}
8766
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008767/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008768/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008769bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008770 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008771 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8772 Error(L, "unexpected token in directive");
8773 return false;
8774 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008775 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008776
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008777 if (!hasThumb()) {
8778 Error(L, "target does not support Thumb mode");
8779 return false;
8780 }
Tim Northovera2292d02013-06-10 23:20:58 +00008781
Jim Grosbach7f882392011-12-07 18:04:19 +00008782 if (!isThumb())
8783 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008784
Jim Grosbach7f882392011-12-07 18:04:19 +00008785 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8786 return false;
8787}
8788
8789/// parseDirectiveARM
8790/// ::= .arm
8791bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008792 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008793 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8794 Error(L, "unexpected token in directive");
8795 return false;
8796 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008797 Parser.Lex();
8798
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008799 if (!hasARM()) {
8800 Error(L, "target does not support ARM mode");
8801 return false;
8802 }
Tim Northovera2292d02013-06-10 23:20:58 +00008803
Jim Grosbach7f882392011-12-07 18:04:19 +00008804 if (isThumb())
8805 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008806
Jim Grosbach7f882392011-12-07 18:04:19 +00008807 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008808 return false;
8809}
8810
Tim Northover1744d0a2013-10-25 12:49:50 +00008811void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8812 if (NextSymbolIsThumb) {
8813 getParser().getStreamer().EmitThumbFunc(Symbol);
8814 NextSymbolIsThumb = false;
8815 }
8816}
8817
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008818/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008819/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008820bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008821 MCAsmParser &Parser = getParser();
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008822 const auto Format = getContext().getObjectFileInfo()->getObjectFileType();
8823 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008824
Jim Grosbach1152cc02011-12-21 22:30:16 +00008825 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008826 // ELF doesn't
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008827 if (IsMachO) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008828 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008829 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008830 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8831 Error(L, "unexpected token in .thumb_func directive");
8832 return false;
8833 }
8834
Tim Northover1744d0a2013-10-25 12:49:50 +00008835 MCSymbol *Func =
8836 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8837 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008838 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008839 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008840 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008841 }
8842
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008843 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008844 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8845 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008846 return false;
8847 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008848
Tim Northover1744d0a2013-10-25 12:49:50 +00008849 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008850 return false;
8851}
8852
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008853/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008854/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008855bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008856 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008857 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008858 if (Tok.isNot(AsmToken::Identifier)) {
8859 Error(L, "unexpected token in .syntax directive");
8860 return false;
8861 }
8862
Benjamin Kramer92d89982010-07-14 22:38:02 +00008863 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008864 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008865 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008866 } else if (Mode == "divided" || Mode == "DIVIDED") {
8867 Error(L, "'.syntax divided' arm asssembly not supported");
8868 return false;
8869 } else {
8870 Error(L, "unrecognized syntax mode in .syntax directive");
8871 return false;
8872 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008873
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008874 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8875 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8876 return false;
8877 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008878 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008879
8880 // TODO tell the MC streamer the mode
8881 // getParser().getStreamer().Emit???();
8882 return false;
8883}
8884
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008885/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008886/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008887bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008888 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008889 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008890 if (Tok.isNot(AsmToken::Integer)) {
8891 Error(L, "unexpected token in .code directive");
8892 return false;
8893 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008894 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008895 if (Val != 16 && Val != 32) {
8896 Error(L, "invalid operand to .code directive");
8897 return false;
8898 }
8899 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008900
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008901 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8902 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8903 return false;
8904 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008905 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008906
Evan Cheng284b4672011-07-08 22:36:29 +00008907 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008908 if (!hasThumb()) {
8909 Error(L, "target does not support Thumb mode");
8910 return false;
8911 }
Tim Northovera2292d02013-06-10 23:20:58 +00008912
Jim Grosbachf471ac32011-09-06 18:46:23 +00008913 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008914 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008915 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008916 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008917 if (!hasARM()) {
8918 Error(L, "target does not support ARM mode");
8919 return false;
8920 }
Tim Northovera2292d02013-06-10 23:20:58 +00008921
Jim Grosbachf471ac32011-09-06 18:46:23 +00008922 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008923 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008924 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008925 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008926
Kevin Enderby146dcf22009-10-15 20:48:48 +00008927 return false;
8928}
8929
Jim Grosbachab5830e2011-12-14 02:16:11 +00008930/// parseDirectiveReq
8931/// ::= name .req registername
8932bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008933 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008934 Parser.Lex(); // Eat the '.req' token.
8935 unsigned Reg;
8936 SMLoc SRegLoc, ERegLoc;
8937 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008938 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008939 Error(SRegLoc, "register name expected");
8940 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008941 }
8942
8943 // Shouldn't be anything else.
8944 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008945 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008946 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8947 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008948 }
8949
8950 Parser.Lex(); // Consume the EndOfStatement
8951
David Blaikie5106ce72014-11-19 05:49:42 +00008952 if (!RegisterReqs.insert(std::make_pair(Name, Reg)).second) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008953 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8954 return false;
8955 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00008956
8957 return false;
8958}
8959
8960/// parseDirectiveUneq
8961/// ::= .unreq registername
8962bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008963 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008964 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008965 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008966 Error(L, "unexpected input in .unreq directive.");
8967 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008968 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00008969 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008970 Parser.Lex(); // Eat the identifier.
8971 return false;
8972}
8973
Jason W Kim135d2442011-12-20 17:38:12 +00008974/// parseDirectiveArch
8975/// ::= .arch token
8976bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00008977 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8978
8979 unsigned ID = StringSwitch<unsigned>(Arch)
8980#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8981 .Case(NAME, ARM::ID)
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +00008982#define ARM_ARCH_ALIAS(NAME, ID) \
8983 .Case(NAME, ARM::ID)
Logan Chien439e8f92013-12-11 17:16:25 +00008984#include "MCTargetDesc/ARMArchName.def"
8985 .Default(ARM::INVALID_ARCH);
8986
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008987 if (ID == ARM::INVALID_ARCH) {
8988 Error(L, "Unknown arch name");
8989 return false;
8990 }
Logan Chien439e8f92013-12-11 17:16:25 +00008991
8992 getTargetStreamer().emitArch(ID);
8993 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008994}
8995
8996/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008997/// ::= .eabi_attribute int, int [, "str"]
8998/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00008999bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009000 MCAsmParser &Parser = getParser();
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009001 int64_t Tag;
9002 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009003 TagLoc = Parser.getTok().getLoc();
9004 if (Parser.getTok().is(AsmToken::Identifier)) {
9005 StringRef Name = Parser.getTok().getIdentifier();
9006 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
9007 if (Tag == -1) {
9008 Error(TagLoc, "attribute name not recognised: " + Name);
9009 Parser.eatToEndOfStatement();
9010 return false;
9011 }
9012 Parser.Lex();
9013 } else {
9014 const MCExpr *AttrExpr;
9015
9016 TagLoc = Parser.getTok().getLoc();
9017 if (Parser.parseExpression(AttrExpr)) {
9018 Parser.eatToEndOfStatement();
9019 return false;
9020 }
9021
9022 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
9023 if (!CE) {
9024 Error(TagLoc, "expected numeric constant");
9025 Parser.eatToEndOfStatement();
9026 return false;
9027 }
9028
9029 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009030 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009031
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009032 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009033 Error(Parser.getTok().getLoc(), "comma expected");
9034 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009035 return false;
9036 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009037 Parser.Lex(); // skip comma
9038
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009039 StringRef StringValue = "";
9040 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00009041
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009042 int64_t IntegerValue = 0;
9043 bool IsIntegerValue = false;
9044
9045 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
9046 IsStringValue = true;
9047 else if (Tag == ARMBuildAttrs::compatibility) {
9048 IsStringValue = true;
9049 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00009050 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009051 IsIntegerValue = true;
9052 else if (Tag % 2 == 1)
9053 IsStringValue = true;
9054 else
9055 llvm_unreachable("invalid tag type");
9056
9057 if (IsIntegerValue) {
9058 const MCExpr *ValueExpr;
9059 SMLoc ValueExprLoc = Parser.getTok().getLoc();
9060 if (Parser.parseExpression(ValueExpr)) {
9061 Parser.eatToEndOfStatement();
9062 return false;
9063 }
9064
9065 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
9066 if (!CE) {
9067 Error(ValueExprLoc, "expected numeric constant");
9068 Parser.eatToEndOfStatement();
9069 return false;
9070 }
9071
9072 IntegerValue = CE->getValue();
9073 }
9074
9075 if (Tag == ARMBuildAttrs::compatibility) {
9076 if (Parser.getTok().isNot(AsmToken::Comma))
9077 IsStringValue = false;
9078 else
9079 Parser.Lex();
9080 }
9081
9082 if (IsStringValue) {
9083 if (Parser.getTok().isNot(AsmToken::String)) {
9084 Error(Parser.getTok().getLoc(), "bad string constant");
9085 Parser.eatToEndOfStatement();
9086 return false;
9087 }
9088
9089 StringValue = Parser.getTok().getStringContents();
9090 Parser.Lex();
9091 }
9092
9093 if (IsIntegerValue && IsStringValue) {
9094 assert(Tag == ARMBuildAttrs::compatibility);
9095 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
9096 } else if (IsIntegerValue)
9097 getTargetStreamer().emitAttribute(Tag, IntegerValue);
9098 else if (IsStringValue)
9099 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00009100 return false;
9101}
9102
9103/// parseDirectiveCPU
9104/// ::= .cpu str
9105bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
9106 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
9107 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
Roman Divacky7e6b5952014-12-02 20:03:22 +00009108
Roman Divackyfdf05602014-12-03 18:39:44 +00009109 if (!STI.isCPUStringValid(CPU)) {
Roman Divacky7e6b5952014-12-02 20:03:22 +00009110 Error(L, "Unknown CPU name");
9111 return false;
9112 }
9113
Roman Divacky6fd64ff2014-12-04 21:39:24 +00009114 // FIXME: This switches the CPU features globally, therefore it might
9115 // happen that code you would not expect to assemble will. For details
9116 // see: http://llvm.org/bugs/show_bug.cgi?id=20757
Roman Divacky7e6b5952014-12-02 20:03:22 +00009117 STI.InitMCProcessorInfo(CPU, "");
9118 STI.InitCPUSchedModel(CPU);
9119 unsigned FB = ComputeAvailableFeatures(STI.getFeatureBits());
9120 setAvailableFeatures(FB);
9121
Logan Chien8cbb80d2013-10-28 17:51:12 +00009122 return false;
9123}
9124
Nico Weberae050bb2014-08-16 05:37:51 +00009125// FIXME: This is duplicated in getARMFPUFeatures() in
9126// tools/clang/lib/Driver/Tools.cpp
9127static const struct {
9128 const unsigned Fpu;
9129 const uint64_t Enabled;
9130 const uint64_t Disabled;
9131} Fpus[] = {
9132 {ARM::VFP, ARM::FeatureVFP2, ARM::FeatureNEON},
9133 {ARM::VFPV2, ARM::FeatureVFP2, ARM::FeatureNEON},
9134 {ARM::VFPV3, ARM::FeatureVFP3, ARM::FeatureNEON},
9135 {ARM::VFPV3_D16, ARM::FeatureVFP3 | ARM::FeatureD16, ARM::FeatureNEON},
9136 {ARM::VFPV4, ARM::FeatureVFP4, ARM::FeatureNEON},
9137 {ARM::VFPV4_D16, ARM::FeatureVFP4 | ARM::FeatureD16, ARM::FeatureNEON},
Oliver Stannard37e4daa2014-10-01 09:02:17 +00009138 {ARM::FPV5_D16, ARM::FeatureFPARMv8 | ARM::FeatureD16,
9139 ARM::FeatureNEON | ARM::FeatureCrypto},
Nico Weberae050bb2014-08-16 05:37:51 +00009140 {ARM::FP_ARMV8, ARM::FeatureFPARMv8,
9141 ARM::FeatureNEON | ARM::FeatureCrypto},
9142 {ARM::NEON, ARM::FeatureNEON, 0},
9143 {ARM::NEON_VFPV4, ARM::FeatureVFP4 | ARM::FeatureNEON, 0},
9144 {ARM::NEON_FP_ARMV8, ARM::FeatureFPARMv8 | ARM::FeatureNEON,
9145 ARM::FeatureCrypto},
9146 {ARM::CRYPTO_NEON_FP_ARMV8,
9147 ARM::FeatureFPARMv8 | ARM::FeatureNEON | ARM::FeatureCrypto, 0},
9148 {ARM::SOFTVFP, 0, 0},
9149};
9150
Logan Chien8cbb80d2013-10-28 17:51:12 +00009151/// parseDirectiveFPU
9152/// ::= .fpu str
9153bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
9154 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
9155
9156 unsigned ID = StringSwitch<unsigned>(FPU)
9157#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
9158#include "ARMFPUName.def"
9159 .Default(ARM::INVALID_FPU);
9160
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009161 if (ID == ARM::INVALID_FPU) {
9162 Error(L, "Unknown FPU name");
9163 return false;
9164 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009165
Nico Weberae050bb2014-08-16 05:37:51 +00009166 for (const auto &Fpu : Fpus) {
9167 if (Fpu.Fpu != ID)
9168 continue;
9169
9170 // Need to toggle features that should be on but are off and that
9171 // should off but are on.
Tim Northover26bb14e2014-08-18 11:49:42 +00009172 uint64_t Toggle = (Fpu.Enabled & ~STI.getFeatureBits()) |
Nico Weberae050bb2014-08-16 05:37:51 +00009173 (Fpu.Disabled & STI.getFeatureBits());
9174 setAvailableFeatures(ComputeAvailableFeatures(STI.ToggleFeature(Toggle)));
9175 break;
9176 }
9177
Logan Chien8cbb80d2013-10-28 17:51:12 +00009178 getTargetStreamer().emitFPU(ID);
9179 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00009180}
9181
Logan Chien4ea23b52013-05-10 16:17:24 +00009182/// parseDirectiveFnStart
9183/// ::= .fnstart
9184bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009185 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009186 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009187 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009188 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009189 }
9190
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009191 // Reset the unwind directives parser state
9192 UC.reset();
9193
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009194 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009195
9196 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00009197 return false;
9198}
9199
9200/// parseDirectiveFnEnd
9201/// ::= .fnend
9202bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
9203 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009204 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009205 Error(L, ".fnstart must precede .fnend directive");
9206 return false;
9207 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009208
9209 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009210 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009211
9212 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00009213 return false;
9214}
9215
9216/// parseDirectiveCantUnwind
9217/// ::= .cantunwind
9218bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009219 UC.recordCantUnwind(L);
9220
Logan Chien4ea23b52013-05-10 16:17:24 +00009221 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009222 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009223 Error(L, ".fnstart must precede .cantunwind directive");
9224 return false;
9225 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009226 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009227 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009228 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009229 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009230 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009231 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009232 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009233 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009234 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009235 }
9236
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009237 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00009238 return false;
9239}
9240
9241/// parseDirectivePersonality
9242/// ::= .personality name
9243bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009244 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009245 bool HasExistingPersonality = UC.hasPersonality();
9246
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009247 UC.recordPersonality(L);
9248
Logan Chien4ea23b52013-05-10 16:17:24 +00009249 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009250 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009251 Error(L, ".fnstart must precede .personality directive");
9252 return false;
9253 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009254 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009255 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009256 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009257 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009258 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009259 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009260 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009261 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009262 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009263 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009264 if (HasExistingPersonality) {
9265 Parser.eatToEndOfStatement();
9266 Error(L, "multiple personality directives");
9267 UC.emitPersonalityLocNotes();
9268 return false;
9269 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009270
9271 // Parse the name of the personality routine
9272 if (Parser.getTok().isNot(AsmToken::Identifier)) {
9273 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009274 Error(L, "unexpected input in .personality directive.");
9275 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009276 }
9277 StringRef Name(Parser.getTok().getIdentifier());
9278 Parser.Lex();
9279
9280 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009281 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00009282 return false;
9283}
9284
9285/// parseDirectiveHandlerData
9286/// ::= .handlerdata
9287bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009288 UC.recordHandlerData(L);
9289
Logan Chien4ea23b52013-05-10 16:17:24 +00009290 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009291 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009292 Error(L, ".fnstart must precede .personality directive");
9293 return false;
9294 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009295 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009296 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009297 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009298 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009299 }
9300
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009301 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00009302 return false;
9303}
9304
9305/// parseDirectiveSetFP
9306/// ::= .setfp fpreg, spreg [, offset]
9307bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009308 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009309 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009310 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009311 Error(L, ".fnstart must precede .setfp directive");
9312 return false;
9313 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009314 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009315 Error(L, ".setfp must precede .handlerdata directive");
9316 return false;
9317 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009318
9319 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009320 SMLoc FPRegLoc = Parser.getTok().getLoc();
9321 int FPReg = tryParseRegister();
9322 if (FPReg == -1) {
9323 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009324 return false;
9325 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009326
9327 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009328 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009329 Error(Parser.getTok().getLoc(), "comma expected");
9330 return false;
9331 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009332 Parser.Lex(); // skip comma
9333
9334 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009335 SMLoc SPRegLoc = Parser.getTok().getLoc();
9336 int SPReg = tryParseRegister();
9337 if (SPReg == -1) {
9338 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009339 return false;
9340 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009341
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009342 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
9343 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009344 return false;
9345 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009346
9347 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009348 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00009349
9350 // Parse offset
9351 int64_t Offset = 0;
9352 if (Parser.getTok().is(AsmToken::Comma)) {
9353 Parser.Lex(); // skip comma
9354
9355 if (Parser.getTok().isNot(AsmToken::Hash) &&
9356 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009357 Error(Parser.getTok().getLoc(), "'#' expected");
9358 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009359 }
9360 Parser.Lex(); // skip hash token.
9361
9362 const MCExpr *OffsetExpr;
9363 SMLoc ExLoc = Parser.getTok().getLoc();
9364 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009365 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9366 Error(ExLoc, "malformed setfp offset");
9367 return false;
9368 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009369 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009370 if (!CE) {
9371 Error(ExLoc, "setfp offset must be an immediate");
9372 return false;
9373 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009374
9375 Offset = CE->getValue();
9376 }
9377
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009378 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
9379 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00009380 return false;
9381}
9382
9383/// parseDirective
9384/// ::= .pad offset
9385bool ARMAsmParser::parseDirectivePad(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009386 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009387 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009388 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009389 Error(L, ".fnstart must precede .pad directive");
9390 return false;
9391 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009392 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009393 Error(L, ".pad must precede .handlerdata directive");
9394 return false;
9395 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009396
9397 // Parse the offset
9398 if (Parser.getTok().isNot(AsmToken::Hash) &&
9399 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009400 Error(Parser.getTok().getLoc(), "'#' expected");
9401 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009402 }
9403 Parser.Lex(); // skip hash token.
9404
9405 const MCExpr *OffsetExpr;
9406 SMLoc ExLoc = Parser.getTok().getLoc();
9407 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009408 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9409 Error(ExLoc, "malformed pad offset");
9410 return false;
9411 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009412 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009413 if (!CE) {
9414 Error(ExLoc, "pad offset must be an immediate");
9415 return false;
9416 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009417
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009418 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00009419 return false;
9420}
9421
9422/// parseDirectiveRegSave
9423/// ::= .save { registers }
9424/// ::= .vsave { registers }
9425bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
9426 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009427 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009428 Error(L, ".fnstart must precede .save or .vsave directives");
9429 return false;
9430 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009431 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009432 Error(L, ".save or .vsave must precede .handlerdata directive");
9433 return false;
9434 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009435
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009436 // RAII object to make sure parsed operands are deleted.
David Blaikie960ea3f2014-06-08 16:18:35 +00009437 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009438
Logan Chien4ea23b52013-05-10 16:17:24 +00009439 // Parse the register list
David Blaikie960ea3f2014-06-08 16:18:35 +00009440 if (parseRegisterList(Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00009441 return false;
David Blaikie960ea3f2014-06-08 16:18:35 +00009442 ARMOperand &Op = (ARMOperand &)*Operands[0];
9443 if (!IsVector && !Op.isRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009444 Error(L, ".save expects GPR registers");
9445 return false;
9446 }
David Blaikie960ea3f2014-06-08 16:18:35 +00009447 if (IsVector && !Op.isDPRRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009448 Error(L, ".vsave expects DPR registers");
9449 return false;
9450 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009451
David Blaikie960ea3f2014-06-08 16:18:35 +00009452 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00009453 return false;
9454}
9455
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009456/// parseDirectiveInst
9457/// ::= .inst opcode [, ...]
9458/// ::= .inst.n opcode [, ...]
9459/// ::= .inst.w opcode [, ...]
9460bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009461 MCAsmParser &Parser = getParser();
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009462 int Width;
9463
9464 if (isThumb()) {
9465 switch (Suffix) {
9466 case 'n':
9467 Width = 2;
9468 break;
9469 case 'w':
9470 Width = 4;
9471 break;
9472 default:
9473 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009474 Error(Loc, "cannot determine Thumb instruction size, "
9475 "use inst.n/inst.w instead");
9476 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009477 }
9478 } else {
9479 if (Suffix) {
9480 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009481 Error(Loc, "width suffixes are invalid in ARM mode");
9482 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009483 }
9484 Width = 4;
9485 }
9486
9487 if (getLexer().is(AsmToken::EndOfStatement)) {
9488 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009489 Error(Loc, "expected expression following directive");
9490 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009491 }
9492
9493 for (;;) {
9494 const MCExpr *Expr;
9495
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009496 if (getParser().parseExpression(Expr)) {
9497 Error(Loc, "expected expression");
9498 return false;
9499 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009500
9501 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009502 if (!Value) {
9503 Error(Loc, "expected constant expression");
9504 return false;
9505 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009506
9507 switch (Width) {
9508 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009509 if (Value->getValue() > 0xffff) {
9510 Error(Loc, "inst.n operand is too big, use inst.w instead");
9511 return false;
9512 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009513 break;
9514 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009515 if (Value->getValue() > 0xffffffff) {
9516 Error(Loc,
9517 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
9518 return false;
9519 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009520 break;
9521 default:
9522 llvm_unreachable("only supported widths are 2 and 4");
9523 }
9524
9525 getTargetStreamer().emitInst(Value->getValue(), Suffix);
9526
9527 if (getLexer().is(AsmToken::EndOfStatement))
9528 break;
9529
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009530 if (getLexer().isNot(AsmToken::Comma)) {
9531 Error(Loc, "unexpected token in directive");
9532 return false;
9533 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009534
9535 Parser.Lex();
9536 }
9537
9538 Parser.Lex();
9539 return false;
9540}
9541
David Peixotto80c083a2013-12-19 18:26:07 +00009542/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00009543/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00009544bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00009545 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00009546 return false;
9547}
9548
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009549bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9550 const MCSection *Section = getStreamer().getCurrentSection().first;
9551
9552 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9553 TokError("unexpected token in directive");
9554 return false;
9555 }
9556
9557 if (!Section) {
Rafael Espindola7b61ddf2014-10-15 16:12:52 +00009558 getStreamer().InitSections(false);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009559 Section = getStreamer().getCurrentSection().first;
9560 }
9561
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00009562 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009563 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00009564 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009565 else
Rafael Espindola7b514962014-02-04 18:34:04 +00009566 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009567
9568 return false;
9569}
9570
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009571/// parseDirectivePersonalityIndex
9572/// ::= .personalityindex index
9573bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009574 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009575 bool HasExistingPersonality = UC.hasPersonality();
9576
9577 UC.recordPersonalityIndex(L);
9578
9579 if (!UC.hasFnStart()) {
9580 Parser.eatToEndOfStatement();
9581 Error(L, ".fnstart must precede .personalityindex directive");
9582 return false;
9583 }
9584 if (UC.cantUnwind()) {
9585 Parser.eatToEndOfStatement();
9586 Error(L, ".personalityindex cannot be used with .cantunwind");
9587 UC.emitCantUnwindLocNotes();
9588 return false;
9589 }
9590 if (UC.hasHandlerData()) {
9591 Parser.eatToEndOfStatement();
9592 Error(L, ".personalityindex must precede .handlerdata directive");
9593 UC.emitHandlerDataLocNotes();
9594 return false;
9595 }
9596 if (HasExistingPersonality) {
9597 Parser.eatToEndOfStatement();
9598 Error(L, "multiple personality directives");
9599 UC.emitPersonalityLocNotes();
9600 return false;
9601 }
9602
9603 const MCExpr *IndexExpression;
9604 SMLoc IndexLoc = Parser.getTok().getLoc();
9605 if (Parser.parseExpression(IndexExpression)) {
9606 Parser.eatToEndOfStatement();
9607 return false;
9608 }
9609
9610 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9611 if (!CE) {
9612 Parser.eatToEndOfStatement();
9613 Error(IndexLoc, "index must be a constant number");
9614 return false;
9615 }
9616 if (CE->getValue() < 0 ||
9617 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9618 Parser.eatToEndOfStatement();
9619 Error(IndexLoc, "personality routine index should be in range [0-3]");
9620 return false;
9621 }
9622
9623 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9624 return false;
9625}
9626
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009627/// parseDirectiveUnwindRaw
9628/// ::= .unwind_raw offset, opcode [, opcode...]
9629bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009630 MCAsmParser &Parser = getParser();
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009631 if (!UC.hasFnStart()) {
9632 Parser.eatToEndOfStatement();
9633 Error(L, ".fnstart must precede .unwind_raw directives");
9634 return false;
9635 }
9636
9637 int64_t StackOffset;
9638
9639 const MCExpr *OffsetExpr;
9640 SMLoc OffsetLoc = getLexer().getLoc();
9641 if (getLexer().is(AsmToken::EndOfStatement) ||
9642 getParser().parseExpression(OffsetExpr)) {
9643 Error(OffsetLoc, "expected expression");
9644 Parser.eatToEndOfStatement();
9645 return false;
9646 }
9647
9648 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9649 if (!CE) {
9650 Error(OffsetLoc, "offset must be a constant");
9651 Parser.eatToEndOfStatement();
9652 return false;
9653 }
9654
9655 StackOffset = CE->getValue();
9656
9657 if (getLexer().isNot(AsmToken::Comma)) {
9658 Error(getLexer().getLoc(), "expected comma");
9659 Parser.eatToEndOfStatement();
9660 return false;
9661 }
9662 Parser.Lex();
9663
9664 SmallVector<uint8_t, 16> Opcodes;
9665 for (;;) {
9666 const MCExpr *OE;
9667
9668 SMLoc OpcodeLoc = getLexer().getLoc();
9669 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9670 Error(OpcodeLoc, "expected opcode expression");
9671 Parser.eatToEndOfStatement();
9672 return false;
9673 }
9674
9675 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9676 if (!OC) {
9677 Error(OpcodeLoc, "opcode value must be a constant");
9678 Parser.eatToEndOfStatement();
9679 return false;
9680 }
9681
9682 const int64_t Opcode = OC->getValue();
9683 if (Opcode & ~0xff) {
9684 Error(OpcodeLoc, "invalid opcode");
9685 Parser.eatToEndOfStatement();
9686 return false;
9687 }
9688
9689 Opcodes.push_back(uint8_t(Opcode));
9690
9691 if (getLexer().is(AsmToken::EndOfStatement))
9692 break;
9693
9694 if (getLexer().isNot(AsmToken::Comma)) {
9695 Error(getLexer().getLoc(), "unexpected token in directive");
9696 Parser.eatToEndOfStatement();
9697 return false;
9698 }
9699
9700 Parser.Lex();
9701 }
9702
9703 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9704
9705 Parser.Lex();
9706 return false;
9707}
9708
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009709/// parseDirectiveTLSDescSeq
9710/// ::= .tlsdescseq tls-variable
9711bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009712 MCAsmParser &Parser = getParser();
9713
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009714 if (getLexer().isNot(AsmToken::Identifier)) {
9715 TokError("expected variable after '.tlsdescseq' directive");
9716 Parser.eatToEndOfStatement();
9717 return false;
9718 }
9719
9720 const MCSymbolRefExpr *SRE =
9721 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9722 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9723 Lex();
9724
9725 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9726 Error(Parser.getTok().getLoc(), "unexpected token");
9727 Parser.eatToEndOfStatement();
9728 return false;
9729 }
9730
9731 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9732 return false;
9733}
9734
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009735/// parseDirectiveMovSP
9736/// ::= .movsp reg [, #offset]
9737bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009738 MCAsmParser &Parser = getParser();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009739 if (!UC.hasFnStart()) {
9740 Parser.eatToEndOfStatement();
9741 Error(L, ".fnstart must precede .movsp directives");
9742 return false;
9743 }
9744 if (UC.getFPReg() != ARM::SP) {
9745 Parser.eatToEndOfStatement();
9746 Error(L, "unexpected .movsp directive");
9747 return false;
9748 }
9749
9750 SMLoc SPRegLoc = Parser.getTok().getLoc();
9751 int SPReg = tryParseRegister();
9752 if (SPReg == -1) {
9753 Parser.eatToEndOfStatement();
9754 Error(SPRegLoc, "register expected");
9755 return false;
9756 }
9757
9758 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9759 Parser.eatToEndOfStatement();
9760 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9761 return false;
9762 }
9763
9764 int64_t Offset = 0;
9765 if (Parser.getTok().is(AsmToken::Comma)) {
9766 Parser.Lex();
9767
9768 if (Parser.getTok().isNot(AsmToken::Hash)) {
9769 Error(Parser.getTok().getLoc(), "expected #constant");
9770 Parser.eatToEndOfStatement();
9771 return false;
9772 }
9773 Parser.Lex();
9774
9775 const MCExpr *OffsetExpr;
9776 SMLoc OffsetLoc = Parser.getTok().getLoc();
9777 if (Parser.parseExpression(OffsetExpr)) {
9778 Parser.eatToEndOfStatement();
9779 Error(OffsetLoc, "malformed offset expression");
9780 return false;
9781 }
9782
9783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9784 if (!CE) {
9785 Parser.eatToEndOfStatement();
9786 Error(OffsetLoc, "offset must be an immediate constant");
9787 return false;
9788 }
9789
9790 Offset = CE->getValue();
9791 }
9792
9793 getTargetStreamer().emitMovSP(SPReg, Offset);
9794 UC.saveFPReg(SPReg);
9795
9796 return false;
9797}
9798
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009799/// parseDirectiveObjectArch
9800/// ::= .object_arch name
9801bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009802 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009803 if (getLexer().isNot(AsmToken::Identifier)) {
9804 Error(getLexer().getLoc(), "unexpected token");
9805 Parser.eatToEndOfStatement();
9806 return false;
9807 }
9808
9809 StringRef Arch = Parser.getTok().getString();
9810 SMLoc ArchLoc = Parser.getTok().getLoc();
9811 getLexer().Lex();
9812
9813 unsigned ID = StringSwitch<unsigned>(Arch)
9814#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9815 .Case(NAME, ARM::ID)
9816#define ARM_ARCH_ALIAS(NAME, ID) \
9817 .Case(NAME, ARM::ID)
9818#include "MCTargetDesc/ARMArchName.def"
9819#undef ARM_ARCH_NAME
9820#undef ARM_ARCH_ALIAS
9821 .Default(ARM::INVALID_ARCH);
9822
9823 if (ID == ARM::INVALID_ARCH) {
9824 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9825 Parser.eatToEndOfStatement();
9826 return false;
9827 }
9828
9829 getTargetStreamer().emitObjectArch(ID);
9830
9831 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9832 Error(getLexer().getLoc(), "unexpected token");
9833 Parser.eatToEndOfStatement();
9834 }
9835
9836 return false;
9837}
9838
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009839/// parseDirectiveAlign
9840/// ::= .align
9841bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9842 // NOTE: if this is not the end of the statement, fall back to the target
9843 // agnostic handling for this directive which will correctly handle this.
9844 if (getLexer().isNot(AsmToken::EndOfStatement))
9845 return true;
9846
9847 // '.align' is target specifically handled to mean 2**2 byte alignment.
9848 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9849 getStreamer().EmitCodeAlignment(4, 0);
9850 else
9851 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9852
9853 return false;
9854}
9855
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009856/// parseDirectiveThumbSet
9857/// ::= .thumb_set name, value
9858bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009859 MCAsmParser &Parser = getParser();
9860
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009861 StringRef Name;
9862 if (Parser.parseIdentifier(Name)) {
9863 TokError("expected identifier after '.thumb_set'");
9864 Parser.eatToEndOfStatement();
9865 return false;
9866 }
9867
9868 if (getLexer().isNot(AsmToken::Comma)) {
9869 TokError("expected comma after name '" + Name + "'");
9870 Parser.eatToEndOfStatement();
9871 return false;
9872 }
9873 Lex();
9874
9875 const MCExpr *Value;
9876 if (Parser.parseExpression(Value)) {
9877 TokError("missing expression");
9878 Parser.eatToEndOfStatement();
9879 return false;
9880 }
9881
9882 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9883 TokError("unexpected token");
9884 Parser.eatToEndOfStatement();
9885 return false;
9886 }
9887 Lex();
9888
9889 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
Rafael Espindola466d6632014-04-27 20:23:58 +00009890 getTargetStreamer().emitThumbSet(Alias, Value);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009891 return false;
9892}
9893
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009894/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009895extern "C" void LLVMInitializeARMAsmParser() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00009896 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9897 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9898 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9899 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009900}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009901
Chris Lattner3e4582a2010-09-06 19:11:01 +00009902#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009903#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009904#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009905#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009906
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009907static const struct {
9908 const char *Name;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009909 const unsigned ArchCheck;
9910 const uint64_t Features;
9911} Extensions[] = {
9912 { "crc", Feature_HasV8, ARM::FeatureCRC },
9913 { "crypto", Feature_HasV8,
9914 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9915 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
9916 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
9917 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
9918 // FIXME: iWMMXT not supported
9919 { "iwmmxt", Feature_None, 0 },
9920 // FIXME: iWMMXT2 not supported
9921 { "iwmmxt2", Feature_None, 0 },
9922 // FIXME: Maverick not supported
9923 { "maverick", Feature_None, 0 },
9924 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
9925 // FIXME: ARMv6-m OS Extensions feature not checked
9926 { "os", Feature_None, 0 },
9927 // FIXME: Also available in ARMv6-K
9928 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
9929 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9930 // FIXME: Only available in A-class, isel not predicated
9931 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
9932 // FIXME: xscale not supported
9933 { "xscale", Feature_None, 0 },
9934};
9935
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009936/// parseDirectiveArchExtension
9937/// ::= .arch_extension [no]feature
9938bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009939 MCAsmParser &Parser = getParser();
9940
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009941 if (getLexer().isNot(AsmToken::Identifier)) {
9942 Error(getLexer().getLoc(), "unexpected token");
9943 Parser.eatToEndOfStatement();
9944 return false;
9945 }
9946
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009947 StringRef Name = Parser.getTok().getString();
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009948 SMLoc ExtLoc = Parser.getTok().getLoc();
9949 getLexer().Lex();
9950
9951 bool EnableFeature = true;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009952 if (Name.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009953 EnableFeature = false;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009954 Name = Name.substr(2);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009955 }
9956
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009957 for (const auto &Extension : Extensions) {
9958 if (Extension.Name != Name)
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009959 continue;
9960
Saleem Abdulrasool8988c2a2014-07-27 19:07:09 +00009961 if (!Extension.Features)
9962 report_fatal_error("unsupported architectural extension: " + Name);
9963
9964 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) {
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009965 Error(ExtLoc, "architectural extension '" + Name + "' is not "
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009966 "allowed for the current base architecture");
9967 return false;
9968 }
9969
Tim Northover26bb14e2014-08-18 11:49:42 +00009970 uint64_t ToggleFeatures = EnableFeature
Saleem Abdulrasool78c44722014-08-17 19:20:38 +00009971 ? (~STI.getFeatureBits() & Extension.Features)
9972 : ( STI.getFeatureBits() & Extension.Features);
Tim Northover26bb14e2014-08-18 11:49:42 +00009973 uint64_t Features =
Saleem Abdulrasool78c44722014-08-17 19:20:38 +00009974 ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
9975 setAvailableFeatures(Features);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009976 return false;
9977 }
9978
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009979 Error(ExtLoc, "unknown architectural extension: " + Name);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009980 Parser.eatToEndOfStatement();
9981 return false;
9982}
9983
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009984// Define this matcher function after the auto-generated include so we
9985// have the match class enum definitions.
David Blaikie960ea3f2014-06-08 16:18:35 +00009986unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009987 unsigned Kind) {
David Blaikie960ea3f2014-06-08 16:18:35 +00009988 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009989 // If the kind is a token for a literal immediate, check if our asm
9990 // operand matches. This is for InstAliases which have a fixed-value
9991 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009992 switch (Kind) {
9993 default: break;
9994 case MCK__35_0:
David Blaikie960ea3f2014-06-08 16:18:35 +00009995 if (Op.isImm())
9996 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009997 if (CE->getValue() == 0)
9998 return Match_Success;
9999 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +000010000 case MCK_ModImm:
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010001 case MCK_ARMSOImm:
David Blaikie960ea3f2014-06-08 16:18:35 +000010002 if (Op.isImm()) {
10003 const MCExpr *SOExpr = Op.getImm();
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010004 int64_t Value;
10005 if (!SOExpr->EvaluateAsAbsolute(Value))
Stepan Dyatkovskiydf657cc2014-03-29 13:12:40 +000010006 return Match_Success;
Richard Barton3db1d582014-05-01 11:37:44 +000010007 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
10008 "expression value must be representable in 32 bits");
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010009 }
10010 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +000010011 case MCK_GPRPair:
David Blaikie960ea3f2014-06-08 16:18:35 +000010012 if (Op.isReg() &&
10013 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +000010014 return Match_Success;
10015 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010016 }
10017 return Match_InvalidOperand;
10018}