blob: 71b558d46bb273246d5476a41a11c7917dd8f315 [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"
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +000025#include "llvm/MC/MCELF.h"
Jack Carter718da0b2013-01-30 02:24:33 +000026#include "llvm/MC/MCELFStreamer.h"
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +000027#include "llvm/MC/MCELFSymbolFlags.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000028#include "llvm/MC/MCExpr.h"
29#include "llvm/MC/MCInst.h"
30#include "llvm/MC/MCInstrDesc.h"
Joey Gouly0e76fa72013-09-12 10:28:05 +000031#include "llvm/MC/MCInstrInfo.h"
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +000032#include "llvm/MC/MCObjectFileInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000033#include "llvm/MC/MCParser/MCAsmLexer.h"
34#include "llvm/MC/MCParser/MCAsmParser.h"
35#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
36#include "llvm/MC/MCRegisterInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000037#include "llvm/MC/MCSection.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000038#include "llvm/MC/MCStreamer.h"
39#include "llvm/MC/MCSubtargetInfo.h"
David Peixottoe407d092013-12-19 18:12:36 +000040#include "llvm/MC/MCSymbol.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000041#include "llvm/MC/MCTargetAsmParser.h"
Saleem Abdulrasool278a9f42014-01-19 08:25:27 +000042#include "llvm/Support/ARMBuildAttributes.h"
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000043#include "llvm/Support/ARMEHABI.h"
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +000044#include "llvm/Support/COFF.h"
Tim Northoverd6a729b2014-01-06 14:28:05 +000045#include "llvm/Support/Debug.h"
Jack Carter718da0b2013-01-30 02:24:33 +000046#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000047#include "llvm/Support/MathExtras.h"
48#include "llvm/Support/SourceMgr.h"
49#include "llvm/Support/TargetRegistry.h"
50#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000051
Kevin Enderbyccab3172009-09-15 00:27:25 +000052using namespace llvm;
53
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000054namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000055
56class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000057
Jim Grosbach04945c42011-12-02 00:35:16 +000058enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000059
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000060class UnwindContext {
61 MCAsmParser &Parser;
62
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000063 typedef SmallVector<SMLoc, 4> Locs;
64
65 Locs FnStartLocs;
66 Locs CantUnwindLocs;
67 Locs PersonalityLocs;
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000068 Locs PersonalityIndexLocs;
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000069 Locs HandlerDataLocs;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000070 int FPReg;
71
72public:
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +000073 UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {}
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000074
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000075 bool hasFnStart() const { return !FnStartLocs.empty(); }
76 bool cantUnwind() const { return !CantUnwindLocs.empty(); }
77 bool hasHandlerData() const { return !HandlerDataLocs.empty(); }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000078 bool hasPersonality() const {
79 return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty());
80 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000081
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000082 void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); }
83 void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); }
84 void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); }
85 void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000086 void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000087
88 void saveFPReg(int Reg) { FPReg = Reg; }
89 int getFPReg() const { return FPReg; }
90
91 void emitFnStartLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000092 for (Locs::const_iterator FI = FnStartLocs.begin(), FE = FnStartLocs.end();
93 FI != FE; ++FI)
94 Parser.Note(*FI, ".fnstart was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000095 }
96 void emitCantUnwindLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000097 for (Locs::const_iterator UI = CantUnwindLocs.begin(),
98 UE = CantUnwindLocs.end(); UI != UE; ++UI)
99 Parser.Note(*UI, ".cantunwind was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000100 }
101 void emitHandlerDataLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000102 for (Locs::const_iterator HI = HandlerDataLocs.begin(),
103 HE = HandlerDataLocs.end(); HI != HE; ++HI)
104 Parser.Note(*HI, ".handlerdata was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000105 }
106 void emitPersonalityLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000107 for (Locs::const_iterator PI = PersonalityLocs.begin(),
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000108 PE = PersonalityLocs.end(),
109 PII = PersonalityIndexLocs.begin(),
110 PIE = PersonalityIndexLocs.end();
111 PI != PE || PII != PIE;) {
112 if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer()))
113 Parser.Note(*PI++, ".personality was specified here");
114 else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer()))
115 Parser.Note(*PII++, ".personalityindex was specified here");
116 else
117 llvm_unreachable(".personality and .personalityindex cannot be "
118 "at the same location");
119 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000120 }
121
122 void reset() {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000123 FnStartLocs = Locs();
124 CantUnwindLocs = Locs();
125 PersonalityLocs = Locs();
126 HandlerDataLocs = Locs();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000127 PersonalityIndexLocs = Locs();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000128 FPReg = ARM::SP;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000129 }
130};
131
Evan Cheng11424442011-07-26 00:24:13 +0000132class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +0000133 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000134 MCAsmParser &Parser;
Joey Gouly0e76fa72013-09-12 10:28:05 +0000135 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000136 const MCRegisterInfo *MRI;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000137 UnwindContext UC;
David Peixottoe407d092013-12-19 18:12:36 +0000138
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000139 ARMTargetStreamer &getTargetStreamer() {
Rafael Espindola4a1a3602014-01-14 01:21:46 +0000140 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000141 return static_cast<ARMTargetStreamer &>(TS);
142 }
143
Jim Grosbachab5830e2011-12-14 02:16:11 +0000144 // Map of register aliases registers via the .req directive.
145 StringMap<unsigned> RegisterReqs;
146
Tim Northover1744d0a2013-10-25 12:49:50 +0000147 bool NextSymbolIsThumb;
148
Jim Grosbached16ec42011-08-29 22:24:09 +0000149 struct {
150 ARMCC::CondCodes Cond; // Condition for IT block.
151 unsigned Mask:4; // Condition mask for instructions.
152 // Starting at first 1 (from lsb).
153 // '1' condition as indicated in IT.
154 // '0' inverse of condition (else).
155 // Count of instructions in IT block is
156 // 4 - trailingzeroes(mask)
157
158 bool FirstCond; // Explicit flag for when we're parsing the
159 // First instruction in the IT block. It's
160 // implied in the mask, so needs special
161 // handling.
162
163 unsigned CurPosition; // Current position in parsing of IT
164 // block. In range [0,3]. Initialized
165 // according to count of instructions in block.
166 // ~0U if no active IT block.
167 } ITState;
168 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000169 void forwardITPosition() {
170 if (!inITBlock()) return;
171 // Move to the next instruction in the IT block, if there is one. If not,
172 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000173 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000174 if (++ITState.CurPosition == 5 - TZ)
175 ITState.CurPosition = ~0U; // Done with the IT block after this.
176 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000177
178
Kevin Enderbyccab3172009-09-15 00:27:25 +0000179 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000180 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
181
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000182 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) {
183 return Parser.Note(L, Msg, Ranges);
184 }
Benjamin Kramer673824b2012-04-15 17:04:27 +0000185 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000186 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000187 return Parser.Warning(L, Msg, Ranges);
188 }
189 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000190 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000191 return Parser.Error(L, Msg, Ranges);
192 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000193
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000194 int tryParseRegister();
195 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000196 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000197 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000198 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000199 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
200 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000201 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
202 unsigned &ShiftAmount);
Saleem Abdulrasool38976512014-02-23 06:22:09 +0000203 bool parseLiteralValues(unsigned Size, SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000204 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000205 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000206 bool parseDirectiveThumbFunc(SMLoc L);
207 bool parseDirectiveCode(SMLoc L);
208 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000209 bool parseDirectiveReq(StringRef Name, SMLoc L);
210 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000211 bool parseDirectiveArch(SMLoc L);
212 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000213 bool parseDirectiveCPU(SMLoc L);
214 bool parseDirectiveFPU(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000215 bool parseDirectiveFnStart(SMLoc L);
216 bool parseDirectiveFnEnd(SMLoc L);
217 bool parseDirectiveCantUnwind(SMLoc L);
218 bool parseDirectivePersonality(SMLoc L);
219 bool parseDirectiveHandlerData(SMLoc L);
220 bool parseDirectiveSetFP(SMLoc L);
221 bool parseDirectivePad(SMLoc L);
222 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000223 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
David Peixotto80c083a2013-12-19 18:26:07 +0000224 bool parseDirectiveLtorg(SMLoc L);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +0000225 bool parseDirectiveEven(SMLoc L);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000226 bool parseDirectivePersonalityIndex(SMLoc L);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000227 bool parseDirectiveUnwindRaw(SMLoc L);
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000228 bool parseDirectiveTLSDescSeq(SMLoc L);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000229 bool parseDirectiveMovSP(SMLoc L);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000230 bool parseDirectiveObjectArch(SMLoc L);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +0000231 bool parseDirectiveArchExtension(SMLoc L);
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +0000232 bool parseDirectiveAlign(SMLoc L);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +0000233 bool parseDirectiveThumbSet(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000234
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000235 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000236 bool &CarrySetting, unsigned &ProcessorIMod,
237 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000238 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
239 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000240 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000241
Evan Cheng4d1ca962011-07-08 01:53:10 +0000242 bool isThumb() const {
243 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000244 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000245 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000246 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000247 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000248 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000249 bool isThumbTwo() const {
250 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
251 }
Tim Northovera2292d02013-06-10 23:20:58 +0000252 bool hasThumb() const {
253 return STI.getFeatureBits() & ARM::HasV4TOps;
254 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000255 bool hasV6Ops() const {
256 return STI.getFeatureBits() & ARM::HasV6Ops;
257 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000258 bool hasV6MOps() const {
259 return STI.getFeatureBits() & ARM::HasV6MOps;
260 }
James Molloy21efa7d2011-09-28 14:21:38 +0000261 bool hasV7Ops() const {
262 return STI.getFeatureBits() & ARM::HasV7Ops;
263 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000264 bool hasV8Ops() const {
265 return STI.getFeatureBits() & ARM::HasV8Ops;
266 }
Tim Northovera2292d02013-06-10 23:20:58 +0000267 bool hasARM() const {
268 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
269 }
270
Evan Cheng284b4672011-07-08 22:36:29 +0000271 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000272 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
273 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000274 }
James Molloy21efa7d2011-09-28 14:21:38 +0000275 bool isMClass() const {
276 return STI.getFeatureBits() & ARM::FeatureMClass;
277 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000278
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000279 /// @name Auto-generated Match Functions
280 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000281
Chris Lattner3e4582a2010-09-06 19:11:01 +0000282#define GET_ASSEMBLER_HEADER
283#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000284
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000285 /// }
286
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000287 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000288 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000289 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000290 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000291 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000292 OperandMatchResultTy parseCoprocOptionOperand(
293 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000294 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000295 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000296 OperandMatchResultTy parseInstSyncBarrierOptOperand(
297 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000298 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000299 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000300 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000301 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000302 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
303 StringRef Op, int Low, int High);
304 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
305 return parsePKHImm(O, "lsl", 0, 31);
306 }
307 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
308 return parsePKHImm(O, "asr", 1, 32);
309 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000310 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000311 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000312 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000313 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000314 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000315 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000316 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000317 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000318 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
319 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000320
321 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000322 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000323 const SmallVectorImpl<MCParsedAsmOperand*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000324 void cvtThumbBranches(MCInst &Inst,
325 const SmallVectorImpl<MCParsedAsmOperand*> &);
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +0000326
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000327 bool validateInstruction(MCInst &Inst,
328 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000329 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000330 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000331 bool shouldOmitCCOutOperand(StringRef Mnemonic,
332 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000333 bool shouldOmitPredicateOperand(StringRef Mnemonic,
334 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000335public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000336 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000337 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000338 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000339 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000340 Match_RequiresThumb2,
341#define GET_OPERAND_DIAGNOSTIC_TYPES
342#include "ARMGenAsmMatcher.inc"
343
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000344 };
345
Joey Gouly0e76fa72013-09-12 10:28:05 +0000346 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
Evgeniy Stepanov0a951b72014-04-23 11:16:03 +0000347 const MCInstrInfo &MII,
348 const MCTargetOptions &Options)
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000349 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), UC(_Parser) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000350 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000351
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000352 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000353 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000354
Evan Cheng4d1ca962011-07-08 01:53:10 +0000355 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000356 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000357
358 // Not in an ITBlock to start with.
359 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000360
361 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000362 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000363
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000364 // Implementation of the MCTargetAsmParser interface:
Craig Topperca7e3e52014-03-10 03:19:03 +0000365 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
366 bool
367 ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
368 SMLoc NameLoc,
369 SmallVectorImpl<MCParsedAsmOperand*> &Operands) override;
370 bool ParseDirective(AsmToken DirectiveID) override;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000371
Craig Topperca7e3e52014-03-10 03:19:03 +0000372 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op,
373 unsigned Kind) override;
374 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000375
Chad Rosier49963552012-10-13 00:26:04 +0000376 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000377 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000378 MCStreamer &Out, unsigned &ErrorInfo,
Craig Topperca7e3e52014-03-10 03:19:03 +0000379 bool MatchingInlineAsm) override;
380 void onLabelParsed(MCSymbol *Symbol) override;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000381};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000382} // end anonymous namespace
383
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000384namespace {
385
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000386/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000387/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000388class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000389 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000390 k_CondCode,
391 k_CCOut,
392 k_ITCondMask,
393 k_CoprocNum,
394 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000395 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000396 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000397 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000398 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000399 k_Memory,
400 k_PostIndexRegister,
401 k_MSRMask,
402 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000403 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000404 k_Register,
405 k_RegisterList,
406 k_DPRRegisterList,
407 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000408 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000409 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000410 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000411 k_ShiftedRegister,
412 k_ShiftedImmediate,
413 k_ShifterImmediate,
414 k_RotateImmediate,
415 k_BitfieldDescriptor,
416 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000417 } Kind;
418
Kevin Enderby488f20b2014-04-10 20:18:58 +0000419 SMLoc StartLoc, EndLoc, AlignmentLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000420 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000421
Eric Christopher8996c5d2013-03-15 00:42:55 +0000422 struct CCOp {
423 ARMCC::CondCodes Val;
424 };
425
426 struct CopOp {
427 unsigned Val;
428 };
429
430 struct CoprocOptionOp {
431 unsigned Val;
432 };
433
434 struct ITMaskOp {
435 unsigned Mask:4;
436 };
437
438 struct MBOptOp {
439 ARM_MB::MemBOpt Val;
440 };
441
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000442 struct ISBOptOp {
443 ARM_ISB::InstSyncBOpt Val;
444 };
445
Eric Christopher8996c5d2013-03-15 00:42:55 +0000446 struct IFlagsOp {
447 ARM_PROC::IFlags Val;
448 };
449
450 struct MMaskOp {
451 unsigned Val;
452 };
453
454 struct TokOp {
455 const char *Data;
456 unsigned Length;
457 };
458
459 struct RegOp {
460 unsigned RegNum;
461 };
462
463 // A vector register list is a sequential list of 1 to 4 registers.
464 struct VectorListOp {
465 unsigned RegNum;
466 unsigned Count;
467 unsigned LaneIndex;
468 bool isDoubleSpaced;
469 };
470
471 struct VectorIndexOp {
472 unsigned Val;
473 };
474
475 struct ImmOp {
476 const MCExpr *Val;
477 };
478
479 /// Combined record for all forms of ARM address expressions.
480 struct MemoryOp {
481 unsigned BaseRegNum;
482 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
483 // was specified.
484 const MCConstantExpr *OffsetImm; // Offset immediate value
485 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
486 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
487 unsigned ShiftImm; // shift for OffsetReg.
488 unsigned Alignment; // 0 = no alignment specified
489 // n = alignment in bytes (2, 4, 8, 16, or 32)
490 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
491 };
492
493 struct PostIdxRegOp {
494 unsigned RegNum;
495 bool isAdd;
496 ARM_AM::ShiftOpc ShiftTy;
497 unsigned ShiftImm;
498 };
499
500 struct ShifterImmOp {
501 bool isASR;
502 unsigned Imm;
503 };
504
505 struct RegShiftedRegOp {
506 ARM_AM::ShiftOpc ShiftTy;
507 unsigned SrcReg;
508 unsigned ShiftReg;
509 unsigned ShiftImm;
510 };
511
512 struct RegShiftedImmOp {
513 ARM_AM::ShiftOpc ShiftTy;
514 unsigned SrcReg;
515 unsigned ShiftImm;
516 };
517
518 struct RotImmOp {
519 unsigned Imm;
520 };
521
522 struct BitfieldOp {
523 unsigned LSB;
524 unsigned Width;
525 };
526
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000527 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000528 struct CCOp CC;
529 struct CopOp Cop;
530 struct CoprocOptionOp CoprocOption;
531 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000532 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000533 struct ITMaskOp ITMask;
534 struct IFlagsOp IFlags;
535 struct MMaskOp MMask;
536 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;
547 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000548 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000549
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000550 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
551public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000552 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
553 Kind = o.Kind;
554 StartLoc = o.StartLoc;
555 EndLoc = o.EndLoc;
556 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000557 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000558 CC = o.CC;
559 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000560 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000561 ITMask = o.ITMask;
562 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000563 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000564 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000565 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000566 case k_CCOut:
567 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000568 Reg = o.Reg;
569 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000570 case k_RegisterList:
571 case k_DPRRegisterList:
572 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000573 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000574 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000575 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000576 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000577 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000578 VectorList = o.VectorList;
579 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000580 case k_CoprocNum:
581 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000582 Cop = o.Cop;
583 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000584 case k_CoprocOption:
585 CoprocOption = o.CoprocOption;
586 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000587 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000588 Imm = o.Imm;
589 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000590 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000591 MBOpt = o.MBOpt;
592 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000593 case k_InstSyncBarrierOpt:
594 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000595 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000596 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000597 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000598 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000599 PostIdxReg = o.PostIdxReg;
600 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000601 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000602 MMask = o.MMask;
603 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000604 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000605 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000606 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000607 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000608 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000609 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000610 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000611 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000612 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000613 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000614 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000615 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000616 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000617 RotImm = o.RotImm;
618 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000619 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000620 Bitfield = o.Bitfield;
621 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000622 case k_VectorIndex:
623 VectorIndex = o.VectorIndex;
624 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000625 }
626 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000627
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000628 /// getStartLoc - Get the location of the first token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000629 SMLoc getStartLoc() const override { return StartLoc; }
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000630 /// getEndLoc - Get the location of the last token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000631 SMLoc getEndLoc() const override { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000632 /// getLocRange - Get the range between the first and last token of this
633 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000634 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
635
Kevin Enderby488f20b2014-04-10 20:18:58 +0000636 /// getAlignmentLoc - Get the location of the Alignment token of this operand.
637 SMLoc getAlignmentLoc() const {
638 assert(Kind == k_Memory && "Invalid access!");
639 return AlignmentLoc;
640 }
641
Daniel Dunbard8042b72010-08-11 06:36:53 +0000642 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000643 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000644 return CC.Val;
645 }
646
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000647 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000648 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000649 return Cop.Val;
650 }
651
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000652 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000653 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000654 return StringRef(Tok.Data, Tok.Length);
655 }
656
Craig Topperca7e3e52014-03-10 03:19:03 +0000657 unsigned getReg() const override {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000658 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000659 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000660 }
661
Bill Wendlingbed94652010-11-09 23:28:44 +0000662 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000663 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
664 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000665 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000666 }
667
Kevin Enderbyf5079942009-10-13 22:19:02 +0000668 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000669 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000670 return Imm.Val;
671 }
672
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000673 unsigned getVectorIndex() const {
674 assert(Kind == k_VectorIndex && "Invalid access!");
675 return VectorIndex.Val;
676 }
677
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000678 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000679 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000680 return MBOpt.Val;
681 }
682
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000683 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
684 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
685 return ISBOpt.Val;
686 }
687
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000688 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000689 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000690 return IFlags.Val;
691 }
692
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000693 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000694 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000695 return MMask.Val;
696 }
697
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000698 bool isCoprocNum() const { return Kind == k_CoprocNum; }
699 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000700 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000701 bool isCondCode() const { return Kind == k_CondCode; }
702 bool isCCOut() const { return Kind == k_CCOut; }
703 bool isITMask() const { return Kind == k_ITCondMask; }
704 bool isITCondCode() const { return Kind == k_CondCode; }
Craig Topperca7e3e52014-03-10 03:19:03 +0000705 bool isImm() const override { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000706 // checks whether this operand is an unsigned offset which fits is a field
707 // of specified width and scaled by a specific number of bits
708 template<unsigned width, unsigned scale>
709 bool isUnsignedOffset() const {
710 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000711 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000712 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
713 int64_t Val = CE->getValue();
714 int64_t Align = 1LL << scale;
715 int64_t Max = Align * ((1LL << width) - 1);
716 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
717 }
718 return false;
719 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000720 // checks whether this operand is an signed offset which fits is a field
721 // of specified width and scaled by a specific number of bits
722 template<unsigned width, unsigned scale>
723 bool isSignedOffset() const {
724 if (!isImm()) return false;
725 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
726 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
727 int64_t Val = CE->getValue();
728 int64_t Align = 1LL << scale;
729 int64_t Max = Align * ((1LL << (width-1)) - 1);
730 int64_t Min = -Align * (1LL << (width-1));
731 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
732 }
733 return false;
734 }
735
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000736 // checks whether this operand is a memory operand computed as an offset
737 // applied to PC. the offset may have 8 bits of magnitude and is represented
738 // with two bits of shift. textually it may be either [pc, #imm], #imm or
739 // relocable expression...
740 bool isThumbMemPC() const {
741 int64_t Val = 0;
742 if (isImm()) {
743 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
744 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
745 if (!CE) return false;
746 Val = CE->getValue();
747 }
748 else if (isMem()) {
749 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
750 if(Memory.BaseRegNum != ARM::PC) return false;
751 Val = Memory.OffsetImm->getValue();
752 }
753 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000754 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000755 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000756 bool isFPImm() const {
757 if (!isImm()) return false;
758 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
759 if (!CE) return false;
760 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
761 return Val != -1;
762 }
Jim Grosbachea231912011-12-22 22:19:05 +0000763 bool isFBits16() const {
764 if (!isImm()) return false;
765 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
766 if (!CE) return false;
767 int64_t Value = CE->getValue();
768 return Value >= 0 && Value <= 16;
769 }
770 bool isFBits32() const {
771 if (!isImm()) return false;
772 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
773 if (!CE) return false;
774 int64_t Value = CE->getValue();
775 return Value >= 1 && Value <= 32;
776 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000777 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000778 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000779 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
780 if (!CE) return false;
781 int64_t Value = CE->getValue();
782 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
783 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000784 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000785 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000786 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
787 if (!CE) return false;
788 int64_t Value = CE->getValue();
789 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
790 }
791 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000792 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000793 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
794 if (!CE) return false;
795 int64_t Value = CE->getValue();
796 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
797 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000798 bool isImm0_508s4Neg() const {
799 if (!isImm()) return false;
800 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
801 if (!CE) return false;
802 int64_t Value = -CE->getValue();
803 // explicitly exclude zero. we want that to use the normal 0_508 version.
804 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
805 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000806 bool isImm0_239() const {
807 if (!isImm()) return false;
808 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
809 if (!CE) return false;
810 int64_t Value = CE->getValue();
811 return Value >= 0 && Value < 240;
812 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000813 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000814 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000815 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
816 if (!CE) return false;
817 int64_t Value = CE->getValue();
818 return Value >= 0 && Value < 256;
819 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000820 bool isImm0_4095() const {
821 if (!isImm()) return false;
822 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
823 if (!CE) return false;
824 int64_t Value = CE->getValue();
825 return Value >= 0 && Value < 4096;
826 }
827 bool isImm0_4095Neg() const {
828 if (!isImm()) return false;
829 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
830 if (!CE) return false;
831 int64_t Value = -CE->getValue();
832 return Value > 0 && Value < 4096;
833 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000834 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000835 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000836 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
837 if (!CE) return false;
838 int64_t Value = CE->getValue();
839 return Value >= 0 && Value < 2;
840 }
841 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000842 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000843 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
844 if (!CE) return false;
845 int64_t Value = CE->getValue();
846 return Value >= 0 && Value < 4;
847 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000848 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000849 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000850 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
851 if (!CE) return false;
852 int64_t Value = CE->getValue();
853 return Value >= 0 && Value < 8;
854 }
855 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000856 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000857 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
858 if (!CE) return false;
859 int64_t Value = CE->getValue();
860 return Value >= 0 && Value < 16;
861 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000862 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000863 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000864 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
865 if (!CE) return false;
866 int64_t Value = CE->getValue();
867 return Value >= 0 && Value < 32;
868 }
Jim Grosbach00326402011-12-08 01:30:04 +0000869 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000870 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000871 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
872 if (!CE) return false;
873 int64_t Value = CE->getValue();
874 return Value >= 0 && Value < 64;
875 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000876 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000877 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000878 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
879 if (!CE) return false;
880 int64_t Value = CE->getValue();
881 return Value == 8;
882 }
883 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000884 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000885 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
886 if (!CE) return false;
887 int64_t Value = CE->getValue();
888 return Value == 16;
889 }
890 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000891 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000892 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
893 if (!CE) return false;
894 int64_t Value = CE->getValue();
895 return Value == 32;
896 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000897 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000898 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000899 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
900 if (!CE) return false;
901 int64_t Value = CE->getValue();
902 return Value > 0 && Value <= 8;
903 }
904 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000905 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
907 if (!CE) return false;
908 int64_t Value = CE->getValue();
909 return Value > 0 && Value <= 16;
910 }
911 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000912 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
914 if (!CE) return false;
915 int64_t Value = CE->getValue();
916 return Value > 0 && Value <= 32;
917 }
918 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000919 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000920 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
921 if (!CE) return false;
922 int64_t Value = CE->getValue();
923 return Value > 0 && Value <= 64;
924 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000925 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000926 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
928 if (!CE) return false;
929 int64_t Value = CE->getValue();
930 return Value > 0 && Value < 8;
931 }
932 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000933 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
935 if (!CE) return false;
936 int64_t Value = CE->getValue();
937 return Value > 0 && Value < 16;
938 }
939 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000940 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000941 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
942 if (!CE) return false;
943 int64_t Value = CE->getValue();
944 return Value > 0 && Value < 32;
945 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000946 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000947 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000948 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
949 if (!CE) return false;
950 int64_t Value = CE->getValue();
951 return Value > 0 && Value < 17;
952 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000953 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000954 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000955 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
956 if (!CE) return false;
957 int64_t Value = CE->getValue();
958 return Value > 0 && Value < 33;
959 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000960 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000961 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000962 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
963 if (!CE) return false;
964 int64_t Value = CE->getValue();
965 return Value >= 0 && Value < 33;
966 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000967 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000968 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000969 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
970 if (!CE) return false;
971 int64_t Value = CE->getValue();
972 return Value >= 0 && Value < 65536;
973 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000974 bool isImm256_65535Expr() const {
975 if (!isImm()) return false;
976 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
977 // If it's not a constant expression, it'll generate a fixup and be
978 // handled later.
979 if (!CE) return true;
980 int64_t Value = CE->getValue();
981 return Value >= 256 && Value < 65536;
982 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000983 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000984 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000985 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
986 // If it's not a constant expression, it'll generate a fixup and be
987 // handled later.
988 if (!CE) return true;
989 int64_t Value = CE->getValue();
990 return Value >= 0 && Value < 65536;
991 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000992 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000993 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000994 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
995 if (!CE) return false;
996 int64_t Value = CE->getValue();
997 return Value >= 0 && Value <= 0xffffff;
998 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000999 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001000 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +00001001 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1002 if (!CE) return false;
1003 int64_t Value = CE->getValue();
1004 return Value > 0 && Value < 33;
1005 }
Jim Grosbach27c1e252011-07-21 17:23:04 +00001006 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001007 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001008 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1009 if (!CE) return false;
1010 int64_t Value = CE->getValue();
1011 return Value >= 0 && Value < 32;
1012 }
1013 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001014 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001015 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1016 if (!CE) return false;
1017 int64_t Value = CE->getValue();
1018 return Value > 0 && Value <= 32;
1019 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001020 bool isAdrLabel() const {
1021 // If we have an immediate that's not a constant, treat it as a label
1022 // reference needing a fixup. If it is a constant, but it can't fit
1023 // into shift immediate encoding, we reject it.
1024 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1025 else return (isARMSOImm() || isARMSOImmNeg());
1026 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001027 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001028 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001029 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1030 if (!CE) return false;
1031 int64_t Value = CE->getValue();
1032 return ARM_AM::getSOImmVal(Value) != -1;
1033 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001034 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001035 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001036 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1037 if (!CE) return false;
1038 int64_t Value = CE->getValue();
1039 return ARM_AM::getSOImmVal(~Value) != -1;
1040 }
Jim Grosbach30506252011-12-08 00:31:07 +00001041 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001042 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001043 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1044 if (!CE) return false;
1045 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001046 // Only use this when not representable as a plain so_imm.
1047 return ARM_AM::getSOImmVal(Value) == -1 &&
1048 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001049 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001050 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001051 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001052 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1053 if (!CE) return false;
1054 int64_t Value = CE->getValue();
1055 return ARM_AM::getT2SOImmVal(Value) != -1;
1056 }
Jim Grosbachb009a872011-10-28 22:36:30 +00001057 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001058 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +00001059 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1060 if (!CE) return false;
1061 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +00001062 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1063 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +00001064 }
Jim Grosbach30506252011-12-08 00:31:07 +00001065 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001066 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001067 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1068 if (!CE) return false;
1069 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001070 // Only use this when not representable as a plain so_imm.
1071 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1072 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001073 }
Jim Grosbach0a547702011-07-22 17:44:50 +00001074 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001075 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +00001076 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1077 if (!CE) return false;
1078 int64_t Value = CE->getValue();
1079 return Value == 1 || Value == 0;
1080 }
Craig Topperca7e3e52014-03-10 03:19:03 +00001081 bool isReg() const override { return Kind == k_Register; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001082 bool isRegList() const { return Kind == k_RegisterList; }
1083 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1084 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001085 bool isToken() const override { return Kind == k_Token; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001086 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001087 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001088 bool isMem() const override { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001089 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1090 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1091 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1092 bool isRotImm() const { return Kind == k_RotateImmediate; }
1093 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1094 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001095 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001096 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001097 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001098 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const {
Chad Rosier41099832012-09-11 23:02:35 +00001099 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001100 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001101 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +00001102 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
Kevin Enderby488f20b2014-04-10 20:18:58 +00001103 (alignOK || Memory.Alignment == Alignment);
Jim Grosbacha95ec992011-10-11 17:29:55 +00001104 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001105 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001106 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001107 return false;
1108 // Base register must be PC.
1109 if (Memory.BaseRegNum != ARM::PC)
1110 return false;
1111 // Immediate offset in range [-4095, 4095].
1112 if (!Memory.OffsetImm) return true;
1113 int64_t Val = Memory.OffsetImm->getValue();
1114 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1115 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001116 bool isAlignedMemory() const {
1117 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001118 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001119 bool isAlignedMemoryNone() const {
1120 return isMemNoOffset(false, 0);
1121 }
1122 bool isDupAlignedMemoryNone() const {
1123 return isMemNoOffset(false, 0);
1124 }
1125 bool isAlignedMemory16() const {
1126 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1127 return true;
1128 return isMemNoOffset(false, 0);
1129 }
1130 bool isDupAlignedMemory16() const {
1131 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1132 return true;
1133 return isMemNoOffset(false, 0);
1134 }
1135 bool isAlignedMemory32() const {
1136 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1137 return true;
1138 return isMemNoOffset(false, 0);
1139 }
1140 bool isDupAlignedMemory32() const {
1141 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1142 return true;
1143 return isMemNoOffset(false, 0);
1144 }
1145 bool isAlignedMemory64() const {
1146 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1147 return true;
1148 return isMemNoOffset(false, 0);
1149 }
1150 bool isDupAlignedMemory64() const {
1151 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1152 return true;
1153 return isMemNoOffset(false, 0);
1154 }
1155 bool isAlignedMemory64or128() const {
1156 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1157 return true;
1158 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1159 return true;
1160 return isMemNoOffset(false, 0);
1161 }
1162 bool isDupAlignedMemory64or128() const {
1163 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1164 return true;
1165 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1166 return true;
1167 return isMemNoOffset(false, 0);
1168 }
1169 bool isAlignedMemory64or128or256() const {
1170 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1171 return true;
1172 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1173 return true;
1174 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
1175 return true;
1176 return isMemNoOffset(false, 0);
1177 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001178 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001179 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001180 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001181 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001182 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001183 if (!Memory.OffsetImm) return true;
1184 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001185 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001186 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001187 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001188 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001189 // Immediate offset in range [-4095, 4095].
1190 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1191 if (!CE) return false;
1192 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001193 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001194 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001195 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001196 // If we have an immediate that's not a constant, treat it as a label
1197 // reference needing a fixup. If it is a constant, it's something else
1198 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001199 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001200 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001201 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001202 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001203 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001204 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001205 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001206 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001207 if (!Memory.OffsetImm) return true;
1208 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001209 // The #-0 offset is encoded as INT32_MIN, and we have to check
1210 // for this too.
1211 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001212 }
1213 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001214 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001215 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001216 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001217 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1218 // Immediate offset in range [-255, 255].
1219 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1220 if (!CE) return false;
1221 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001222 // Special case, #-0 is INT32_MIN.
1223 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001224 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001225 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001226 // If we have an immediate that's not a constant, treat it as a label
1227 // reference needing a fixup. If it is a constant, it's something else
1228 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001229 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001230 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001231 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001232 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001233 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001234 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001235 if (!Memory.OffsetImm) return true;
1236 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001237 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001238 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001239 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001240 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001241 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001242 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001243 return false;
1244 return true;
1245 }
1246 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001247 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001248 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1249 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001250 return false;
1251 return true;
1252 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001253 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001254 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001255 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001256 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001257 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001258 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001259 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001260 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001261 return false;
1262 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001263 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001264 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001265 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001266 return false;
1267 return true;
1268 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001269 bool isMemThumbRR() const {
1270 // Thumb reg+reg addressing is simple. Just two registers, a base and
1271 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001272 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001273 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001274 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001275 return isARMLowRegister(Memory.BaseRegNum) &&
1276 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001277 }
1278 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001279 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001280 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001281 return false;
1282 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001283 if (!Memory.OffsetImm) return true;
1284 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001285 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1286 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001287 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001288 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001289 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001290 return false;
1291 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001292 if (!Memory.OffsetImm) return true;
1293 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001294 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1295 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001296 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001297 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001298 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001299 return false;
1300 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001301 if (!Memory.OffsetImm) return true;
1302 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001303 return Val >= 0 && Val <= 31;
1304 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001305 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001306 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001307 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001308 return false;
1309 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001310 if (!Memory.OffsetImm) return true;
1311 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001312 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001313 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001314 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001315 // If we have an immediate that's not a constant, treat it as a label
1316 // reference needing a fixup. If it is a constant, it's something else
1317 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001318 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001319 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001320 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001321 return false;
1322 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001323 if (!Memory.OffsetImm) return true;
1324 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001325 // Special case, #-0 is INT32_MIN.
1326 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001327 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001328 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001329 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001330 return false;
1331 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001332 if (!Memory.OffsetImm) return true;
1333 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001334 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1335 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001336 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001337 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001338 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001339 // Base reg of PC isn't allowed for these encodings.
1340 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001341 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001342 if (!Memory.OffsetImm) return true;
1343 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001344 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001345 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001346 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001347 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001348 return false;
1349 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001350 if (!Memory.OffsetImm) return true;
1351 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001352 return Val >= 0 && Val < 256;
1353 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001354 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001355 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001356 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001357 // Base reg of PC isn't allowed for these encodings.
1358 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001359 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001360 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001361 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001362 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001363 }
1364 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001365 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001366 return false;
1367 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001368 if (!Memory.OffsetImm) return true;
1369 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001370 return (Val >= 0 && Val < 4096);
1371 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001372 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001373 // If we have an immediate that's not a constant, treat it as a label
1374 // reference needing a fixup. If it is a constant, it's something else
1375 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001376 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001377 return true;
1378
Chad Rosier41099832012-09-11 23:02:35 +00001379 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001380 return false;
1381 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001382 if (!Memory.OffsetImm) return true;
1383 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001384 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001385 }
1386 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001387 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001388 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1389 if (!CE) return false;
1390 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001391 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001392 }
Jim Grosbach93981412011-10-11 21:55:36 +00001393 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001394 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001395 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1396 if (!CE) return false;
1397 int64_t Val = CE->getValue();
1398 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1399 (Val == INT32_MIN);
1400 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001401
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001402 bool isMSRMask() const { return Kind == k_MSRMask; }
1403 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001404
Jim Grosbach741cd732011-10-17 22:26:03 +00001405 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001406 bool isSingleSpacedVectorList() const {
1407 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1408 }
1409 bool isDoubleSpacedVectorList() const {
1410 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1411 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001412 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001413 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001414 return VectorList.Count == 1;
1415 }
1416
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001417 bool isVecListDPair() const {
1418 if (!isSingleSpacedVectorList()) return false;
1419 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1420 .contains(VectorList.RegNum));
1421 }
1422
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001423 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001424 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001425 return VectorList.Count == 3;
1426 }
1427
Jim Grosbach846bcff2011-10-21 20:35:01 +00001428 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001429 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001430 return VectorList.Count == 4;
1431 }
1432
Jim Grosbache5307f92012-03-05 21:43:40 +00001433 bool isVecListDPairSpaced() const {
Kevin Enderby56113982014-03-26 21:54:11 +00001434 if (Kind != k_VectorList) return false;
Kevin Enderby816ca272012-03-20 17:41:51 +00001435 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001436 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1437 .contains(VectorList.RegNum));
1438 }
1439
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001440 bool isVecListThreeQ() const {
1441 if (!isDoubleSpacedVectorList()) return false;
1442 return VectorList.Count == 3;
1443 }
1444
Jim Grosbach1e946a42012-01-24 00:43:12 +00001445 bool isVecListFourQ() const {
1446 if (!isDoubleSpacedVectorList()) return false;
1447 return VectorList.Count == 4;
1448 }
1449
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001450 bool isSingleSpacedVectorAllLanes() const {
1451 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1452 }
1453 bool isDoubleSpacedVectorAllLanes() const {
1454 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1455 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001456 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001457 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001458 return VectorList.Count == 1;
1459 }
1460
Jim Grosbach13a292c2012-03-06 22:01:44 +00001461 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001462 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001463 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1464 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001465 }
1466
Jim Grosbached428bc2012-03-06 23:10:38 +00001467 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001468 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001469 return VectorList.Count == 2;
1470 }
1471
Jim Grosbachb78403c2012-01-24 23:47:04 +00001472 bool isVecListThreeDAllLanes() const {
1473 if (!isSingleSpacedVectorAllLanes()) return false;
1474 return VectorList.Count == 3;
1475 }
1476
1477 bool isVecListThreeQAllLanes() const {
1478 if (!isDoubleSpacedVectorAllLanes()) return false;
1479 return VectorList.Count == 3;
1480 }
1481
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001482 bool isVecListFourDAllLanes() const {
1483 if (!isSingleSpacedVectorAllLanes()) return false;
1484 return VectorList.Count == 4;
1485 }
1486
1487 bool isVecListFourQAllLanes() const {
1488 if (!isDoubleSpacedVectorAllLanes()) return false;
1489 return VectorList.Count == 4;
1490 }
1491
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001492 bool isSingleSpacedVectorIndexed() const {
1493 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1494 }
1495 bool isDoubleSpacedVectorIndexed() const {
1496 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1497 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001498 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001499 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001500 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1501 }
1502
Jim Grosbachda511042011-12-14 23:35:06 +00001503 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001504 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001505 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1506 }
1507
1508 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001509 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001510 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1511 }
1512
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001513 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001514 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001515 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1516 }
1517
Jim Grosbachda511042011-12-14 23:35:06 +00001518 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001519 if (!isSingleSpacedVectorIndexed()) return false;
1520 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1521 }
1522
1523 bool isVecListTwoQWordIndexed() const {
1524 if (!isDoubleSpacedVectorIndexed()) return false;
1525 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1526 }
1527
1528 bool isVecListTwoQHWordIndexed() const {
1529 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001530 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1531 }
1532
1533 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001534 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001535 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1536 }
1537
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001538 bool isVecListThreeDByteIndexed() const {
1539 if (!isSingleSpacedVectorIndexed()) return false;
1540 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1541 }
1542
1543 bool isVecListThreeDHWordIndexed() const {
1544 if (!isSingleSpacedVectorIndexed()) return false;
1545 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1546 }
1547
1548 bool isVecListThreeQWordIndexed() const {
1549 if (!isDoubleSpacedVectorIndexed()) return false;
1550 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1551 }
1552
1553 bool isVecListThreeQHWordIndexed() const {
1554 if (!isDoubleSpacedVectorIndexed()) return false;
1555 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1556 }
1557
1558 bool isVecListThreeDWordIndexed() const {
1559 if (!isSingleSpacedVectorIndexed()) return false;
1560 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1561 }
1562
Jim Grosbach14952a02012-01-24 18:37:25 +00001563 bool isVecListFourDByteIndexed() const {
1564 if (!isSingleSpacedVectorIndexed()) return false;
1565 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1566 }
1567
1568 bool isVecListFourDHWordIndexed() const {
1569 if (!isSingleSpacedVectorIndexed()) return false;
1570 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1571 }
1572
1573 bool isVecListFourQWordIndexed() const {
1574 if (!isDoubleSpacedVectorIndexed()) return false;
1575 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1576 }
1577
1578 bool isVecListFourQHWordIndexed() const {
1579 if (!isDoubleSpacedVectorIndexed()) return false;
1580 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1581 }
1582
1583 bool isVecListFourDWordIndexed() const {
1584 if (!isSingleSpacedVectorIndexed()) return false;
1585 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1586 }
1587
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001588 bool isVectorIndex8() const {
1589 if (Kind != k_VectorIndex) return false;
1590 return VectorIndex.Val < 8;
1591 }
1592 bool isVectorIndex16() const {
1593 if (Kind != k_VectorIndex) return false;
1594 return VectorIndex.Val < 4;
1595 }
1596 bool isVectorIndex32() const {
1597 if (Kind != k_VectorIndex) return false;
1598 return VectorIndex.Val < 2;
1599 }
1600
Jim Grosbach741cd732011-10-17 22:26:03 +00001601 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001602 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001603 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1604 // Must be a constant.
1605 if (!CE) return false;
1606 int64_t Value = CE->getValue();
1607 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1608 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001609 return Value >= 0 && Value < 256;
1610 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001611
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001612 bool isNEONi16splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001613 if (isNEONByteReplicate(2))
1614 return false; // Leave that for bytes replication and forbid by default.
1615 if (!isImm())
1616 return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001617 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1618 // Must be a constant.
1619 if (!CE) return false;
1620 int64_t Value = CE->getValue();
1621 // i16 value in the range [0,255] or [0x0100, 0xff00]
1622 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1623 }
1624
Jim Grosbach8211c052011-10-18 00:22:00 +00001625 bool isNEONi32splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001626 if (isNEONByteReplicate(4))
1627 return false; // Leave that for bytes replication and forbid by default.
1628 if (!isImm())
1629 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001630 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1631 // Must be a constant.
1632 if (!CE) return false;
1633 int64_t Value = CE->getValue();
1634 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1635 return (Value >= 0 && Value < 256) ||
1636 (Value >= 0x0100 && Value <= 0xff00) ||
1637 (Value >= 0x010000 && Value <= 0xff0000) ||
1638 (Value >= 0x01000000 && Value <= 0xff000000);
1639 }
1640
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001641 bool isNEONByteReplicate(unsigned NumBytes) const {
1642 if (!isImm())
1643 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001644 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1645 // Must be a constant.
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001646 if (!CE)
1647 return false;
1648 int64_t Value = CE->getValue();
1649 if (!Value)
1650 return false; // Don't bother with zero.
1651
1652 unsigned char B = Value & 0xff;
1653 for (unsigned i = 1; i < NumBytes; ++i) {
1654 Value >>= 8;
1655 if ((Value & 0xff) != B)
1656 return false;
1657 }
1658 return true;
1659 }
1660 bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); }
1661 bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); }
1662 bool isNEONi32vmov() const {
1663 if (isNEONByteReplicate(4))
1664 return false; // Let it to be classified as byte-replicate case.
1665 if (!isImm())
1666 return false;
1667 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1668 // Must be a constant.
1669 if (!CE)
1670 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001671 int64_t Value = CE->getValue();
1672 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1673 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1674 return (Value >= 0 && Value < 256) ||
1675 (Value >= 0x0100 && Value <= 0xff00) ||
1676 (Value >= 0x010000 && Value <= 0xff0000) ||
1677 (Value >= 0x01000000 && Value <= 0xff000000) ||
1678 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1679 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1680 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001681 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001682 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1684 // Must be a constant.
1685 if (!CE) return false;
1686 int64_t Value = ~CE->getValue();
1687 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1688 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1689 return (Value >= 0 && Value < 256) ||
1690 (Value >= 0x0100 && Value <= 0xff00) ||
1691 (Value >= 0x010000 && Value <= 0xff0000) ||
1692 (Value >= 0x01000000 && Value <= 0xff000000) ||
1693 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1694 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1695 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001696
Jim Grosbache4454e02011-10-18 16:18:11 +00001697 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001698 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1700 // Must be a constant.
1701 if (!CE) return false;
1702 uint64_t Value = CE->getValue();
1703 // i64 value with each byte being either 0 or 0xff.
1704 for (unsigned i = 0; i < 8; ++i)
1705 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1706 return true;
1707 }
1708
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001709 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001710 // Add as immediates when possible. Null MCExpr = 0.
1711 if (Expr == 0)
1712 Inst.addOperand(MCOperand::CreateImm(0));
1713 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001714 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1715 else
1716 Inst.addOperand(MCOperand::CreateExpr(Expr));
1717 }
1718
Daniel Dunbard8042b72010-08-11 06:36:53 +00001719 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001720 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001721 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001722 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1723 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001724 }
1725
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001726 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1727 assert(N == 1 && "Invalid number of operands!");
1728 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1729 }
1730
Jim Grosbach48399582011-10-12 17:34:41 +00001731 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1732 assert(N == 1 && "Invalid number of operands!");
1733 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1734 }
1735
1736 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1737 assert(N == 1 && "Invalid number of operands!");
1738 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1739 }
1740
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001741 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1742 assert(N == 1 && "Invalid number of operands!");
1743 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1744 }
1745
1746 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1747 assert(N == 1 && "Invalid number of operands!");
1748 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1749 }
1750
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001751 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1752 assert(N == 1 && "Invalid number of operands!");
1753 Inst.addOperand(MCOperand::CreateReg(getReg()));
1754 }
1755
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001756 void addRegOperands(MCInst &Inst, unsigned N) const {
1757 assert(N == 1 && "Invalid number of operands!");
1758 Inst.addOperand(MCOperand::CreateReg(getReg()));
1759 }
1760
Jim Grosbachac798e12011-07-25 20:49:51 +00001761 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001762 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001763 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001764 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001765 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1766 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001767 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001768 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001769 }
1770
Jim Grosbachac798e12011-07-25 20:49:51 +00001771 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001772 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001773 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001774 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001775 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001776 // Shift of #32 is encoded as 0 where permitted
1777 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001778 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001779 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001780 }
1781
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001782 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001783 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001784 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1785 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001786 }
1787
Bill Wendling8d2aa032010-11-08 23:49:57 +00001788 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001789 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001790 const SmallVectorImpl<unsigned> &RegList = getRegList();
1791 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001792 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1793 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001794 }
1795
Bill Wendling9898ac92010-11-17 04:32:08 +00001796 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1797 addRegListOperands(Inst, N);
1798 }
1799
1800 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1801 addRegListOperands(Inst, N);
1802 }
1803
Jim Grosbach833b9d32011-07-27 20:15:40 +00001804 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1805 assert(N == 1 && "Invalid number of operands!");
1806 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1807 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1808 }
1809
Jim Grosbach864b6092011-07-28 21:34:26 +00001810 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1811 assert(N == 1 && "Invalid number of operands!");
1812 // Munge the lsb/width into a bitfield mask.
1813 unsigned lsb = Bitfield.LSB;
1814 unsigned width = Bitfield.Width;
1815 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1816 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1817 (32 - (lsb + width)));
1818 Inst.addOperand(MCOperand::CreateImm(Mask));
1819 }
1820
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001821 void addImmOperands(MCInst &Inst, unsigned N) const {
1822 assert(N == 1 && "Invalid number of operands!");
1823 addExpr(Inst, getImm());
1824 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001825
Jim Grosbachea231912011-12-22 22:19:05 +00001826 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1827 assert(N == 1 && "Invalid number of operands!");
1828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1829 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1830 }
1831
1832 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1833 assert(N == 1 && "Invalid number of operands!");
1834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1835 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1836 }
1837
Jim Grosbache7fbce72011-10-03 23:38:36 +00001838 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1839 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001840 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1841 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1842 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001843 }
1844
Jim Grosbach7db8d692011-09-08 22:07:06 +00001845 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1846 assert(N == 1 && "Invalid number of operands!");
1847 // FIXME: We really want to scale the value here, but the LDRD/STRD
1848 // instruction don't encode operands that way yet.
1849 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1850 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1851 }
1852
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001853 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1854 assert(N == 1 && "Invalid number of operands!");
1855 // The immediate is scaled by four in the encoding and is stored
1856 // in the MCInst as such. Lop off the low two bits here.
1857 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1858 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1859 }
1860
Jim Grosbach930f2f62012-04-05 20:57:13 +00001861 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1862 assert(N == 1 && "Invalid number of operands!");
1863 // The immediate is scaled by four in the encoding and is stored
1864 // in the MCInst as such. Lop off the low two bits here.
1865 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1866 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1867 }
1868
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001869 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1870 assert(N == 1 && "Invalid number of operands!");
1871 // The immediate is scaled by four in the encoding and is stored
1872 // in the MCInst as such. Lop off the low two bits here.
1873 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1874 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1875 }
1876
Jim Grosbach475c6db2011-07-25 23:09:14 +00001877 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1878 assert(N == 1 && "Invalid number of operands!");
1879 // The constant encodes as the immediate-1, and we store in the instruction
1880 // the bits as encoded, so subtract off one here.
1881 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1882 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1883 }
1884
Jim Grosbach801e0a32011-07-22 23:16:18 +00001885 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1886 assert(N == 1 && "Invalid number of operands!");
1887 // The constant encodes as the immediate-1, and we store in the instruction
1888 // the bits as encoded, so subtract off one here.
1889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1890 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1891 }
1892
Jim Grosbach46dd4132011-08-17 21:51:27 +00001893 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1894 assert(N == 1 && "Invalid number of operands!");
1895 // The constant encodes as the immediate, except for 32, which encodes as
1896 // zero.
1897 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1898 unsigned Imm = CE->getValue();
1899 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1900 }
1901
Jim Grosbach27c1e252011-07-21 17:23:04 +00001902 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1903 assert(N == 1 && "Invalid number of operands!");
1904 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1905 // the instruction as well.
1906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1907 int Val = CE->getValue();
1908 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1909 }
1910
Jim Grosbachb009a872011-10-28 22:36:30 +00001911 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1912 assert(N == 1 && "Invalid number of operands!");
1913 // The operand is actually a t2_so_imm, but we have its bitwise
1914 // negation in the assembly source, so twiddle it here.
1915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1916 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1917 }
1918
Jim Grosbach30506252011-12-08 00:31:07 +00001919 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1920 assert(N == 1 && "Invalid number of operands!");
1921 // The operand is actually a t2_so_imm, but we have its
1922 // negation in the assembly source, so twiddle it here.
1923 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1924 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1925 }
1926
Jim Grosbach930f2f62012-04-05 20:57:13 +00001927 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1928 assert(N == 1 && "Invalid number of operands!");
1929 // The operand is actually an imm0_4095, but we have its
1930 // negation in the assembly source, so twiddle it here.
1931 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1932 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1933 }
1934
Mihai Popad36cbaa2013-07-03 09:21:44 +00001935 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1936 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1937 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1938 return;
1939 }
1940
1941 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1942 assert(SR && "Unknown value type!");
1943 Inst.addOperand(MCOperand::CreateExpr(SR));
1944 }
1945
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001946 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1947 assert(N == 1 && "Invalid number of operands!");
1948 if (isImm()) {
1949 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1950 if (CE) {
1951 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1952 return;
1953 }
1954
1955 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1956 assert(SR && "Unknown value type!");
1957 Inst.addOperand(MCOperand::CreateExpr(SR));
1958 return;
1959 }
1960
1961 assert(isMem() && "Unknown value type!");
1962 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1963 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1964 }
1965
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001966 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1967 assert(N == 1 && "Invalid number of operands!");
1968 // The operand is actually a so_imm, but we have its bitwise
1969 // negation in the assembly source, so twiddle it here.
1970 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1971 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1972 }
1973
Jim Grosbach30506252011-12-08 00:31:07 +00001974 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1975 assert(N == 1 && "Invalid number of operands!");
1976 // The operand is actually a so_imm, but we have its
1977 // negation in the assembly source, so twiddle it here.
1978 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1979 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1980 }
1981
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001982 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1983 assert(N == 1 && "Invalid number of operands!");
1984 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1985 }
1986
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001987 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1988 assert(N == 1 && "Invalid number of operands!");
1989 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1990 }
1991
Jim Grosbachd3595712011-08-03 23:50:40 +00001992 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1993 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001994 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001995 }
1996
Jim Grosbach94298a92012-01-18 22:46:46 +00001997 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1998 assert(N == 1 && "Invalid number of operands!");
1999 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00002000 Inst.addOperand(MCOperand::CreateImm(Imm));
2001 }
2002
Jiangning Liu10dd40e2012-08-02 08:13:13 +00002003 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
2004 assert(N == 1 && "Invalid number of operands!");
2005 assert(isImm() && "Not an immediate!");
2006
2007 // If we have an immediate that's not a constant, treat it as a label
2008 // reference needing a fixup.
2009 if (!isa<MCConstantExpr>(getImm())) {
2010 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2011 return;
2012 }
2013
2014 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2015 int Val = CE->getValue();
2016 Inst.addOperand(MCOperand::CreateImm(Val));
2017 }
2018
Jim Grosbacha95ec992011-10-11 17:29:55 +00002019 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
2020 assert(N == 2 && "Invalid number of operands!");
2021 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2022 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
2023 }
2024
Kevin Enderby488f20b2014-04-10 20:18:58 +00002025 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2026 addAlignedMemoryOperands(Inst, N);
2027 }
2028
2029 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2030 addAlignedMemoryOperands(Inst, N);
2031 }
2032
2033 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2034 addAlignedMemoryOperands(Inst, N);
2035 }
2036
2037 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2038 addAlignedMemoryOperands(Inst, N);
2039 }
2040
2041 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2042 addAlignedMemoryOperands(Inst, N);
2043 }
2044
2045 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2046 addAlignedMemoryOperands(Inst, N);
2047 }
2048
2049 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2050 addAlignedMemoryOperands(Inst, N);
2051 }
2052
2053 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2054 addAlignedMemoryOperands(Inst, N);
2055 }
2056
2057 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2058 addAlignedMemoryOperands(Inst, N);
2059 }
2060
2061 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2062 addAlignedMemoryOperands(Inst, N);
2063 }
2064
2065 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
2066 addAlignedMemoryOperands(Inst, N);
2067 }
2068
Jim Grosbachd3595712011-08-03 23:50:40 +00002069 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
2070 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002071 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2072 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00002073 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2074 // Special case for #-0
2075 if (Val == INT32_MIN) Val = 0;
2076 if (Val < 0) Val = -Val;
2077 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2078 } else {
2079 // For register offset, we encode the shift type and negation flag
2080 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002081 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2082 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002083 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002084 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2085 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002086 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002087 }
2088
Jim Grosbachcd17c122011-08-04 23:01:30 +00002089 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
2090 assert(N == 2 && "Invalid number of operands!");
2091 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2092 assert(CE && "non-constant AM2OffsetImm operand!");
2093 int32_t Val = CE->getValue();
2094 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2095 // Special case for #-0
2096 if (Val == INT32_MIN) Val = 0;
2097 if (Val < 0) Val = -Val;
2098 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2099 Inst.addOperand(MCOperand::CreateReg(0));
2100 Inst.addOperand(MCOperand::CreateImm(Val));
2101 }
2102
Jim Grosbach5b96b802011-08-10 20:29:19 +00002103 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
2104 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002105 // If we have an immediate that's not a constant, treat it as a label
2106 // reference needing a fixup. If it is a constant, it's something else
2107 // and we reject it.
2108 if (isImm()) {
2109 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2110 Inst.addOperand(MCOperand::CreateReg(0));
2111 Inst.addOperand(MCOperand::CreateImm(0));
2112 return;
2113 }
2114
Jim Grosbach871dff72011-10-11 15:59:20 +00002115 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2116 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002117 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2118 // Special case for #-0
2119 if (Val == INT32_MIN) Val = 0;
2120 if (Val < 0) Val = -Val;
2121 Val = ARM_AM::getAM3Opc(AddSub, Val);
2122 } else {
2123 // For register offset, we encode the shift type and negation flag
2124 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002125 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002126 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002127 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2128 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00002129 Inst.addOperand(MCOperand::CreateImm(Val));
2130 }
2131
2132 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
2133 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002134 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002135 int32_t Val =
2136 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
2137 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2138 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002139 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00002140 }
2141
2142 // Constant offset.
2143 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2144 int32_t Val = CE->getValue();
2145 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2146 // Special case for #-0
2147 if (Val == INT32_MIN) Val = 0;
2148 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002149 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002150 Inst.addOperand(MCOperand::CreateReg(0));
2151 Inst.addOperand(MCOperand::CreateImm(Val));
2152 }
2153
Jim Grosbachd3595712011-08-03 23:50:40 +00002154 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2155 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00002156 // If we have an immediate that's not a constant, treat it as a label
2157 // reference needing a fixup. If it is a constant, it's something else
2158 // and we reject it.
2159 if (isImm()) {
2160 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2161 Inst.addOperand(MCOperand::CreateImm(0));
2162 return;
2163 }
2164
Jim Grosbachd3595712011-08-03 23:50:40 +00002165 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002166 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002167 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2168 // Special case for #-0
2169 if (Val == INT32_MIN) Val = 0;
2170 if (Val < 0) Val = -Val;
2171 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002172 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002173 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002174 }
2175
Jim Grosbach7db8d692011-09-08 22:07:06 +00002176 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2177 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002178 // If we have an immediate that's not a constant, treat it as a label
2179 // reference needing a fixup. If it is a constant, it's something else
2180 // and we reject it.
2181 if (isImm()) {
2182 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2183 Inst.addOperand(MCOperand::CreateImm(0));
2184 return;
2185 }
2186
Jim Grosbach871dff72011-10-11 15:59:20 +00002187 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2188 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002189 Inst.addOperand(MCOperand::CreateImm(Val));
2190 }
2191
Jim Grosbacha05627e2011-09-09 18:37:27 +00002192 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2193 assert(N == 2 && "Invalid number of operands!");
2194 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002195 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2196 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002197 Inst.addOperand(MCOperand::CreateImm(Val));
2198 }
2199
Jim Grosbachd3595712011-08-03 23:50:40 +00002200 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2201 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002202 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2203 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002204 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002205 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002206
Jim Grosbach2392c532011-09-07 23:39:14 +00002207 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2208 addMemImm8OffsetOperands(Inst, N);
2209 }
2210
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002211 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002212 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002213 }
2214
2215 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2216 assert(N == 2 && "Invalid number of operands!");
2217 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002218 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002219 addExpr(Inst, getImm());
2220 Inst.addOperand(MCOperand::CreateImm(0));
2221 return;
2222 }
2223
2224 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002225 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2226 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002227 Inst.addOperand(MCOperand::CreateImm(Val));
2228 }
2229
Jim Grosbachd3595712011-08-03 23:50:40 +00002230 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2231 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002232 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002233 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002234 addExpr(Inst, getImm());
2235 Inst.addOperand(MCOperand::CreateImm(0));
2236 return;
2237 }
2238
2239 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002240 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2241 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002242 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002243 }
Bill Wendling811c9362010-11-30 07:44:32 +00002244
Jim Grosbach05541f42011-09-19 22:21:13 +00002245 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2246 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002247 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2248 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002249 }
2250
2251 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2252 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002253 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2254 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002255 }
2256
Jim Grosbachd3595712011-08-03 23:50:40 +00002257 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2258 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002259 unsigned Val =
2260 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2261 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002262 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2263 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002264 Inst.addOperand(MCOperand::CreateImm(Val));
2265 }
2266
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002267 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2268 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002269 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2270 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2271 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002272 }
2273
Jim Grosbachd3595712011-08-03 23:50:40 +00002274 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2275 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002276 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2277 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002278 }
2279
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002280 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2281 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002282 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2283 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002284 Inst.addOperand(MCOperand::CreateImm(Val));
2285 }
2286
Jim Grosbach26d35872011-08-19 18:55:51 +00002287 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2288 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002289 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2290 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002291 Inst.addOperand(MCOperand::CreateImm(Val));
2292 }
2293
Jim Grosbacha32c7532011-08-19 18:49:59 +00002294 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2295 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002296 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2297 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002298 Inst.addOperand(MCOperand::CreateImm(Val));
2299 }
2300
Jim Grosbach23983d62011-08-19 18:13:48 +00002301 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2302 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002303 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2304 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002305 Inst.addOperand(MCOperand::CreateImm(Val));
2306 }
2307
Jim Grosbachd3595712011-08-03 23:50:40 +00002308 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2309 assert(N == 1 && "Invalid number of operands!");
2310 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2311 assert(CE && "non-constant post-idx-imm8 operand!");
2312 int Imm = CE->getValue();
2313 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002314 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002315 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2316 Inst.addOperand(MCOperand::CreateImm(Imm));
2317 }
2318
Jim Grosbach93981412011-10-11 21:55:36 +00002319 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2320 assert(N == 1 && "Invalid number of operands!");
2321 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2322 assert(CE && "non-constant post-idx-imm8s4 operand!");
2323 int Imm = CE->getValue();
2324 bool isAdd = Imm >= 0;
2325 if (Imm == INT32_MIN) Imm = 0;
2326 // Immediate is scaled by 4.
2327 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2328 Inst.addOperand(MCOperand::CreateImm(Imm));
2329 }
2330
Jim Grosbachd3595712011-08-03 23:50:40 +00002331 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2332 assert(N == 2 && "Invalid number of operands!");
2333 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002334 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2335 }
2336
2337 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2338 assert(N == 2 && "Invalid number of operands!");
2339 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2340 // The sign, shift type, and shift amount are encoded in a single operand
2341 // using the AM2 encoding helpers.
2342 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2343 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2344 PostIdxReg.ShiftTy);
2345 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002346 }
2347
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002348 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2349 assert(N == 1 && "Invalid number of operands!");
2350 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2351 }
2352
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002353 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2354 assert(N == 1 && "Invalid number of operands!");
2355 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2356 }
2357
Jim Grosbach182b6a02011-11-29 23:51:09 +00002358 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002359 assert(N == 1 && "Invalid number of operands!");
2360 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2361 }
2362
Jim Grosbach04945c42011-12-02 00:35:16 +00002363 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2364 assert(N == 2 && "Invalid number of operands!");
2365 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2366 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2367 }
2368
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002369 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2370 assert(N == 1 && "Invalid number of operands!");
2371 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2372 }
2373
2374 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2375 assert(N == 1 && "Invalid number of operands!");
2376 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2377 }
2378
2379 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2380 assert(N == 1 && "Invalid number of operands!");
2381 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2382 }
2383
Jim Grosbach741cd732011-10-17 22:26:03 +00002384 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2385 assert(N == 1 && "Invalid number of operands!");
2386 // The immediate encodes the type of constant as well as the value.
2387 // Mask in that this is an i8 splat.
2388 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2389 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2390 }
2391
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002392 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2393 assert(N == 1 && "Invalid number of operands!");
2394 // The immediate encodes the type of constant as well as the value.
2395 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2396 unsigned Value = CE->getValue();
2397 if (Value >= 256)
2398 Value = (Value >> 8) | 0xa00;
2399 else
2400 Value |= 0x800;
2401 Inst.addOperand(MCOperand::CreateImm(Value));
2402 }
2403
Jim Grosbach8211c052011-10-18 00:22:00 +00002404 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2405 assert(N == 1 && "Invalid number of operands!");
2406 // The immediate encodes the type of constant as well as the value.
2407 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2408 unsigned Value = CE->getValue();
2409 if (Value >= 256 && Value <= 0xff00)
2410 Value = (Value >> 8) | 0x200;
2411 else if (Value > 0xffff && Value <= 0xff0000)
2412 Value = (Value >> 16) | 0x400;
2413 else if (Value > 0xffffff)
2414 Value = (Value >> 24) | 0x600;
2415 Inst.addOperand(MCOperand::CreateImm(Value));
2416 }
2417
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002418 void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const {
2419 assert(N == 1 && "Invalid number of operands!");
2420 // The immediate encodes the type of constant as well as the value.
2421 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2422 unsigned Value = CE->getValue();
2423 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2424 Inst.getOpcode() == ARM::VMOVv16i8) &&
2425 "All vmvn instructions that wants to replicate non-zero byte "
2426 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2427 unsigned B = ((~Value) & 0xff);
2428 B |= 0xe00; // cmode = 0b1110
2429 Inst.addOperand(MCOperand::CreateImm(B));
2430 }
Jim Grosbach8211c052011-10-18 00:22:00 +00002431 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2432 assert(N == 1 && "Invalid number of operands!");
2433 // The immediate encodes the type of constant as well as the value.
2434 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2435 unsigned Value = CE->getValue();
2436 if (Value >= 256 && Value <= 0xffff)
2437 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2438 else if (Value > 0xffff && Value <= 0xffffff)
2439 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2440 else if (Value > 0xffffff)
2441 Value = (Value >> 24) | 0x600;
2442 Inst.addOperand(MCOperand::CreateImm(Value));
2443 }
2444
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002445 void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const {
2446 assert(N == 1 && "Invalid number of operands!");
2447 // The immediate encodes the type of constant as well as the value.
2448 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2449 unsigned Value = CE->getValue();
2450 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2451 Inst.getOpcode() == ARM::VMOVv16i8) &&
2452 "All instructions that wants to replicate non-zero byte "
2453 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2454 unsigned B = Value & 0xff;
2455 B |= 0xe00; // cmode = 0b1110
2456 Inst.addOperand(MCOperand::CreateImm(B));
2457 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00002458 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2459 assert(N == 1 && "Invalid number of operands!");
2460 // The immediate encodes the type of constant as well as the value.
2461 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2462 unsigned Value = ~CE->getValue();
2463 if (Value >= 256 && Value <= 0xffff)
2464 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2465 else if (Value > 0xffff && Value <= 0xffffff)
2466 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2467 else if (Value > 0xffffff)
2468 Value = (Value >> 24) | 0x600;
2469 Inst.addOperand(MCOperand::CreateImm(Value));
2470 }
2471
Jim Grosbache4454e02011-10-18 16:18:11 +00002472 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2473 assert(N == 1 && "Invalid number of operands!");
2474 // The immediate encodes the type of constant as well as the value.
2475 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2476 uint64_t Value = CE->getValue();
2477 unsigned Imm = 0;
2478 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2479 Imm |= (Value & 1) << i;
2480 }
2481 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2482 }
2483
Craig Topperca7e3e52014-03-10 03:19:03 +00002484 void print(raw_ostream &OS) const override;
Daniel Dunbarebace222010-08-11 06:37:04 +00002485
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002486 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002487 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002488 Op->ITMask.Mask = Mask;
2489 Op->StartLoc = S;
2490 Op->EndLoc = S;
2491 return Op;
2492 }
2493
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002494 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002495 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002496 Op->CC.Val = CC;
2497 Op->StartLoc = S;
2498 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002499 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002500 }
2501
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002502 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002503 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002504 Op->Cop.Val = CopVal;
2505 Op->StartLoc = S;
2506 Op->EndLoc = S;
2507 return Op;
2508 }
2509
2510 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002511 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002512 Op->Cop.Val = CopVal;
2513 Op->StartLoc = S;
2514 Op->EndLoc = S;
2515 return Op;
2516 }
2517
Jim Grosbach48399582011-10-12 17:34:41 +00002518 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2519 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2520 Op->Cop.Val = Val;
2521 Op->StartLoc = S;
2522 Op->EndLoc = E;
2523 return Op;
2524 }
2525
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002526 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002527 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002528 Op->Reg.RegNum = RegNum;
2529 Op->StartLoc = S;
2530 Op->EndLoc = S;
2531 return Op;
2532 }
2533
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002534 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002535 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002536 Op->Tok.Data = Str.data();
2537 Op->Tok.Length = Str.size();
2538 Op->StartLoc = S;
2539 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002540 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002541 }
2542
Bill Wendling2063b842010-11-18 23:43:05 +00002543 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002544 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002545 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002546 Op->StartLoc = S;
2547 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002548 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002549 }
2550
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002551 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2552 unsigned SrcReg,
2553 unsigned ShiftReg,
2554 unsigned ShiftImm,
2555 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002556 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002557 Op->RegShiftedReg.ShiftTy = ShTy;
2558 Op->RegShiftedReg.SrcReg = SrcReg;
2559 Op->RegShiftedReg.ShiftReg = ShiftReg;
2560 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002561 Op->StartLoc = S;
2562 Op->EndLoc = E;
2563 return Op;
2564 }
2565
Owen Andersonb595ed02011-07-21 18:54:16 +00002566 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2567 unsigned SrcReg,
2568 unsigned ShiftImm,
2569 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002570 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002571 Op->RegShiftedImm.ShiftTy = ShTy;
2572 Op->RegShiftedImm.SrcReg = SrcReg;
2573 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002574 Op->StartLoc = S;
2575 Op->EndLoc = E;
2576 return Op;
2577 }
2578
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002579 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002580 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002581 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002582 Op->ShifterImm.isASR = isASR;
2583 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002584 Op->StartLoc = S;
2585 Op->EndLoc = E;
2586 return Op;
2587 }
2588
Jim Grosbach833b9d32011-07-27 20:15:40 +00002589 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002590 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002591 Op->RotImm.Imm = Imm;
2592 Op->StartLoc = S;
2593 Op->EndLoc = E;
2594 return Op;
2595 }
2596
Jim Grosbach864b6092011-07-28 21:34:26 +00002597 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2598 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002599 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002600 Op->Bitfield.LSB = LSB;
2601 Op->Bitfield.Width = Width;
2602 Op->StartLoc = S;
2603 Op->EndLoc = E;
2604 return Op;
2605 }
2606
Bill Wendling2cae3272010-11-09 22:44:22 +00002607 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002608 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002609 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002610 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002611 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002612
Chad Rosierfa705ee2013-07-01 20:49:23 +00002613 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002614 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002615 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002616 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002617 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002618
Chad Rosierfa705ee2013-07-01 20:49:23 +00002619 // Sort based on the register encoding values.
2620 array_pod_sort(Regs.begin(), Regs.end());
2621
Bill Wendling9898ac92010-11-17 04:32:08 +00002622 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002623 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002624 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002625 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002626 Op->StartLoc = StartLoc;
2627 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002628 return Op;
2629 }
2630
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002631 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002632 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002633 ARMOperand *Op = new ARMOperand(k_VectorList);
2634 Op->VectorList.RegNum = RegNum;
2635 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002636 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002637 Op->StartLoc = S;
2638 Op->EndLoc = E;
2639 return Op;
2640 }
2641
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002642 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002643 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002644 SMLoc S, SMLoc E) {
2645 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2646 Op->VectorList.RegNum = RegNum;
2647 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002648 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002649 Op->StartLoc = S;
2650 Op->EndLoc = E;
2651 return Op;
2652 }
2653
Jim Grosbach04945c42011-12-02 00:35:16 +00002654 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002655 unsigned Index,
2656 bool isDoubleSpaced,
2657 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002658 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2659 Op->VectorList.RegNum = RegNum;
2660 Op->VectorList.Count = Count;
2661 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002662 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002663 Op->StartLoc = S;
2664 Op->EndLoc = E;
2665 return Op;
2666 }
2667
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002668 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2669 MCContext &Ctx) {
2670 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2671 Op->VectorIndex.Val = Idx;
2672 Op->StartLoc = S;
2673 Op->EndLoc = E;
2674 return Op;
2675 }
2676
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002677 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002678 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002679 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002680 Op->StartLoc = S;
2681 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002682 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002683 }
2684
Jim Grosbachd3595712011-08-03 23:50:40 +00002685 static ARMOperand *CreateMem(unsigned BaseRegNum,
2686 const MCConstantExpr *OffsetImm,
2687 unsigned OffsetRegNum,
2688 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002689 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002690 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002691 bool isNegative,
Kevin Enderby488f20b2014-04-10 20:18:58 +00002692 SMLoc S, SMLoc E,
2693 SMLoc AlignmentLoc = SMLoc()) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002694 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002695 Op->Memory.BaseRegNum = BaseRegNum;
2696 Op->Memory.OffsetImm = OffsetImm;
2697 Op->Memory.OffsetRegNum = OffsetRegNum;
2698 Op->Memory.ShiftType = ShiftType;
2699 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002700 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002701 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002702 Op->StartLoc = S;
2703 Op->EndLoc = E;
Kevin Enderby488f20b2014-04-10 20:18:58 +00002704 Op->AlignmentLoc = AlignmentLoc;
Jim Grosbachd3595712011-08-03 23:50:40 +00002705 return Op;
2706 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002707
Jim Grosbachc320c852011-08-05 21:28:30 +00002708 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2709 ARM_AM::ShiftOpc ShiftTy,
2710 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002711 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002712 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002713 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002714 Op->PostIdxReg.isAdd = isAdd;
2715 Op->PostIdxReg.ShiftTy = ShiftTy;
2716 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002717 Op->StartLoc = S;
2718 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002719 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002720 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002721
2722 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002723 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002724 Op->MBOpt.Val = Opt;
2725 Op->StartLoc = S;
2726 Op->EndLoc = S;
2727 return Op;
2728 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002729
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002730 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2731 SMLoc S) {
2732 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2733 Op->ISBOpt.Val = Opt;
2734 Op->StartLoc = S;
2735 Op->EndLoc = S;
2736 return Op;
2737 }
2738
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002739 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002740 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002741 Op->IFlags.Val = IFlags;
2742 Op->StartLoc = S;
2743 Op->EndLoc = S;
2744 return Op;
2745 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002746
2747 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002748 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002749 Op->MMask.Val = MMask;
2750 Op->StartLoc = S;
2751 Op->EndLoc = S;
2752 return Op;
2753 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002754};
2755
2756} // end anonymous namespace.
2757
Jim Grosbach602aa902011-07-13 15:34:57 +00002758void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002759 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002760 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002761 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002762 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002763 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002764 OS << "<ccout " << getReg() << ">";
2765 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002766 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002767 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002768 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2769 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2770 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002771 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2772 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2773 break;
2774 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002775 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002776 OS << "<coprocessor number: " << getCoproc() << ">";
2777 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002778 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002779 OS << "<coprocessor register: " << getCoproc() << ">";
2780 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002781 case k_CoprocOption:
2782 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2783 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002784 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002785 OS << "<mask: " << getMSRMask() << ">";
2786 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002787 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002788 getImm()->print(OS);
2789 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002790 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002791 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002792 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002793 case k_InstSyncBarrierOpt:
2794 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2795 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002796 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002797 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002798 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002799 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002800 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002801 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002802 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2803 << PostIdxReg.RegNum;
2804 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2805 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2806 << PostIdxReg.ShiftImm;
2807 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002808 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002809 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002810 OS << "<ARM_PROC::";
2811 unsigned IFlags = getProcIFlags();
2812 for (int i=2; i >= 0; --i)
2813 if (IFlags & (1 << i))
2814 OS << ARM_PROC::IFlagsToString(1 << i);
2815 OS << ">";
2816 break;
2817 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002818 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002819 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002820 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002821 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002822 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2823 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002824 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002825 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002826 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002827 << RegShiftedReg.SrcReg << " "
2828 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2829 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002830 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002831 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002832 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002833 << RegShiftedImm.SrcReg << " "
2834 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2835 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002836 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002837 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002838 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2839 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002840 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002841 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2842 << ", width: " << Bitfield.Width << ">";
2843 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002844 case k_RegisterList:
2845 case k_DPRRegisterList:
2846 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002847 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002848
Bill Wendlingbed94652010-11-09 23:28:44 +00002849 const SmallVectorImpl<unsigned> &RegList = getRegList();
2850 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002851 I = RegList.begin(), E = RegList.end(); I != E; ) {
2852 OS << *I;
2853 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002854 }
2855
2856 OS << ">";
2857 break;
2858 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002859 case k_VectorList:
2860 OS << "<vector_list " << VectorList.Count << " * "
2861 << VectorList.RegNum << ">";
2862 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002863 case k_VectorListAllLanes:
2864 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2865 << VectorList.RegNum << ">";
2866 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002867 case k_VectorListIndexed:
2868 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2869 << VectorList.Count << " * " << VectorList.RegNum << ">";
2870 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002871 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002872 OS << "'" << getToken() << "'";
2873 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002874 case k_VectorIndex:
2875 OS << "<vectorindex " << getVectorIndex() << ">";
2876 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002877 }
2878}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002879
2880/// @name Auto-generated Match Functions
2881/// {
2882
2883static unsigned MatchRegisterName(StringRef Name);
2884
2885/// }
2886
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002887bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2888 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002889 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002890 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002891 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002892
2893 return (RegNo == (unsigned)-1);
2894}
2895
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002896/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002897/// and if it is a register name the token is eaten and the register number is
2898/// returned. Otherwise return -1.
2899///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002900int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002901 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002902 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002903
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002904 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002905 unsigned RegNum = MatchRegisterName(lowerCase);
2906 if (!RegNum) {
2907 RegNum = StringSwitch<unsigned>(lowerCase)
2908 .Case("r13", ARM::SP)
2909 .Case("r14", ARM::LR)
2910 .Case("r15", ARM::PC)
2911 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002912 // Additional register name aliases for 'gas' compatibility.
2913 .Case("a1", ARM::R0)
2914 .Case("a2", ARM::R1)
2915 .Case("a3", ARM::R2)
2916 .Case("a4", ARM::R3)
2917 .Case("v1", ARM::R4)
2918 .Case("v2", ARM::R5)
2919 .Case("v3", ARM::R6)
2920 .Case("v4", ARM::R7)
2921 .Case("v5", ARM::R8)
2922 .Case("v6", ARM::R9)
2923 .Case("v7", ARM::R10)
2924 .Case("v8", ARM::R11)
2925 .Case("sb", ARM::R9)
2926 .Case("sl", ARM::R10)
2927 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002928 .Default(0);
2929 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002930 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002931 // Check for aliases registered via .req. Canonicalize to lower case.
2932 // That's more consistent since register names are case insensitive, and
2933 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2934 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002935 // If no match, return failure.
2936 if (Entry == RegisterReqs.end())
2937 return -1;
2938 Parser.Lex(); // Eat identifier token.
2939 return Entry->getValue();
2940 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002941
Chris Lattner44e5981c2010-10-30 04:09:10 +00002942 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002943
Chris Lattner44e5981c2010-10-30 04:09:10 +00002944 return RegNum;
2945}
Jim Grosbach99710a82010-11-01 16:44:21 +00002946
Jim Grosbachbb24c592011-07-13 18:49:30 +00002947// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2948// If a recoverable error occurs, return 1. If an irrecoverable error
2949// occurs, return -1. An irrecoverable error is one where tokens have been
2950// consumed in the process of trying to parse the shifter (i.e., when it is
2951// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002952int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002953 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2954 SMLoc S = Parser.getTok().getLoc();
2955 const AsmToken &Tok = Parser.getTok();
Kevin Enderby62873712014-02-17 21:45:27 +00002956 if (Tok.isNot(AsmToken::Identifier))
2957 return -1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002958
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002959 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002960 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002961 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002962 .Case("lsl", ARM_AM::lsl)
2963 .Case("lsr", ARM_AM::lsr)
2964 .Case("asr", ARM_AM::asr)
2965 .Case("ror", ARM_AM::ror)
2966 .Case("rrx", ARM_AM::rrx)
2967 .Default(ARM_AM::no_shift);
2968
2969 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002970 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002971
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002972 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002973
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002974 // The source register for the shift has already been added to the
2975 // operand list, so we need to pop it off and combine it into the shifted
2976 // register operand instead.
Benjamin Kramerd2da7202014-04-21 09:34:48 +00002977 std::unique_ptr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002978 if (!PrevOp->isReg())
2979 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2980 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002981
2982 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002983 int64_t Imm = 0;
2984 int ShiftReg = 0;
2985 if (ShiftTy == ARM_AM::rrx) {
2986 // RRX Doesn't have an explicit shift amount. The encoder expects
2987 // the shift register to be the same as the source register. Seems odd,
2988 // but OK.
2989 ShiftReg = SrcReg;
2990 } else {
2991 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002992 if (Parser.getTok().is(AsmToken::Hash) ||
2993 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002994 Parser.Lex(); // Eat hash.
2995 SMLoc ImmLoc = Parser.getTok().getLoc();
2996 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002997 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002998 Error(ImmLoc, "invalid immediate shift value");
2999 return -1;
3000 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003001 // The expression must be evaluatable as an immediate.
3002 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00003003 if (!CE) {
3004 Error(ImmLoc, "invalid immediate shift value");
3005 return -1;
3006 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003007 // Range check the immediate.
3008 // lsl, ror: 0 <= imm <= 31
3009 // lsr, asr: 0 <= imm <= 32
3010 Imm = CE->getValue();
3011 if (Imm < 0 ||
3012 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
3013 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003014 Error(ImmLoc, "immediate shift value out of range");
3015 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003016 }
Jim Grosbach21488b82011-12-22 17:37:00 +00003017 // shift by zero is a nop. Always send it through as lsl.
3018 // ('as' compatibility)
3019 if (Imm == 0)
3020 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003021 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003022 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003023 EndLoc = Parser.getTok().getEndLoc();
3024 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00003025 if (ShiftReg == -1) {
3026 Error (L, "expected immediate or register in shift operand");
3027 return -1;
3028 }
3029 } else {
3030 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003031 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003032 return -1;
3033 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003034 }
3035
Owen Andersonb595ed02011-07-21 18:54:16 +00003036 if (ShiftReg && ShiftTy != ARM_AM::rrx)
3037 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00003038 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003039 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00003040 else
3041 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003042 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003043
Jim Grosbachbb24c592011-07-13 18:49:30 +00003044 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003045}
3046
3047
Bill Wendling2063b842010-11-18 23:43:05 +00003048/// Try to parse a register name. The token must be an Identifier when called.
3049/// If it's a register, an AsmOperand is created. Another AsmOperand is created
3050/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00003051///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00003052/// TODO this is likely to change to allow different register types and or to
3053/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00003054bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003055tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003056 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003057 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00003058 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00003059 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00003060
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003061 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
3062 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003063
Chris Lattner44e5981c2010-10-30 04:09:10 +00003064 const AsmToken &ExclaimTok = Parser.getTok();
3065 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00003066 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
3067 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00003068 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003069 return false;
3070 }
3071
3072 // Also check for an index operand. This is only legal for vector registers,
3073 // but that'll get caught OK in operand matching, so we don't need to
3074 // explicitly filter everything else out here.
3075 if (Parser.getTok().is(AsmToken::LBrac)) {
3076 SMLoc SIdx = Parser.getTok().getLoc();
3077 Parser.Lex(); // Eat left bracket token.
3078
3079 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003080 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00003081 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003082 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003083 if (!MCE)
3084 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003085
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003086 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003087 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003088
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003089 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003090 Parser.Lex(); // Eat right bracket token.
3091
3092 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
3093 SIdx, E,
3094 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00003095 }
3096
Bill Wendling2063b842010-11-18 23:43:05 +00003097 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003098}
3099
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003100/// MatchCoprocessorOperandName - Try to parse an coprocessor related
3101/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
3102/// "c5", ...
3103static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003104 // Use the same layout as the tablegen'erated register name matcher. Ugly,
3105 // but efficient.
3106 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00003107 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003108 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003109 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003110 return -1;
3111 switch (Name[1]) {
3112 default: return -1;
3113 case '0': return 0;
3114 case '1': return 1;
3115 case '2': return 2;
3116 case '3': return 3;
3117 case '4': return 4;
3118 case '5': return 5;
3119 case '6': return 6;
3120 case '7': return 7;
3121 case '8': return 8;
3122 case '9': return 9;
3123 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003124 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003125 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003126 return -1;
3127 switch (Name[2]) {
3128 default: return -1;
Artyom Skrobov86534432013-11-08 09:16:31 +00003129 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
3130 case '0': return CoprocOp == 'p'? -1: 10;
3131 case '1': return CoprocOp == 'p'? -1: 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003132 case '2': return 12;
3133 case '3': return 13;
3134 case '4': return 14;
3135 case '5': return 15;
3136 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003137 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003138}
3139
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003140/// parseITCondCode - Try to parse a condition code for an IT instruction.
3141ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3142parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3143 SMLoc S = Parser.getTok().getLoc();
3144 const AsmToken &Tok = Parser.getTok();
3145 if (!Tok.is(AsmToken::Identifier))
3146 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00003147 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003148 .Case("eq", ARMCC::EQ)
3149 .Case("ne", ARMCC::NE)
3150 .Case("hs", ARMCC::HS)
3151 .Case("cs", ARMCC::HS)
3152 .Case("lo", ARMCC::LO)
3153 .Case("cc", ARMCC::LO)
3154 .Case("mi", ARMCC::MI)
3155 .Case("pl", ARMCC::PL)
3156 .Case("vs", ARMCC::VS)
3157 .Case("vc", ARMCC::VC)
3158 .Case("hi", ARMCC::HI)
3159 .Case("ls", ARMCC::LS)
3160 .Case("ge", ARMCC::GE)
3161 .Case("lt", ARMCC::LT)
3162 .Case("gt", ARMCC::GT)
3163 .Case("le", ARMCC::LE)
3164 .Case("al", ARMCC::AL)
3165 .Default(~0U);
3166 if (CC == ~0U)
3167 return MatchOperand_NoMatch;
3168 Parser.Lex(); // Eat the token.
3169
3170 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3171
3172 return MatchOperand_Success;
3173}
3174
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003175/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003176/// token must be an Identifier when called, and if it is a coprocessor
3177/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003178ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003179parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003180 SMLoc S = Parser.getTok().getLoc();
3181 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003182 if (Tok.isNot(AsmToken::Identifier))
3183 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003184
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003185 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003186 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003187 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003188
3189 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003190 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003191 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003192}
3193
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003194/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003195/// token must be an Identifier when called, and if it is a coprocessor
3196/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003197ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003198parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003199 SMLoc S = Parser.getTok().getLoc();
3200 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003201 if (Tok.isNot(AsmToken::Identifier))
3202 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003203
3204 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3205 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003206 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003207
3208 Parser.Lex(); // Eat identifier token.
3209 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003210 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003211}
3212
Jim Grosbach48399582011-10-12 17:34:41 +00003213/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3214/// coproc_option : '{' imm0_255 '}'
3215ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3216parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3217 SMLoc S = Parser.getTok().getLoc();
3218
3219 // If this isn't a '{', this isn't a coprocessor immediate operand.
3220 if (Parser.getTok().isNot(AsmToken::LCurly))
3221 return MatchOperand_NoMatch;
3222 Parser.Lex(); // Eat the '{'
3223
3224 const MCExpr *Expr;
3225 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003226 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003227 Error(Loc, "illegal expression");
3228 return MatchOperand_ParseFail;
3229 }
3230 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3231 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3232 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3233 return MatchOperand_ParseFail;
3234 }
3235 int Val = CE->getValue();
3236
3237 // Check for and consume the closing '}'
3238 if (Parser.getTok().isNot(AsmToken::RCurly))
3239 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003240 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003241 Parser.Lex(); // Eat the '}'
3242
3243 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3244 return MatchOperand_Success;
3245}
3246
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003247// For register list parsing, we need to map from raw GPR register numbering
3248// to the enumeration values. The enumeration values aren't sorted by
3249// register number due to our using "sp", "lr" and "pc" as canonical names.
3250static unsigned getNextRegister(unsigned Reg) {
3251 // If this is a GPR, we need to do it manually, otherwise we can rely
3252 // on the sort ordering of the enumeration since the other reg-classes
3253 // are sane.
3254 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3255 return Reg + 1;
3256 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003257 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003258 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3259 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3260 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3261 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3262 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3263 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3264 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3265 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3266 }
3267}
3268
Jim Grosbach85a23432011-11-11 21:27:40 +00003269// Return the low-subreg of a given Q register.
3270static unsigned getDRegFromQReg(unsigned QReg) {
3271 switch (QReg) {
3272 default: llvm_unreachable("expected a Q register!");
3273 case ARM::Q0: return ARM::D0;
3274 case ARM::Q1: return ARM::D2;
3275 case ARM::Q2: return ARM::D4;
3276 case ARM::Q3: return ARM::D6;
3277 case ARM::Q4: return ARM::D8;
3278 case ARM::Q5: return ARM::D10;
3279 case ARM::Q6: return ARM::D12;
3280 case ARM::Q7: return ARM::D14;
3281 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003282 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003283 case ARM::Q10: return ARM::D20;
3284 case ARM::Q11: return ARM::D22;
3285 case ARM::Q12: return ARM::D24;
3286 case ARM::Q13: return ARM::D26;
3287 case ARM::Q14: return ARM::D28;
3288 case ARM::Q15: return ARM::D30;
3289 }
3290}
3291
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003292/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003293bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003294parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003295 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003296 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003297 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003298 Parser.Lex(); // Eat '{' token.
3299 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003300
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003301 // Check the first register in the list to see what register class
3302 // this is a list of.
3303 int Reg = tryParseRegister();
3304 if (Reg == -1)
3305 return Error(RegLoc, "register expected");
3306
Jim Grosbach85a23432011-11-11 21:27:40 +00003307 // The reglist instructions have at most 16 registers, so reserve
3308 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003309 int EReg = 0;
3310 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003311
3312 // Allow Q regs and just interpret them as the two D sub-registers.
3313 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3314 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003315 EReg = MRI->getEncodingValue(Reg);
3316 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003317 ++Reg;
3318 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003319 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003320 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3321 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3322 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3323 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3324 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3325 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3326 else
3327 return Error(RegLoc, "invalid register in register list");
3328
Jim Grosbach85a23432011-11-11 21:27:40 +00003329 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003330 EReg = MRI->getEncodingValue(Reg);
3331 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003332
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003333 // This starts immediately after the first register token in the list,
3334 // so we can see either a comma or a minus (range separator) as a legal
3335 // next token.
3336 while (Parser.getTok().is(AsmToken::Comma) ||
3337 Parser.getTok().is(AsmToken::Minus)) {
3338 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003339 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003340 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003341 int EndReg = tryParseRegister();
3342 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003343 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003344 // Allow Q regs and just interpret them as the two D sub-registers.
3345 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3346 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003347 // If the register is the same as the start reg, there's nothing
3348 // more to do.
3349 if (Reg == EndReg)
3350 continue;
3351 // The register must be in the same register class as the first.
3352 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003353 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003354 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003355 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003356 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003357
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003358 // Add all the registers in the range to the register list.
3359 while (Reg != EndReg) {
3360 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003361 EReg = MRI->getEncodingValue(Reg);
3362 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003363 }
3364 continue;
3365 }
3366 Parser.Lex(); // Eat the comma.
3367 RegLoc = Parser.getTok().getLoc();
3368 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003369 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003370 Reg = tryParseRegister();
3371 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003372 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003373 // Allow Q regs and just interpret them as the two D sub-registers.
3374 bool isQReg = false;
3375 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3376 Reg = getDRegFromQReg(Reg);
3377 isQReg = true;
3378 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003379 // The register must be in the same register class as the first.
3380 if (!RC->contains(Reg))
3381 return Error(RegLoc, "invalid register in register list");
3382 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003383 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003384 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3385 Warning(RegLoc, "register list not in ascending order");
3386 else
3387 return Error(RegLoc, "register list not in ascending order");
3388 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003389 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003390 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3391 ") in register list");
3392 continue;
3393 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003394 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003395 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3396 Reg != OldReg + 1)
3397 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003398 EReg = MRI->getEncodingValue(Reg);
3399 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3400 if (isQReg) {
3401 EReg = MRI->getEncodingValue(++Reg);
3402 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3403 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003404 }
3405
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003406 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003407 return Error(Parser.getTok().getLoc(), "'}' expected");
3408 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003409 Parser.Lex(); // Eat '}' token.
3410
Jim Grosbach18bf3632011-12-13 21:48:29 +00003411 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003412 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003413
3414 // The ARM system instruction variants for LDM/STM have a '^' token here.
3415 if (Parser.getTok().is(AsmToken::Caret)) {
3416 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3417 Parser.Lex(); // Eat '^' token.
3418 }
3419
Bill Wendling2063b842010-11-18 23:43:05 +00003420 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003421}
3422
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003423// Helper function to parse the lane index for vector lists.
3424ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003425parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003426 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003427 if (Parser.getTok().is(AsmToken::LBrac)) {
3428 Parser.Lex(); // Eat the '['.
3429 if (Parser.getTok().is(AsmToken::RBrac)) {
3430 // "Dn[]" is the 'all lanes' syntax.
3431 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003432 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003433 Parser.Lex(); // Eat the ']'.
3434 return MatchOperand_Success;
3435 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003436
3437 // There's an optional '#' token here. Normally there wouldn't be, but
3438 // inline assemble puts one in, and it's friendly to accept that.
3439 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003440 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003441
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003442 const MCExpr *LaneIndex;
3443 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003444 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003445 Error(Loc, "illegal expression");
3446 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003447 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003448 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3449 if (!CE) {
3450 Error(Loc, "lane index must be empty or an integer");
3451 return MatchOperand_ParseFail;
3452 }
3453 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3454 Error(Parser.getTok().getLoc(), "']' expected");
3455 return MatchOperand_ParseFail;
3456 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003457 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003458 Parser.Lex(); // Eat the ']'.
3459 int64_t Val = CE->getValue();
3460
3461 // FIXME: Make this range check context sensitive for .8, .16, .32.
3462 if (Val < 0 || Val > 7) {
3463 Error(Parser.getTok().getLoc(), "lane index out of range");
3464 return MatchOperand_ParseFail;
3465 }
3466 Index = Val;
3467 LaneKind = IndexedLane;
3468 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003469 }
3470 LaneKind = NoLanes;
3471 return MatchOperand_Success;
3472}
3473
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003474// parse a vector register list
3475ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3476parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003477 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003478 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003479 SMLoc S = Parser.getTok().getLoc();
3480 // As an extension (to match gas), support a plain D register or Q register
3481 // (without encosing curly braces) as a single or double entry list,
3482 // respectively.
3483 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003484 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003485 int Reg = tryParseRegister();
3486 if (Reg == -1)
3487 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003488 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003489 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003490 if (Res != MatchOperand_Success)
3491 return Res;
3492 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003493 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003494 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003495 break;
3496 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003497 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3498 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003499 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003500 case IndexedLane:
3501 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003502 LaneIndex,
3503 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003504 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003505 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003506 return MatchOperand_Success;
3507 }
3508 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3509 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003510 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003511 if (Res != MatchOperand_Success)
3512 return Res;
3513 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003514 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003515 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003516 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003517 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003518 break;
3519 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003520 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3521 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003522 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3523 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003524 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003525 case IndexedLane:
3526 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003527 LaneIndex,
3528 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003529 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003530 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003531 return MatchOperand_Success;
3532 }
3533 Error(S, "vector register expected");
3534 return MatchOperand_ParseFail;
3535 }
3536
3537 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003538 return MatchOperand_NoMatch;
3539
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003540 Parser.Lex(); // Eat '{' token.
3541 SMLoc RegLoc = Parser.getTok().getLoc();
3542
3543 int Reg = tryParseRegister();
3544 if (Reg == -1) {
3545 Error(RegLoc, "register expected");
3546 return MatchOperand_ParseFail;
3547 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003548 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003549 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003550 unsigned FirstReg = Reg;
3551 // The list is of D registers, but we also allow Q regs and just interpret
3552 // them as the two D sub-registers.
3553 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3554 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003555 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3556 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003557 ++Reg;
3558 ++Count;
3559 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003560
3561 SMLoc E;
3562 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003563 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003564
Jim Grosbache891fe82011-11-15 23:19:15 +00003565 while (Parser.getTok().is(AsmToken::Comma) ||
3566 Parser.getTok().is(AsmToken::Minus)) {
3567 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003568 if (!Spacing)
3569 Spacing = 1; // Register range implies a single spaced list.
3570 else if (Spacing == 2) {
3571 Error(Parser.getTok().getLoc(),
3572 "sequential registers in double spaced list");
3573 return MatchOperand_ParseFail;
3574 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003575 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003576 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003577 int EndReg = tryParseRegister();
3578 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003579 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003580 return MatchOperand_ParseFail;
3581 }
3582 // Allow Q regs and just interpret them as the two D sub-registers.
3583 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3584 EndReg = getDRegFromQReg(EndReg) + 1;
3585 // If the register is the same as the start reg, there's nothing
3586 // more to do.
3587 if (Reg == EndReg)
3588 continue;
3589 // The register must be in the same register class as the first.
3590 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003591 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003592 return MatchOperand_ParseFail;
3593 }
3594 // Ranges must go from low to high.
3595 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003596 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003597 return MatchOperand_ParseFail;
3598 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003599 // Parse the lane specifier if present.
3600 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003601 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003602 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3603 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003604 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003605 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003606 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003607 return MatchOperand_ParseFail;
3608 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003609
3610 // Add all the registers in the range to the register list.
3611 Count += EndReg - Reg;
3612 Reg = EndReg;
3613 continue;
3614 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003615 Parser.Lex(); // Eat the comma.
3616 RegLoc = Parser.getTok().getLoc();
3617 int OldReg = Reg;
3618 Reg = tryParseRegister();
3619 if (Reg == -1) {
3620 Error(RegLoc, "register expected");
3621 return MatchOperand_ParseFail;
3622 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003623 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003624 // It's OK to use the enumeration values directly here rather, as the
3625 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003626 //
3627 // The list is of D registers, but we also allow Q regs and just interpret
3628 // them as the two D sub-registers.
3629 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003630 if (!Spacing)
3631 Spacing = 1; // Register range implies a single spaced list.
3632 else if (Spacing == 2) {
3633 Error(RegLoc,
3634 "invalid register in double-spaced list (must be 'D' register')");
3635 return MatchOperand_ParseFail;
3636 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003637 Reg = getDRegFromQReg(Reg);
3638 if (Reg != OldReg + 1) {
3639 Error(RegLoc, "non-contiguous register range");
3640 return MatchOperand_ParseFail;
3641 }
3642 ++Reg;
3643 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003644 // Parse the lane specifier if present.
3645 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003646 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003647 SMLoc LaneLoc = Parser.getTok().getLoc();
3648 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3649 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003650 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003651 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003652 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003653 return MatchOperand_ParseFail;
3654 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003655 continue;
3656 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003657 // Normal D register.
3658 // Figure out the register spacing (single or double) of the list if
3659 // we don't know it already.
3660 if (!Spacing)
3661 Spacing = 1 + (Reg == OldReg + 2);
3662
3663 // Just check that it's contiguous and keep going.
3664 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003665 Error(RegLoc, "non-contiguous register range");
3666 return MatchOperand_ParseFail;
3667 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003668 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003669 // Parse the lane specifier if present.
3670 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003671 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003672 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003673 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003674 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003675 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003676 Error(EndLoc, "mismatched lane index in register list");
3677 return MatchOperand_ParseFail;
3678 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003679 }
3680
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003681 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003682 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003683 return MatchOperand_ParseFail;
3684 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003685 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003686 Parser.Lex(); // Eat '}' token.
3687
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003688 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003689 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003690 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003691 // composite register classes.
3692 if (Count == 2) {
3693 const MCRegisterClass *RC = (Spacing == 1) ?
3694 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3695 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3696 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3697 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003698
Jim Grosbach2f50e922011-12-15 21:44:33 +00003699 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3700 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003701 break;
3702 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003703 // Two-register operands have been converted to the
3704 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003705 if (Count == 2) {
3706 const MCRegisterClass *RC = (Spacing == 1) ?
3707 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3708 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003709 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3710 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003711 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003712 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003713 S, E));
3714 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003715 case IndexedLane:
3716 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003717 LaneIndex,
3718 (Spacing == 2),
3719 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003720 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003721 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003722 return MatchOperand_Success;
3723}
3724
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003725/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003726ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003727parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003728 SMLoc S = Parser.getTok().getLoc();
3729 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003730 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003731
Jiangning Liu288e1af2012-08-02 08:21:27 +00003732 if (Tok.is(AsmToken::Identifier)) {
3733 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003734
Jiangning Liu288e1af2012-08-02 08:21:27 +00003735 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3736 .Case("sy", ARM_MB::SY)
3737 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003738 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003739 .Case("sh", ARM_MB::ISH)
3740 .Case("ish", ARM_MB::ISH)
3741 .Case("shst", ARM_MB::ISHST)
3742 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003743 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003744 .Case("nsh", ARM_MB::NSH)
3745 .Case("un", ARM_MB::NSH)
3746 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003747 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003748 .Case("unst", ARM_MB::NSHST)
3749 .Case("osh", ARM_MB::OSH)
3750 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003751 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003752 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003753
Joey Gouly926d3f52013-09-05 15:35:24 +00003754 // ishld, oshld, nshld and ld are only available from ARMv8.
3755 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3756 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3757 Opt = ~0U;
3758
Jiangning Liu288e1af2012-08-02 08:21:27 +00003759 if (Opt == ~0U)
3760 return MatchOperand_NoMatch;
3761
3762 Parser.Lex(); // Eat identifier token.
3763 } else if (Tok.is(AsmToken::Hash) ||
3764 Tok.is(AsmToken::Dollar) ||
3765 Tok.is(AsmToken::Integer)) {
3766 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003767 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003768 SMLoc Loc = Parser.getTok().getLoc();
3769
3770 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003771 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003772 Error(Loc, "illegal expression");
3773 return MatchOperand_ParseFail;
3774 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00003775
Jiangning Liu288e1af2012-08-02 08:21:27 +00003776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3777 if (!CE) {
3778 Error(Loc, "constant expression expected");
3779 return MatchOperand_ParseFail;
3780 }
3781
3782 int Val = CE->getValue();
3783 if (Val & ~0xf) {
3784 Error(Loc, "immediate value out of range");
3785 return MatchOperand_ParseFail;
3786 }
3787
3788 Opt = ARM_MB::RESERVED_0 + Val;
3789 } else
3790 return MatchOperand_ParseFail;
3791
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003792 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003793 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003794}
3795
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003796/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3797ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3798parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3799 SMLoc S = Parser.getTok().getLoc();
3800 const AsmToken &Tok = Parser.getTok();
3801 unsigned Opt;
3802
3803 if (Tok.is(AsmToken::Identifier)) {
3804 StringRef OptStr = Tok.getString();
3805
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003806 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003807 Opt = ARM_ISB::SY;
3808 else
3809 return MatchOperand_NoMatch;
3810
3811 Parser.Lex(); // Eat identifier token.
3812 } else if (Tok.is(AsmToken::Hash) ||
3813 Tok.is(AsmToken::Dollar) ||
3814 Tok.is(AsmToken::Integer)) {
3815 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003816 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003817 SMLoc Loc = Parser.getTok().getLoc();
3818
3819 const MCExpr *ISBarrierID;
3820 if (getParser().parseExpression(ISBarrierID)) {
3821 Error(Loc, "illegal expression");
3822 return MatchOperand_ParseFail;
3823 }
3824
3825 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3826 if (!CE) {
3827 Error(Loc, "constant expression expected");
3828 return MatchOperand_ParseFail;
3829 }
3830
3831 int Val = CE->getValue();
3832 if (Val & ~0xf) {
3833 Error(Loc, "immediate value out of range");
3834 return MatchOperand_ParseFail;
3835 }
3836
3837 Opt = ARM_ISB::RESERVED_0 + Val;
3838 } else
3839 return MatchOperand_ParseFail;
3840
3841 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3842 (ARM_ISB::InstSyncBOpt)Opt, S));
3843 return MatchOperand_Success;
3844}
3845
3846
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003847/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003848ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003849parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003850 SMLoc S = Parser.getTok().getLoc();
3851 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003852 if (!Tok.is(AsmToken::Identifier))
3853 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003854 StringRef IFlagsStr = Tok.getString();
3855
Owen Anderson10c5b122011-10-05 17:16:40 +00003856 // An iflags string of "none" is interpreted to mean that none of the AIF
3857 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003858 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003859 if (IFlagsStr != "none") {
3860 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3861 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3862 .Case("a", ARM_PROC::A)
3863 .Case("i", ARM_PROC::I)
3864 .Case("f", ARM_PROC::F)
3865 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003866
Owen Anderson10c5b122011-10-05 17:16:40 +00003867 // If some specific iflag is already set, it means that some letter is
3868 // present more than once, this is not acceptable.
3869 if (Flag == ~0U || (IFlags & Flag))
3870 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003871
Owen Anderson10c5b122011-10-05 17:16:40 +00003872 IFlags |= Flag;
3873 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003874 }
3875
3876 Parser.Lex(); // Eat identifier token.
3877 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3878 return MatchOperand_Success;
3879}
3880
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003881/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003882ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003883parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003884 SMLoc S = Parser.getTok().getLoc();
3885 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003886 if (!Tok.is(AsmToken::Identifier))
3887 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003888 StringRef Mask = Tok.getString();
3889
James Molloy21efa7d2011-09-28 14:21:38 +00003890 if (isMClass()) {
3891 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003892 std::string Name = Mask.lower();
3893 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003894 // Note: in the documentation:
3895 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3896 // for MSR APSR_nzcvq.
3897 // but we do make it an alias here. This is so to get the "mask encoding"
3898 // bits correct on MSR APSR writes.
3899 //
3900 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3901 // should really only be allowed when writing a special register. Note
3902 // they get dropped in the MRS instruction reading a special register as
3903 // the SYSm field is only 8 bits.
3904 //
3905 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3906 // includes the DSP extension but that is not checked.
3907 .Case("apsr", 0x800)
3908 .Case("apsr_nzcvq", 0x800)
3909 .Case("apsr_g", 0x400)
3910 .Case("apsr_nzcvqg", 0xc00)
3911 .Case("iapsr", 0x801)
3912 .Case("iapsr_nzcvq", 0x801)
3913 .Case("iapsr_g", 0x401)
3914 .Case("iapsr_nzcvqg", 0xc01)
3915 .Case("eapsr", 0x802)
3916 .Case("eapsr_nzcvq", 0x802)
3917 .Case("eapsr_g", 0x402)
3918 .Case("eapsr_nzcvqg", 0xc02)
3919 .Case("xpsr", 0x803)
3920 .Case("xpsr_nzcvq", 0x803)
3921 .Case("xpsr_g", 0x403)
3922 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003923 .Case("ipsr", 0x805)
3924 .Case("epsr", 0x806)
3925 .Case("iepsr", 0x807)
3926 .Case("msp", 0x808)
3927 .Case("psp", 0x809)
3928 .Case("primask", 0x810)
3929 .Case("basepri", 0x811)
3930 .Case("basepri_max", 0x812)
3931 .Case("faultmask", 0x813)
3932 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003933 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003934
James Molloy21efa7d2011-09-28 14:21:38 +00003935 if (FlagsVal == ~0U)
3936 return MatchOperand_NoMatch;
3937
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003938 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003939 // basepri, basepri_max and faultmask only valid for V7m.
3940 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003941
James Molloy21efa7d2011-09-28 14:21:38 +00003942 Parser.Lex(); // Eat identifier token.
3943 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3944 return MatchOperand_Success;
3945 }
3946
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003947 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3948 size_t Start = 0, Next = Mask.find('_');
3949 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003950 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003951 if (Next != StringRef::npos)
3952 Flags = Mask.slice(Next+1, Mask.size());
3953
3954 // FlagsVal contains the complete mask:
3955 // 3-0: Mask
3956 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3957 unsigned FlagsVal = 0;
3958
3959 if (SpecReg == "apsr") {
3960 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003961 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003962 .Case("g", 0x4) // same as CPSR_s
3963 .Case("nzcvqg", 0xc) // same as CPSR_fs
3964 .Default(~0U);
3965
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003966 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003967 if (!Flags.empty())
3968 return MatchOperand_NoMatch;
3969 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003970 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003971 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003972 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003973 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3974 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003975 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003976 for (int i = 0, e = Flags.size(); i != e; ++i) {
3977 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3978 .Case("c", 1)
3979 .Case("x", 2)
3980 .Case("s", 4)
3981 .Case("f", 8)
3982 .Default(~0U);
3983
3984 // If some specific flag is already set, it means that some letter is
3985 // present more than once, this is not acceptable.
3986 if (FlagsVal == ~0U || (FlagsVal & Flag))
3987 return MatchOperand_NoMatch;
3988 FlagsVal |= Flag;
3989 }
3990 } else // No match for special register.
3991 return MatchOperand_NoMatch;
3992
Owen Anderson03a173e2011-10-21 18:43:28 +00003993 // Special register without flags is NOT equivalent to "fc" flags.
3994 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3995 // two lines would enable gas compatibility at the expense of breaking
3996 // round-tripping.
3997 //
3998 // if (!FlagsVal)
3999 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004000
4001 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4002 if (SpecReg == "spsr")
4003 FlagsVal |= 16;
4004
4005 Parser.Lex(); // Eat identifier token.
4006 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4007 return MatchOperand_Success;
4008}
4009
Jim Grosbach27c1e252011-07-21 17:23:04 +00004010ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4011parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
4012 int Low, int High) {
4013 const AsmToken &Tok = Parser.getTok();
4014 if (Tok.isNot(AsmToken::Identifier)) {
4015 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4016 return MatchOperand_ParseFail;
4017 }
4018 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004019 std::string LowerOp = Op.lower();
4020 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004021 if (ShiftName != LowerOp && ShiftName != UpperOp) {
4022 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4023 return MatchOperand_ParseFail;
4024 }
4025 Parser.Lex(); // Eat shift type token.
4026
4027 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004028 if (Parser.getTok().isNot(AsmToken::Hash) &&
4029 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004030 Error(Parser.getTok().getLoc(), "'#' expected");
4031 return MatchOperand_ParseFail;
4032 }
4033 Parser.Lex(); // Eat hash token.
4034
4035 const MCExpr *ShiftAmount;
4036 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004037 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004038 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004039 Error(Loc, "illegal expression");
4040 return MatchOperand_ParseFail;
4041 }
4042 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4043 if (!CE) {
4044 Error(Loc, "constant expression expected");
4045 return MatchOperand_ParseFail;
4046 }
4047 int Val = CE->getValue();
4048 if (Val < Low || Val > High) {
4049 Error(Loc, "immediate value out of range");
4050 return MatchOperand_ParseFail;
4051 }
4052
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004053 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00004054
4055 return MatchOperand_Success;
4056}
4057
Jim Grosbach0a547702011-07-22 17:44:50 +00004058ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4059parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4060 const AsmToken &Tok = Parser.getTok();
4061 SMLoc S = Tok.getLoc();
4062 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004063 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004064 return MatchOperand_ParseFail;
4065 }
Tim Northover4d141442013-05-31 15:58:45 +00004066 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00004067 .Case("be", 1)
4068 .Case("le", 0)
4069 .Default(-1);
4070 Parser.Lex(); // Eat the token.
4071
4072 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004073 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004074 return MatchOperand_ParseFail;
4075 }
4076 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4077 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004078 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00004079 return MatchOperand_Success;
4080}
4081
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004082/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
4083/// instructions. Legal values are:
4084/// lsl #n 'n' in [0,31]
4085/// asr #n 'n' in [1,32]
4086/// n == 32 encoded as n == 0.
4087ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4088parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4089 const AsmToken &Tok = Parser.getTok();
4090 SMLoc S = Tok.getLoc();
4091 if (Tok.isNot(AsmToken::Identifier)) {
4092 Error(S, "shift operator 'asr' or 'lsl' expected");
4093 return MatchOperand_ParseFail;
4094 }
4095 StringRef ShiftName = Tok.getString();
4096 bool isASR;
4097 if (ShiftName == "lsl" || ShiftName == "LSL")
4098 isASR = false;
4099 else if (ShiftName == "asr" || ShiftName == "ASR")
4100 isASR = true;
4101 else {
4102 Error(S, "shift operator 'asr' or 'lsl' expected");
4103 return MatchOperand_ParseFail;
4104 }
4105 Parser.Lex(); // Eat the operator.
4106
4107 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004108 if (Parser.getTok().isNot(AsmToken::Hash) &&
4109 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004110 Error(Parser.getTok().getLoc(), "'#' expected");
4111 return MatchOperand_ParseFail;
4112 }
4113 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004114 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004115
4116 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004117 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004118 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004119 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004120 return MatchOperand_ParseFail;
4121 }
4122 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4123 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004124 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004125 return MatchOperand_ParseFail;
4126 }
4127
4128 int64_t Val = CE->getValue();
4129 if (isASR) {
4130 // Shift amount must be in [1,32]
4131 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004132 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004133 return MatchOperand_ParseFail;
4134 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00004135 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4136 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004137 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00004138 return MatchOperand_ParseFail;
4139 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004140 if (Val == 32) Val = 0;
4141 } else {
4142 // Shift amount must be in [1,32]
4143 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004144 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004145 return MatchOperand_ParseFail;
4146 }
4147 }
4148
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004149 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004150
4151 return MatchOperand_Success;
4152}
4153
Jim Grosbach833b9d32011-07-27 20:15:40 +00004154/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4155/// of instructions. Legal values are:
4156/// ror #n 'n' in {0, 8, 16, 24}
4157ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4158parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4159 const AsmToken &Tok = Parser.getTok();
4160 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00004161 if (Tok.isNot(AsmToken::Identifier))
4162 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004163 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00004164 if (ShiftName != "ror" && ShiftName != "ROR")
4165 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004166 Parser.Lex(); // Eat the operator.
4167
4168 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004169 if (Parser.getTok().isNot(AsmToken::Hash) &&
4170 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004171 Error(Parser.getTok().getLoc(), "'#' expected");
4172 return MatchOperand_ParseFail;
4173 }
4174 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004175 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004176
4177 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004178 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004179 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004180 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004181 return MatchOperand_ParseFail;
4182 }
4183 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4184 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004185 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004186 return MatchOperand_ParseFail;
4187 }
4188
4189 int64_t Val = CE->getValue();
4190 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4191 // normally, zero is represented in asm by omitting the rotate operand
4192 // entirely.
4193 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004194 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004195 return MatchOperand_ParseFail;
4196 }
4197
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004198 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004199
4200 return MatchOperand_Success;
4201}
4202
Jim Grosbach864b6092011-07-28 21:34:26 +00004203ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4204parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4205 SMLoc S = Parser.getTok().getLoc();
4206 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004207 if (Parser.getTok().isNot(AsmToken::Hash) &&
4208 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004209 Error(Parser.getTok().getLoc(), "'#' expected");
4210 return MatchOperand_ParseFail;
4211 }
4212 Parser.Lex(); // Eat hash token.
4213
4214 const MCExpr *LSBExpr;
4215 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004216 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004217 Error(E, "malformed immediate expression");
4218 return MatchOperand_ParseFail;
4219 }
4220 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4221 if (!CE) {
4222 Error(E, "'lsb' operand must be an immediate");
4223 return MatchOperand_ParseFail;
4224 }
4225
4226 int64_t LSB = CE->getValue();
4227 // The LSB must be in the range [0,31]
4228 if (LSB < 0 || LSB > 31) {
4229 Error(E, "'lsb' operand must be in the range [0,31]");
4230 return MatchOperand_ParseFail;
4231 }
4232 E = Parser.getTok().getLoc();
4233
4234 // Expect another immediate operand.
4235 if (Parser.getTok().isNot(AsmToken::Comma)) {
4236 Error(Parser.getTok().getLoc(), "too few operands");
4237 return MatchOperand_ParseFail;
4238 }
4239 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004240 if (Parser.getTok().isNot(AsmToken::Hash) &&
4241 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004242 Error(Parser.getTok().getLoc(), "'#' expected");
4243 return MatchOperand_ParseFail;
4244 }
4245 Parser.Lex(); // Eat hash token.
4246
4247 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004248 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004249 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004250 Error(E, "malformed immediate expression");
4251 return MatchOperand_ParseFail;
4252 }
4253 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4254 if (!CE) {
4255 Error(E, "'width' operand must be an immediate");
4256 return MatchOperand_ParseFail;
4257 }
4258
4259 int64_t Width = CE->getValue();
4260 // The LSB must be in the range [1,32-lsb]
4261 if (Width < 1 || Width > 32 - LSB) {
4262 Error(E, "'width' operand must be in the range [1,32-lsb]");
4263 return MatchOperand_ParseFail;
4264 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004265
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004266 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004267
4268 return MatchOperand_Success;
4269}
4270
Jim Grosbachd3595712011-08-03 23:50:40 +00004271ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4272parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4273 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004274 // postidx_reg := '+' register {, shift}
4275 // | '-' register {, shift}
4276 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004277
4278 // This method must return MatchOperand_NoMatch without consuming any tokens
4279 // in the case where there is no match, as other alternatives take other
4280 // parse methods.
4281 AsmToken Tok = Parser.getTok();
4282 SMLoc S = Tok.getLoc();
4283 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004284 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004285 if (Tok.is(AsmToken::Plus)) {
4286 Parser.Lex(); // Eat the '+' token.
4287 haveEaten = true;
4288 } else if (Tok.is(AsmToken::Minus)) {
4289 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004290 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004291 haveEaten = true;
4292 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004293
4294 SMLoc E = Parser.getTok().getEndLoc();
4295 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004296 if (Reg == -1) {
4297 if (!haveEaten)
4298 return MatchOperand_NoMatch;
4299 Error(Parser.getTok().getLoc(), "register expected");
4300 return MatchOperand_ParseFail;
4301 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004302
Jim Grosbachc320c852011-08-05 21:28:30 +00004303 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4304 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004305 if (Parser.getTok().is(AsmToken::Comma)) {
4306 Parser.Lex(); // Eat the ','.
4307 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4308 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004309
4310 // FIXME: Only approximates end...may include intervening whitespace.
4311 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004312 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004313
4314 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4315 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004316
4317 return MatchOperand_Success;
4318}
4319
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004320ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4321parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4322 // Check for a post-index addressing register operand. Specifically:
4323 // am3offset := '+' register
4324 // | '-' register
4325 // | register
4326 // | # imm
4327 // | # + imm
4328 // | # - imm
4329
4330 // This method must return MatchOperand_NoMatch without consuming any tokens
4331 // in the case where there is no match, as other alternatives take other
4332 // parse methods.
4333 AsmToken Tok = Parser.getTok();
4334 SMLoc S = Tok.getLoc();
4335
4336 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004337 if (Parser.getTok().is(AsmToken::Hash) ||
4338 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004339 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004340 // Explicitly look for a '-', as we need to encode negative zero
4341 // differently.
4342 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4343 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004344 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004345 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004346 return MatchOperand_ParseFail;
4347 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4348 if (!CE) {
4349 Error(S, "constant expression expected");
4350 return MatchOperand_ParseFail;
4351 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004352 // Negative zero is encoded as the flag value INT32_MIN.
4353 int32_t Val = CE->getValue();
4354 if (isNegative && Val == 0)
4355 Val = INT32_MIN;
4356
4357 Operands.push_back(
4358 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4359
4360 return MatchOperand_Success;
4361 }
4362
4363
4364 bool haveEaten = false;
4365 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004366 if (Tok.is(AsmToken::Plus)) {
4367 Parser.Lex(); // Eat the '+' token.
4368 haveEaten = true;
4369 } else if (Tok.is(AsmToken::Minus)) {
4370 Parser.Lex(); // Eat the '-' token.
4371 isAdd = false;
4372 haveEaten = true;
4373 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004374
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004375 Tok = Parser.getTok();
4376 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004377 if (Reg == -1) {
4378 if (!haveEaten)
4379 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004380 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004381 return MatchOperand_ParseFail;
4382 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004383
4384 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004385 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004386
4387 return MatchOperand_Success;
4388}
4389
Tim Northovereb5e4d52013-07-22 09:06:12 +00004390/// Convert parsed operands to MCInst. Needed here because this instruction
4391/// only has two register operands, but multiplication is commutative so
4392/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004393void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004394cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004395 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004396 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4397 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004398 // If we have a three-operand form, make sure to set Rn to be the operand
4399 // that isn't the same as Rd.
4400 unsigned RegOp = 4;
4401 if (Operands.size() == 6 &&
4402 ((ARMOperand*)Operands[4])->getReg() ==
4403 ((ARMOperand*)Operands[3])->getReg())
4404 RegOp = 5;
4405 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4406 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004407 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004408}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004409
Mihai Popaad18d3c2013-08-09 10:38:32 +00004410void ARMAsmParser::
4411cvtThumbBranches(MCInst &Inst,
4412 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4413 int CondOp = -1, ImmOp = -1;
4414 switch(Inst.getOpcode()) {
4415 case ARM::tB:
4416 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4417
4418 case ARM::t2B:
4419 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4420
4421 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4422 }
4423 // first decide whether or not the branch should be conditional
4424 // by looking at it's location relative to an IT block
4425 if(inITBlock()) {
4426 // inside an IT block we cannot have any conditional branches. any
4427 // such instructions needs to be converted to unconditional form
4428 switch(Inst.getOpcode()) {
4429 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4430 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4431 }
4432 } else {
4433 // outside IT blocks we can only have unconditional branches with AL
4434 // condition code or conditional branches with non-AL condition code
4435 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4436 switch(Inst.getOpcode()) {
4437 case ARM::tB:
4438 case ARM::tBcc:
4439 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4440 break;
4441 case ARM::t2B:
4442 case ARM::t2Bcc:
4443 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4444 break;
4445 }
4446 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004447
Mihai Popaad18d3c2013-08-09 10:38:32 +00004448 // now decide on encoding size based on branch target range
4449 switch(Inst.getOpcode()) {
4450 // classify tB as either t2B or t1B based on range of immediate operand
4451 case ARM::tB: {
4452 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4453 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4454 Inst.setOpcode(ARM::t2B);
4455 break;
4456 }
4457 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4458 case ARM::tBcc: {
4459 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4460 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4461 Inst.setOpcode(ARM::t2Bcc);
4462 break;
4463 }
4464 }
4465 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4466 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4467}
4468
Bill Wendlinge18980a2010-11-06 22:36:58 +00004469/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004470/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004471bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004472parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004473 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004474 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004475 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004476 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004477 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004478
Sean Callanan936b0d32010-01-19 21:44:56 +00004479 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004480 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004481 if (BaseRegNum == -1)
4482 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004483
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004484 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004485 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004486 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4487 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004488 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004489
Jim Grosbachd3595712011-08-03 23:50:40 +00004490 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004491 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004492 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004493
Jim Grosbachd3595712011-08-03 23:50:40 +00004494 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004495 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004496
Jim Grosbach40700e02011-09-19 18:42:21 +00004497 // If there's a pre-indexing writeback marker, '!', just add it as a token
4498 // operand. It's rather odd, but syntactically valid.
4499 if (Parser.getTok().is(AsmToken::Exclaim)) {
4500 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4501 Parser.Lex(); // Eat the '!'.
4502 }
4503
Jim Grosbachd3595712011-08-03 23:50:40 +00004504 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004505 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004506
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004507 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4508 "Lost colon or comma in memory operand?!");
4509 if (Tok.is(AsmToken::Comma)) {
4510 Parser.Lex(); // Eat the comma.
4511 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004512
Jim Grosbacha95ec992011-10-11 17:29:55 +00004513 // If we have a ':', it's an alignment specifier.
4514 if (Parser.getTok().is(AsmToken::Colon)) {
4515 Parser.Lex(); // Eat the ':'.
4516 E = Parser.getTok().getLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00004517 SMLoc AlignmentLoc = Tok.getLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004518
4519 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004520 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004521 return true;
4522
4523 // The expression has to be a constant. Memory references with relocations
4524 // don't come through here, as they use the <label> forms of the relevant
4525 // instructions.
4526 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4527 if (!CE)
4528 return Error (E, "constant expression expected");
4529
4530 unsigned Align = 0;
4531 switch (CE->getValue()) {
4532 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004533 return Error(E,
4534 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4535 case 16: Align = 2; break;
4536 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004537 case 64: Align = 8; break;
4538 case 128: Align = 16; break;
4539 case 256: Align = 32; break;
4540 }
4541
4542 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004543 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004544 return Error(Parser.getTok().getLoc(), "']' expected");
4545 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004546 Parser.Lex(); // Eat right bracket token.
4547
4548 // Don't worry about range checking the value here. That's handled by
4549 // the is*() predicates.
4550 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4551 ARM_AM::no_shift, 0, Align,
Kevin Enderby488f20b2014-04-10 20:18:58 +00004552 false, S, E, AlignmentLoc));
Jim Grosbacha95ec992011-10-11 17:29:55 +00004553
4554 // If there's a pre-indexing writeback marker, '!', just add it as a token
4555 // operand.
4556 if (Parser.getTok().is(AsmToken::Exclaim)) {
4557 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4558 Parser.Lex(); // Eat the '!'.
4559 }
4560
4561 return false;
4562 }
4563
4564 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004565 // offset. Be friendly and also accept a plain integer (without a leading
4566 // hash) for gas compatibility.
4567 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004568 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004569 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004570 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004571 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004572 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004573
Owen Anderson967674d2011-08-29 19:36:44 +00004574 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004575 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004576 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004577 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004578
4579 // The expression has to be a constant. Memory references with relocations
4580 // don't come through here, as they use the <label> forms of the relevant
4581 // instructions.
4582 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4583 if (!CE)
4584 return Error (E, "constant expression expected");
4585
Owen Anderson967674d2011-08-29 19:36:44 +00004586 // If the constant was #-0, represent it as INT32_MIN.
4587 int32_t Val = CE->getValue();
4588 if (isNegative && Val == 0)
4589 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4590
Jim Grosbachd3595712011-08-03 23:50:40 +00004591 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004592 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004593 return Error(Parser.getTok().getLoc(), "']' expected");
4594 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004595 Parser.Lex(); // Eat right bracket token.
4596
4597 // Don't worry about range checking the value here. That's handled by
4598 // the is*() predicates.
4599 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004600 ARM_AM::no_shift, 0, 0,
4601 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004602
4603 // If there's a pre-indexing writeback marker, '!', just add it as a token
4604 // operand.
4605 if (Parser.getTok().is(AsmToken::Exclaim)) {
4606 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4607 Parser.Lex(); // Eat the '!'.
4608 }
4609
4610 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004611 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004612
4613 // The register offset is optionally preceded by a '+' or '-'
4614 bool isNegative = false;
4615 if (Parser.getTok().is(AsmToken::Minus)) {
4616 isNegative = true;
4617 Parser.Lex(); // Eat the '-'.
4618 } else if (Parser.getTok().is(AsmToken::Plus)) {
4619 // Nothing to do.
4620 Parser.Lex(); // Eat the '+'.
4621 }
4622
4623 E = Parser.getTok().getLoc();
4624 int OffsetRegNum = tryParseRegister();
4625 if (OffsetRegNum == -1)
4626 return Error(E, "register expected");
4627
4628 // If there's a shift operator, handle it.
4629 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004630 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004631 if (Parser.getTok().is(AsmToken::Comma)) {
4632 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004633 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004634 return true;
4635 }
4636
4637 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004638 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004639 return Error(Parser.getTok().getLoc(), "']' expected");
4640 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004641 Parser.Lex(); // Eat right bracket token.
4642
4643 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004644 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004645 S, E));
4646
Jim Grosbachc320c852011-08-05 21:28:30 +00004647 // If there's a pre-indexing writeback marker, '!', just add it as a token
4648 // operand.
4649 if (Parser.getTok().is(AsmToken::Exclaim)) {
4650 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4651 Parser.Lex(); // Eat the '!'.
4652 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004653
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004654 return false;
4655}
4656
Jim Grosbachd3595712011-08-03 23:50:40 +00004657/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004658/// ( lsl | lsr | asr | ror ) , # shift_amount
4659/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004660/// return true if it parses a shift otherwise it returns false.
4661bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4662 unsigned &Amount) {
4663 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004664 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004665 if (Tok.isNot(AsmToken::Identifier))
4666 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004667 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004668 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4669 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004670 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004671 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004672 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004673 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004674 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004675 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004676 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004677 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004678 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004679 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004680 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004681 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004682
Jim Grosbachd3595712011-08-03 23:50:40 +00004683 // rrx stands alone.
4684 Amount = 0;
4685 if (St != ARM_AM::rrx) {
4686 Loc = Parser.getTok().getLoc();
4687 // A '#' and a shift amount.
4688 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004689 if (HashTok.isNot(AsmToken::Hash) &&
4690 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004691 return Error(HashTok.getLoc(), "'#' expected");
4692 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004693
Jim Grosbachd3595712011-08-03 23:50:40 +00004694 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004695 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004696 return true;
4697 // Range check the immediate.
4698 // lsl, ror: 0 <= imm <= 31
4699 // lsr, asr: 0 <= imm <= 32
4700 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4701 if (!CE)
4702 return Error(Loc, "shift amount must be an immediate");
4703 int64_t Imm = CE->getValue();
4704 if (Imm < 0 ||
4705 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4706 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4707 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004708 // If <ShiftTy> #0, turn it into a no_shift.
4709 if (Imm == 0)
4710 St = ARM_AM::lsl;
4711 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4712 if (Imm == 32)
4713 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004714 Amount = Imm;
4715 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004716
4717 return false;
4718}
4719
Jim Grosbache7fbce72011-10-03 23:38:36 +00004720/// parseFPImm - A floating point immediate expression operand.
4721ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4722parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004723 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004724 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004725 // integer only.
4726 //
4727 // This routine still creates a generic Immediate operand, containing
4728 // a bitcast of the 64-bit floating point value. The various operands
4729 // that accept floats can check whether the value is valid for them
4730 // via the standard is*() predicates.
4731
Jim Grosbache7fbce72011-10-03 23:38:36 +00004732 SMLoc S = Parser.getTok().getLoc();
4733
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004734 if (Parser.getTok().isNot(AsmToken::Hash) &&
4735 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004736 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004737
4738 // Disambiguate the VMOV forms that can accept an FP immediate.
4739 // vmov.f32 <sreg>, #imm
4740 // vmov.f64 <dreg>, #imm
4741 // vmov.f32 <dreg>, #imm @ vector f32x2
4742 // vmov.f32 <qreg>, #imm @ vector f32x4
4743 //
4744 // There are also the NEON VMOV instructions which expect an
4745 // integer constant. Make sure we don't try to parse an FPImm
4746 // for these:
4747 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4748 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
David Peixottoa872e0e2014-01-07 18:19:23 +00004749 bool isVmovf = TyOp->isToken() && (TyOp->getToken() == ".f32" ||
4750 TyOp->getToken() == ".f64");
4751 ARMOperand *Mnemonic = static_cast<ARMOperand*>(Operands[0]);
4752 bool isFconst = Mnemonic->isToken() && (Mnemonic->getToken() == "fconstd" ||
4753 Mnemonic->getToken() == "fconsts");
4754 if (!(isVmovf || isFconst))
Jim Grosbach741cd732011-10-17 22:26:03 +00004755 return MatchOperand_NoMatch;
4756
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004757 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004758
4759 // Handle negation, as that still comes through as a separate token.
4760 bool isNegative = false;
4761 if (Parser.getTok().is(AsmToken::Minus)) {
4762 isNegative = true;
4763 Parser.Lex();
4764 }
4765 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004766 SMLoc Loc = Tok.getLoc();
David Peixottoa872e0e2014-01-07 18:19:23 +00004767 if (Tok.is(AsmToken::Real) && isVmovf) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004768 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004769 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4770 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004771 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004772 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004773 Operands.push_back(ARMOperand::CreateImm(
4774 MCConstantExpr::Create(IntVal, getContext()),
4775 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004776 return MatchOperand_Success;
4777 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004778 // Also handle plain integers. Instructions which allow floating point
4779 // immediates also allow a raw encoded 8-bit value.
David Peixottoa872e0e2014-01-07 18:19:23 +00004780 if (Tok.is(AsmToken::Integer) && isFconst) {
Jim Grosbache7fbce72011-10-03 23:38:36 +00004781 int64_t Val = Tok.getIntVal();
4782 Parser.Lex(); // Eat the token.
4783 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004784 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004785 return MatchOperand_ParseFail;
4786 }
David Peixottoa872e0e2014-01-07 18:19:23 +00004787 float RealVal = ARM_AM::getFPImmFloat(Val);
4788 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
4789
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004790 Operands.push_back(ARMOperand::CreateImm(
4791 MCConstantExpr::Create(Val, getContext()), S,
4792 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004793 return MatchOperand_Success;
4794 }
4795
Jim Grosbach235c8d22012-01-19 02:47:30 +00004796 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004797 return MatchOperand_ParseFail;
4798}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004799
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004800/// Parse a arm instruction operand. For now this parses the operand regardless
4801/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004802bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004803 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004804 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004805
4806 // Check if the current operand has a custom associated parser, if so, try to
4807 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004808 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4809 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004810 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004811 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4812 // there was a match, but an error occurred, in which case, just return that
4813 // the operand parsing failed.
4814 if (ResTy == MatchOperand_ParseFail)
4815 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004816
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004817 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004818 default:
4819 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004820 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004821 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004822 // If we've seen a branch mnemonic, the next operand must be a label. This
4823 // is true even if the label is a register name. So "br r1" means branch to
4824 // label "r1".
4825 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4826 if (!ExpectLabel) {
4827 if (!tryParseRegisterWithWriteBack(Operands))
4828 return false;
4829 int Res = tryParseShiftRegister(Operands);
4830 if (Res == 0) // success
4831 return false;
4832 else if (Res == -1) // irrecoverable error
4833 return true;
4834 // If this is VMRS, check for the apsr_nzcv operand.
4835 if (Mnemonic == "vmrs" &&
4836 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4837 S = Parser.getTok().getLoc();
4838 Parser.Lex();
4839 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4840 return false;
4841 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004842 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004843
4844 // Fall though for the Identifier case that is not a register or a
4845 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004846 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004847 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004848 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004849 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004850 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004851 // This was not a register so parse other operands that start with an
4852 // identifier (like labels) as expressions and create them as immediates.
4853 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004854 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004855 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004856 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004857 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004858 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4859 return false;
4860 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004861 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004862 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004863 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004864 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004865 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004866 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004867 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004868 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004869 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004870
4871 if (Parser.getTok().isNot(AsmToken::Colon)) {
4872 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4873 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004874 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004875 return true;
4876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4877 if (CE) {
4878 int32_t Val = CE->getValue();
4879 if (isNegative && Val == 0)
4880 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4881 }
4882 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4883 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004884
4885 // There can be a trailing '!' on operands that we want as a separate
Saleem Abdulrasool83e37702013-12-28 03:07:12 +00004886 // '!' Token operand. Handle that here. For example, the compatibility
Jim Grosbach9be2d712013-02-23 00:52:09 +00004887 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4888 if (Parser.getTok().is(AsmToken::Exclaim)) {
4889 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4890 Parser.getTok().getLoc()));
4891 Parser.Lex(); // Eat exclaim token
4892 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004893 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004894 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004895 // w/ a ':' after the '#', it's just like a plain ':'.
4896 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004897 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004898 case AsmToken::Colon: {
4899 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004900 // FIXME: Check it's an expression prefix,
4901 // e.g. (FOO - :lower16:BAR) isn't legal.
4902 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004903 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004904 return true;
4905
Evan Cheng965b3c72011-01-13 07:58:56 +00004906 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004907 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004908 return true;
4909
Evan Cheng965b3c72011-01-13 07:58:56 +00004910 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004911 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004912 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004913 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004914 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004915 }
David Peixottoe407d092013-12-19 18:12:36 +00004916 case AsmToken::Equal: {
4917 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4918 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4919
David Peixottoe407d092013-12-19 18:12:36 +00004920 Parser.Lex(); // Eat '='
4921 const MCExpr *SubExprVal;
4922 if (getParser().parseExpression(SubExprVal))
4923 return true;
4924 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4925
David Peixottob9b73622014-02-04 17:22:40 +00004926 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
David Peixottoe407d092013-12-19 18:12:36 +00004927 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4928 return false;
4929 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004930 }
4931}
4932
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004933// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004934// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004935bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004936 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004937
Saleem Abdulrasool435f4562014-01-10 04:38:40 +00004938 // consume an optional '#' (GNU compatibility)
4939 if (getLexer().is(AsmToken::Hash))
4940 Parser.Lex();
4941
Jason W Kim1f7bc072011-01-11 23:53:41 +00004942 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004943 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004944 Parser.Lex(); // Eat ':'
4945
4946 if (getLexer().isNot(AsmToken::Identifier)) {
4947 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4948 return true;
4949 }
4950
4951 StringRef IDVal = Parser.getTok().getIdentifier();
4952 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004953 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004954 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004955 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004956 } else {
4957 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4958 return true;
4959 }
4960 Parser.Lex();
4961
4962 if (getLexer().isNot(AsmToken::Colon)) {
4963 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4964 return true;
4965 }
4966 Parser.Lex(); // Eat the last ':'
4967 return false;
4968}
4969
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004970/// \brief Given a mnemonic, split out possible predication code and carry
4971/// setting letters to form a canonical mnemonic and flags.
4972//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004973// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004974// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004975StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004976 unsigned &PredicationCode,
4977 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004978 unsigned &ProcessorIMod,
4979 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004980 PredicationCode = ARMCC::AL;
4981 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004982 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004983
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004984 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004985 //
4986 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004987 if ((Mnemonic == "movs" && isThumb()) ||
4988 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4989 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4990 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4991 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004992 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004993 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4994 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004995 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004996 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004997 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4998 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4999 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005000 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005001
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005002 // First, split out any predication code. Ignore mnemonics we know aren't
5003 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00005004 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00005005 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00005006 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00005007 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005008 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
5009 .Case("eq", ARMCC::EQ)
5010 .Case("ne", ARMCC::NE)
5011 .Case("hs", ARMCC::HS)
5012 .Case("cs", ARMCC::HS)
5013 .Case("lo", ARMCC::LO)
5014 .Case("cc", ARMCC::LO)
5015 .Case("mi", ARMCC::MI)
5016 .Case("pl", ARMCC::PL)
5017 .Case("vs", ARMCC::VS)
5018 .Case("vc", ARMCC::VC)
5019 .Case("hi", ARMCC::HI)
5020 .Case("ls", ARMCC::LS)
5021 .Case("ge", ARMCC::GE)
5022 .Case("lt", ARMCC::LT)
5023 .Case("gt", ARMCC::GT)
5024 .Case("le", ARMCC::LE)
5025 .Case("al", ARMCC::AL)
5026 .Default(~0U);
5027 if (CC != ~0U) {
5028 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
5029 PredicationCode = CC;
5030 }
Bill Wendling193961b2010-10-29 23:50:21 +00005031 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005032
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005033 // Next, determine if we have a carry setting bit. We explicitly ignore all
5034 // the instructions we know end in 's'.
5035 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00005036 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005037 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
5038 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
5039 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00005040 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00005041 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00005042 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00005043 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
David Peixottoa872e0e2014-01-07 18:19:23 +00005044 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00005045 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005046 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
5047 CarrySetting = true;
5048 }
5049
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005050 // The "cps" instruction can have a interrupt mode operand which is glued into
5051 // the mnemonic. Check if this is the case, split it and parse the imod op
5052 if (Mnemonic.startswith("cps")) {
5053 // Split out any imod code.
5054 unsigned IMod =
5055 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
5056 .Case("ie", ARM_PROC::IE)
5057 .Case("id", ARM_PROC::ID)
5058 .Default(~0U);
5059 if (IMod != ~0U) {
5060 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5061 ProcessorIMod = IMod;
5062 }
5063 }
5064
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005065 // The "it" instruction has the condition mask on the end of the mnemonic.
5066 if (Mnemonic.startswith("it")) {
5067 ITMask = Mnemonic.slice(2, Mnemonic.size());
5068 Mnemonic = Mnemonic.slice(0, 2);
5069 }
5070
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005071 return Mnemonic;
5072}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005073
5074/// \brief Given a canonical mnemonic, determine if the instruction ever allows
5075/// inclusion of carry set or predication code operands.
5076//
5077// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00005078void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00005079getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5080 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005081 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5082 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005083 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005084 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005085 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005086 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005087 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00005088 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005089 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005090 Mnemonic == "mla" || Mnemonic == "smlal" ||
5091 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005092 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00005093 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00005094 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005095
Tim Northover2c45a382013-06-26 16:52:40 +00005096 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5097 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Joey Gouly2f8890e2013-09-18 09:45:55 +00005098 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00005099 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
5100 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005101 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
5102 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00005103 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
5104 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5105 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00005106 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005107 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005108 } else if (!isThumb()) {
5109 // Some instructions are only predicable in Thumb mode
5110 CanAcceptPredicationCode
5111 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5112 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5113 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5114 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5115 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5116 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5117 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5118 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00005119 if (hasV6MOps())
5120 CanAcceptPredicationCode = Mnemonic != "movs";
5121 else
5122 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005123 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005124 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005125}
5126
Jim Grosbach7283da92011-08-16 21:12:37 +00005127bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
5128 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005129 // FIXME: This is all horribly hacky. We really need a better way to deal
5130 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005131
5132 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5133 // another does not. Specifically, the MOVW instruction does not. So we
5134 // special case it here and remove the defaulted (non-setting) cc_out
5135 // operand if that's the instruction we're trying to match.
5136 //
5137 // We do this as post-processing of the explicit operands rather than just
5138 // conditionally adding the cc_out in the first place because we need
5139 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005140 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00005141 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
5142 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
5143 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5144 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005145
5146 // Register-register 'add' for thumb does not have a cc_out operand
5147 // when there are only two register operands.
5148 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
5149 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5150 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5151 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5152 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005153 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005154 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5155 // have to check the immediate range here since Thumb2 has a variant
5156 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005157 if (((isThumb() && Mnemonic == "add") ||
5158 (isThumbTwo() && Mnemonic == "sub")) &&
5159 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005160 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5161 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5162 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005163 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005164 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005165 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005166 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005167 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5168 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005169 // selecting via the generic "add" mnemonic, so to know that we
5170 // should remove the cc_out operand, we have to explicitly check that
5171 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005172 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
5173 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005174 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5175 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5176 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5177 // Nest conditions rather than one big 'if' statement for readability.
5178 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005179 // If both registers are low, we're in an IT block, and the immediate is
5180 // in range, we should use encoding T1 instead, which has a cc_out.
5181 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005182 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005183 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5184 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5185 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005186 // Check against T3. If the second register is the PC, this is an
5187 // alternate form of ADR, which uses encoding T4, so check for that too.
5188 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5189 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5190 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005191
5192 // Otherwise, we use encoding T4, which does not have a cc_out
5193 // operand.
5194 return true;
5195 }
5196
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005197 // The thumb2 multiply instruction doesn't have a CCOut register, so
5198 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5199 // use the 16-bit encoding or not.
5200 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5201 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5202 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5203 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5204 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5205 // If the registers aren't low regs, the destination reg isn't the
5206 // same as one of the source regs, or the cc_out operand is zero
5207 // outside of an IT block, we have to use the 32-bit encoding, so
5208 // remove the cc_out operand.
5209 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5210 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00005211 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005212 !inITBlock() ||
5213 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5214 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5215 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5216 static_cast<ARMOperand*>(Operands[4])->getReg())))
5217 return true;
5218
Jim Grosbachefa7e952011-11-15 19:55:16 +00005219 // Also check the 'mul' syntax variant that doesn't specify an explicit
5220 // destination register.
5221 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5222 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5223 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5224 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5225 // If the registers aren't low regs or the cc_out operand is zero
5226 // outside of an IT block, we have to use the 32-bit encoding, so
5227 // remove the cc_out operand.
5228 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5229 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5230 !inITBlock()))
5231 return true;
5232
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005233
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005234
Jim Grosbach4b701af2011-08-24 21:42:27 +00005235 // Register-register 'add/sub' for thumb does not have a cc_out operand
5236 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5237 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5238 // right, this will result in better diagnostics (which operand is off)
5239 // anyway.
5240 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5241 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005242 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5243 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005244 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5245 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5246 (Operands.size() == 6 &&
5247 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005248 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005249
Jim Grosbach7283da92011-08-16 21:12:37 +00005250 return false;
5251}
5252
Joey Goulye8602552013-07-19 16:34:16 +00005253bool ARMAsmParser::shouldOmitPredicateOperand(
5254 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
5255 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5256 unsigned RegIdx = 3;
5257 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5258 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
5259 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
5260 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
5261 RegIdx = 4;
5262
5263 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
5264 (ARMMCRegisterClasses[ARM::DPRRegClassID]
5265 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
5266 ARMMCRegisterClasses[ARM::QPRRegClassID]
5267 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
5268 return true;
5269 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005270 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005271}
5272
Jim Grosbach12952fe2011-11-11 23:08:10 +00005273static bool isDataTypeToken(StringRef Tok) {
5274 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5275 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5276 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5277 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5278 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5279 Tok == ".f" || Tok == ".d";
5280}
5281
5282// FIXME: This bit should probably be handled via an explicit match class
5283// in the .td files that matches the suffix instead of having it be
5284// a literal string token the way it is now.
5285static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5286 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5287}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005288static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5289 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005290
5291static bool RequiresVFPRegListValidation(StringRef Inst,
5292 bool &AcceptSinglePrecisionOnly,
5293 bool &AcceptDoublePrecisionOnly) {
5294 if (Inst.size() < 7)
5295 return false;
5296
5297 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5298 StringRef AddressingMode = Inst.substr(4, 2);
5299 if (AddressingMode == "ia" || AddressingMode == "db" ||
5300 AddressingMode == "ea" || AddressingMode == "fd") {
5301 AcceptSinglePrecisionOnly = Inst[6] == 's';
5302 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5303 return true;
5304 }
5305 }
5306
5307 return false;
5308}
5309
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005310/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005311bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5312 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005313 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005314 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005315 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005316 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005317 bool AcceptDoublePrecisionOnly;
5318 RequireVFPRegisterListCheck =
5319 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5320 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005321
Jim Grosbach8be2f652011-12-09 23:34:09 +00005322 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005323 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005324 // The generic tblgen'erated code does this later, at the start of
5325 // MatchInstructionImpl(), but that's too late for aliases that include
5326 // any sort of suffix.
5327 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005328 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5329 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005330
Jim Grosbachab5830e2011-12-14 02:16:11 +00005331 // First check for the ARM-specific .req directive.
5332 if (Parser.getTok().is(AsmToken::Identifier) &&
5333 Parser.getTok().getIdentifier() == ".req") {
5334 parseDirectiveReq(Name, NameLoc);
5335 // We always return 'error' for this, as we're done with this
5336 // statement and don't need to match the 'instruction."
5337 return true;
5338 }
5339
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005340 // Create the leading tokens for the mnemonic, split by '.' characters.
5341 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005342 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005343
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005344 // Split out the predication code and carry setting flag from the mnemonic.
5345 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005346 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005347 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005348 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005349 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005350 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005351
Jim Grosbach1c171b12011-08-25 17:23:55 +00005352 // In Thumb1, only the branch (B) instruction can be predicated.
5353 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005354 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005355 return Error(NameLoc, "conditional execution not supported in Thumb1");
5356 }
5357
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005358 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5359
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005360 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5361 // is the mask as it will be for the IT encoding if the conditional
5362 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5363 // where the conditional bit0 is zero, the instruction post-processing
5364 // will adjust the mask accordingly.
5365 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005366 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5367 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005368 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005369 return Error(Loc, "too many conditions on IT instruction");
5370 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005371 unsigned Mask = 8;
5372 for (unsigned i = ITMask.size(); i != 0; --i) {
5373 char pos = ITMask[i - 1];
5374 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005375 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005376 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005377 }
5378 Mask >>= 1;
5379 if (ITMask[i - 1] == 't')
5380 Mask |= 8;
5381 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005382 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005383 }
5384
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005385 // FIXME: This is all a pretty gross hack. We should automatically handle
5386 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005387
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005388 // Next, add the CCOut and ConditionCode operands, if needed.
5389 //
5390 // For mnemonics which can ever incorporate a carry setting bit or predication
5391 // code, our matching model involves us always generating CCOut and
5392 // ConditionCode operands to match the mnemonic "as written" and then we let
5393 // the matcher deal with finding the right instruction or generating an
5394 // appropriate error.
5395 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005396 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005397
Jim Grosbach03a8a162011-07-14 22:04:21 +00005398 // If we had a carry-set on an instruction that can't do that, issue an
5399 // error.
5400 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005401 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005402 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005403 "' can not set flags, but 's' suffix specified");
5404 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005405 // If we had a predication code on an instruction that can't do that, issue an
5406 // error.
5407 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005408 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005409 return Error(NameLoc, "instruction '" + Mnemonic +
5410 "' is not predicable, but condition code specified");
5411 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005412
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005413 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005414 if (CanAcceptCarrySet) {
5415 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005416 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005417 Loc));
5418 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005419
5420 // Add the predication code operand, if necessary.
5421 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005422 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5423 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005424 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005425 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005426 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005427
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005428 // Add the processor imod operand, if necessary.
5429 if (ProcessorIMod) {
5430 Operands.push_back(ARMOperand::CreateImm(
5431 MCConstantExpr::Create(ProcessorIMod, getContext()),
5432 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005433 }
5434
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005435 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005436 while (Next != StringRef::npos) {
5437 Start = Next;
5438 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005439 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005440
Jim Grosbach12952fe2011-11-11 23:08:10 +00005441 // Some NEON instructions have an optional datatype suffix that is
5442 // completely ignored. Check for that.
5443 if (isDataTypeToken(ExtraToken) &&
5444 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5445 continue;
5446
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005447 // For for ARM mode generate an error if the .n qualifier is used.
5448 if (ExtraToken == ".n" && !isThumb()) {
5449 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005450 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005451 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5452 "arm mode");
5453 }
5454
5455 // The .n qualifier is always discarded as that is what the tables
5456 // and matcher expect. In ARM mode the .w qualifier has no effect,
5457 // so discard it to avoid errors that can be caused by the matcher.
5458 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005459 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5460 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5461 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005462 }
5463
5464 // Read the remaining operands.
5465 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005466 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005467 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005468 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005469 return true;
5470 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005471
5472 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005473 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005474
5475 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005476 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005477 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005478 return true;
5479 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005480 }
5481 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005482
Chris Lattnera2a9d162010-09-11 16:18:25 +00005483 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005484 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005485 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005486 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005487 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005488
Chris Lattner91689c12010-09-08 05:10:46 +00005489 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005490
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005491 if (RequireVFPRegisterListCheck) {
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005492 ARMOperand *Op = static_cast<ARMOperand*>(Operands.back());
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005493 if (AcceptSinglePrecisionOnly && !Op->isSPRRegList())
5494 return Error(Op->getStartLoc(),
5495 "VFP/Neon single precision register expected");
5496 if (AcceptDoublePrecisionOnly && !Op->isDPRRegList())
5497 return Error(Op->getStartLoc(),
5498 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005499 }
5500
Jim Grosbach7283da92011-08-16 21:12:37 +00005501 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5502 // do and don't have a cc_out optional-def operand. With some spot-checks
5503 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005504 // parse and adjust accordingly before actually matching. We shouldn't ever
5505 // try to remove a cc_out operand that was explicitly set on the the
5506 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5507 // table driven matcher doesn't fit well with the ARM instruction set.
5508 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005509 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5510 Operands.erase(Operands.begin() + 1);
5511 delete Op;
5512 }
5513
Joey Goulye8602552013-07-19 16:34:16 +00005514 // Some instructions have the same mnemonic, but don't always
5515 // have a predicate. Distinguish them here and delete the
5516 // predicate if needed.
5517 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5518 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5519 Operands.erase(Operands.begin() + 1);
5520 delete Op;
5521 }
5522
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005523 // ARM mode 'blx' need special handling, as the register operand version
5524 // is predicable, but the label operand version is not. So, we can't rely
5525 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005526 // a k_CondCode operand in the list. If we're trying to match the label
5527 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005528 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5529 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5530 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5531 Operands.erase(Operands.begin() + 1);
5532 delete Op;
5533 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005534
Weiming Zhao8f56f882012-11-16 21:55:34 +00005535 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5536 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5537 // a single GPRPair reg operand is used in the .td file to replace the two
5538 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5539 // expressed as a GPRPair, so we have to manually merge them.
5540 // FIXME: We would really like to be able to tablegen'erate this.
5541 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005542 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5543 Mnemonic == "stlexd")) {
5544 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005545 unsigned Idx = isLoad ? 2 : 3;
5546 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5547 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5548
5549 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5550 // Adjust only if Op1 and Op2 are GPRs.
5551 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5552 MRC.contains(Op2->getReg())) {
5553 unsigned Reg1 = Op1->getReg();
5554 unsigned Reg2 = Op2->getReg();
5555 unsigned Rt = MRI->getEncodingValue(Reg1);
5556 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5557
5558 // Rt2 must be Rt + 1 and Rt must be even.
5559 if (Rt + 1 != Rt2 || (Rt & 1)) {
5560 Error(Op2->getStartLoc(), isLoad ?
5561 "destination operands must be sequential" :
5562 "source operands must be sequential");
5563 return true;
5564 }
5565 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5566 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5567 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5568 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5569 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5570 delete Op1;
5571 delete Op2;
5572 }
5573 }
5574
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005575 // GNU Assembler extension (compatibility)
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005576 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
5577 ARMOperand *Op2 = static_cast<ARMOperand *>(Operands[2]);
5578 ARMOperand *Op3 = static_cast<ARMOperand *>(Operands[3]);
5579 if (Op3->isMem()) {
5580 assert(Op2->isReg() && "expected register argument");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005581
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005582 unsigned SuperReg = MRI->getMatchingSuperReg(
5583 Op2->getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005584
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005585 assert(SuperReg && "expected register pair");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005586
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005587 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005588
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005589 Operands.insert(Operands.begin() + 3,
5590 ARMOperand::CreateReg(PairedReg,
5591 Op2->getStartLoc(),
5592 Op2->getEndLoc()));
5593 }
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005594 }
5595
Kevin Enderby78f95722013-07-31 21:05:30 +00005596 // FIXME: As said above, this is all a pretty gross hack. This instruction
5597 // does not fit with other "subs" and tblgen.
5598 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5599 // so the Mnemonic is the original name "subs" and delete the predicate
5600 // operand so it will match the table entry.
5601 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5602 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5603 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5604 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5605 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5606 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5607 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5608 Operands.erase(Operands.begin());
5609 delete Op0;
5610 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5611
5612 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5613 Operands.erase(Operands.begin() + 1);
5614 delete Op1;
5615 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005616 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005617}
5618
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005619// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005620
5621// return 'true' if register list contains non-low GPR registers,
5622// 'false' otherwise. If Reg is in the register list or is HiReg, set
5623// 'containsReg' to true.
5624static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5625 unsigned HiReg, bool &containsReg) {
5626 containsReg = false;
5627 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5628 unsigned OpReg = Inst.getOperand(i).getReg();
5629 if (OpReg == Reg)
5630 containsReg = true;
5631 // Anything other than a low register isn't legal here.
5632 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5633 return true;
5634 }
5635 return false;
5636}
5637
Jim Grosbacha31f2232011-09-07 18:05:34 +00005638// Check if the specified regisgter is in the register list of the inst,
5639// starting at the indicated operand number.
5640static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5641 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5642 unsigned OpReg = Inst.getOperand(i).getReg();
5643 if (OpReg == Reg)
5644 return true;
5645 }
5646 return false;
5647}
5648
Richard Barton8d519fe2013-09-05 14:14:19 +00005649// Return true if instruction has the interesting property of being
5650// allowed in IT blocks, but not being predicable.
5651static bool instIsBreakpoint(const MCInst &Inst) {
5652 return Inst.getOpcode() == ARM::tBKPT ||
5653 Inst.getOpcode() == ARM::BKPT ||
5654 Inst.getOpcode() == ARM::tHLT ||
5655 Inst.getOpcode() == ARM::HLT;
5656
5657}
5658
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005659// FIXME: We would really like to be able to tablegen'erate this.
5660bool ARMAsmParser::
5661validateInstruction(MCInst &Inst,
5662 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005663 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005664 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005665
Jim Grosbached16ec42011-08-29 22:24:09 +00005666 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005667 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005668 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005669 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005670 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005671 if (ITState.FirstCond)
5672 ITState.FirstCond = false;
5673 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005674 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005675 // The instruction must be predicable.
5676 if (!MCID.isPredicable())
5677 return Error(Loc, "instructions in IT block must be predicable");
5678 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005679 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005680 ARMCC::getOppositeCondition(ITState.Cond);
5681 if (Cond != ITCond) {
5682 // Find the condition code Operand to get its SMLoc information.
5683 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005684 for (unsigned I = 1; I < Operands.size(); ++I)
5685 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5686 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005687 return Error(CondLoc, "incorrect condition in IT block; got '" +
5688 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5689 "', but expected '" +
5690 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5691 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005692 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005693 } else if (isThumbTwo() && MCID.isPredicable() &&
5694 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005695 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5696 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005697 return Error(Loc, "predicated instructions must be in IT block");
5698
Tilmann Scheller255722b2013-09-30 16:11:48 +00005699 const unsigned Opcode = Inst.getOpcode();
5700 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005701 case ARM::LDRD:
5702 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005703 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005704 const unsigned RtReg = Inst.getOperand(0).getReg();
5705
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005706 // Rt can't be R14.
5707 if (RtReg == ARM::LR)
5708 return Error(Operands[3]->getStartLoc(),
5709 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005710
5711 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005712 // Rt must be even-numbered.
5713 if ((Rt & 1) == 1)
5714 return Error(Operands[3]->getStartLoc(),
5715 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005716
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005717 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005718 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005719 if (Rt2 != Rt + 1)
5720 return Error(Operands[3]->getStartLoc(),
5721 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005722
5723 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5724 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5725 // For addressing modes with writeback, the base register needs to be
5726 // different from the destination registers.
5727 if (Rn == Rt || Rn == Rt2)
5728 return Error(Operands[3]->getStartLoc(),
5729 "base register needs to be different from destination "
5730 "registers");
5731 }
5732
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005733 return false;
5734 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005735 case ARM::t2LDRDi8:
5736 case ARM::t2LDRD_PRE:
5737 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005738 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005739 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5740 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5741 if (Rt2 == Rt)
5742 return Error(Operands[3]->getStartLoc(),
5743 "destination operands can't be identical");
5744 return false;
5745 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005746 case ARM::STRD: {
5747 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005748 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5749 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005750 if (Rt2 != Rt + 1)
5751 return Error(Operands[3]->getStartLoc(),
5752 "source operands must be sequential");
5753 return false;
5754 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005755 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005756 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005757 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005758 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5759 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005760 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005761 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005762 "source operands must be sequential");
5763 return false;
5764 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005765 case ARM::SBFX:
5766 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005767 // Width must be in range [1, 32-lsb].
5768 unsigned LSB = Inst.getOperand(2).getImm();
5769 unsigned Widthm1 = Inst.getOperand(3).getImm();
5770 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005771 return Error(Operands[5]->getStartLoc(),
5772 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005773 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005774 }
Tim Northover08a86602013-10-22 19:00:39 +00005775 // Notionally handles ARM::tLDMIA_UPD too.
Jim Grosbach90103cc2011-08-18 21:50:53 +00005776 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005777 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005778 // most cases that are normally illegal for a Thumb1 LDM instruction.
5779 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005780 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005781 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005782 // in the register list.
5783 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005784 bool HasWritebackToken =
Jim Grosbach139acd22011-08-22 23:01:07 +00005785 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5786 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005787 bool ListContainsBase;
5788 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5789 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005790 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005791 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005792 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005793 return Error(Operands[2]->getStartLoc(),
5794 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005795 // If we should not have writeback, there must not be a '!'. This is
5796 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005797 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005798 return Error(Operands[3]->getStartLoc(),
5799 "writeback operator '!' not allowed when base register "
5800 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005801
5802 break;
5803 }
Tim Northover08a86602013-10-22 19:00:39 +00005804 case ARM::LDMIA_UPD:
5805 case ARM::LDMDB_UPD:
5806 case ARM::LDMIB_UPD:
5807 case ARM::LDMDA_UPD:
5808 // ARM variants loading and updating the same register are only officially
5809 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5810 if (!hasV7Ops())
5811 break;
5812 // Fallthrough
5813 case ARM::t2LDMIA_UPD:
5814 case ARM::t2LDMDB_UPD:
5815 case ARM::t2STMIA_UPD:
5816 case ARM::t2STMDB_UPD: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005817 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
Tim Northover741e6ef2013-10-24 09:37:18 +00005818 return Error(Operands.back()->getStartLoc(),
5819 "writeback register not allowed in register list");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005820 break;
5821 }
Tim Northover8eaf1542013-11-12 21:32:41 +00005822 case ARM::sysLDMIA_UPD:
5823 case ARM::sysLDMDA_UPD:
5824 case ARM::sysLDMDB_UPD:
5825 case ARM::sysLDMIB_UPD:
5826 if (!listContainsReg(Inst, 3, ARM::PC))
5827 return Error(Operands[4]->getStartLoc(),
5828 "writeback register only allowed on system LDM "
5829 "if PC in register-list");
5830 break;
5831 case ARM::sysSTMIA_UPD:
5832 case ARM::sysSTMDA_UPD:
5833 case ARM::sysSTMDB_UPD:
5834 case ARM::sysSTMIB_UPD:
5835 return Error(Operands[2]->getStartLoc(),
5836 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005837 case ARM::tMUL: {
5838 // The second source operand must be the same register as the destination
5839 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005840 //
5841 // In this case, we must directly check the parsed operands because the
5842 // cvtThumbMultiply() function is written in such a way that it guarantees
5843 // this first statement is always true for the new Inst. Essentially, the
5844 // destination is unconditionally copied into the second source operand
5845 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005846 if (Operands.size() == 6 &&
5847 (((ARMOperand*)Operands[3])->getReg() !=
5848 ((ARMOperand*)Operands[5])->getReg()) &&
5849 (((ARMOperand*)Operands[3])->getReg() !=
5850 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005851 return Error(Operands[3]->getStartLoc(),
5852 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005853 }
5854 break;
5855 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005856 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5857 // so only issue a diagnostic for thumb1. The instructions will be
5858 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005859 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005860 bool ListContainsBase;
5861 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005862 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005863 return Error(Operands[2]->getStartLoc(),
5864 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005865 break;
5866 }
5867 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005868 bool ListContainsBase;
5869 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005870 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005871 return Error(Operands[2]->getStartLoc(),
5872 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005873 break;
5874 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005875 case ARM::tSTMIA_UPD: {
Tim Northover08a86602013-10-22 19:00:39 +00005876 bool ListContainsBase, InvalidLowList;
5877 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5878 0, ListContainsBase);
5879 if (InvalidLowList && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005880 return Error(Operands[4]->getStartLoc(),
5881 "registers must be in range r0-r7");
Tim Northover08a86602013-10-22 19:00:39 +00005882
5883 // This would be converted to a 32-bit stm, but that's not valid if the
5884 // writeback register is in the list.
5885 if (InvalidLowList && ListContainsBase)
5886 return Error(Operands[4]->getStartLoc(),
5887 "writeback operator '!' not allowed when base register "
5888 "in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00005889 break;
5890 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005891 case ARM::tADDrSP: {
5892 // If the non-SP source operand and the destination operand are not the
5893 // same, we need thumb2 (for the wide encoding), or we have an error.
5894 if (!isThumbTwo() &&
5895 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5896 return Error(Operands[4]->getStartLoc(),
5897 "source register must be the same as destination");
5898 }
5899 break;
5900 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005901 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005902 case ARM::tB:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005903 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5904 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005905 break;
5906 case ARM::t2B: {
5907 int op = (Operands[2]->isImm()) ? 2 : 3;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005908 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5909 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005910 break;
5911 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005912 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005913 case ARM::tBcc:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005914 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5915 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005916 break;
5917 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005918 int Op = (Operands[2]->isImm()) ? 2 : 3;
5919 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5920 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005921 break;
5922 }
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00005923 case ARM::MOVi16:
5924 case ARM::t2MOVi16:
5925 case ARM::t2MOVTi16:
5926 {
5927 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
5928 // especially when we turn it into a movw and the expression <symbol> does
5929 // not have a :lower16: or :upper16 as part of the expression. We don't
5930 // want the behavior of silently truncating, which can be unexpected and
5931 // lead to bugs that are difficult to find since this is an easy mistake
5932 // to make.
5933 int i = (Operands[3]->isImm()) ? 3 : 4;
5934 ARMOperand *Op = static_cast<ARMOperand*>(Operands[i]);
5935 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5936 if (CE) break;
5937 const MCExpr *E = dyn_cast<MCExpr>(Op->getImm());
5938 if (!E) break;
5939 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
5940 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
5941 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16)) {
5942 return Error(Op->getStartLoc(),
5943 "immediate expression for mov requires :lower16: or :upper16");
5944 break;
5945 }
5946 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005947 }
5948
5949 return false;
5950}
5951
Jim Grosbach1a747242012-01-23 23:45:44 +00005952static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005953 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005954 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005955 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005956 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5957 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5958 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5959 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5960 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5961 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5962 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5963 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5964 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005965
5966 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005967 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5968 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5969 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5970 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5971 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005972
Jim Grosbach1e946a42012-01-24 00:43:12 +00005973 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5974 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5975 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5976 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5977 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005978
Jim Grosbach1e946a42012-01-24 00:43:12 +00005979 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5980 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5981 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5982 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5983 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005984
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005985 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005986 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5987 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5988 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5989 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5990 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5991 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5992 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5993 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5994 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5995 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5996 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5997 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5998 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5999 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
6000 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006001
Jim Grosbach1a747242012-01-23 23:45:44 +00006002 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006003 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6004 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6005 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6006 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6007 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6008 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6009 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6010 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6011 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6012 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6013 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6014 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6015 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
6016 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
6017 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
6018 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
6019 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
6020 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00006021
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006022 // VST4LN
6023 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6024 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6025 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6026 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
6027 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6028 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6029 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6030 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6031 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
6032 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6033 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
6034 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
6035 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
6036 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
6037 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
6038
Jim Grosbachda70eac2012-01-24 00:58:13 +00006039 // VST4
6040 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6041 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6042 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6043 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6044 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6045 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6046 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6047 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6048 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6049 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6050 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6051 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6052 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6053 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6054 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6055 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6056 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6057 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00006058 }
6059}
6060
Jim Grosbach1a747242012-01-23 23:45:44 +00006061static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00006062 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006063 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006064 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006065 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6066 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6067 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6068 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6069 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6070 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6071 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6072 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6073 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006074
6075 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006076 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6077 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6078 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6079 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6080 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6081 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6082 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6083 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6084 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6085 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6086 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6087 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6088 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6089 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6090 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006091
Jim Grosbachb78403c2012-01-24 23:47:04 +00006092 // VLD3DUP
6093 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6094 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6095 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6096 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
Kevin Enderbyd88fec32014-04-08 18:00:52 +00006097 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
Jim Grosbachb78403c2012-01-24 23:47:04 +00006098 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6099 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6100 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6101 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6102 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6103 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6104 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6105 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6106 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6107 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6108 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6109 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6110 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6111
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006112 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006113 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6114 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6115 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6116 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6117 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6118 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6119 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6120 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6121 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6122 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6123 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6124 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6125 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6126 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6127 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006128
6129 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006130 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6131 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6132 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6133 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6134 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6135 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6136 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6137 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6138 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6139 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6140 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6141 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6142 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6143 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6144 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6145 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6146 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6147 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00006148
Jim Grosbach14952a02012-01-24 18:37:25 +00006149 // VLD4LN
6150 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6151 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6152 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00006153 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00006154 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6155 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6156 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6157 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6158 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6159 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6160 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6161 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6162 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6163 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6164 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6165
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006166 // VLD4DUP
6167 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6168 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6169 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6170 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6171 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6172 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6173 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6174 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6175 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6176 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6177 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6178 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6179 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6180 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6181 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6182 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6183 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6184 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6185
Jim Grosbached561fc2012-01-24 00:43:17 +00006186 // VLD4
6187 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6188 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6189 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6190 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6191 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6192 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6193 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6194 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6195 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6196 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6197 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6198 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6199 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6200 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6201 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6202 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6203 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6204 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006205 }
6206}
6207
Jim Grosbachafad0532011-11-10 23:42:14 +00006208bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006209processInstruction(MCInst &Inst,
6210 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
6211 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006212 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6213 case ARM::LDRT_POST:
6214 case ARM::LDRBT_POST: {
6215 const unsigned Opcode =
6216 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6217 : ARM::LDRBT_POST_IMM;
6218 MCInst TmpInst;
6219 TmpInst.setOpcode(Opcode);
6220 TmpInst.addOperand(Inst.getOperand(0));
6221 TmpInst.addOperand(Inst.getOperand(1));
6222 TmpInst.addOperand(Inst.getOperand(1));
6223 TmpInst.addOperand(MCOperand::CreateReg(0));
6224 TmpInst.addOperand(MCOperand::CreateImm(0));
6225 TmpInst.addOperand(Inst.getOperand(2));
6226 TmpInst.addOperand(Inst.getOperand(3));
6227 Inst = TmpInst;
6228 return true;
6229 }
6230 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6231 case ARM::STRT_POST:
6232 case ARM::STRBT_POST: {
6233 const unsigned Opcode =
6234 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6235 : ARM::STRBT_POST_IMM;
6236 MCInst TmpInst;
6237 TmpInst.setOpcode(Opcode);
6238 TmpInst.addOperand(Inst.getOperand(1));
6239 TmpInst.addOperand(Inst.getOperand(0));
6240 TmpInst.addOperand(Inst.getOperand(1));
6241 TmpInst.addOperand(MCOperand::CreateReg(0));
6242 TmpInst.addOperand(MCOperand::CreateImm(0));
6243 TmpInst.addOperand(Inst.getOperand(2));
6244 TmpInst.addOperand(Inst.getOperand(3));
6245 Inst = TmpInst;
6246 return true;
6247 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006248 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6249 case ARM::ADDri: {
6250 if (Inst.getOperand(1).getReg() != ARM::PC ||
6251 Inst.getOperand(5).getReg() != 0)
6252 return false;
6253 MCInst TmpInst;
6254 TmpInst.setOpcode(ARM::ADR);
6255 TmpInst.addOperand(Inst.getOperand(0));
6256 TmpInst.addOperand(Inst.getOperand(2));
6257 TmpInst.addOperand(Inst.getOperand(3));
6258 TmpInst.addOperand(Inst.getOperand(4));
6259 Inst = TmpInst;
6260 return true;
6261 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006262 // Aliases for alternate PC+imm syntax of LDR instructions.
6263 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006264 // Select the narrow version if the immediate will fit.
6265 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006266 Inst.getOperand(1).getImm() <= 0xff &&
6267 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
6268 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006269 Inst.setOpcode(ARM::tLDRpci);
6270 else
6271 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006272 return true;
6273 case ARM::t2LDRBpcrel:
6274 Inst.setOpcode(ARM::t2LDRBpci);
6275 return true;
6276 case ARM::t2LDRHpcrel:
6277 Inst.setOpcode(ARM::t2LDRHpci);
6278 return true;
6279 case ARM::t2LDRSBpcrel:
6280 Inst.setOpcode(ARM::t2LDRSBpci);
6281 return true;
6282 case ARM::t2LDRSHpcrel:
6283 Inst.setOpcode(ARM::t2LDRSHpci);
6284 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006285 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006286 case ARM::VST1LNdWB_register_Asm_8:
6287 case ARM::VST1LNdWB_register_Asm_16:
6288 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006289 MCInst TmpInst;
6290 // Shuffle the operands around so the lane index operand is in the
6291 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006292 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006293 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006294 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6295 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6296 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6297 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6298 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6299 TmpInst.addOperand(Inst.getOperand(1)); // lane
6300 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6301 TmpInst.addOperand(Inst.getOperand(6));
6302 Inst = TmpInst;
6303 return true;
6304 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006305
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006306 case ARM::VST2LNdWB_register_Asm_8:
6307 case ARM::VST2LNdWB_register_Asm_16:
6308 case ARM::VST2LNdWB_register_Asm_32:
6309 case ARM::VST2LNqWB_register_Asm_16:
6310 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006311 MCInst TmpInst;
6312 // Shuffle the operands around so the lane index operand is in the
6313 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006314 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006315 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006316 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6317 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6318 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6319 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6320 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006321 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6322 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006323 TmpInst.addOperand(Inst.getOperand(1)); // lane
6324 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6325 TmpInst.addOperand(Inst.getOperand(6));
6326 Inst = TmpInst;
6327 return true;
6328 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006329
6330 case ARM::VST3LNdWB_register_Asm_8:
6331 case ARM::VST3LNdWB_register_Asm_16:
6332 case ARM::VST3LNdWB_register_Asm_32:
6333 case ARM::VST3LNqWB_register_Asm_16:
6334 case ARM::VST3LNqWB_register_Asm_32: {
6335 MCInst TmpInst;
6336 // Shuffle the operands around so the lane index operand is in the
6337 // right place.
6338 unsigned Spacing;
6339 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6340 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6341 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6342 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6343 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6344 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6345 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6346 Spacing));
6347 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6348 Spacing * 2));
6349 TmpInst.addOperand(Inst.getOperand(1)); // lane
6350 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6351 TmpInst.addOperand(Inst.getOperand(6));
6352 Inst = TmpInst;
6353 return true;
6354 }
6355
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006356 case ARM::VST4LNdWB_register_Asm_8:
6357 case ARM::VST4LNdWB_register_Asm_16:
6358 case ARM::VST4LNdWB_register_Asm_32:
6359 case ARM::VST4LNqWB_register_Asm_16:
6360 case ARM::VST4LNqWB_register_Asm_32: {
6361 MCInst TmpInst;
6362 // Shuffle the operands around so the lane index operand is in the
6363 // right place.
6364 unsigned Spacing;
6365 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6366 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6367 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6368 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6369 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6370 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6371 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6372 Spacing));
6373 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6374 Spacing * 2));
6375 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6376 Spacing * 3));
6377 TmpInst.addOperand(Inst.getOperand(1)); // lane
6378 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6379 TmpInst.addOperand(Inst.getOperand(6));
6380 Inst = TmpInst;
6381 return true;
6382 }
6383
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006384 case ARM::VST1LNdWB_fixed_Asm_8:
6385 case ARM::VST1LNdWB_fixed_Asm_16:
6386 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006387 MCInst TmpInst;
6388 // Shuffle the operands around so the lane index operand is in the
6389 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006390 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006391 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006392 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6393 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6394 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6395 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6396 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6397 TmpInst.addOperand(Inst.getOperand(1)); // lane
6398 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6399 TmpInst.addOperand(Inst.getOperand(5));
6400 Inst = TmpInst;
6401 return true;
6402 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006403
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006404 case ARM::VST2LNdWB_fixed_Asm_8:
6405 case ARM::VST2LNdWB_fixed_Asm_16:
6406 case ARM::VST2LNdWB_fixed_Asm_32:
6407 case ARM::VST2LNqWB_fixed_Asm_16:
6408 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006409 MCInst TmpInst;
6410 // Shuffle the operands around so the lane index operand is in the
6411 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006412 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006413 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006414 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6415 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6416 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6417 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6418 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006419 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6420 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006421 TmpInst.addOperand(Inst.getOperand(1)); // lane
6422 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6423 TmpInst.addOperand(Inst.getOperand(5));
6424 Inst = TmpInst;
6425 return true;
6426 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006427
6428 case ARM::VST3LNdWB_fixed_Asm_8:
6429 case ARM::VST3LNdWB_fixed_Asm_16:
6430 case ARM::VST3LNdWB_fixed_Asm_32:
6431 case ARM::VST3LNqWB_fixed_Asm_16:
6432 case ARM::VST3LNqWB_fixed_Asm_32: {
6433 MCInst TmpInst;
6434 // Shuffle the operands around so the lane index operand is in the
6435 // right place.
6436 unsigned Spacing;
6437 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6438 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6439 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6440 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6441 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6442 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6443 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6444 Spacing));
6445 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6446 Spacing * 2));
6447 TmpInst.addOperand(Inst.getOperand(1)); // lane
6448 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6449 TmpInst.addOperand(Inst.getOperand(5));
6450 Inst = TmpInst;
6451 return true;
6452 }
6453
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006454 case ARM::VST4LNdWB_fixed_Asm_8:
6455 case ARM::VST4LNdWB_fixed_Asm_16:
6456 case ARM::VST4LNdWB_fixed_Asm_32:
6457 case ARM::VST4LNqWB_fixed_Asm_16:
6458 case ARM::VST4LNqWB_fixed_Asm_32: {
6459 MCInst TmpInst;
6460 // Shuffle the operands around so the lane index operand is in the
6461 // right place.
6462 unsigned Spacing;
6463 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6464 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6465 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6466 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6467 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6468 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6469 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6470 Spacing));
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6472 Spacing * 2));
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6474 Spacing * 3));
6475 TmpInst.addOperand(Inst.getOperand(1)); // lane
6476 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6477 TmpInst.addOperand(Inst.getOperand(5));
6478 Inst = TmpInst;
6479 return true;
6480 }
6481
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006482 case ARM::VST1LNdAsm_8:
6483 case ARM::VST1LNdAsm_16:
6484 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006485 MCInst TmpInst;
6486 // Shuffle the operands around so the lane index operand is in the
6487 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006488 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006489 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006490 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6491 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6492 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6493 TmpInst.addOperand(Inst.getOperand(1)); // lane
6494 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6495 TmpInst.addOperand(Inst.getOperand(5));
6496 Inst = TmpInst;
6497 return true;
6498 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006499
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006500 case ARM::VST2LNdAsm_8:
6501 case ARM::VST2LNdAsm_16:
6502 case ARM::VST2LNdAsm_32:
6503 case ARM::VST2LNqAsm_16:
6504 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006505 MCInst TmpInst;
6506 // Shuffle the operands around so the lane index operand is in the
6507 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006508 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006509 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006510 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6511 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6512 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006513 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6514 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006515 TmpInst.addOperand(Inst.getOperand(1)); // lane
6516 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6517 TmpInst.addOperand(Inst.getOperand(5));
6518 Inst = TmpInst;
6519 return true;
6520 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006521
6522 case ARM::VST3LNdAsm_8:
6523 case ARM::VST3LNdAsm_16:
6524 case ARM::VST3LNdAsm_32:
6525 case ARM::VST3LNqAsm_16:
6526 case ARM::VST3LNqAsm_32: {
6527 MCInst TmpInst;
6528 // Shuffle the operands around so the lane index operand is in the
6529 // right place.
6530 unsigned Spacing;
6531 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6532 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6533 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6534 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6535 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6536 Spacing));
6537 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6538 Spacing * 2));
6539 TmpInst.addOperand(Inst.getOperand(1)); // lane
6540 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6541 TmpInst.addOperand(Inst.getOperand(5));
6542 Inst = TmpInst;
6543 return true;
6544 }
6545
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006546 case ARM::VST4LNdAsm_8:
6547 case ARM::VST4LNdAsm_16:
6548 case ARM::VST4LNdAsm_32:
6549 case ARM::VST4LNqAsm_16:
6550 case ARM::VST4LNqAsm_32: {
6551 MCInst TmpInst;
6552 // Shuffle the operands around so the lane index operand is in the
6553 // right place.
6554 unsigned Spacing;
6555 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6556 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6557 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6558 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6559 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6560 Spacing));
6561 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6562 Spacing * 2));
6563 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6564 Spacing * 3));
6565 TmpInst.addOperand(Inst.getOperand(1)); // lane
6566 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6567 TmpInst.addOperand(Inst.getOperand(5));
6568 Inst = TmpInst;
6569 return true;
6570 }
6571
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006572 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006573 case ARM::VLD1LNdWB_register_Asm_8:
6574 case ARM::VLD1LNdWB_register_Asm_16:
6575 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006576 MCInst TmpInst;
6577 // Shuffle the operands around so the lane index operand is in the
6578 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006579 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006580 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006581 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6582 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6583 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6584 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6585 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6586 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6587 TmpInst.addOperand(Inst.getOperand(1)); // lane
6588 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6589 TmpInst.addOperand(Inst.getOperand(6));
6590 Inst = TmpInst;
6591 return true;
6592 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006593
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006594 case ARM::VLD2LNdWB_register_Asm_8:
6595 case ARM::VLD2LNdWB_register_Asm_16:
6596 case ARM::VLD2LNdWB_register_Asm_32:
6597 case ARM::VLD2LNqWB_register_Asm_16:
6598 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006599 MCInst TmpInst;
6600 // Shuffle the operands around so the lane index operand is in the
6601 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006602 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006603 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006604 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006605 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6606 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006607 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6608 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6609 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6610 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6611 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006612 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6613 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006614 TmpInst.addOperand(Inst.getOperand(1)); // lane
6615 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6616 TmpInst.addOperand(Inst.getOperand(6));
6617 Inst = TmpInst;
6618 return true;
6619 }
6620
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006621 case ARM::VLD3LNdWB_register_Asm_8:
6622 case ARM::VLD3LNdWB_register_Asm_16:
6623 case ARM::VLD3LNdWB_register_Asm_32:
6624 case ARM::VLD3LNqWB_register_Asm_16:
6625 case ARM::VLD3LNqWB_register_Asm_32: {
6626 MCInst TmpInst;
6627 // Shuffle the operands around so the lane index operand is in the
6628 // right place.
6629 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006630 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006631 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6632 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6633 Spacing));
6634 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006635 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006636 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6637 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6638 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6639 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6640 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6641 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6642 Spacing));
6643 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006644 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006645 TmpInst.addOperand(Inst.getOperand(1)); // lane
6646 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6647 TmpInst.addOperand(Inst.getOperand(6));
6648 Inst = TmpInst;
6649 return true;
6650 }
6651
Jim Grosbach14952a02012-01-24 18:37:25 +00006652 case ARM::VLD4LNdWB_register_Asm_8:
6653 case ARM::VLD4LNdWB_register_Asm_16:
6654 case ARM::VLD4LNdWB_register_Asm_32:
6655 case ARM::VLD4LNqWB_register_Asm_16:
6656 case ARM::VLD4LNqWB_register_Asm_32: {
6657 MCInst TmpInst;
6658 // Shuffle the operands around so the lane index operand is in the
6659 // right place.
6660 unsigned Spacing;
6661 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6662 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6663 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6664 Spacing));
6665 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6666 Spacing * 2));
6667 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6668 Spacing * 3));
6669 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6670 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6671 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6672 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6673 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6675 Spacing));
6676 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6677 Spacing * 2));
6678 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6679 Spacing * 3));
6680 TmpInst.addOperand(Inst.getOperand(1)); // lane
6681 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6682 TmpInst.addOperand(Inst.getOperand(6));
6683 Inst = TmpInst;
6684 return true;
6685 }
6686
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006687 case ARM::VLD1LNdWB_fixed_Asm_8:
6688 case ARM::VLD1LNdWB_fixed_Asm_16:
6689 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006690 MCInst TmpInst;
6691 // Shuffle the operands around so the lane index operand is in the
6692 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006693 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006694 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006695 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6696 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6697 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6698 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6699 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6700 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6701 TmpInst.addOperand(Inst.getOperand(1)); // lane
6702 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6703 TmpInst.addOperand(Inst.getOperand(5));
6704 Inst = TmpInst;
6705 return true;
6706 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006707
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006708 case ARM::VLD2LNdWB_fixed_Asm_8:
6709 case ARM::VLD2LNdWB_fixed_Asm_16:
6710 case ARM::VLD2LNdWB_fixed_Asm_32:
6711 case ARM::VLD2LNqWB_fixed_Asm_16:
6712 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006713 MCInst TmpInst;
6714 // Shuffle the operands around so the lane index operand is in the
6715 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006716 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006717 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006718 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006719 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6720 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006721 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6722 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6723 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6724 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6725 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006726 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6727 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006728 TmpInst.addOperand(Inst.getOperand(1)); // lane
6729 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6730 TmpInst.addOperand(Inst.getOperand(5));
6731 Inst = TmpInst;
6732 return true;
6733 }
6734
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006735 case ARM::VLD3LNdWB_fixed_Asm_8:
6736 case ARM::VLD3LNdWB_fixed_Asm_16:
6737 case ARM::VLD3LNdWB_fixed_Asm_32:
6738 case ARM::VLD3LNqWB_fixed_Asm_16:
6739 case ARM::VLD3LNqWB_fixed_Asm_32: {
6740 MCInst TmpInst;
6741 // Shuffle the operands around so the lane index operand is in the
6742 // right place.
6743 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006744 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006745 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6746 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6747 Spacing));
6748 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006749 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006750 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6751 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6752 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6753 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6754 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6755 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6756 Spacing));
6757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006758 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006759 TmpInst.addOperand(Inst.getOperand(1)); // lane
6760 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6761 TmpInst.addOperand(Inst.getOperand(5));
6762 Inst = TmpInst;
6763 return true;
6764 }
6765
Jim Grosbach14952a02012-01-24 18:37:25 +00006766 case ARM::VLD4LNdWB_fixed_Asm_8:
6767 case ARM::VLD4LNdWB_fixed_Asm_16:
6768 case ARM::VLD4LNdWB_fixed_Asm_32:
6769 case ARM::VLD4LNqWB_fixed_Asm_16:
6770 case ARM::VLD4LNqWB_fixed_Asm_32: {
6771 MCInst TmpInst;
6772 // Shuffle the operands around so the lane index operand is in the
6773 // right place.
6774 unsigned Spacing;
6775 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6776 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6778 Spacing));
6779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6780 Spacing * 2));
6781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6782 Spacing * 3));
6783 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6784 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6785 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6786 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6787 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6788 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6789 Spacing));
6790 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6791 Spacing * 2));
6792 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6793 Spacing * 3));
6794 TmpInst.addOperand(Inst.getOperand(1)); // lane
6795 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6796 TmpInst.addOperand(Inst.getOperand(5));
6797 Inst = TmpInst;
6798 return true;
6799 }
6800
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006801 case ARM::VLD1LNdAsm_8:
6802 case ARM::VLD1LNdAsm_16:
6803 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006804 MCInst TmpInst;
6805 // Shuffle the operands around so the lane index operand is in the
6806 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006807 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006808 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006809 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6810 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6811 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6812 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6813 TmpInst.addOperand(Inst.getOperand(1)); // lane
6814 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6815 TmpInst.addOperand(Inst.getOperand(5));
6816 Inst = TmpInst;
6817 return true;
6818 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006819
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006820 case ARM::VLD2LNdAsm_8:
6821 case ARM::VLD2LNdAsm_16:
6822 case ARM::VLD2LNdAsm_32:
6823 case ARM::VLD2LNqAsm_16:
6824 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006825 MCInst TmpInst;
6826 // Shuffle the operands around so the lane index operand is in the
6827 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006828 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006829 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006830 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006831 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6832 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006833 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6834 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6835 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006836 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6837 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006838 TmpInst.addOperand(Inst.getOperand(1)); // lane
6839 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6840 TmpInst.addOperand(Inst.getOperand(5));
6841 Inst = TmpInst;
6842 return true;
6843 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006844
6845 case ARM::VLD3LNdAsm_8:
6846 case ARM::VLD3LNdAsm_16:
6847 case ARM::VLD3LNdAsm_32:
6848 case ARM::VLD3LNqAsm_16:
6849 case ARM::VLD3LNqAsm_32: {
6850 MCInst TmpInst;
6851 // Shuffle the operands around so the lane index operand is in the
6852 // right place.
6853 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006854 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006855 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6856 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6857 Spacing));
6858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006859 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006860 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6861 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6862 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6863 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6864 Spacing));
6865 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006866 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006867 TmpInst.addOperand(Inst.getOperand(1)); // lane
6868 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6869 TmpInst.addOperand(Inst.getOperand(5));
6870 Inst = TmpInst;
6871 return true;
6872 }
6873
Jim Grosbach14952a02012-01-24 18:37:25 +00006874 case ARM::VLD4LNdAsm_8:
6875 case ARM::VLD4LNdAsm_16:
6876 case ARM::VLD4LNdAsm_32:
6877 case ARM::VLD4LNqAsm_16:
6878 case ARM::VLD4LNqAsm_32: {
6879 MCInst TmpInst;
6880 // Shuffle the operands around so the lane index operand is in the
6881 // right place.
6882 unsigned Spacing;
6883 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6884 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6885 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6886 Spacing));
6887 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6888 Spacing * 2));
6889 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6890 Spacing * 3));
6891 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6892 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6893 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6894 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6895 Spacing));
6896 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6897 Spacing * 2));
6898 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6899 Spacing * 3));
6900 TmpInst.addOperand(Inst.getOperand(1)); // lane
6901 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6902 TmpInst.addOperand(Inst.getOperand(5));
6903 Inst = TmpInst;
6904 return true;
6905 }
6906
Jim Grosbachb78403c2012-01-24 23:47:04 +00006907 // VLD3DUP single 3-element structure to all lanes instructions.
6908 case ARM::VLD3DUPdAsm_8:
6909 case ARM::VLD3DUPdAsm_16:
6910 case ARM::VLD3DUPdAsm_32:
6911 case ARM::VLD3DUPqAsm_8:
6912 case ARM::VLD3DUPqAsm_16:
6913 case ARM::VLD3DUPqAsm_32: {
6914 MCInst TmpInst;
6915 unsigned Spacing;
6916 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6917 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6918 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6919 Spacing));
6920 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6921 Spacing * 2));
6922 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6923 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6924 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6925 TmpInst.addOperand(Inst.getOperand(4));
6926 Inst = TmpInst;
6927 return true;
6928 }
6929
6930 case ARM::VLD3DUPdWB_fixed_Asm_8:
6931 case ARM::VLD3DUPdWB_fixed_Asm_16:
6932 case ARM::VLD3DUPdWB_fixed_Asm_32:
6933 case ARM::VLD3DUPqWB_fixed_Asm_8:
6934 case ARM::VLD3DUPqWB_fixed_Asm_16:
6935 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6936 MCInst TmpInst;
6937 unsigned Spacing;
6938 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6939 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6940 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6941 Spacing));
6942 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6943 Spacing * 2));
6944 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6945 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6946 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6947 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6948 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6949 TmpInst.addOperand(Inst.getOperand(4));
6950 Inst = TmpInst;
6951 return true;
6952 }
6953
6954 case ARM::VLD3DUPdWB_register_Asm_8:
6955 case ARM::VLD3DUPdWB_register_Asm_16:
6956 case ARM::VLD3DUPdWB_register_Asm_32:
6957 case ARM::VLD3DUPqWB_register_Asm_8:
6958 case ARM::VLD3DUPqWB_register_Asm_16:
6959 case ARM::VLD3DUPqWB_register_Asm_32: {
6960 MCInst TmpInst;
6961 unsigned Spacing;
6962 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6963 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6964 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6965 Spacing));
6966 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6967 Spacing * 2));
6968 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6969 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6970 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6971 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6972 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6973 TmpInst.addOperand(Inst.getOperand(5));
6974 Inst = TmpInst;
6975 return true;
6976 }
6977
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006978 // VLD3 multiple 3-element structure instructions.
6979 case ARM::VLD3dAsm_8:
6980 case ARM::VLD3dAsm_16:
6981 case ARM::VLD3dAsm_32:
6982 case ARM::VLD3qAsm_8:
6983 case ARM::VLD3qAsm_16:
6984 case ARM::VLD3qAsm_32: {
6985 MCInst TmpInst;
6986 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006987 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006988 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6989 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6990 Spacing));
6991 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6992 Spacing * 2));
6993 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6994 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6995 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6996 TmpInst.addOperand(Inst.getOperand(4));
6997 Inst = TmpInst;
6998 return true;
6999 }
7000
7001 case ARM::VLD3dWB_fixed_Asm_8:
7002 case ARM::VLD3dWB_fixed_Asm_16:
7003 case ARM::VLD3dWB_fixed_Asm_32:
7004 case ARM::VLD3qWB_fixed_Asm_8:
7005 case ARM::VLD3qWB_fixed_Asm_16:
7006 case ARM::VLD3qWB_fixed_Asm_32: {
7007 MCInst TmpInst;
7008 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007009 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007010 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7011 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7012 Spacing));
7013 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7014 Spacing * 2));
7015 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7016 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7017 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7018 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7019 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7020 TmpInst.addOperand(Inst.getOperand(4));
7021 Inst = TmpInst;
7022 return true;
7023 }
7024
7025 case ARM::VLD3dWB_register_Asm_8:
7026 case ARM::VLD3dWB_register_Asm_16:
7027 case ARM::VLD3dWB_register_Asm_32:
7028 case ARM::VLD3qWB_register_Asm_8:
7029 case ARM::VLD3qWB_register_Asm_16:
7030 case ARM::VLD3qWB_register_Asm_32: {
7031 MCInst TmpInst;
7032 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007033 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007034 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7035 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7036 Spacing));
7037 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7038 Spacing * 2));
7039 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7040 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7041 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7042 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7043 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7044 TmpInst.addOperand(Inst.getOperand(5));
7045 Inst = TmpInst;
7046 return true;
7047 }
7048
Jim Grosbach086cbfa2012-01-25 00:01:08 +00007049 // VLD4DUP single 3-element structure to all lanes instructions.
7050 case ARM::VLD4DUPdAsm_8:
7051 case ARM::VLD4DUPdAsm_16:
7052 case ARM::VLD4DUPdAsm_32:
7053 case ARM::VLD4DUPqAsm_8:
7054 case ARM::VLD4DUPqAsm_16:
7055 case ARM::VLD4DUPqAsm_32: {
7056 MCInst TmpInst;
7057 unsigned Spacing;
7058 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7059 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7060 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7061 Spacing));
7062 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7063 Spacing * 2));
7064 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7065 Spacing * 3));
7066 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7067 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7068 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7069 TmpInst.addOperand(Inst.getOperand(4));
7070 Inst = TmpInst;
7071 return true;
7072 }
7073
7074 case ARM::VLD4DUPdWB_fixed_Asm_8:
7075 case ARM::VLD4DUPdWB_fixed_Asm_16:
7076 case ARM::VLD4DUPdWB_fixed_Asm_32:
7077 case ARM::VLD4DUPqWB_fixed_Asm_8:
7078 case ARM::VLD4DUPqWB_fixed_Asm_16:
7079 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7080 MCInst TmpInst;
7081 unsigned Spacing;
7082 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7083 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7084 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7085 Spacing));
7086 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7087 Spacing * 2));
7088 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7089 Spacing * 3));
7090 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7091 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7092 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7093 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7094 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7095 TmpInst.addOperand(Inst.getOperand(4));
7096 Inst = TmpInst;
7097 return true;
7098 }
7099
7100 case ARM::VLD4DUPdWB_register_Asm_8:
7101 case ARM::VLD4DUPdWB_register_Asm_16:
7102 case ARM::VLD4DUPdWB_register_Asm_32:
7103 case ARM::VLD4DUPqWB_register_Asm_8:
7104 case ARM::VLD4DUPqWB_register_Asm_16:
7105 case ARM::VLD4DUPqWB_register_Asm_32: {
7106 MCInst TmpInst;
7107 unsigned Spacing;
7108 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7109 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7110 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7111 Spacing));
7112 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7113 Spacing * 2));
7114 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7115 Spacing * 3));
7116 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7117 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7118 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7119 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7120 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7121 TmpInst.addOperand(Inst.getOperand(5));
7122 Inst = TmpInst;
7123 return true;
7124 }
7125
7126 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00007127 case ARM::VLD4dAsm_8:
7128 case ARM::VLD4dAsm_16:
7129 case ARM::VLD4dAsm_32:
7130 case ARM::VLD4qAsm_8:
7131 case ARM::VLD4qAsm_16:
7132 case ARM::VLD4qAsm_32: {
7133 MCInst TmpInst;
7134 unsigned Spacing;
7135 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7136 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7137 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7138 Spacing));
7139 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7140 Spacing * 2));
7141 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7142 Spacing * 3));
7143 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7144 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7145 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7146 TmpInst.addOperand(Inst.getOperand(4));
7147 Inst = TmpInst;
7148 return true;
7149 }
7150
7151 case ARM::VLD4dWB_fixed_Asm_8:
7152 case ARM::VLD4dWB_fixed_Asm_16:
7153 case ARM::VLD4dWB_fixed_Asm_32:
7154 case ARM::VLD4qWB_fixed_Asm_8:
7155 case ARM::VLD4qWB_fixed_Asm_16:
7156 case ARM::VLD4qWB_fixed_Asm_32: {
7157 MCInst TmpInst;
7158 unsigned Spacing;
7159 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7160 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7161 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7162 Spacing));
7163 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7164 Spacing * 2));
7165 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7166 Spacing * 3));
7167 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7168 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7169 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7170 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7171 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7172 TmpInst.addOperand(Inst.getOperand(4));
7173 Inst = TmpInst;
7174 return true;
7175 }
7176
7177 case ARM::VLD4dWB_register_Asm_8:
7178 case ARM::VLD4dWB_register_Asm_16:
7179 case ARM::VLD4dWB_register_Asm_32:
7180 case ARM::VLD4qWB_register_Asm_8:
7181 case ARM::VLD4qWB_register_Asm_16:
7182 case ARM::VLD4qWB_register_Asm_32: {
7183 MCInst TmpInst;
7184 unsigned Spacing;
7185 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7186 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7187 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7188 Spacing));
7189 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7190 Spacing * 2));
7191 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7192 Spacing * 3));
7193 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7194 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7195 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7196 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7197 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7198 TmpInst.addOperand(Inst.getOperand(5));
7199 Inst = TmpInst;
7200 return true;
7201 }
7202
Jim Grosbach1a747242012-01-23 23:45:44 +00007203 // VST3 multiple 3-element structure instructions.
7204 case ARM::VST3dAsm_8:
7205 case ARM::VST3dAsm_16:
7206 case ARM::VST3dAsm_32:
7207 case ARM::VST3qAsm_8:
7208 case ARM::VST3qAsm_16:
7209 case ARM::VST3qAsm_32: {
7210 MCInst TmpInst;
7211 unsigned Spacing;
7212 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7213 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7214 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7215 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7216 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7217 Spacing));
7218 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7219 Spacing * 2));
7220 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7221 TmpInst.addOperand(Inst.getOperand(4));
7222 Inst = TmpInst;
7223 return true;
7224 }
7225
7226 case ARM::VST3dWB_fixed_Asm_8:
7227 case ARM::VST3dWB_fixed_Asm_16:
7228 case ARM::VST3dWB_fixed_Asm_32:
7229 case ARM::VST3qWB_fixed_Asm_8:
7230 case ARM::VST3qWB_fixed_Asm_16:
7231 case ARM::VST3qWB_fixed_Asm_32: {
7232 MCInst TmpInst;
7233 unsigned Spacing;
7234 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7235 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7236 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7237 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7238 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7239 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7240 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7241 Spacing));
7242 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7243 Spacing * 2));
7244 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7245 TmpInst.addOperand(Inst.getOperand(4));
7246 Inst = TmpInst;
7247 return true;
7248 }
7249
7250 case ARM::VST3dWB_register_Asm_8:
7251 case ARM::VST3dWB_register_Asm_16:
7252 case ARM::VST3dWB_register_Asm_32:
7253 case ARM::VST3qWB_register_Asm_8:
7254 case ARM::VST3qWB_register_Asm_16:
7255 case ARM::VST3qWB_register_Asm_32: {
7256 MCInst TmpInst;
7257 unsigned Spacing;
7258 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7259 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7260 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7261 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7262 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7263 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7264 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7265 Spacing));
7266 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7267 Spacing * 2));
7268 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7269 TmpInst.addOperand(Inst.getOperand(5));
7270 Inst = TmpInst;
7271 return true;
7272 }
7273
Jim Grosbachda70eac2012-01-24 00:58:13 +00007274 // VST4 multiple 3-element structure instructions.
7275 case ARM::VST4dAsm_8:
7276 case ARM::VST4dAsm_16:
7277 case ARM::VST4dAsm_32:
7278 case ARM::VST4qAsm_8:
7279 case ARM::VST4qAsm_16:
7280 case ARM::VST4qAsm_32: {
7281 MCInst TmpInst;
7282 unsigned Spacing;
7283 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7284 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7285 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7286 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7287 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7288 Spacing));
7289 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7290 Spacing * 2));
7291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7292 Spacing * 3));
7293 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7294 TmpInst.addOperand(Inst.getOperand(4));
7295 Inst = TmpInst;
7296 return true;
7297 }
7298
7299 case ARM::VST4dWB_fixed_Asm_8:
7300 case ARM::VST4dWB_fixed_Asm_16:
7301 case ARM::VST4dWB_fixed_Asm_32:
7302 case ARM::VST4qWB_fixed_Asm_8:
7303 case ARM::VST4qWB_fixed_Asm_16:
7304 case ARM::VST4qWB_fixed_Asm_32: {
7305 MCInst TmpInst;
7306 unsigned Spacing;
7307 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7308 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7309 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7310 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7311 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7312 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7313 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7314 Spacing));
7315 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7316 Spacing * 2));
7317 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7318 Spacing * 3));
7319 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7320 TmpInst.addOperand(Inst.getOperand(4));
7321 Inst = TmpInst;
7322 return true;
7323 }
7324
7325 case ARM::VST4dWB_register_Asm_8:
7326 case ARM::VST4dWB_register_Asm_16:
7327 case ARM::VST4dWB_register_Asm_32:
7328 case ARM::VST4qWB_register_Asm_8:
7329 case ARM::VST4qWB_register_Asm_16:
7330 case ARM::VST4qWB_register_Asm_32: {
7331 MCInst TmpInst;
7332 unsigned Spacing;
7333 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7334 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7335 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7336 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7337 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7338 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7339 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7340 Spacing));
7341 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7342 Spacing * 2));
7343 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7344 Spacing * 3));
7345 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7346 TmpInst.addOperand(Inst.getOperand(5));
7347 Inst = TmpInst;
7348 return true;
7349 }
7350
Jim Grosbachad66de12012-04-11 00:15:16 +00007351 // Handle encoding choice for the shift-immediate instructions.
7352 case ARM::t2LSLri:
7353 case ARM::t2LSRri:
7354 case ARM::t2ASRri: {
7355 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7356 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7357 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7358 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
7359 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
7360 unsigned NewOpc;
7361 switch (Inst.getOpcode()) {
7362 default: llvm_unreachable("unexpected opcode");
7363 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7364 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7365 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7366 }
7367 // The Thumb1 operands aren't in the same order. Awesome, eh?
7368 MCInst TmpInst;
7369 TmpInst.setOpcode(NewOpc);
7370 TmpInst.addOperand(Inst.getOperand(0));
7371 TmpInst.addOperand(Inst.getOperand(5));
7372 TmpInst.addOperand(Inst.getOperand(1));
7373 TmpInst.addOperand(Inst.getOperand(2));
7374 TmpInst.addOperand(Inst.getOperand(3));
7375 TmpInst.addOperand(Inst.getOperand(4));
7376 Inst = TmpInst;
7377 return true;
7378 }
7379 return false;
7380 }
7381
Jim Grosbach485e5622011-12-13 22:45:11 +00007382 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007383 case ARM::t2MOVsr:
7384 case ARM::t2MOVSsr: {
7385 // Which instruction to expand to depends on the CCOut operand and
7386 // whether we're in an IT block if the register operands are low
7387 // registers.
7388 bool isNarrow = false;
7389 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7390 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7391 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7392 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7393 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7394 isNarrow = true;
7395 MCInst TmpInst;
7396 unsigned newOpc;
7397 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7398 default: llvm_unreachable("unexpected opcode!");
7399 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7400 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7401 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7402 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7403 }
7404 TmpInst.setOpcode(newOpc);
7405 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7406 if (isNarrow)
7407 TmpInst.addOperand(MCOperand::CreateReg(
7408 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7409 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7410 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7411 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7412 TmpInst.addOperand(Inst.getOperand(5));
7413 if (!isNarrow)
7414 TmpInst.addOperand(MCOperand::CreateReg(
7415 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7416 Inst = TmpInst;
7417 return true;
7418 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007419 case ARM::t2MOVsi:
7420 case ARM::t2MOVSsi: {
7421 // Which instruction to expand to depends on the CCOut operand and
7422 // whether we're in an IT block if the register operands are low
7423 // registers.
7424 bool isNarrow = false;
7425 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7426 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7427 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7428 isNarrow = true;
7429 MCInst TmpInst;
7430 unsigned newOpc;
7431 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7432 default: llvm_unreachable("unexpected opcode!");
7433 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7434 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7435 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7436 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007437 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007438 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007439 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7440 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007441 TmpInst.setOpcode(newOpc);
7442 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7443 if (isNarrow)
7444 TmpInst.addOperand(MCOperand::CreateReg(
7445 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7446 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007447 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007448 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007449 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7450 TmpInst.addOperand(Inst.getOperand(4));
7451 if (!isNarrow)
7452 TmpInst.addOperand(MCOperand::CreateReg(
7453 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7454 Inst = TmpInst;
7455 return true;
7456 }
7457 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007458 case ARM::ASRr:
7459 case ARM::LSRr:
7460 case ARM::LSLr:
7461 case ARM::RORr: {
7462 ARM_AM::ShiftOpc ShiftTy;
7463 switch(Inst.getOpcode()) {
7464 default: llvm_unreachable("unexpected opcode!");
7465 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7466 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7467 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7468 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7469 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007470 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7471 MCInst TmpInst;
7472 TmpInst.setOpcode(ARM::MOVsr);
7473 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7474 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7475 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7476 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7477 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7478 TmpInst.addOperand(Inst.getOperand(4));
7479 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7480 Inst = TmpInst;
7481 return true;
7482 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007483 case ARM::ASRi:
7484 case ARM::LSRi:
7485 case ARM::LSLi:
7486 case ARM::RORi: {
7487 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007488 switch(Inst.getOpcode()) {
7489 default: llvm_unreachable("unexpected opcode!");
7490 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7491 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7492 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7493 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7494 }
7495 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007496 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007497 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007498 // A shift by 32 should be encoded as 0 when permitted
7499 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7500 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007501 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007502 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007503 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007504 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7505 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007506 if (Opc == ARM::MOVsi)
7507 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007508 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7509 TmpInst.addOperand(Inst.getOperand(4));
7510 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7511 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007512 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007513 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007514 case ARM::RRXi: {
7515 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7516 MCInst TmpInst;
7517 TmpInst.setOpcode(ARM::MOVsi);
7518 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7519 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7520 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7521 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7522 TmpInst.addOperand(Inst.getOperand(3));
7523 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7524 Inst = TmpInst;
7525 return true;
7526 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007527 case ARM::t2LDMIA_UPD: {
7528 // If this is a load of a single register, then we should use
7529 // a post-indexed LDR instruction instead, per the ARM ARM.
7530 if (Inst.getNumOperands() != 5)
7531 return false;
7532 MCInst TmpInst;
7533 TmpInst.setOpcode(ARM::t2LDR_POST);
7534 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7535 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7536 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7537 TmpInst.addOperand(MCOperand::CreateImm(4));
7538 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7539 TmpInst.addOperand(Inst.getOperand(3));
7540 Inst = TmpInst;
7541 return true;
7542 }
7543 case ARM::t2STMDB_UPD: {
7544 // If this is a store of a single register, then we should use
7545 // a pre-indexed STR instruction instead, per the ARM ARM.
7546 if (Inst.getNumOperands() != 5)
7547 return false;
7548 MCInst TmpInst;
7549 TmpInst.setOpcode(ARM::t2STR_PRE);
7550 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7551 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7552 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7553 TmpInst.addOperand(MCOperand::CreateImm(-4));
7554 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7555 TmpInst.addOperand(Inst.getOperand(3));
7556 Inst = TmpInst;
7557 return true;
7558 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007559 case ARM::LDMIA_UPD:
7560 // If this is a load of a single register via a 'pop', then we should use
7561 // a post-indexed LDR instruction instead, per the ARM ARM.
7562 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7563 Inst.getNumOperands() == 5) {
7564 MCInst TmpInst;
7565 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7566 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7567 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7568 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7569 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7570 TmpInst.addOperand(MCOperand::CreateImm(4));
7571 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7572 TmpInst.addOperand(Inst.getOperand(3));
7573 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007574 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007575 }
7576 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007577 case ARM::STMDB_UPD:
7578 // If this is a store of a single register via a 'push', then we should use
7579 // a pre-indexed STR instruction instead, per the ARM ARM.
7580 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7581 Inst.getNumOperands() == 5) {
7582 MCInst TmpInst;
7583 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7584 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7585 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7586 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7587 TmpInst.addOperand(MCOperand::CreateImm(-4));
7588 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7589 TmpInst.addOperand(Inst.getOperand(3));
7590 Inst = TmpInst;
7591 }
7592 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007593 case ARM::t2ADDri12:
7594 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7595 // mnemonic was used (not "addw"), encoding T3 is preferred.
7596 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7597 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7598 break;
7599 Inst.setOpcode(ARM::t2ADDri);
7600 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7601 break;
7602 case ARM::t2SUBri12:
7603 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7604 // mnemonic was used (not "subw"), encoding T3 is preferred.
7605 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7606 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7607 break;
7608 Inst.setOpcode(ARM::t2SUBri);
7609 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7610 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007611 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007612 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007613 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7614 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7615 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007616 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007617 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007618 return true;
7619 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007620 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007621 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007622 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007623 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7624 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7625 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007626 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007627 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007628 return true;
7629 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007630 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007631 case ARM::t2ADDri:
7632 case ARM::t2SUBri: {
7633 // If the destination and first source operand are the same, and
7634 // the flags are compatible with the current IT status, use encoding T2
7635 // instead of T3. For compatibility with the system 'as'. Make sure the
7636 // wide encoding wasn't explicit.
7637 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007638 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007639 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7640 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7641 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7642 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7643 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7644 break;
7645 MCInst TmpInst;
7646 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7647 ARM::tADDi8 : ARM::tSUBi8);
7648 TmpInst.addOperand(Inst.getOperand(0));
7649 TmpInst.addOperand(Inst.getOperand(5));
7650 TmpInst.addOperand(Inst.getOperand(0));
7651 TmpInst.addOperand(Inst.getOperand(2));
7652 TmpInst.addOperand(Inst.getOperand(3));
7653 TmpInst.addOperand(Inst.getOperand(4));
7654 Inst = TmpInst;
7655 return true;
7656 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007657 case ARM::t2ADDrr: {
7658 // If the destination and first source operand are the same, and
7659 // there's no setting of the flags, use encoding T2 instead of T3.
7660 // Note that this is only for ADD, not SUB. This mirrors the system
7661 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7662 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7663 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007664 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7665 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007666 break;
7667 MCInst TmpInst;
7668 TmpInst.setOpcode(ARM::tADDhirr);
7669 TmpInst.addOperand(Inst.getOperand(0));
7670 TmpInst.addOperand(Inst.getOperand(0));
7671 TmpInst.addOperand(Inst.getOperand(2));
7672 TmpInst.addOperand(Inst.getOperand(3));
7673 TmpInst.addOperand(Inst.getOperand(4));
7674 Inst = TmpInst;
7675 return true;
7676 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007677 case ARM::tADDrSP: {
7678 // If the non-SP source operand and the destination operand are not the
7679 // same, we need to use the 32-bit encoding if it's available.
7680 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7681 Inst.setOpcode(ARM::t2ADDrr);
7682 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7683 return true;
7684 }
7685 break;
7686 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007687 case ARM::tB:
7688 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007689 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007690 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007691 return true;
7692 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007693 break;
7694 case ARM::t2B:
7695 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007696 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007697 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007698 return true;
7699 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007700 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007701 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007702 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007703 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007704 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007705 return true;
7706 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007707 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007708 case ARM::tBcc:
7709 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007710 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007711 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007712 return true;
7713 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007714 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007715 case ARM::tLDMIA: {
7716 // If the register list contains any high registers, or if the writeback
7717 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7718 // instead if we're in Thumb2. Otherwise, this should have generated
7719 // an error in validateInstruction().
7720 unsigned Rn = Inst.getOperand(0).getReg();
7721 bool hasWritebackToken =
7722 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7723 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7724 bool listContainsBase;
7725 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7726 (!listContainsBase && !hasWritebackToken) ||
7727 (listContainsBase && hasWritebackToken)) {
7728 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7729 assert (isThumbTwo());
7730 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7731 // If we're switching to the updating version, we need to insert
7732 // the writeback tied operand.
7733 if (hasWritebackToken)
7734 Inst.insert(Inst.begin(),
7735 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007736 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007737 }
7738 break;
7739 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007740 case ARM::tSTMIA_UPD: {
7741 // If the register list contains any high registers, we need to use
7742 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7743 // should have generated an error in validateInstruction().
7744 unsigned Rn = Inst.getOperand(0).getReg();
7745 bool listContainsBase;
7746 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7747 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7748 assert (isThumbTwo());
7749 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007750 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007751 }
7752 break;
7753 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007754 case ARM::tPOP: {
7755 bool listContainsBase;
7756 // If the register list contains any high registers, we need to use
7757 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7758 // should have generated an error in validateInstruction().
7759 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007760 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007761 assert (isThumbTwo());
7762 Inst.setOpcode(ARM::t2LDMIA_UPD);
7763 // Add the base register and writeback operands.
7764 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7765 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007766 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007767 }
7768 case ARM::tPUSH: {
7769 bool listContainsBase;
7770 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007771 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007772 assert (isThumbTwo());
7773 Inst.setOpcode(ARM::t2STMDB_UPD);
7774 // Add the base register and writeback operands.
7775 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7776 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007777 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007778 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007779 case ARM::t2MOVi: {
7780 // If we can use the 16-bit encoding and the user didn't explicitly
7781 // request the 32-bit variant, transform it here.
7782 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007783 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007784 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7785 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7786 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007787 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7788 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7789 // The operands aren't in the same order for tMOVi8...
7790 MCInst TmpInst;
7791 TmpInst.setOpcode(ARM::tMOVi8);
7792 TmpInst.addOperand(Inst.getOperand(0));
7793 TmpInst.addOperand(Inst.getOperand(4));
7794 TmpInst.addOperand(Inst.getOperand(1));
7795 TmpInst.addOperand(Inst.getOperand(2));
7796 TmpInst.addOperand(Inst.getOperand(3));
7797 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007798 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007799 }
7800 break;
7801 }
7802 case ARM::t2MOVr: {
7803 // If we can use the 16-bit encoding and the user didn't explicitly
7804 // request the 32-bit variant, transform it here.
7805 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7806 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7807 Inst.getOperand(2).getImm() == ARMCC::AL &&
7808 Inst.getOperand(4).getReg() == ARM::CPSR &&
7809 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7810 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7811 // The operands aren't the same for tMOV[S]r... (no cc_out)
7812 MCInst TmpInst;
7813 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7814 TmpInst.addOperand(Inst.getOperand(0));
7815 TmpInst.addOperand(Inst.getOperand(1));
7816 TmpInst.addOperand(Inst.getOperand(2));
7817 TmpInst.addOperand(Inst.getOperand(3));
7818 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007819 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007820 }
7821 break;
7822 }
Jim Grosbach82213192011-09-19 20:29:33 +00007823 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007824 case ARM::t2SXTB:
7825 case ARM::t2UXTH:
7826 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007827 // If we can use the 16-bit encoding and the user didn't explicitly
7828 // request the 32-bit variant, transform it here.
7829 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7830 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7831 Inst.getOperand(2).getImm() == 0 &&
7832 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7833 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007834 unsigned NewOpc;
7835 switch (Inst.getOpcode()) {
7836 default: llvm_unreachable("Illegal opcode!");
7837 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7838 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7839 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7840 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7841 }
Jim Grosbach82213192011-09-19 20:29:33 +00007842 // The operands aren't the same for thumb1 (no rotate operand).
7843 MCInst TmpInst;
7844 TmpInst.setOpcode(NewOpc);
7845 TmpInst.addOperand(Inst.getOperand(0));
7846 TmpInst.addOperand(Inst.getOperand(1));
7847 TmpInst.addOperand(Inst.getOperand(3));
7848 TmpInst.addOperand(Inst.getOperand(4));
7849 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007850 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007851 }
7852 break;
7853 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007854 case ARM::MOVsi: {
7855 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007856 // rrx shifts and asr/lsr of #32 is encoded as 0
7857 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7858 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007859 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7860 // Shifting by zero is accepted as a vanilla 'MOVr'
7861 MCInst TmpInst;
7862 TmpInst.setOpcode(ARM::MOVr);
7863 TmpInst.addOperand(Inst.getOperand(0));
7864 TmpInst.addOperand(Inst.getOperand(1));
7865 TmpInst.addOperand(Inst.getOperand(3));
7866 TmpInst.addOperand(Inst.getOperand(4));
7867 TmpInst.addOperand(Inst.getOperand(5));
7868 Inst = TmpInst;
7869 return true;
7870 }
7871 return false;
7872 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007873 case ARM::ANDrsi:
7874 case ARM::ORRrsi:
7875 case ARM::EORrsi:
7876 case ARM::BICrsi:
7877 case ARM::SUBrsi:
7878 case ARM::ADDrsi: {
7879 unsigned newOpc;
7880 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7881 if (SOpc == ARM_AM::rrx) return false;
7882 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007883 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007884 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7885 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7886 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7887 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7888 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7889 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7890 }
7891 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007892 // The exception is for right shifts, where 0 == 32
7893 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7894 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007895 MCInst TmpInst;
7896 TmpInst.setOpcode(newOpc);
7897 TmpInst.addOperand(Inst.getOperand(0));
7898 TmpInst.addOperand(Inst.getOperand(1));
7899 TmpInst.addOperand(Inst.getOperand(2));
7900 TmpInst.addOperand(Inst.getOperand(4));
7901 TmpInst.addOperand(Inst.getOperand(5));
7902 TmpInst.addOperand(Inst.getOperand(6));
7903 Inst = TmpInst;
7904 return true;
7905 }
7906 return false;
7907 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007908 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007909 case ARM::t2IT: {
7910 // The mask bits for all but the first condition are represented as
7911 // the low bit of the condition code value implies 't'. We currently
7912 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007913 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007914 MCOperand &MO = Inst.getOperand(1);
7915 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007916 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007917 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007918 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007919 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007920 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007921 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007922 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007923
7924 // Set up the IT block state according to the IT instruction we just
7925 // matched.
7926 assert(!inITBlock() && "nested IT blocks?!");
7927 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7928 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7929 ITState.CurPosition = 0;
7930 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007931 break;
7932 }
Richard Bartona39625e2012-07-09 16:12:24 +00007933 case ARM::t2LSLrr:
7934 case ARM::t2LSRrr:
7935 case ARM::t2ASRrr:
7936 case ARM::t2SBCrr:
7937 case ARM::t2RORrr:
7938 case ARM::t2BICrr:
7939 {
Richard Bartond5660372012-07-09 16:14:28 +00007940 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007941 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7942 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7943 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007944 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7945 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007946 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7947 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7948 unsigned NewOpc;
7949 switch (Inst.getOpcode()) {
7950 default: llvm_unreachable("unexpected opcode");
7951 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7952 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7953 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7954 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7955 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7956 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7957 }
7958 MCInst TmpInst;
7959 TmpInst.setOpcode(NewOpc);
7960 TmpInst.addOperand(Inst.getOperand(0));
7961 TmpInst.addOperand(Inst.getOperand(5));
7962 TmpInst.addOperand(Inst.getOperand(1));
7963 TmpInst.addOperand(Inst.getOperand(2));
7964 TmpInst.addOperand(Inst.getOperand(3));
7965 TmpInst.addOperand(Inst.getOperand(4));
7966 Inst = TmpInst;
7967 return true;
7968 }
7969 return false;
7970 }
7971 case ARM::t2ANDrr:
7972 case ARM::t2EORrr:
7973 case ARM::t2ADCrr:
7974 case ARM::t2ORRrr:
7975 {
Richard Bartond5660372012-07-09 16:14:28 +00007976 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007977 // These instructions are special in that they are commutable, so shorter encodings
7978 // are available more often.
7979 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7980 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7981 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7982 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007983 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7984 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007985 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7986 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7987 unsigned NewOpc;
7988 switch (Inst.getOpcode()) {
7989 default: llvm_unreachable("unexpected opcode");
7990 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7991 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7992 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7993 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7994 }
7995 MCInst TmpInst;
7996 TmpInst.setOpcode(NewOpc);
7997 TmpInst.addOperand(Inst.getOperand(0));
7998 TmpInst.addOperand(Inst.getOperand(5));
7999 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
8000 TmpInst.addOperand(Inst.getOperand(1));
8001 TmpInst.addOperand(Inst.getOperand(2));
8002 } else {
8003 TmpInst.addOperand(Inst.getOperand(2));
8004 TmpInst.addOperand(Inst.getOperand(1));
8005 }
8006 TmpInst.addOperand(Inst.getOperand(3));
8007 TmpInst.addOperand(Inst.getOperand(4));
8008 Inst = TmpInst;
8009 return true;
8010 }
8011 return false;
8012 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008013 }
Jim Grosbachafad0532011-11-10 23:42:14 +00008014 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008015}
8016
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008017unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
8018 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
8019 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008020 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00008021 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008022 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
8023 assert(MCID.hasOptionalDef() &&
8024 "optionally flag setting instruction missing optional def operand");
8025 assert(MCID.NumOperands == Inst.getNumOperands() &&
8026 "operand count mismatch!");
8027 // Find the optional-def operand (cc_out).
8028 unsigned OpNo;
8029 for (OpNo = 0;
8030 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
8031 ++OpNo)
8032 ;
8033 // If we're parsing Thumb1, reject it completely.
8034 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
8035 return Match_MnemonicFail;
8036 // If we're parsing Thumb2, which form is legal depends on whether we're
8037 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00008038 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
8039 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008040 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00008041 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8042 inITBlock())
8043 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008044 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008045 // Some high-register supporting Thumb1 encodings only allow both registers
8046 // to be from r0-r7 when in Thumb2.
8047 else if (Opc == ARM::tADDhirr && isThumbOne() &&
8048 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8049 isARMLowRegister(Inst.getOperand(2).getReg()))
8050 return Match_RequiresThumb2;
8051 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00008052 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008053 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8054 isARMLowRegister(Inst.getOperand(1).getReg()))
8055 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008056 return Match_Success;
8057}
8058
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008059namespace llvm {
8060template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008061 return true; // In an assembly source, no need to second-guess
8062}
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008063}
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008064
Jim Grosbach5117ef72012-04-24 22:40:08 +00008065static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00008066bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00008067MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00008068 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00008069 MCStreamer &Out, unsigned &ErrorInfo,
8070 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00008071 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00008072 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00008073
Chad Rosier2f480a82012-10-12 22:53:36 +00008074 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00008075 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00008076 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00008077 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008078 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008079 // Context sensitive operand constraints aren't handled by the matcher,
8080 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008081 if (validateInstruction(Inst, Operands)) {
8082 // Still progress the IT block, otherwise one wrong condition causes
8083 // nasty cascading errors.
8084 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008085 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008086 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008087
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008088 { // processInstruction() updates inITBlock state, we need to save it away
8089 bool wasInITBlock = inITBlock();
8090
8091 // Some instructions need post-processing to, for example, tweak which
8092 // encoding is selected. Loop on it while changes happen so the
8093 // individual transformations can chain off each other. E.g.,
8094 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
8095 while (processInstruction(Inst, Operands))
8096 ;
8097
8098 // Only after the instruction is fully processed, we can validate it
8099 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00008100 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008101 Warning(IDLoc, "deprecated instruction in IT block");
8102 }
8103 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008104
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008105 // Only move forward at the very end so that everything in validate
8106 // and process gets a consistent answer about whether we're in an IT
8107 // block.
8108 forwardITPosition();
8109
Jim Grosbach82f76d12012-01-25 19:52:01 +00008110 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8111 // doesn't actually encode.
8112 if (Inst.getOpcode() == ARM::ITasm)
8113 return false;
8114
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00008115 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00008116 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00008117 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008118 case Match_MissingFeature: {
8119 assert(ErrorInfo && "Unknown missing feature!");
8120 // Special case the error message for the very common case where only
8121 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8122 std::string Msg = "instruction requires:";
8123 unsigned Mask = 1;
8124 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8125 if (ErrorInfo & Mask) {
8126 Msg += " ";
8127 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8128 }
8129 Mask <<= 1;
8130 }
8131 return Error(IDLoc, Msg);
8132 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008133 case Match_InvalidOperand: {
8134 SMLoc ErrorLoc = IDLoc;
8135 if (ErrorInfo != ~0U) {
8136 if (ErrorInfo >= Operands.size())
8137 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00008138
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008139 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
8140 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8141 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008142
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008143 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00008144 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008145 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00008146 return Error(IDLoc, "invalid instruction",
8147 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00008148 case Match_RequiresNotITBlock:
8149 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008150 case Match_RequiresITBlock:
8151 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008152 case Match_RequiresV6:
8153 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8154 case Match_RequiresThumb2:
8155 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00008156 case Match_ImmRange0_15: {
8157 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
8158 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8159 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8160 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008161 case Match_ImmRange0_239: {
8162 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
8163 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8164 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8165 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00008166 case Match_AlignedMemoryRequiresNone:
8167 case Match_DupAlignedMemoryRequiresNone:
8168 case Match_AlignedMemoryRequires16:
8169 case Match_DupAlignedMemoryRequires16:
8170 case Match_AlignedMemoryRequires32:
8171 case Match_DupAlignedMemoryRequires32:
8172 case Match_AlignedMemoryRequires64:
8173 case Match_DupAlignedMemoryRequires64:
8174 case Match_AlignedMemoryRequires64or128:
8175 case Match_DupAlignedMemoryRequires64or128:
8176 case Match_AlignedMemoryRequires64or128or256:
8177 {
8178 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getAlignmentLoc();
8179 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8180 switch (MatchResult) {
8181 default:
8182 llvm_unreachable("Missing Match_Aligned type");
8183 case Match_AlignedMemoryRequiresNone:
8184 case Match_DupAlignedMemoryRequiresNone:
8185 return Error(ErrorLoc, "alignment must be omitted");
8186 case Match_AlignedMemoryRequires16:
8187 case Match_DupAlignedMemoryRequires16:
8188 return Error(ErrorLoc, "alignment must be 16 or omitted");
8189 case Match_AlignedMemoryRequires32:
8190 case Match_DupAlignedMemoryRequires32:
8191 return Error(ErrorLoc, "alignment must be 32 or omitted");
8192 case Match_AlignedMemoryRequires64:
8193 case Match_DupAlignedMemoryRequires64:
8194 return Error(ErrorLoc, "alignment must be 64 or omitted");
8195 case Match_AlignedMemoryRequires64or128:
8196 case Match_DupAlignedMemoryRequires64or128:
8197 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8198 case Match_AlignedMemoryRequires64or128or256:
8199 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8200 }
8201 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008202 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008203
Eric Christopher91d7b902010-10-29 09:26:59 +00008204 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00008205}
8206
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008207/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00008208bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008209 const MCObjectFileInfo::Environment Format =
8210 getContext().getObjectFileInfo()->getObjectFileType();
8211 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
8212
Kevin Enderbyccab3172009-09-15 00:27:25 +00008213 StringRef IDVal = DirectiveID.getIdentifier();
8214 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008215 return parseLiteralValues(4, DirectiveID.getLoc());
8216 else if (IDVal == ".short" || IDVal == ".hword")
8217 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008218 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008219 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00008220 else if (IDVal == ".arm")
8221 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008222 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008223 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008224 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008225 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008226 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008227 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008228 else if (IDVal == ".unreq")
8229 return parseDirectiveUnreq(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00008230 else if (IDVal == ".fnend")
8231 return parseDirectiveFnEnd(DirectiveID.getLoc());
8232 else if (IDVal == ".cantunwind")
8233 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8234 else if (IDVal == ".personality")
8235 return parseDirectivePersonality(DirectiveID.getLoc());
8236 else if (IDVal == ".handlerdata")
8237 return parseDirectiveHandlerData(DirectiveID.getLoc());
8238 else if (IDVal == ".setfp")
8239 return parseDirectiveSetFP(DirectiveID.getLoc());
8240 else if (IDVal == ".pad")
8241 return parseDirectivePad(DirectiveID.getLoc());
8242 else if (IDVal == ".save")
8243 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8244 else if (IDVal == ".vsave")
8245 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008246 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008247 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008248 else if (IDVal == ".even")
8249 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008250 else if (IDVal == ".personalityindex")
8251 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008252 else if (IDVal == ".unwind_raw")
8253 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008254 else if (IDVal == ".movsp")
8255 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008256 else if (IDVal == ".arch_extension")
8257 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008258 else if (IDVal == ".align")
8259 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008260 else if (IDVal == ".thumb_set")
8261 return parseDirectiveThumbSet(DirectiveID.getLoc());
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008262
8263 if (!IsMachO) {
8264 if (IDVal == ".arch")
8265 return parseDirectiveArch(DirectiveID.getLoc());
8266 else if (IDVal == ".cpu")
8267 return parseDirectiveCPU(DirectiveID.getLoc());
8268 else if (IDVal == ".eabi_attribute")
8269 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8270 else if (IDVal == ".fpu")
8271 return parseDirectiveFPU(DirectiveID.getLoc());
8272 else if (IDVal == ".fnstart")
8273 return parseDirectiveFnStart(DirectiveID.getLoc());
8274 else if (IDVal == ".inst")
8275 return parseDirectiveInst(DirectiveID.getLoc());
8276 else if (IDVal == ".inst.n")
8277 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8278 else if (IDVal == ".inst.w")
8279 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8280 else if (IDVal == ".object_arch")
8281 return parseDirectiveObjectArch(DirectiveID.getLoc());
8282 else if (IDVal == ".tlsdescseq")
8283 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8284 }
8285
Kevin Enderbyccab3172009-09-15 00:27:25 +00008286 return true;
8287}
8288
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008289/// parseLiteralValues
8290/// ::= .hword expression [, expression]*
8291/// ::= .short expression [, expression]*
8292/// ::= .word expression [, expression]*
8293bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00008294 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8295 for (;;) {
8296 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008297 if (getParser().parseExpression(Value)) {
8298 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008299 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008300 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008301
Eric Christopherbf7bc492013-01-09 03:52:05 +00008302 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008303
8304 if (getLexer().is(AsmToken::EndOfStatement))
8305 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008306
Kevin Enderbyccab3172009-09-15 00:27:25 +00008307 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008308 if (getLexer().isNot(AsmToken::Comma)) {
8309 Error(L, "unexpected token in directive");
8310 return false;
8311 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008312 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008313 }
8314 }
8315
Sean Callanana83fd7d2010-01-19 20:27:46 +00008316 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008317 return false;
8318}
8319
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008320/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008321/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008322bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008323 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8324 Error(L, "unexpected token in directive");
8325 return false;
8326 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008327 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008328
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008329 if (!hasThumb()) {
8330 Error(L, "target does not support Thumb mode");
8331 return false;
8332 }
Tim Northovera2292d02013-06-10 23:20:58 +00008333
Jim Grosbach7f882392011-12-07 18:04:19 +00008334 if (!isThumb())
8335 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008336
Jim Grosbach7f882392011-12-07 18:04:19 +00008337 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8338 return false;
8339}
8340
8341/// parseDirectiveARM
8342/// ::= .arm
8343bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008344 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8345 Error(L, "unexpected token in directive");
8346 return false;
8347 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008348 Parser.Lex();
8349
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008350 if (!hasARM()) {
8351 Error(L, "target does not support ARM mode");
8352 return false;
8353 }
Tim Northovera2292d02013-06-10 23:20:58 +00008354
Jim Grosbach7f882392011-12-07 18:04:19 +00008355 if (isThumb())
8356 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008357
Jim Grosbach7f882392011-12-07 18:04:19 +00008358 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008359 return false;
8360}
8361
Tim Northover1744d0a2013-10-25 12:49:50 +00008362void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8363 if (NextSymbolIsThumb) {
8364 getParser().getStreamer().EmitThumbFunc(Symbol);
8365 NextSymbolIsThumb = false;
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008366 return;
8367 }
8368
8369 if (!isThumb())
8370 return;
8371
8372 const MCObjectFileInfo::Environment Format =
8373 getContext().getObjectFileInfo()->getObjectFileType();
8374 switch (Format) {
8375 case MCObjectFileInfo::IsCOFF: {
8376 const MCSymbolData &SD =
8377 getParser().getStreamer().getOrCreateSymbolData(Symbol);
8378 char Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
8379 if (SD.getFlags() & (Type << COFF::SF_TypeShift))
8380 getParser().getStreamer().EmitThumbFunc(Symbol);
8381 break;
8382 }
8383 case MCObjectFileInfo::IsELF: {
8384 const MCSymbolData &SD =
8385 getParser().getStreamer().getOrCreateSymbolData(Symbol);
8386 if (MCELF::GetType(SD) & (ELF::STT_FUNC << ELF_STT_Shift))
8387 getParser().getStreamer().EmitThumbFunc(Symbol);
8388 break;
8389 }
8390 case MCObjectFileInfo::IsMachO:
8391 break;
Tim Northover1744d0a2013-10-25 12:49:50 +00008392 }
8393}
8394
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008395/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008396/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008397bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00008398 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8399 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008400
Jim Grosbach1152cc02011-12-21 22:30:16 +00008401 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008402 // ELF doesn't
8403 if (isMachO) {
8404 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008405 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008406 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8407 Error(L, "unexpected token in .thumb_func directive");
8408 return false;
8409 }
8410
Tim Northover1744d0a2013-10-25 12:49:50 +00008411 MCSymbol *Func =
8412 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8413 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008414 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008415 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008416 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008417 }
8418
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008419 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8420 Error(L, "unexpected token in directive");
8421 return false;
8422 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008423
Tim Northover1744d0a2013-10-25 12:49:50 +00008424 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008425 return false;
8426}
8427
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008428/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008429/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008430bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008431 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008432 if (Tok.isNot(AsmToken::Identifier)) {
8433 Error(L, "unexpected token in .syntax directive");
8434 return false;
8435 }
8436
Benjamin Kramer92d89982010-07-14 22:38:02 +00008437 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008438 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008439 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008440 } else if (Mode == "divided" || Mode == "DIVIDED") {
8441 Error(L, "'.syntax divided' arm asssembly not supported");
8442 return false;
8443 } else {
8444 Error(L, "unrecognized syntax mode in .syntax directive");
8445 return false;
8446 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008447
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008448 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8449 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8450 return false;
8451 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008452 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008453
8454 // TODO tell the MC streamer the mode
8455 // getParser().getStreamer().Emit???();
8456 return false;
8457}
8458
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008459/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008460/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008461bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008462 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008463 if (Tok.isNot(AsmToken::Integer)) {
8464 Error(L, "unexpected token in .code directive");
8465 return false;
8466 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008467 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008468 if (Val != 16 && Val != 32) {
8469 Error(L, "invalid operand to .code directive");
8470 return false;
8471 }
8472 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008473
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008474 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8475 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8476 return false;
8477 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008478 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008479
Evan Cheng284b4672011-07-08 22:36:29 +00008480 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008481 if (!hasThumb()) {
8482 Error(L, "target does not support Thumb mode");
8483 return false;
8484 }
Tim Northovera2292d02013-06-10 23:20:58 +00008485
Jim Grosbachf471ac32011-09-06 18:46:23 +00008486 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008487 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008488 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008489 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008490 if (!hasARM()) {
8491 Error(L, "target does not support ARM mode");
8492 return false;
8493 }
Tim Northovera2292d02013-06-10 23:20:58 +00008494
Jim Grosbachf471ac32011-09-06 18:46:23 +00008495 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008496 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008497 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008498 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008499
Kevin Enderby146dcf22009-10-15 20:48:48 +00008500 return false;
8501}
8502
Jim Grosbachab5830e2011-12-14 02:16:11 +00008503/// parseDirectiveReq
8504/// ::= name .req registername
8505bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8506 Parser.Lex(); // Eat the '.req' token.
8507 unsigned Reg;
8508 SMLoc SRegLoc, ERegLoc;
8509 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008510 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008511 Error(SRegLoc, "register name expected");
8512 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008513 }
8514
8515 // Shouldn't be anything else.
8516 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008517 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008518 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8519 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008520 }
8521
8522 Parser.Lex(); // Consume the EndOfStatement
8523
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008524 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) {
8525 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8526 return false;
8527 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00008528
8529 return false;
8530}
8531
8532/// parseDirectiveUneq
8533/// ::= .unreq registername
8534bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8535 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008536 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008537 Error(L, "unexpected input in .unreq directive.");
8538 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008539 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00008540 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008541 Parser.Lex(); // Eat the identifier.
8542 return false;
8543}
8544
Jason W Kim135d2442011-12-20 17:38:12 +00008545/// parseDirectiveArch
8546/// ::= .arch token
8547bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00008548 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8549
8550 unsigned ID = StringSwitch<unsigned>(Arch)
8551#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8552 .Case(NAME, ARM::ID)
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +00008553#define ARM_ARCH_ALIAS(NAME, ID) \
8554 .Case(NAME, ARM::ID)
Logan Chien439e8f92013-12-11 17:16:25 +00008555#include "MCTargetDesc/ARMArchName.def"
8556 .Default(ARM::INVALID_ARCH);
8557
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008558 if (ID == ARM::INVALID_ARCH) {
8559 Error(L, "Unknown arch name");
8560 return false;
8561 }
Logan Chien439e8f92013-12-11 17:16:25 +00008562
8563 getTargetStreamer().emitArch(ID);
8564 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008565}
8566
8567/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008568/// ::= .eabi_attribute int, int [, "str"]
8569/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00008570bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008571 int64_t Tag;
8572 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008573 TagLoc = Parser.getTok().getLoc();
8574 if (Parser.getTok().is(AsmToken::Identifier)) {
8575 StringRef Name = Parser.getTok().getIdentifier();
8576 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
8577 if (Tag == -1) {
8578 Error(TagLoc, "attribute name not recognised: " + Name);
8579 Parser.eatToEndOfStatement();
8580 return false;
8581 }
8582 Parser.Lex();
8583 } else {
8584 const MCExpr *AttrExpr;
8585
8586 TagLoc = Parser.getTok().getLoc();
8587 if (Parser.parseExpression(AttrExpr)) {
8588 Parser.eatToEndOfStatement();
8589 return false;
8590 }
8591
8592 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
8593 if (!CE) {
8594 Error(TagLoc, "expected numeric constant");
8595 Parser.eatToEndOfStatement();
8596 return false;
8597 }
8598
8599 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008600 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008601
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008602 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008603 Error(Parser.getTok().getLoc(), "comma expected");
8604 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008605 return false;
8606 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008607 Parser.Lex(); // skip comma
8608
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008609 StringRef StringValue = "";
8610 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00008611
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008612 int64_t IntegerValue = 0;
8613 bool IsIntegerValue = false;
8614
8615 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
8616 IsStringValue = true;
8617 else if (Tag == ARMBuildAttrs::compatibility) {
8618 IsStringValue = true;
8619 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00008620 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008621 IsIntegerValue = true;
8622 else if (Tag % 2 == 1)
8623 IsStringValue = true;
8624 else
8625 llvm_unreachable("invalid tag type");
8626
8627 if (IsIntegerValue) {
8628 const MCExpr *ValueExpr;
8629 SMLoc ValueExprLoc = Parser.getTok().getLoc();
8630 if (Parser.parseExpression(ValueExpr)) {
8631 Parser.eatToEndOfStatement();
8632 return false;
8633 }
8634
8635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
8636 if (!CE) {
8637 Error(ValueExprLoc, "expected numeric constant");
8638 Parser.eatToEndOfStatement();
8639 return false;
8640 }
8641
8642 IntegerValue = CE->getValue();
8643 }
8644
8645 if (Tag == ARMBuildAttrs::compatibility) {
8646 if (Parser.getTok().isNot(AsmToken::Comma))
8647 IsStringValue = false;
8648 else
8649 Parser.Lex();
8650 }
8651
8652 if (IsStringValue) {
8653 if (Parser.getTok().isNot(AsmToken::String)) {
8654 Error(Parser.getTok().getLoc(), "bad string constant");
8655 Parser.eatToEndOfStatement();
8656 return false;
8657 }
8658
8659 StringValue = Parser.getTok().getStringContents();
8660 Parser.Lex();
8661 }
8662
8663 if (IsIntegerValue && IsStringValue) {
8664 assert(Tag == ARMBuildAttrs::compatibility);
8665 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
8666 } else if (IsIntegerValue)
8667 getTargetStreamer().emitAttribute(Tag, IntegerValue);
8668 else if (IsStringValue)
8669 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00008670 return false;
8671}
8672
8673/// parseDirectiveCPU
8674/// ::= .cpu str
8675bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8676 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8677 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8678 return false;
8679}
8680
8681/// parseDirectiveFPU
8682/// ::= .fpu str
8683bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8684 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8685
8686 unsigned ID = StringSwitch<unsigned>(FPU)
8687#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8688#include "ARMFPUName.def"
8689 .Default(ARM::INVALID_FPU);
8690
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008691 if (ID == ARM::INVALID_FPU) {
8692 Error(L, "Unknown FPU name");
8693 return false;
8694 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008695
8696 getTargetStreamer().emitFPU(ID);
8697 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008698}
8699
Logan Chien4ea23b52013-05-10 16:17:24 +00008700/// parseDirectiveFnStart
8701/// ::= .fnstart
8702bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008703 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008704 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008705 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008706 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008707 }
8708
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008709 // Reset the unwind directives parser state
8710 UC.reset();
8711
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008712 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008713
8714 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00008715 return false;
8716}
8717
8718/// parseDirectiveFnEnd
8719/// ::= .fnend
8720bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8721 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008722 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008723 Error(L, ".fnstart must precede .fnend directive");
8724 return false;
8725 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008726
8727 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008728 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008729
8730 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00008731 return false;
8732}
8733
8734/// parseDirectiveCantUnwind
8735/// ::= .cantunwind
8736bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008737 UC.recordCantUnwind(L);
8738
Logan Chien4ea23b52013-05-10 16:17:24 +00008739 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008740 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008741 Error(L, ".fnstart must precede .cantunwind directive");
8742 return false;
8743 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008744 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008745 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008746 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008747 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008748 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008749 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008750 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008751 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008752 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008753 }
8754
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008755 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00008756 return false;
8757}
8758
8759/// parseDirectivePersonality
8760/// ::= .personality name
8761bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008762 bool HasExistingPersonality = UC.hasPersonality();
8763
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008764 UC.recordPersonality(L);
8765
Logan Chien4ea23b52013-05-10 16:17:24 +00008766 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008767 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008768 Error(L, ".fnstart must precede .personality directive");
8769 return false;
8770 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008771 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008772 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008773 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008774 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008775 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008776 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008777 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008778 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008779 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008780 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008781 if (HasExistingPersonality) {
8782 Parser.eatToEndOfStatement();
8783 Error(L, "multiple personality directives");
8784 UC.emitPersonalityLocNotes();
8785 return false;
8786 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008787
8788 // Parse the name of the personality routine
8789 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8790 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008791 Error(L, "unexpected input in .personality directive.");
8792 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008793 }
8794 StringRef Name(Parser.getTok().getIdentifier());
8795 Parser.Lex();
8796
8797 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008798 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00008799 return false;
8800}
8801
8802/// parseDirectiveHandlerData
8803/// ::= .handlerdata
8804bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008805 UC.recordHandlerData(L);
8806
Logan Chien4ea23b52013-05-10 16:17:24 +00008807 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008808 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008809 Error(L, ".fnstart must precede .personality directive");
8810 return false;
8811 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008812 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008813 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008814 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008815 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008816 }
8817
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008818 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00008819 return false;
8820}
8821
8822/// parseDirectiveSetFP
8823/// ::= .setfp fpreg, spreg [, offset]
8824bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8825 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008826 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008827 Error(L, ".fnstart must precede .setfp directive");
8828 return false;
8829 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008830 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008831 Error(L, ".setfp must precede .handlerdata directive");
8832 return false;
8833 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008834
8835 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008836 SMLoc FPRegLoc = Parser.getTok().getLoc();
8837 int FPReg = tryParseRegister();
8838 if (FPReg == -1) {
8839 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008840 return false;
8841 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008842
8843 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008844 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008845 Error(Parser.getTok().getLoc(), "comma expected");
8846 return false;
8847 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008848 Parser.Lex(); // skip comma
8849
8850 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008851 SMLoc SPRegLoc = Parser.getTok().getLoc();
8852 int SPReg = tryParseRegister();
8853 if (SPReg == -1) {
8854 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008855 return false;
8856 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008857
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008858 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
8859 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008860 return false;
8861 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008862
8863 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008864 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00008865
8866 // Parse offset
8867 int64_t Offset = 0;
8868 if (Parser.getTok().is(AsmToken::Comma)) {
8869 Parser.Lex(); // skip comma
8870
8871 if (Parser.getTok().isNot(AsmToken::Hash) &&
8872 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008873 Error(Parser.getTok().getLoc(), "'#' expected");
8874 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008875 }
8876 Parser.Lex(); // skip hash token.
8877
8878 const MCExpr *OffsetExpr;
8879 SMLoc ExLoc = Parser.getTok().getLoc();
8880 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008881 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8882 Error(ExLoc, "malformed setfp offset");
8883 return false;
8884 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008885 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008886 if (!CE) {
8887 Error(ExLoc, "setfp offset must be an immediate");
8888 return false;
8889 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008890
8891 Offset = CE->getValue();
8892 }
8893
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008894 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
8895 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00008896 return false;
8897}
8898
8899/// parseDirective
8900/// ::= .pad offset
8901bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8902 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008903 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008904 Error(L, ".fnstart must precede .pad directive");
8905 return false;
8906 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008907 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008908 Error(L, ".pad must precede .handlerdata directive");
8909 return false;
8910 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008911
8912 // Parse the offset
8913 if (Parser.getTok().isNot(AsmToken::Hash) &&
8914 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008915 Error(Parser.getTok().getLoc(), "'#' expected");
8916 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008917 }
8918 Parser.Lex(); // skip hash token.
8919
8920 const MCExpr *OffsetExpr;
8921 SMLoc ExLoc = Parser.getTok().getLoc();
8922 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008923 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8924 Error(ExLoc, "malformed pad offset");
8925 return false;
8926 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008928 if (!CE) {
8929 Error(ExLoc, "pad offset must be an immediate");
8930 return false;
8931 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008932
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008933 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00008934 return false;
8935}
8936
8937/// parseDirectiveRegSave
8938/// ::= .save { registers }
8939/// ::= .vsave { registers }
8940bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8941 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008942 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008943 Error(L, ".fnstart must precede .save or .vsave directives");
8944 return false;
8945 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008946 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008947 Error(L, ".save or .vsave must precede .handlerdata directive");
8948 return false;
8949 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008950
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008951 // RAII object to make sure parsed operands are deleted.
8952 struct CleanupObject {
8953 SmallVector<MCParsedAsmOperand *, 1> Operands;
8954 ~CleanupObject() {
8955 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8956 delete Operands[I];
8957 }
8958 } CO;
8959
Logan Chien4ea23b52013-05-10 16:17:24 +00008960 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008961 if (parseRegisterList(CO.Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008962 return false;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008963 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008964 if (!IsVector && !Op->isRegList()) {
8965 Error(L, ".save expects GPR registers");
8966 return false;
8967 }
8968 if (IsVector && !Op->isDPRRegList()) {
8969 Error(L, ".vsave expects DPR registers");
8970 return false;
8971 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008972
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008973 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00008974 return false;
8975}
8976
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008977/// parseDirectiveInst
8978/// ::= .inst opcode [, ...]
8979/// ::= .inst.n opcode [, ...]
8980/// ::= .inst.w opcode [, ...]
8981bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8982 int Width;
8983
8984 if (isThumb()) {
8985 switch (Suffix) {
8986 case 'n':
8987 Width = 2;
8988 break;
8989 case 'w':
8990 Width = 4;
8991 break;
8992 default:
8993 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008994 Error(Loc, "cannot determine Thumb instruction size, "
8995 "use inst.n/inst.w instead");
8996 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008997 }
8998 } else {
8999 if (Suffix) {
9000 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009001 Error(Loc, "width suffixes are invalid in ARM mode");
9002 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009003 }
9004 Width = 4;
9005 }
9006
9007 if (getLexer().is(AsmToken::EndOfStatement)) {
9008 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009009 Error(Loc, "expected expression following directive");
9010 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009011 }
9012
9013 for (;;) {
9014 const MCExpr *Expr;
9015
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009016 if (getParser().parseExpression(Expr)) {
9017 Error(Loc, "expected expression");
9018 return false;
9019 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009020
9021 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009022 if (!Value) {
9023 Error(Loc, "expected constant expression");
9024 return false;
9025 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009026
9027 switch (Width) {
9028 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009029 if (Value->getValue() > 0xffff) {
9030 Error(Loc, "inst.n operand is too big, use inst.w instead");
9031 return false;
9032 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009033 break;
9034 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009035 if (Value->getValue() > 0xffffffff) {
9036 Error(Loc,
9037 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
9038 return false;
9039 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009040 break;
9041 default:
9042 llvm_unreachable("only supported widths are 2 and 4");
9043 }
9044
9045 getTargetStreamer().emitInst(Value->getValue(), Suffix);
9046
9047 if (getLexer().is(AsmToken::EndOfStatement))
9048 break;
9049
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009050 if (getLexer().isNot(AsmToken::Comma)) {
9051 Error(Loc, "unexpected token in directive");
9052 return false;
9053 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009054
9055 Parser.Lex();
9056 }
9057
9058 Parser.Lex();
9059 return false;
9060}
9061
David Peixotto80c083a2013-12-19 18:26:07 +00009062/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00009063/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00009064bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00009065 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00009066 return false;
9067}
9068
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009069bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9070 const MCSection *Section = getStreamer().getCurrentSection().first;
9071
9072 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9073 TokError("unexpected token in directive");
9074 return false;
9075 }
9076
9077 if (!Section) {
Rafael Espindolaf1440342014-01-23 23:14:14 +00009078 getStreamer().InitSections();
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009079 Section = getStreamer().getCurrentSection().first;
9080 }
9081
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00009082 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009083 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00009084 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009085 else
Rafael Espindola7b514962014-02-04 18:34:04 +00009086 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009087
9088 return false;
9089}
9090
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009091/// parseDirectivePersonalityIndex
9092/// ::= .personalityindex index
9093bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
9094 bool HasExistingPersonality = UC.hasPersonality();
9095
9096 UC.recordPersonalityIndex(L);
9097
9098 if (!UC.hasFnStart()) {
9099 Parser.eatToEndOfStatement();
9100 Error(L, ".fnstart must precede .personalityindex directive");
9101 return false;
9102 }
9103 if (UC.cantUnwind()) {
9104 Parser.eatToEndOfStatement();
9105 Error(L, ".personalityindex cannot be used with .cantunwind");
9106 UC.emitCantUnwindLocNotes();
9107 return false;
9108 }
9109 if (UC.hasHandlerData()) {
9110 Parser.eatToEndOfStatement();
9111 Error(L, ".personalityindex must precede .handlerdata directive");
9112 UC.emitHandlerDataLocNotes();
9113 return false;
9114 }
9115 if (HasExistingPersonality) {
9116 Parser.eatToEndOfStatement();
9117 Error(L, "multiple personality directives");
9118 UC.emitPersonalityLocNotes();
9119 return false;
9120 }
9121
9122 const MCExpr *IndexExpression;
9123 SMLoc IndexLoc = Parser.getTok().getLoc();
9124 if (Parser.parseExpression(IndexExpression)) {
9125 Parser.eatToEndOfStatement();
9126 return false;
9127 }
9128
9129 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9130 if (!CE) {
9131 Parser.eatToEndOfStatement();
9132 Error(IndexLoc, "index must be a constant number");
9133 return false;
9134 }
9135 if (CE->getValue() < 0 ||
9136 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9137 Parser.eatToEndOfStatement();
9138 Error(IndexLoc, "personality routine index should be in range [0-3]");
9139 return false;
9140 }
9141
9142 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9143 return false;
9144}
9145
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009146/// parseDirectiveUnwindRaw
9147/// ::= .unwind_raw offset, opcode [, opcode...]
9148bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
9149 if (!UC.hasFnStart()) {
9150 Parser.eatToEndOfStatement();
9151 Error(L, ".fnstart must precede .unwind_raw directives");
9152 return false;
9153 }
9154
9155 int64_t StackOffset;
9156
9157 const MCExpr *OffsetExpr;
9158 SMLoc OffsetLoc = getLexer().getLoc();
9159 if (getLexer().is(AsmToken::EndOfStatement) ||
9160 getParser().parseExpression(OffsetExpr)) {
9161 Error(OffsetLoc, "expected expression");
9162 Parser.eatToEndOfStatement();
9163 return false;
9164 }
9165
9166 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9167 if (!CE) {
9168 Error(OffsetLoc, "offset must be a constant");
9169 Parser.eatToEndOfStatement();
9170 return false;
9171 }
9172
9173 StackOffset = CE->getValue();
9174
9175 if (getLexer().isNot(AsmToken::Comma)) {
9176 Error(getLexer().getLoc(), "expected comma");
9177 Parser.eatToEndOfStatement();
9178 return false;
9179 }
9180 Parser.Lex();
9181
9182 SmallVector<uint8_t, 16> Opcodes;
9183 for (;;) {
9184 const MCExpr *OE;
9185
9186 SMLoc OpcodeLoc = getLexer().getLoc();
9187 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9188 Error(OpcodeLoc, "expected opcode expression");
9189 Parser.eatToEndOfStatement();
9190 return false;
9191 }
9192
9193 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9194 if (!OC) {
9195 Error(OpcodeLoc, "opcode value must be a constant");
9196 Parser.eatToEndOfStatement();
9197 return false;
9198 }
9199
9200 const int64_t Opcode = OC->getValue();
9201 if (Opcode & ~0xff) {
9202 Error(OpcodeLoc, "invalid opcode");
9203 Parser.eatToEndOfStatement();
9204 return false;
9205 }
9206
9207 Opcodes.push_back(uint8_t(Opcode));
9208
9209 if (getLexer().is(AsmToken::EndOfStatement))
9210 break;
9211
9212 if (getLexer().isNot(AsmToken::Comma)) {
9213 Error(getLexer().getLoc(), "unexpected token in directive");
9214 Parser.eatToEndOfStatement();
9215 return false;
9216 }
9217
9218 Parser.Lex();
9219 }
9220
9221 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9222
9223 Parser.Lex();
9224 return false;
9225}
9226
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009227/// parseDirectiveTLSDescSeq
9228/// ::= .tlsdescseq tls-variable
9229bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
9230 if (getLexer().isNot(AsmToken::Identifier)) {
9231 TokError("expected variable after '.tlsdescseq' directive");
9232 Parser.eatToEndOfStatement();
9233 return false;
9234 }
9235
9236 const MCSymbolRefExpr *SRE =
9237 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9238 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9239 Lex();
9240
9241 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9242 Error(Parser.getTok().getLoc(), "unexpected token");
9243 Parser.eatToEndOfStatement();
9244 return false;
9245 }
9246
9247 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9248 return false;
9249}
9250
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009251/// parseDirectiveMovSP
9252/// ::= .movsp reg [, #offset]
9253bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
9254 if (!UC.hasFnStart()) {
9255 Parser.eatToEndOfStatement();
9256 Error(L, ".fnstart must precede .movsp directives");
9257 return false;
9258 }
9259 if (UC.getFPReg() != ARM::SP) {
9260 Parser.eatToEndOfStatement();
9261 Error(L, "unexpected .movsp directive");
9262 return false;
9263 }
9264
9265 SMLoc SPRegLoc = Parser.getTok().getLoc();
9266 int SPReg = tryParseRegister();
9267 if (SPReg == -1) {
9268 Parser.eatToEndOfStatement();
9269 Error(SPRegLoc, "register expected");
9270 return false;
9271 }
9272
9273 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9274 Parser.eatToEndOfStatement();
9275 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9276 return false;
9277 }
9278
9279 int64_t Offset = 0;
9280 if (Parser.getTok().is(AsmToken::Comma)) {
9281 Parser.Lex();
9282
9283 if (Parser.getTok().isNot(AsmToken::Hash)) {
9284 Error(Parser.getTok().getLoc(), "expected #constant");
9285 Parser.eatToEndOfStatement();
9286 return false;
9287 }
9288 Parser.Lex();
9289
9290 const MCExpr *OffsetExpr;
9291 SMLoc OffsetLoc = Parser.getTok().getLoc();
9292 if (Parser.parseExpression(OffsetExpr)) {
9293 Parser.eatToEndOfStatement();
9294 Error(OffsetLoc, "malformed offset expression");
9295 return false;
9296 }
9297
9298 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9299 if (!CE) {
9300 Parser.eatToEndOfStatement();
9301 Error(OffsetLoc, "offset must be an immediate constant");
9302 return false;
9303 }
9304
9305 Offset = CE->getValue();
9306 }
9307
9308 getTargetStreamer().emitMovSP(SPReg, Offset);
9309 UC.saveFPReg(SPReg);
9310
9311 return false;
9312}
9313
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009314/// parseDirectiveObjectArch
9315/// ::= .object_arch name
9316bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
9317 if (getLexer().isNot(AsmToken::Identifier)) {
9318 Error(getLexer().getLoc(), "unexpected token");
9319 Parser.eatToEndOfStatement();
9320 return false;
9321 }
9322
9323 StringRef Arch = Parser.getTok().getString();
9324 SMLoc ArchLoc = Parser.getTok().getLoc();
9325 getLexer().Lex();
9326
9327 unsigned ID = StringSwitch<unsigned>(Arch)
9328#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9329 .Case(NAME, ARM::ID)
9330#define ARM_ARCH_ALIAS(NAME, ID) \
9331 .Case(NAME, ARM::ID)
9332#include "MCTargetDesc/ARMArchName.def"
9333#undef ARM_ARCH_NAME
9334#undef ARM_ARCH_ALIAS
9335 .Default(ARM::INVALID_ARCH);
9336
9337 if (ID == ARM::INVALID_ARCH) {
9338 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9339 Parser.eatToEndOfStatement();
9340 return false;
9341 }
9342
9343 getTargetStreamer().emitObjectArch(ID);
9344
9345 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9346 Error(getLexer().getLoc(), "unexpected token");
9347 Parser.eatToEndOfStatement();
9348 }
9349
9350 return false;
9351}
9352
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009353/// parseDirectiveAlign
9354/// ::= .align
9355bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9356 // NOTE: if this is not the end of the statement, fall back to the target
9357 // agnostic handling for this directive which will correctly handle this.
9358 if (getLexer().isNot(AsmToken::EndOfStatement))
9359 return true;
9360
9361 // '.align' is target specifically handled to mean 2**2 byte alignment.
9362 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9363 getStreamer().EmitCodeAlignment(4, 0);
9364 else
9365 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9366
9367 return false;
9368}
9369
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009370/// parseDirectiveThumbSet
9371/// ::= .thumb_set name, value
9372bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
9373 StringRef Name;
9374 if (Parser.parseIdentifier(Name)) {
9375 TokError("expected identifier after '.thumb_set'");
9376 Parser.eatToEndOfStatement();
9377 return false;
9378 }
9379
9380 if (getLexer().isNot(AsmToken::Comma)) {
9381 TokError("expected comma after name '" + Name + "'");
9382 Parser.eatToEndOfStatement();
9383 return false;
9384 }
9385 Lex();
9386
9387 const MCExpr *Value;
9388 if (Parser.parseExpression(Value)) {
9389 TokError("missing expression");
9390 Parser.eatToEndOfStatement();
9391 return false;
9392 }
9393
9394 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9395 TokError("unexpected token");
9396 Parser.eatToEndOfStatement();
9397 return false;
9398 }
9399 Lex();
9400
9401 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
9402 if (const MCSymbolRefExpr *SRE = dyn_cast<MCSymbolRefExpr>(Value)) {
9403 MCSymbol *Sym = getContext().LookupSymbol(SRE->getSymbol().getName());
9404 if (!Sym->isDefined()) {
9405 getStreamer().EmitSymbolAttribute(Sym, MCSA_Global);
9406 getStreamer().EmitAssignment(Alias, Value);
9407 return false;
9408 }
9409
9410 const MCObjectFileInfo::Environment Format =
9411 getContext().getObjectFileInfo()->getObjectFileType();
9412 switch (Format) {
9413 case MCObjectFileInfo::IsCOFF: {
9414 char Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
9415 getStreamer().EmitCOFFSymbolType(Type);
9416 // .set values are always local in COFF
9417 getStreamer().EmitSymbolAttribute(Alias, MCSA_Local);
9418 break;
9419 }
9420 case MCObjectFileInfo::IsELF:
9421 getStreamer().EmitSymbolAttribute(Alias, MCSA_ELF_TypeFunction);
9422 break;
9423 case MCObjectFileInfo::IsMachO:
9424 break;
9425 }
9426 }
9427
9428 // FIXME: set the function as being a thumb function via the assembler
9429 getStreamer().EmitThumbFunc(Alias);
9430 getStreamer().EmitAssignment(Alias, Value);
9431
9432 return false;
9433}
9434
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009435/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009436extern "C" void LLVMInitializeARMAsmParser() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00009437 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9438 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9439 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9440 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009441}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009442
Chris Lattner3e4582a2010-09-06 19:11:01 +00009443#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009444#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009445#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009446#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009447
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009448static const struct ExtMapEntry {
9449 const char *Extension;
9450 const unsigned ArchCheck;
9451 const uint64_t Features;
9452} Extensions[] = {
9453 { "crc", Feature_HasV8, ARM::FeatureCRC },
9454 { "crypto", Feature_HasV8,
9455 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9456 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
9457 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
9458 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
9459 // FIXME: iWMMXT not supported
9460 { "iwmmxt", Feature_None, 0 },
9461 // FIXME: iWMMXT2 not supported
9462 { "iwmmxt2", Feature_None, 0 },
9463 // FIXME: Maverick not supported
9464 { "maverick", Feature_None, 0 },
9465 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
9466 // FIXME: ARMv6-m OS Extensions feature not checked
9467 { "os", Feature_None, 0 },
9468 // FIXME: Also available in ARMv6-K
9469 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
9470 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9471 // FIXME: Only available in A-class, isel not predicated
9472 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
9473 // FIXME: xscale not supported
9474 { "xscale", Feature_None, 0 },
9475};
9476
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009477/// parseDirectiveArchExtension
9478/// ::= .arch_extension [no]feature
9479bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
9480 if (getLexer().isNot(AsmToken::Identifier)) {
9481 Error(getLexer().getLoc(), "unexpected token");
9482 Parser.eatToEndOfStatement();
9483 return false;
9484 }
9485
9486 StringRef Extension = Parser.getTok().getString();
9487 SMLoc ExtLoc = Parser.getTok().getLoc();
9488 getLexer().Lex();
9489
9490 bool EnableFeature = true;
Benjamin Kramere9391a52014-02-20 17:36:31 +00009491 if (Extension.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009492 EnableFeature = false;
9493 Extension = Extension.substr(2);
9494 }
9495
Benjamin Kramere9391a52014-02-20 17:36:31 +00009496 for (unsigned EI = 0, EE = array_lengthof(Extensions); EI != EE; ++EI) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009497 if (Extensions[EI].Extension != Extension)
9498 continue;
9499
9500 unsigned FB = getAvailableFeatures();
9501 if ((FB & Extensions[EI].ArchCheck) != Extensions[EI].ArchCheck) {
9502 Error(ExtLoc, "architectural extension '" + Extension + "' is not "
9503 "allowed for the current base architecture");
9504 return false;
9505 }
9506
9507 if (!Extensions[EI].Features)
9508 report_fatal_error("unsupported architectural extension: " + Extension);
9509
9510 if (EnableFeature)
9511 FB |= ComputeAvailableFeatures(Extensions[EI].Features);
9512 else
9513 FB &= ~ComputeAvailableFeatures(Extensions[EI].Features);
9514
9515 setAvailableFeatures(FB);
9516 return false;
9517 }
9518
9519 Error(ExtLoc, "unknown architectural extension: " + Extension);
9520 Parser.eatToEndOfStatement();
9521 return false;
9522}
9523
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009524// Define this matcher function after the auto-generated include so we
9525// have the match class enum definitions.
9526unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
9527 unsigned Kind) {
9528 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
9529 // If the kind is a token for a literal immediate, check if our asm
9530 // operand matches. This is for InstAliases which have a fixed-value
9531 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009532 switch (Kind) {
9533 default: break;
9534 case MCK__35_0:
9535 if (Op->isImm())
9536 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm()))
9537 if (CE->getValue() == 0)
9538 return Match_Success;
9539 break;
9540 case MCK_ARMSOImm:
9541 if (Op->isImm()) {
9542 const MCExpr *SOExpr = Op->getImm();
9543 int64_t Value;
9544 if (!SOExpr->EvaluateAsAbsolute(Value))
Stepan Dyatkovskiydf657cc2014-03-29 13:12:40 +00009545 return Match_Success;
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009546 assert((Value >= INT32_MIN && Value <= INT32_MAX) &&
9547 "expression value must be representiable in 32 bits");
9548 }
9549 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00009550 case MCK_GPRPair:
9551 if (Op->isReg() &&
9552 MRI->getRegClass(ARM::GPRRegClassID).contains(Op->getReg()))
9553 return Match_Success;
9554 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009555 }
9556 return Match_InvalidOperand;
9557}