blob: f661d8a4bebfe4356bb762c5cb74a7b4da5361a2 [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 {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001613 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1615 // Must be a constant.
1616 if (!CE) return false;
1617 int64_t Value = CE->getValue();
1618 // i16 value in the range [0,255] or [0x0100, 0xff00]
1619 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1620 }
1621
Jim Grosbach8211c052011-10-18 00:22:00 +00001622 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001623 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001624 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1625 // Must be a constant.
1626 if (!CE) return false;
1627 int64_t Value = CE->getValue();
1628 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1629 return (Value >= 0 && Value < 256) ||
1630 (Value >= 0x0100 && Value <= 0xff00) ||
1631 (Value >= 0x010000 && Value <= 0xff0000) ||
1632 (Value >= 0x01000000 && Value <= 0xff000000);
1633 }
1634
1635 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001636 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001637 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1638 // Must be a constant.
1639 if (!CE) return false;
1640 int64_t Value = CE->getValue();
1641 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1642 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1643 return (Value >= 0 && Value < 256) ||
1644 (Value >= 0x0100 && Value <= 0xff00) ||
1645 (Value >= 0x010000 && Value <= 0xff0000) ||
1646 (Value >= 0x01000000 && Value <= 0xff000000) ||
1647 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1648 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1649 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001650 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001651 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001652 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1653 // Must be a constant.
1654 if (!CE) return false;
1655 int64_t Value = ~CE->getValue();
1656 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1657 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1658 return (Value >= 0 && Value < 256) ||
1659 (Value >= 0x0100 && Value <= 0xff00) ||
1660 (Value >= 0x010000 && Value <= 0xff0000) ||
1661 (Value >= 0x01000000 && Value <= 0xff000000) ||
1662 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1663 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1664 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001665
Jim Grosbache4454e02011-10-18 16:18:11 +00001666 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001667 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1669 // Must be a constant.
1670 if (!CE) return false;
1671 uint64_t Value = CE->getValue();
1672 // i64 value with each byte being either 0 or 0xff.
1673 for (unsigned i = 0; i < 8; ++i)
1674 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1675 return true;
1676 }
1677
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001678 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001679 // Add as immediates when possible. Null MCExpr = 0.
1680 if (Expr == 0)
1681 Inst.addOperand(MCOperand::CreateImm(0));
1682 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001683 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1684 else
1685 Inst.addOperand(MCOperand::CreateExpr(Expr));
1686 }
1687
Daniel Dunbard8042b72010-08-11 06:36:53 +00001688 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001689 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001690 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001691 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1692 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001693 }
1694
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001695 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1696 assert(N == 1 && "Invalid number of operands!");
1697 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1698 }
1699
Jim Grosbach48399582011-10-12 17:34:41 +00001700 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1701 assert(N == 1 && "Invalid number of operands!");
1702 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1703 }
1704
1705 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1706 assert(N == 1 && "Invalid number of operands!");
1707 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1708 }
1709
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001710 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1711 assert(N == 1 && "Invalid number of operands!");
1712 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1713 }
1714
1715 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1716 assert(N == 1 && "Invalid number of operands!");
1717 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1718 }
1719
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001720 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1721 assert(N == 1 && "Invalid number of operands!");
1722 Inst.addOperand(MCOperand::CreateReg(getReg()));
1723 }
1724
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001725 void addRegOperands(MCInst &Inst, unsigned N) const {
1726 assert(N == 1 && "Invalid number of operands!");
1727 Inst.addOperand(MCOperand::CreateReg(getReg()));
1728 }
1729
Jim Grosbachac798e12011-07-25 20:49:51 +00001730 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001731 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001732 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001733 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001734 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1735 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001736 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001737 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001738 }
1739
Jim Grosbachac798e12011-07-25 20:49:51 +00001740 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001741 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001742 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001743 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001744 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001745 // Shift of #32 is encoded as 0 where permitted
1746 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001747 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001748 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001749 }
1750
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001751 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001752 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001753 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1754 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001755 }
1756
Bill Wendling8d2aa032010-11-08 23:49:57 +00001757 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001758 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001759 const SmallVectorImpl<unsigned> &RegList = getRegList();
1760 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001761 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1762 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001763 }
1764
Bill Wendling9898ac92010-11-17 04:32:08 +00001765 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1766 addRegListOperands(Inst, N);
1767 }
1768
1769 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1770 addRegListOperands(Inst, N);
1771 }
1772
Jim Grosbach833b9d32011-07-27 20:15:40 +00001773 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1774 assert(N == 1 && "Invalid number of operands!");
1775 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1776 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1777 }
1778
Jim Grosbach864b6092011-07-28 21:34:26 +00001779 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1780 assert(N == 1 && "Invalid number of operands!");
1781 // Munge the lsb/width into a bitfield mask.
1782 unsigned lsb = Bitfield.LSB;
1783 unsigned width = Bitfield.Width;
1784 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1785 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1786 (32 - (lsb + width)));
1787 Inst.addOperand(MCOperand::CreateImm(Mask));
1788 }
1789
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001790 void addImmOperands(MCInst &Inst, unsigned N) const {
1791 assert(N == 1 && "Invalid number of operands!");
1792 addExpr(Inst, getImm());
1793 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001794
Jim Grosbachea231912011-12-22 22:19:05 +00001795 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1796 assert(N == 1 && "Invalid number of operands!");
1797 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1798 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1799 }
1800
1801 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1802 assert(N == 1 && "Invalid number of operands!");
1803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1804 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1805 }
1806
Jim Grosbache7fbce72011-10-03 23:38:36 +00001807 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1808 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001809 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1810 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1811 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001812 }
1813
Jim Grosbach7db8d692011-09-08 22:07:06 +00001814 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1815 assert(N == 1 && "Invalid number of operands!");
1816 // FIXME: We really want to scale the value here, but the LDRD/STRD
1817 // instruction don't encode operands that way yet.
1818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1819 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1820 }
1821
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001822 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1823 assert(N == 1 && "Invalid number of operands!");
1824 // The immediate is scaled by four in the encoding and is stored
1825 // in the MCInst as such. Lop off the low two bits here.
1826 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1827 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1828 }
1829
Jim Grosbach930f2f62012-04-05 20:57:13 +00001830 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1831 assert(N == 1 && "Invalid number of operands!");
1832 // The immediate is scaled by four in the encoding and is stored
1833 // in the MCInst as such. Lop off the low two bits here.
1834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1835 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1836 }
1837
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001838 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1839 assert(N == 1 && "Invalid number of operands!");
1840 // The immediate is scaled by four in the encoding and is stored
1841 // in the MCInst as such. Lop off the low two bits here.
1842 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1843 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1844 }
1845
Jim Grosbach475c6db2011-07-25 23:09:14 +00001846 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1847 assert(N == 1 && "Invalid number of operands!");
1848 // The constant encodes as the immediate-1, and we store in the instruction
1849 // the bits as encoded, so subtract off one here.
1850 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1851 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1852 }
1853
Jim Grosbach801e0a32011-07-22 23:16:18 +00001854 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1855 assert(N == 1 && "Invalid number of operands!");
1856 // The constant encodes as the immediate-1, and we store in the instruction
1857 // the bits as encoded, so subtract off one here.
1858 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1859 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1860 }
1861
Jim Grosbach46dd4132011-08-17 21:51:27 +00001862 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1863 assert(N == 1 && "Invalid number of operands!");
1864 // The constant encodes as the immediate, except for 32, which encodes as
1865 // zero.
1866 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1867 unsigned Imm = CE->getValue();
1868 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1869 }
1870
Jim Grosbach27c1e252011-07-21 17:23:04 +00001871 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1872 assert(N == 1 && "Invalid number of operands!");
1873 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1874 // the instruction as well.
1875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1876 int Val = CE->getValue();
1877 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1878 }
1879
Jim Grosbachb009a872011-10-28 22:36:30 +00001880 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1881 assert(N == 1 && "Invalid number of operands!");
1882 // The operand is actually a t2_so_imm, but we have its bitwise
1883 // negation in the assembly source, so twiddle it here.
1884 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1885 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1886 }
1887
Jim Grosbach30506252011-12-08 00:31:07 +00001888 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1889 assert(N == 1 && "Invalid number of operands!");
1890 // The operand is actually a t2_so_imm, but we have its
1891 // negation in the assembly source, so twiddle it here.
1892 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1893 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1894 }
1895
Jim Grosbach930f2f62012-04-05 20:57:13 +00001896 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1897 assert(N == 1 && "Invalid number of operands!");
1898 // The operand is actually an imm0_4095, but we have its
1899 // negation in the assembly source, so twiddle it here.
1900 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1901 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1902 }
1903
Mihai Popad36cbaa2013-07-03 09:21:44 +00001904 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1905 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1906 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1907 return;
1908 }
1909
1910 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1911 assert(SR && "Unknown value type!");
1912 Inst.addOperand(MCOperand::CreateExpr(SR));
1913 }
1914
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001915 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1916 assert(N == 1 && "Invalid number of operands!");
1917 if (isImm()) {
1918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1919 if (CE) {
1920 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1921 return;
1922 }
1923
1924 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1925 assert(SR && "Unknown value type!");
1926 Inst.addOperand(MCOperand::CreateExpr(SR));
1927 return;
1928 }
1929
1930 assert(isMem() && "Unknown value type!");
1931 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1932 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1933 }
1934
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001935 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1936 assert(N == 1 && "Invalid number of operands!");
1937 // The operand is actually a so_imm, but we have its bitwise
1938 // negation in the assembly source, so twiddle it here.
1939 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1940 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1941 }
1942
Jim Grosbach30506252011-12-08 00:31:07 +00001943 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1944 assert(N == 1 && "Invalid number of operands!");
1945 // The operand is actually a so_imm, but we have its
1946 // negation in the assembly source, so twiddle it here.
1947 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1948 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1949 }
1950
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001951 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1952 assert(N == 1 && "Invalid number of operands!");
1953 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1954 }
1955
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001956 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1957 assert(N == 1 && "Invalid number of operands!");
1958 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1959 }
1960
Jim Grosbachd3595712011-08-03 23:50:40 +00001961 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1962 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001963 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001964 }
1965
Jim Grosbach94298a92012-01-18 22:46:46 +00001966 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1967 assert(N == 1 && "Invalid number of operands!");
1968 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001969 Inst.addOperand(MCOperand::CreateImm(Imm));
1970 }
1971
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001972 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1973 assert(N == 1 && "Invalid number of operands!");
1974 assert(isImm() && "Not an immediate!");
1975
1976 // If we have an immediate that's not a constant, treat it as a label
1977 // reference needing a fixup.
1978 if (!isa<MCConstantExpr>(getImm())) {
1979 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1980 return;
1981 }
1982
1983 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1984 int Val = CE->getValue();
1985 Inst.addOperand(MCOperand::CreateImm(Val));
1986 }
1987
Jim Grosbacha95ec992011-10-11 17:29:55 +00001988 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1989 assert(N == 2 && "Invalid number of operands!");
1990 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1991 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1992 }
1993
Kevin Enderby488f20b2014-04-10 20:18:58 +00001994 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
1995 addAlignedMemoryOperands(Inst, N);
1996 }
1997
1998 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
1999 addAlignedMemoryOperands(Inst, N);
2000 }
2001
2002 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2003 addAlignedMemoryOperands(Inst, N);
2004 }
2005
2006 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2007 addAlignedMemoryOperands(Inst, N);
2008 }
2009
2010 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2011 addAlignedMemoryOperands(Inst, N);
2012 }
2013
2014 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2015 addAlignedMemoryOperands(Inst, N);
2016 }
2017
2018 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2019 addAlignedMemoryOperands(Inst, N);
2020 }
2021
2022 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2023 addAlignedMemoryOperands(Inst, N);
2024 }
2025
2026 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2027 addAlignedMemoryOperands(Inst, N);
2028 }
2029
2030 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2031 addAlignedMemoryOperands(Inst, N);
2032 }
2033
2034 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
2035 addAlignedMemoryOperands(Inst, N);
2036 }
2037
Jim Grosbachd3595712011-08-03 23:50:40 +00002038 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
2039 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002040 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2041 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00002042 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2043 // Special case for #-0
2044 if (Val == INT32_MIN) Val = 0;
2045 if (Val < 0) Val = -Val;
2046 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2047 } else {
2048 // For register offset, we encode the shift type and negation flag
2049 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002050 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2051 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002052 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002053 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2054 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002055 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002056 }
2057
Jim Grosbachcd17c122011-08-04 23:01:30 +00002058 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
2059 assert(N == 2 && "Invalid number of operands!");
2060 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2061 assert(CE && "non-constant AM2OffsetImm operand!");
2062 int32_t Val = CE->getValue();
2063 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2064 // Special case for #-0
2065 if (Val == INT32_MIN) Val = 0;
2066 if (Val < 0) Val = -Val;
2067 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2068 Inst.addOperand(MCOperand::CreateReg(0));
2069 Inst.addOperand(MCOperand::CreateImm(Val));
2070 }
2071
Jim Grosbach5b96b802011-08-10 20:29:19 +00002072 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
2073 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002074 // If we have an immediate that's not a constant, treat it as a label
2075 // reference needing a fixup. If it is a constant, it's something else
2076 // and we reject it.
2077 if (isImm()) {
2078 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2079 Inst.addOperand(MCOperand::CreateReg(0));
2080 Inst.addOperand(MCOperand::CreateImm(0));
2081 return;
2082 }
2083
Jim Grosbach871dff72011-10-11 15:59:20 +00002084 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2085 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002086 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2087 // Special case for #-0
2088 if (Val == INT32_MIN) Val = 0;
2089 if (Val < 0) Val = -Val;
2090 Val = ARM_AM::getAM3Opc(AddSub, Val);
2091 } else {
2092 // For register offset, we encode the shift type and negation flag
2093 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002094 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002095 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002096 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2097 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00002098 Inst.addOperand(MCOperand::CreateImm(Val));
2099 }
2100
2101 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
2102 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002103 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002104 int32_t Val =
2105 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
2106 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2107 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002108 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00002109 }
2110
2111 // Constant offset.
2112 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2113 int32_t Val = CE->getValue();
2114 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2115 // Special case for #-0
2116 if (Val == INT32_MIN) Val = 0;
2117 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002118 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002119 Inst.addOperand(MCOperand::CreateReg(0));
2120 Inst.addOperand(MCOperand::CreateImm(Val));
2121 }
2122
Jim Grosbachd3595712011-08-03 23:50:40 +00002123 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2124 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00002125 // If we have an immediate that's not a constant, treat it as a label
2126 // reference needing a fixup. If it is a constant, it's something else
2127 // and we reject it.
2128 if (isImm()) {
2129 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2130 Inst.addOperand(MCOperand::CreateImm(0));
2131 return;
2132 }
2133
Jim Grosbachd3595712011-08-03 23:50:40 +00002134 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002135 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002136 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2137 // Special case for #-0
2138 if (Val == INT32_MIN) Val = 0;
2139 if (Val < 0) Val = -Val;
2140 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002141 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002142 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002143 }
2144
Jim Grosbach7db8d692011-09-08 22:07:06 +00002145 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2146 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002147 // If we have an immediate that's not a constant, treat it as a label
2148 // reference needing a fixup. If it is a constant, it's something else
2149 // and we reject it.
2150 if (isImm()) {
2151 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2152 Inst.addOperand(MCOperand::CreateImm(0));
2153 return;
2154 }
2155
Jim Grosbach871dff72011-10-11 15:59:20 +00002156 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2157 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002158 Inst.addOperand(MCOperand::CreateImm(Val));
2159 }
2160
Jim Grosbacha05627e2011-09-09 18:37:27 +00002161 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2162 assert(N == 2 && "Invalid number of operands!");
2163 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002164 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2165 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002166 Inst.addOperand(MCOperand::CreateImm(Val));
2167 }
2168
Jim Grosbachd3595712011-08-03 23:50:40 +00002169 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2170 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002171 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2172 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002173 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002174 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002175
Jim Grosbach2392c532011-09-07 23:39:14 +00002176 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2177 addMemImm8OffsetOperands(Inst, N);
2178 }
2179
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002180 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002181 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002182 }
2183
2184 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2185 assert(N == 2 && "Invalid number of operands!");
2186 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002187 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002188 addExpr(Inst, getImm());
2189 Inst.addOperand(MCOperand::CreateImm(0));
2190 return;
2191 }
2192
2193 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002194 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2195 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002196 Inst.addOperand(MCOperand::CreateImm(Val));
2197 }
2198
Jim Grosbachd3595712011-08-03 23:50:40 +00002199 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2200 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002201 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002202 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002203 addExpr(Inst, getImm());
2204 Inst.addOperand(MCOperand::CreateImm(0));
2205 return;
2206 }
2207
2208 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002209 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2210 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002211 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002212 }
Bill Wendling811c9362010-11-30 07:44:32 +00002213
Jim Grosbach05541f42011-09-19 22:21:13 +00002214 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2215 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002216 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2217 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002218 }
2219
2220 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2221 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002222 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2223 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002224 }
2225
Jim Grosbachd3595712011-08-03 23:50:40 +00002226 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2227 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002228 unsigned Val =
2229 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2230 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002231 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2232 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002233 Inst.addOperand(MCOperand::CreateImm(Val));
2234 }
2235
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002236 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2237 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002238 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2239 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2240 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002241 }
2242
Jim Grosbachd3595712011-08-03 23:50:40 +00002243 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2244 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002245 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2246 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002247 }
2248
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002249 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2250 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002251 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2252 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002253 Inst.addOperand(MCOperand::CreateImm(Val));
2254 }
2255
Jim Grosbach26d35872011-08-19 18:55:51 +00002256 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2257 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002258 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2259 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002260 Inst.addOperand(MCOperand::CreateImm(Val));
2261 }
2262
Jim Grosbacha32c7532011-08-19 18:49:59 +00002263 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2264 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002265 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2266 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002267 Inst.addOperand(MCOperand::CreateImm(Val));
2268 }
2269
Jim Grosbach23983d62011-08-19 18:13:48 +00002270 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2271 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002272 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2273 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002274 Inst.addOperand(MCOperand::CreateImm(Val));
2275 }
2276
Jim Grosbachd3595712011-08-03 23:50:40 +00002277 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2278 assert(N == 1 && "Invalid number of operands!");
2279 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2280 assert(CE && "non-constant post-idx-imm8 operand!");
2281 int Imm = CE->getValue();
2282 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002283 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002284 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2285 Inst.addOperand(MCOperand::CreateImm(Imm));
2286 }
2287
Jim Grosbach93981412011-10-11 21:55:36 +00002288 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2289 assert(N == 1 && "Invalid number of operands!");
2290 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2291 assert(CE && "non-constant post-idx-imm8s4 operand!");
2292 int Imm = CE->getValue();
2293 bool isAdd = Imm >= 0;
2294 if (Imm == INT32_MIN) Imm = 0;
2295 // Immediate is scaled by 4.
2296 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2297 Inst.addOperand(MCOperand::CreateImm(Imm));
2298 }
2299
Jim Grosbachd3595712011-08-03 23:50:40 +00002300 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2301 assert(N == 2 && "Invalid number of operands!");
2302 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002303 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2304 }
2305
2306 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2307 assert(N == 2 && "Invalid number of operands!");
2308 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2309 // The sign, shift type, and shift amount are encoded in a single operand
2310 // using the AM2 encoding helpers.
2311 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2312 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2313 PostIdxReg.ShiftTy);
2314 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002315 }
2316
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002317 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2318 assert(N == 1 && "Invalid number of operands!");
2319 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2320 }
2321
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002322 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2323 assert(N == 1 && "Invalid number of operands!");
2324 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2325 }
2326
Jim Grosbach182b6a02011-11-29 23:51:09 +00002327 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002328 assert(N == 1 && "Invalid number of operands!");
2329 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2330 }
2331
Jim Grosbach04945c42011-12-02 00:35:16 +00002332 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2333 assert(N == 2 && "Invalid number of operands!");
2334 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2335 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2336 }
2337
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002338 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2339 assert(N == 1 && "Invalid number of operands!");
2340 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2341 }
2342
2343 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2344 assert(N == 1 && "Invalid number of operands!");
2345 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2346 }
2347
2348 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2349 assert(N == 1 && "Invalid number of operands!");
2350 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2351 }
2352
Jim Grosbach741cd732011-10-17 22:26:03 +00002353 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2354 assert(N == 1 && "Invalid number of operands!");
2355 // The immediate encodes the type of constant as well as the value.
2356 // Mask in that this is an i8 splat.
2357 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2358 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2359 }
2360
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002361 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2362 assert(N == 1 && "Invalid number of operands!");
2363 // The immediate encodes the type of constant as well as the value.
2364 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2365 unsigned Value = CE->getValue();
2366 if (Value >= 256)
2367 Value = (Value >> 8) | 0xa00;
2368 else
2369 Value |= 0x800;
2370 Inst.addOperand(MCOperand::CreateImm(Value));
2371 }
2372
Jim Grosbach8211c052011-10-18 00:22:00 +00002373 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2374 assert(N == 1 && "Invalid number of operands!");
2375 // The immediate encodes the type of constant as well as the value.
2376 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2377 unsigned Value = CE->getValue();
2378 if (Value >= 256 && Value <= 0xff00)
2379 Value = (Value >> 8) | 0x200;
2380 else if (Value > 0xffff && Value <= 0xff0000)
2381 Value = (Value >> 16) | 0x400;
2382 else if (Value > 0xffffff)
2383 Value = (Value >> 24) | 0x600;
2384 Inst.addOperand(MCOperand::CreateImm(Value));
2385 }
2386
2387 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2388 assert(N == 1 && "Invalid number of operands!");
2389 // The immediate encodes the type of constant as well as the value.
2390 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2391 unsigned Value = CE->getValue();
2392 if (Value >= 256 && Value <= 0xffff)
2393 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2394 else if (Value > 0xffff && Value <= 0xffffff)
2395 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2396 else if (Value > 0xffffff)
2397 Value = (Value >> 24) | 0x600;
2398 Inst.addOperand(MCOperand::CreateImm(Value));
2399 }
2400
Jim Grosbach045b6c72011-12-19 23:51:07 +00002401 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2402 assert(N == 1 && "Invalid number of operands!");
2403 // The immediate encodes the type of constant as well as the value.
2404 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2405 unsigned Value = ~CE->getValue();
2406 if (Value >= 256 && Value <= 0xffff)
2407 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2408 else if (Value > 0xffff && Value <= 0xffffff)
2409 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2410 else if (Value > 0xffffff)
2411 Value = (Value >> 24) | 0x600;
2412 Inst.addOperand(MCOperand::CreateImm(Value));
2413 }
2414
Jim Grosbache4454e02011-10-18 16:18:11 +00002415 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2416 assert(N == 1 && "Invalid number of operands!");
2417 // The immediate encodes the type of constant as well as the value.
2418 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2419 uint64_t Value = CE->getValue();
2420 unsigned Imm = 0;
2421 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2422 Imm |= (Value & 1) << i;
2423 }
2424 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2425 }
2426
Craig Topperca7e3e52014-03-10 03:19:03 +00002427 void print(raw_ostream &OS) const override;
Daniel Dunbarebace222010-08-11 06:37:04 +00002428
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002429 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002430 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002431 Op->ITMask.Mask = Mask;
2432 Op->StartLoc = S;
2433 Op->EndLoc = S;
2434 return Op;
2435 }
2436
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002437 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002438 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002439 Op->CC.Val = CC;
2440 Op->StartLoc = S;
2441 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002442 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002443 }
2444
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002445 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002446 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002447 Op->Cop.Val = CopVal;
2448 Op->StartLoc = S;
2449 Op->EndLoc = S;
2450 return Op;
2451 }
2452
2453 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002454 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002455 Op->Cop.Val = CopVal;
2456 Op->StartLoc = S;
2457 Op->EndLoc = S;
2458 return Op;
2459 }
2460
Jim Grosbach48399582011-10-12 17:34:41 +00002461 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2462 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2463 Op->Cop.Val = Val;
2464 Op->StartLoc = S;
2465 Op->EndLoc = E;
2466 return Op;
2467 }
2468
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002469 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002470 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002471 Op->Reg.RegNum = RegNum;
2472 Op->StartLoc = S;
2473 Op->EndLoc = S;
2474 return Op;
2475 }
2476
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002477 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002478 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002479 Op->Tok.Data = Str.data();
2480 Op->Tok.Length = Str.size();
2481 Op->StartLoc = S;
2482 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002483 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002484 }
2485
Bill Wendling2063b842010-11-18 23:43:05 +00002486 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002487 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002488 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002489 Op->StartLoc = S;
2490 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002491 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002492 }
2493
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002494 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2495 unsigned SrcReg,
2496 unsigned ShiftReg,
2497 unsigned ShiftImm,
2498 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002499 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002500 Op->RegShiftedReg.ShiftTy = ShTy;
2501 Op->RegShiftedReg.SrcReg = SrcReg;
2502 Op->RegShiftedReg.ShiftReg = ShiftReg;
2503 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002504 Op->StartLoc = S;
2505 Op->EndLoc = E;
2506 return Op;
2507 }
2508
Owen Andersonb595ed02011-07-21 18:54:16 +00002509 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2510 unsigned SrcReg,
2511 unsigned ShiftImm,
2512 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002513 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002514 Op->RegShiftedImm.ShiftTy = ShTy;
2515 Op->RegShiftedImm.SrcReg = SrcReg;
2516 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002517 Op->StartLoc = S;
2518 Op->EndLoc = E;
2519 return Op;
2520 }
2521
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002522 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002523 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002524 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002525 Op->ShifterImm.isASR = isASR;
2526 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002527 Op->StartLoc = S;
2528 Op->EndLoc = E;
2529 return Op;
2530 }
2531
Jim Grosbach833b9d32011-07-27 20:15:40 +00002532 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002533 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002534 Op->RotImm.Imm = Imm;
2535 Op->StartLoc = S;
2536 Op->EndLoc = E;
2537 return Op;
2538 }
2539
Jim Grosbach864b6092011-07-28 21:34:26 +00002540 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2541 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002542 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002543 Op->Bitfield.LSB = LSB;
2544 Op->Bitfield.Width = Width;
2545 Op->StartLoc = S;
2546 Op->EndLoc = E;
2547 return Op;
2548 }
2549
Bill Wendling2cae3272010-11-09 22:44:22 +00002550 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002551 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002552 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002553 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002554 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002555
Chad Rosierfa705ee2013-07-01 20:49:23 +00002556 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002557 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002558 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002559 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002560 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002561
Chad Rosierfa705ee2013-07-01 20:49:23 +00002562 // Sort based on the register encoding values.
2563 array_pod_sort(Regs.begin(), Regs.end());
2564
Bill Wendling9898ac92010-11-17 04:32:08 +00002565 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002566 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002567 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002568 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002569 Op->StartLoc = StartLoc;
2570 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002571 return Op;
2572 }
2573
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002574 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002575 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002576 ARMOperand *Op = new ARMOperand(k_VectorList);
2577 Op->VectorList.RegNum = RegNum;
2578 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002579 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002580 Op->StartLoc = S;
2581 Op->EndLoc = E;
2582 return Op;
2583 }
2584
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002585 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002586 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002587 SMLoc S, SMLoc E) {
2588 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2589 Op->VectorList.RegNum = RegNum;
2590 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002591 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002592 Op->StartLoc = S;
2593 Op->EndLoc = E;
2594 return Op;
2595 }
2596
Jim Grosbach04945c42011-12-02 00:35:16 +00002597 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002598 unsigned Index,
2599 bool isDoubleSpaced,
2600 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002601 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2602 Op->VectorList.RegNum = RegNum;
2603 Op->VectorList.Count = Count;
2604 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002605 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002606 Op->StartLoc = S;
2607 Op->EndLoc = E;
2608 return Op;
2609 }
2610
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002611 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2612 MCContext &Ctx) {
2613 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2614 Op->VectorIndex.Val = Idx;
2615 Op->StartLoc = S;
2616 Op->EndLoc = E;
2617 return Op;
2618 }
2619
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002620 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002621 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002622 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002623 Op->StartLoc = S;
2624 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002625 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002626 }
2627
Jim Grosbachd3595712011-08-03 23:50:40 +00002628 static ARMOperand *CreateMem(unsigned BaseRegNum,
2629 const MCConstantExpr *OffsetImm,
2630 unsigned OffsetRegNum,
2631 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002632 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002633 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002634 bool isNegative,
Kevin Enderby488f20b2014-04-10 20:18:58 +00002635 SMLoc S, SMLoc E,
2636 SMLoc AlignmentLoc = SMLoc()) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002637 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002638 Op->Memory.BaseRegNum = BaseRegNum;
2639 Op->Memory.OffsetImm = OffsetImm;
2640 Op->Memory.OffsetRegNum = OffsetRegNum;
2641 Op->Memory.ShiftType = ShiftType;
2642 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002643 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002644 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002645 Op->StartLoc = S;
2646 Op->EndLoc = E;
Kevin Enderby488f20b2014-04-10 20:18:58 +00002647 Op->AlignmentLoc = AlignmentLoc;
Jim Grosbachd3595712011-08-03 23:50:40 +00002648 return Op;
2649 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002650
Jim Grosbachc320c852011-08-05 21:28:30 +00002651 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2652 ARM_AM::ShiftOpc ShiftTy,
2653 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002654 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002655 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002656 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002657 Op->PostIdxReg.isAdd = isAdd;
2658 Op->PostIdxReg.ShiftTy = ShiftTy;
2659 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002660 Op->StartLoc = S;
2661 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002662 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002663 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002664
2665 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002666 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002667 Op->MBOpt.Val = Opt;
2668 Op->StartLoc = S;
2669 Op->EndLoc = S;
2670 return Op;
2671 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002672
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002673 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2674 SMLoc S) {
2675 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2676 Op->ISBOpt.Val = Opt;
2677 Op->StartLoc = S;
2678 Op->EndLoc = S;
2679 return Op;
2680 }
2681
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002682 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002683 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002684 Op->IFlags.Val = IFlags;
2685 Op->StartLoc = S;
2686 Op->EndLoc = S;
2687 return Op;
2688 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002689
2690 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002691 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002692 Op->MMask.Val = MMask;
2693 Op->StartLoc = S;
2694 Op->EndLoc = S;
2695 return Op;
2696 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002697};
2698
2699} // end anonymous namespace.
2700
Jim Grosbach602aa902011-07-13 15:34:57 +00002701void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002702 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002703 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002704 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002705 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002706 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002707 OS << "<ccout " << getReg() << ">";
2708 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002709 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002710 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002711 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2712 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2713 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002714 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2715 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2716 break;
2717 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002718 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002719 OS << "<coprocessor number: " << getCoproc() << ">";
2720 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002721 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002722 OS << "<coprocessor register: " << getCoproc() << ">";
2723 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002724 case k_CoprocOption:
2725 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2726 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002727 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002728 OS << "<mask: " << getMSRMask() << ">";
2729 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002730 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002731 getImm()->print(OS);
2732 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002733 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002734 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002735 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002736 case k_InstSyncBarrierOpt:
2737 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2738 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002739 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002740 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002741 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002742 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002743 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002744 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002745 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2746 << PostIdxReg.RegNum;
2747 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2748 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2749 << PostIdxReg.ShiftImm;
2750 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002751 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002752 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002753 OS << "<ARM_PROC::";
2754 unsigned IFlags = getProcIFlags();
2755 for (int i=2; i >= 0; --i)
2756 if (IFlags & (1 << i))
2757 OS << ARM_PROC::IFlagsToString(1 << i);
2758 OS << ">";
2759 break;
2760 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002761 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002762 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002763 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002764 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002765 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2766 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002767 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002768 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002769 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002770 << RegShiftedReg.SrcReg << " "
2771 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2772 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002773 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002774 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002775 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002776 << RegShiftedImm.SrcReg << " "
2777 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2778 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002779 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002780 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002781 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2782 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002783 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002784 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2785 << ", width: " << Bitfield.Width << ">";
2786 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002787 case k_RegisterList:
2788 case k_DPRRegisterList:
2789 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002790 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002791
Bill Wendlingbed94652010-11-09 23:28:44 +00002792 const SmallVectorImpl<unsigned> &RegList = getRegList();
2793 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002794 I = RegList.begin(), E = RegList.end(); I != E; ) {
2795 OS << *I;
2796 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002797 }
2798
2799 OS << ">";
2800 break;
2801 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002802 case k_VectorList:
2803 OS << "<vector_list " << VectorList.Count << " * "
2804 << VectorList.RegNum << ">";
2805 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002806 case k_VectorListAllLanes:
2807 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2808 << VectorList.RegNum << ">";
2809 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002810 case k_VectorListIndexed:
2811 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2812 << VectorList.Count << " * " << VectorList.RegNum << ">";
2813 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002814 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002815 OS << "'" << getToken() << "'";
2816 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002817 case k_VectorIndex:
2818 OS << "<vectorindex " << getVectorIndex() << ">";
2819 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002820 }
2821}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002822
2823/// @name Auto-generated Match Functions
2824/// {
2825
2826static unsigned MatchRegisterName(StringRef Name);
2827
2828/// }
2829
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002830bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2831 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002832 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002833 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002834 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002835
2836 return (RegNo == (unsigned)-1);
2837}
2838
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002839/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002840/// and if it is a register name the token is eaten and the register number is
2841/// returned. Otherwise return -1.
2842///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002843int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002844 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002845 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002846
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002847 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002848 unsigned RegNum = MatchRegisterName(lowerCase);
2849 if (!RegNum) {
2850 RegNum = StringSwitch<unsigned>(lowerCase)
2851 .Case("r13", ARM::SP)
2852 .Case("r14", ARM::LR)
2853 .Case("r15", ARM::PC)
2854 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002855 // Additional register name aliases for 'gas' compatibility.
2856 .Case("a1", ARM::R0)
2857 .Case("a2", ARM::R1)
2858 .Case("a3", ARM::R2)
2859 .Case("a4", ARM::R3)
2860 .Case("v1", ARM::R4)
2861 .Case("v2", ARM::R5)
2862 .Case("v3", ARM::R6)
2863 .Case("v4", ARM::R7)
2864 .Case("v5", ARM::R8)
2865 .Case("v6", ARM::R9)
2866 .Case("v7", ARM::R10)
2867 .Case("v8", ARM::R11)
2868 .Case("sb", ARM::R9)
2869 .Case("sl", ARM::R10)
2870 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002871 .Default(0);
2872 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002873 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002874 // Check for aliases registered via .req. Canonicalize to lower case.
2875 // That's more consistent since register names are case insensitive, and
2876 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2877 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002878 // If no match, return failure.
2879 if (Entry == RegisterReqs.end())
2880 return -1;
2881 Parser.Lex(); // Eat identifier token.
2882 return Entry->getValue();
2883 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002884
Chris Lattner44e5981c2010-10-30 04:09:10 +00002885 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002886
Chris Lattner44e5981c2010-10-30 04:09:10 +00002887 return RegNum;
2888}
Jim Grosbach99710a82010-11-01 16:44:21 +00002889
Jim Grosbachbb24c592011-07-13 18:49:30 +00002890// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2891// If a recoverable error occurs, return 1. If an irrecoverable error
2892// occurs, return -1. An irrecoverable error is one where tokens have been
2893// consumed in the process of trying to parse the shifter (i.e., when it is
2894// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002895int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002896 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2897 SMLoc S = Parser.getTok().getLoc();
2898 const AsmToken &Tok = Parser.getTok();
Kevin Enderby62873712014-02-17 21:45:27 +00002899 if (Tok.isNot(AsmToken::Identifier))
2900 return -1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002901
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002902 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002903 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002904 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002905 .Case("lsl", ARM_AM::lsl)
2906 .Case("lsr", ARM_AM::lsr)
2907 .Case("asr", ARM_AM::asr)
2908 .Case("ror", ARM_AM::ror)
2909 .Case("rrx", ARM_AM::rrx)
2910 .Default(ARM_AM::no_shift);
2911
2912 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002913 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002914
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002915 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002916
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002917 // The source register for the shift has already been added to the
2918 // operand list, so we need to pop it off and combine it into the shifted
2919 // register operand instead.
Benjamin Kramerd2da7202014-04-21 09:34:48 +00002920 std::unique_ptr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002921 if (!PrevOp->isReg())
2922 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2923 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002924
2925 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002926 int64_t Imm = 0;
2927 int ShiftReg = 0;
2928 if (ShiftTy == ARM_AM::rrx) {
2929 // RRX Doesn't have an explicit shift amount. The encoder expects
2930 // the shift register to be the same as the source register. Seems odd,
2931 // but OK.
2932 ShiftReg = SrcReg;
2933 } else {
2934 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002935 if (Parser.getTok().is(AsmToken::Hash) ||
2936 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002937 Parser.Lex(); // Eat hash.
2938 SMLoc ImmLoc = Parser.getTok().getLoc();
2939 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002940 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002941 Error(ImmLoc, "invalid immediate shift value");
2942 return -1;
2943 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002944 // The expression must be evaluatable as an immediate.
2945 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002946 if (!CE) {
2947 Error(ImmLoc, "invalid immediate shift value");
2948 return -1;
2949 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002950 // Range check the immediate.
2951 // lsl, ror: 0 <= imm <= 31
2952 // lsr, asr: 0 <= imm <= 32
2953 Imm = CE->getValue();
2954 if (Imm < 0 ||
2955 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2956 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002957 Error(ImmLoc, "immediate shift value out of range");
2958 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002959 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002960 // shift by zero is a nop. Always send it through as lsl.
2961 // ('as' compatibility)
2962 if (Imm == 0)
2963 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002964 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002965 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002966 EndLoc = Parser.getTok().getEndLoc();
2967 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002968 if (ShiftReg == -1) {
2969 Error (L, "expected immediate or register in shift operand");
2970 return -1;
2971 }
2972 } else {
2973 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002974 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002975 return -1;
2976 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002977 }
2978
Owen Andersonb595ed02011-07-21 18:54:16 +00002979 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2980 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002981 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002982 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002983 else
2984 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002985 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002986
Jim Grosbachbb24c592011-07-13 18:49:30 +00002987 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002988}
2989
2990
Bill Wendling2063b842010-11-18 23:43:05 +00002991/// Try to parse a register name. The token must be an Identifier when called.
2992/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2993/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002994///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002995/// TODO this is likely to change to allow different register types and or to
2996/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002997bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002998tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002999 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003000 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00003001 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00003002 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00003003
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003004 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
3005 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003006
Chris Lattner44e5981c2010-10-30 04:09:10 +00003007 const AsmToken &ExclaimTok = Parser.getTok();
3008 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00003009 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
3010 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00003011 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003012 return false;
3013 }
3014
3015 // Also check for an index operand. This is only legal for vector registers,
3016 // but that'll get caught OK in operand matching, so we don't need to
3017 // explicitly filter everything else out here.
3018 if (Parser.getTok().is(AsmToken::LBrac)) {
3019 SMLoc SIdx = Parser.getTok().getLoc();
3020 Parser.Lex(); // Eat left bracket token.
3021
3022 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003023 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00003024 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003025 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003026 if (!MCE)
3027 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003028
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003029 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003030 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003031
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003032 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003033 Parser.Lex(); // Eat right bracket token.
3034
3035 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
3036 SIdx, E,
3037 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00003038 }
3039
Bill Wendling2063b842010-11-18 23:43:05 +00003040 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003041}
3042
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003043/// MatchCoprocessorOperandName - Try to parse an coprocessor related
3044/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
3045/// "c5", ...
3046static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003047 // Use the same layout as the tablegen'erated register name matcher. Ugly,
3048 // but efficient.
3049 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00003050 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003051 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003052 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003053 return -1;
3054 switch (Name[1]) {
3055 default: return -1;
3056 case '0': return 0;
3057 case '1': return 1;
3058 case '2': return 2;
3059 case '3': return 3;
3060 case '4': return 4;
3061 case '5': return 5;
3062 case '6': return 6;
3063 case '7': return 7;
3064 case '8': return 8;
3065 case '9': return 9;
3066 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003067 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003068 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003069 return -1;
3070 switch (Name[2]) {
3071 default: return -1;
Artyom Skrobov86534432013-11-08 09:16:31 +00003072 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
3073 case '0': return CoprocOp == 'p'? -1: 10;
3074 case '1': return CoprocOp == 'p'? -1: 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003075 case '2': return 12;
3076 case '3': return 13;
3077 case '4': return 14;
3078 case '5': return 15;
3079 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003080 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003081}
3082
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003083/// parseITCondCode - Try to parse a condition code for an IT instruction.
3084ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3085parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3086 SMLoc S = Parser.getTok().getLoc();
3087 const AsmToken &Tok = Parser.getTok();
3088 if (!Tok.is(AsmToken::Identifier))
3089 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00003090 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003091 .Case("eq", ARMCC::EQ)
3092 .Case("ne", ARMCC::NE)
3093 .Case("hs", ARMCC::HS)
3094 .Case("cs", ARMCC::HS)
3095 .Case("lo", ARMCC::LO)
3096 .Case("cc", ARMCC::LO)
3097 .Case("mi", ARMCC::MI)
3098 .Case("pl", ARMCC::PL)
3099 .Case("vs", ARMCC::VS)
3100 .Case("vc", ARMCC::VC)
3101 .Case("hi", ARMCC::HI)
3102 .Case("ls", ARMCC::LS)
3103 .Case("ge", ARMCC::GE)
3104 .Case("lt", ARMCC::LT)
3105 .Case("gt", ARMCC::GT)
3106 .Case("le", ARMCC::LE)
3107 .Case("al", ARMCC::AL)
3108 .Default(~0U);
3109 if (CC == ~0U)
3110 return MatchOperand_NoMatch;
3111 Parser.Lex(); // Eat the token.
3112
3113 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3114
3115 return MatchOperand_Success;
3116}
3117
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003118/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003119/// token must be an Identifier when called, and if it is a coprocessor
3120/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003121ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003122parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003123 SMLoc S = Parser.getTok().getLoc();
3124 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003125 if (Tok.isNot(AsmToken::Identifier))
3126 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003127
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003128 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003129 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003130 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003131
3132 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003133 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003134 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003135}
3136
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003137/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003138/// token must be an Identifier when called, and if it is a coprocessor
3139/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003140ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003141parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003142 SMLoc S = Parser.getTok().getLoc();
3143 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003144 if (Tok.isNot(AsmToken::Identifier))
3145 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003146
3147 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3148 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003149 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003150
3151 Parser.Lex(); // Eat identifier token.
3152 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003153 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003154}
3155
Jim Grosbach48399582011-10-12 17:34:41 +00003156/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3157/// coproc_option : '{' imm0_255 '}'
3158ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3159parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3160 SMLoc S = Parser.getTok().getLoc();
3161
3162 // If this isn't a '{', this isn't a coprocessor immediate operand.
3163 if (Parser.getTok().isNot(AsmToken::LCurly))
3164 return MatchOperand_NoMatch;
3165 Parser.Lex(); // Eat the '{'
3166
3167 const MCExpr *Expr;
3168 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003169 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003170 Error(Loc, "illegal expression");
3171 return MatchOperand_ParseFail;
3172 }
3173 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3174 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3175 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3176 return MatchOperand_ParseFail;
3177 }
3178 int Val = CE->getValue();
3179
3180 // Check for and consume the closing '}'
3181 if (Parser.getTok().isNot(AsmToken::RCurly))
3182 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003183 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003184 Parser.Lex(); // Eat the '}'
3185
3186 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3187 return MatchOperand_Success;
3188}
3189
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003190// For register list parsing, we need to map from raw GPR register numbering
3191// to the enumeration values. The enumeration values aren't sorted by
3192// register number due to our using "sp", "lr" and "pc" as canonical names.
3193static unsigned getNextRegister(unsigned Reg) {
3194 // If this is a GPR, we need to do it manually, otherwise we can rely
3195 // on the sort ordering of the enumeration since the other reg-classes
3196 // are sane.
3197 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3198 return Reg + 1;
3199 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003200 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003201 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3202 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3203 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3204 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3205 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3206 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3207 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3208 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3209 }
3210}
3211
Jim Grosbach85a23432011-11-11 21:27:40 +00003212// Return the low-subreg of a given Q register.
3213static unsigned getDRegFromQReg(unsigned QReg) {
3214 switch (QReg) {
3215 default: llvm_unreachable("expected a Q register!");
3216 case ARM::Q0: return ARM::D0;
3217 case ARM::Q1: return ARM::D2;
3218 case ARM::Q2: return ARM::D4;
3219 case ARM::Q3: return ARM::D6;
3220 case ARM::Q4: return ARM::D8;
3221 case ARM::Q5: return ARM::D10;
3222 case ARM::Q6: return ARM::D12;
3223 case ARM::Q7: return ARM::D14;
3224 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003225 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003226 case ARM::Q10: return ARM::D20;
3227 case ARM::Q11: return ARM::D22;
3228 case ARM::Q12: return ARM::D24;
3229 case ARM::Q13: return ARM::D26;
3230 case ARM::Q14: return ARM::D28;
3231 case ARM::Q15: return ARM::D30;
3232 }
3233}
3234
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003235/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003236bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003237parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003238 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003239 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003240 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003241 Parser.Lex(); // Eat '{' token.
3242 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003243
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003244 // Check the first register in the list to see what register class
3245 // this is a list of.
3246 int Reg = tryParseRegister();
3247 if (Reg == -1)
3248 return Error(RegLoc, "register expected");
3249
Jim Grosbach85a23432011-11-11 21:27:40 +00003250 // The reglist instructions have at most 16 registers, so reserve
3251 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003252 int EReg = 0;
3253 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003254
3255 // Allow Q regs and just interpret them as the two D sub-registers.
3256 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3257 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003258 EReg = MRI->getEncodingValue(Reg);
3259 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003260 ++Reg;
3261 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003262 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003263 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3264 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3265 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3266 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3267 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3268 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3269 else
3270 return Error(RegLoc, "invalid register in register list");
3271
Jim Grosbach85a23432011-11-11 21:27:40 +00003272 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003273 EReg = MRI->getEncodingValue(Reg);
3274 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003275
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003276 // This starts immediately after the first register token in the list,
3277 // so we can see either a comma or a minus (range separator) as a legal
3278 // next token.
3279 while (Parser.getTok().is(AsmToken::Comma) ||
3280 Parser.getTok().is(AsmToken::Minus)) {
3281 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003282 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003283 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003284 int EndReg = tryParseRegister();
3285 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003286 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003287 // Allow Q regs and just interpret them as the two D sub-registers.
3288 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3289 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003290 // If the register is the same as the start reg, there's nothing
3291 // more to do.
3292 if (Reg == EndReg)
3293 continue;
3294 // The register must be in the same register class as the first.
3295 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003296 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003297 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003298 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003299 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003300
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003301 // Add all the registers in the range to the register list.
3302 while (Reg != EndReg) {
3303 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003304 EReg = MRI->getEncodingValue(Reg);
3305 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003306 }
3307 continue;
3308 }
3309 Parser.Lex(); // Eat the comma.
3310 RegLoc = Parser.getTok().getLoc();
3311 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003312 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003313 Reg = tryParseRegister();
3314 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003315 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003316 // Allow Q regs and just interpret them as the two D sub-registers.
3317 bool isQReg = false;
3318 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3319 Reg = getDRegFromQReg(Reg);
3320 isQReg = true;
3321 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003322 // The register must be in the same register class as the first.
3323 if (!RC->contains(Reg))
3324 return Error(RegLoc, "invalid register in register list");
3325 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003326 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003327 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3328 Warning(RegLoc, "register list not in ascending order");
3329 else
3330 return Error(RegLoc, "register list not in ascending order");
3331 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003332 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003333 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3334 ") in register list");
3335 continue;
3336 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003337 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003338 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3339 Reg != OldReg + 1)
3340 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003341 EReg = MRI->getEncodingValue(Reg);
3342 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3343 if (isQReg) {
3344 EReg = MRI->getEncodingValue(++Reg);
3345 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3346 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003347 }
3348
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003349 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003350 return Error(Parser.getTok().getLoc(), "'}' expected");
3351 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003352 Parser.Lex(); // Eat '}' token.
3353
Jim Grosbach18bf3632011-12-13 21:48:29 +00003354 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003355 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003356
3357 // The ARM system instruction variants for LDM/STM have a '^' token here.
3358 if (Parser.getTok().is(AsmToken::Caret)) {
3359 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3360 Parser.Lex(); // Eat '^' token.
3361 }
3362
Bill Wendling2063b842010-11-18 23:43:05 +00003363 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003364}
3365
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003366// Helper function to parse the lane index for vector lists.
3367ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003368parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003369 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003370 if (Parser.getTok().is(AsmToken::LBrac)) {
3371 Parser.Lex(); // Eat the '['.
3372 if (Parser.getTok().is(AsmToken::RBrac)) {
3373 // "Dn[]" is the 'all lanes' syntax.
3374 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003375 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003376 Parser.Lex(); // Eat the ']'.
3377 return MatchOperand_Success;
3378 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003379
3380 // There's an optional '#' token here. Normally there wouldn't be, but
3381 // inline assemble puts one in, and it's friendly to accept that.
3382 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003383 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003384
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003385 const MCExpr *LaneIndex;
3386 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003387 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003388 Error(Loc, "illegal expression");
3389 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003390 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003391 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3392 if (!CE) {
3393 Error(Loc, "lane index must be empty or an integer");
3394 return MatchOperand_ParseFail;
3395 }
3396 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3397 Error(Parser.getTok().getLoc(), "']' expected");
3398 return MatchOperand_ParseFail;
3399 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003400 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003401 Parser.Lex(); // Eat the ']'.
3402 int64_t Val = CE->getValue();
3403
3404 // FIXME: Make this range check context sensitive for .8, .16, .32.
3405 if (Val < 0 || Val > 7) {
3406 Error(Parser.getTok().getLoc(), "lane index out of range");
3407 return MatchOperand_ParseFail;
3408 }
3409 Index = Val;
3410 LaneKind = IndexedLane;
3411 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003412 }
3413 LaneKind = NoLanes;
3414 return MatchOperand_Success;
3415}
3416
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003417// parse a vector register list
3418ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3419parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003420 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003421 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003422 SMLoc S = Parser.getTok().getLoc();
3423 // As an extension (to match gas), support a plain D register or Q register
3424 // (without encosing curly braces) as a single or double entry list,
3425 // respectively.
3426 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003427 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003428 int Reg = tryParseRegister();
3429 if (Reg == -1)
3430 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003431 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003432 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003433 if (Res != MatchOperand_Success)
3434 return Res;
3435 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003436 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003437 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003438 break;
3439 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003440 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3441 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003442 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003443 case IndexedLane:
3444 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003445 LaneIndex,
3446 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003447 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003448 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003449 return MatchOperand_Success;
3450 }
3451 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3452 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003453 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003454 if (Res != MatchOperand_Success)
3455 return Res;
3456 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003457 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003458 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003459 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003460 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003461 break;
3462 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003463 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3464 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003465 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3466 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003467 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003468 case IndexedLane:
3469 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003470 LaneIndex,
3471 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003472 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003473 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003474 return MatchOperand_Success;
3475 }
3476 Error(S, "vector register expected");
3477 return MatchOperand_ParseFail;
3478 }
3479
3480 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003481 return MatchOperand_NoMatch;
3482
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003483 Parser.Lex(); // Eat '{' token.
3484 SMLoc RegLoc = Parser.getTok().getLoc();
3485
3486 int Reg = tryParseRegister();
3487 if (Reg == -1) {
3488 Error(RegLoc, "register expected");
3489 return MatchOperand_ParseFail;
3490 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003491 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003492 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003493 unsigned FirstReg = Reg;
3494 // The list is of D registers, but we also allow Q regs and just interpret
3495 // them as the two D sub-registers.
3496 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3497 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003498 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3499 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003500 ++Reg;
3501 ++Count;
3502 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003503
3504 SMLoc E;
3505 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003506 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003507
Jim Grosbache891fe82011-11-15 23:19:15 +00003508 while (Parser.getTok().is(AsmToken::Comma) ||
3509 Parser.getTok().is(AsmToken::Minus)) {
3510 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003511 if (!Spacing)
3512 Spacing = 1; // Register range implies a single spaced list.
3513 else if (Spacing == 2) {
3514 Error(Parser.getTok().getLoc(),
3515 "sequential registers in double spaced list");
3516 return MatchOperand_ParseFail;
3517 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003518 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003519 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003520 int EndReg = tryParseRegister();
3521 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003522 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003523 return MatchOperand_ParseFail;
3524 }
3525 // Allow Q regs and just interpret them as the two D sub-registers.
3526 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3527 EndReg = getDRegFromQReg(EndReg) + 1;
3528 // If the register is the same as the start reg, there's nothing
3529 // more to do.
3530 if (Reg == EndReg)
3531 continue;
3532 // The register must be in the same register class as the first.
3533 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003534 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003535 return MatchOperand_ParseFail;
3536 }
3537 // Ranges must go from low to high.
3538 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003539 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003540 return MatchOperand_ParseFail;
3541 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003542 // Parse the lane specifier if present.
3543 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003544 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003545 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3546 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003547 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003548 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003549 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003550 return MatchOperand_ParseFail;
3551 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003552
3553 // Add all the registers in the range to the register list.
3554 Count += EndReg - Reg;
3555 Reg = EndReg;
3556 continue;
3557 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003558 Parser.Lex(); // Eat the comma.
3559 RegLoc = Parser.getTok().getLoc();
3560 int OldReg = Reg;
3561 Reg = tryParseRegister();
3562 if (Reg == -1) {
3563 Error(RegLoc, "register expected");
3564 return MatchOperand_ParseFail;
3565 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003566 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003567 // It's OK to use the enumeration values directly here rather, as the
3568 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003569 //
3570 // The list is of D registers, but we also allow Q regs and just interpret
3571 // them as the two D sub-registers.
3572 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003573 if (!Spacing)
3574 Spacing = 1; // Register range implies a single spaced list.
3575 else if (Spacing == 2) {
3576 Error(RegLoc,
3577 "invalid register in double-spaced list (must be 'D' register')");
3578 return MatchOperand_ParseFail;
3579 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003580 Reg = getDRegFromQReg(Reg);
3581 if (Reg != OldReg + 1) {
3582 Error(RegLoc, "non-contiguous register range");
3583 return MatchOperand_ParseFail;
3584 }
3585 ++Reg;
3586 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003587 // Parse the lane specifier if present.
3588 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003589 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003590 SMLoc LaneLoc = Parser.getTok().getLoc();
3591 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3592 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003593 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003594 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003595 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003596 return MatchOperand_ParseFail;
3597 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003598 continue;
3599 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003600 // Normal D register.
3601 // Figure out the register spacing (single or double) of the list if
3602 // we don't know it already.
3603 if (!Spacing)
3604 Spacing = 1 + (Reg == OldReg + 2);
3605
3606 // Just check that it's contiguous and keep going.
3607 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003608 Error(RegLoc, "non-contiguous register range");
3609 return MatchOperand_ParseFail;
3610 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003611 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003612 // Parse the lane specifier if present.
3613 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003614 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003615 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003616 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003617 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003618 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003619 Error(EndLoc, "mismatched lane index in register list");
3620 return MatchOperand_ParseFail;
3621 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003622 }
3623
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003624 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003625 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003626 return MatchOperand_ParseFail;
3627 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003628 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003629 Parser.Lex(); // Eat '}' token.
3630
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003631 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003632 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003633 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003634 // composite register classes.
3635 if (Count == 2) {
3636 const MCRegisterClass *RC = (Spacing == 1) ?
3637 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3638 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3639 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3640 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003641
Jim Grosbach2f50e922011-12-15 21:44:33 +00003642 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3643 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003644 break;
3645 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003646 // Two-register operands have been converted to the
3647 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003648 if (Count == 2) {
3649 const MCRegisterClass *RC = (Spacing == 1) ?
3650 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3651 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003652 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3653 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003654 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003655 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003656 S, E));
3657 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003658 case IndexedLane:
3659 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003660 LaneIndex,
3661 (Spacing == 2),
3662 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003663 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003664 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003665 return MatchOperand_Success;
3666}
3667
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003668/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003669ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003670parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003671 SMLoc S = Parser.getTok().getLoc();
3672 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003673 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003674
Jiangning Liu288e1af2012-08-02 08:21:27 +00003675 if (Tok.is(AsmToken::Identifier)) {
3676 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003677
Jiangning Liu288e1af2012-08-02 08:21:27 +00003678 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3679 .Case("sy", ARM_MB::SY)
3680 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003681 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003682 .Case("sh", ARM_MB::ISH)
3683 .Case("ish", ARM_MB::ISH)
3684 .Case("shst", ARM_MB::ISHST)
3685 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003686 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003687 .Case("nsh", ARM_MB::NSH)
3688 .Case("un", ARM_MB::NSH)
3689 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003690 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003691 .Case("unst", ARM_MB::NSHST)
3692 .Case("osh", ARM_MB::OSH)
3693 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003694 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003695 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003696
Joey Gouly926d3f52013-09-05 15:35:24 +00003697 // ishld, oshld, nshld and ld are only available from ARMv8.
3698 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3699 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3700 Opt = ~0U;
3701
Jiangning Liu288e1af2012-08-02 08:21:27 +00003702 if (Opt == ~0U)
3703 return MatchOperand_NoMatch;
3704
3705 Parser.Lex(); // Eat identifier token.
3706 } else if (Tok.is(AsmToken::Hash) ||
3707 Tok.is(AsmToken::Dollar) ||
3708 Tok.is(AsmToken::Integer)) {
3709 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003710 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003711 SMLoc Loc = Parser.getTok().getLoc();
3712
3713 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003714 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003715 Error(Loc, "illegal expression");
3716 return MatchOperand_ParseFail;
3717 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00003718
Jiangning Liu288e1af2012-08-02 08:21:27 +00003719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3720 if (!CE) {
3721 Error(Loc, "constant expression expected");
3722 return MatchOperand_ParseFail;
3723 }
3724
3725 int Val = CE->getValue();
3726 if (Val & ~0xf) {
3727 Error(Loc, "immediate value out of range");
3728 return MatchOperand_ParseFail;
3729 }
3730
3731 Opt = ARM_MB::RESERVED_0 + Val;
3732 } else
3733 return MatchOperand_ParseFail;
3734
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003735 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003736 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003737}
3738
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003739/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3740ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3741parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3742 SMLoc S = Parser.getTok().getLoc();
3743 const AsmToken &Tok = Parser.getTok();
3744 unsigned Opt;
3745
3746 if (Tok.is(AsmToken::Identifier)) {
3747 StringRef OptStr = Tok.getString();
3748
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003749 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003750 Opt = ARM_ISB::SY;
3751 else
3752 return MatchOperand_NoMatch;
3753
3754 Parser.Lex(); // Eat identifier token.
3755 } else if (Tok.is(AsmToken::Hash) ||
3756 Tok.is(AsmToken::Dollar) ||
3757 Tok.is(AsmToken::Integer)) {
3758 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003759 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003760 SMLoc Loc = Parser.getTok().getLoc();
3761
3762 const MCExpr *ISBarrierID;
3763 if (getParser().parseExpression(ISBarrierID)) {
3764 Error(Loc, "illegal expression");
3765 return MatchOperand_ParseFail;
3766 }
3767
3768 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3769 if (!CE) {
3770 Error(Loc, "constant expression expected");
3771 return MatchOperand_ParseFail;
3772 }
3773
3774 int Val = CE->getValue();
3775 if (Val & ~0xf) {
3776 Error(Loc, "immediate value out of range");
3777 return MatchOperand_ParseFail;
3778 }
3779
3780 Opt = ARM_ISB::RESERVED_0 + Val;
3781 } else
3782 return MatchOperand_ParseFail;
3783
3784 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3785 (ARM_ISB::InstSyncBOpt)Opt, S));
3786 return MatchOperand_Success;
3787}
3788
3789
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003790/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003791ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003792parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003793 SMLoc S = Parser.getTok().getLoc();
3794 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003795 if (!Tok.is(AsmToken::Identifier))
3796 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003797 StringRef IFlagsStr = Tok.getString();
3798
Owen Anderson10c5b122011-10-05 17:16:40 +00003799 // An iflags string of "none" is interpreted to mean that none of the AIF
3800 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003801 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003802 if (IFlagsStr != "none") {
3803 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3804 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3805 .Case("a", ARM_PROC::A)
3806 .Case("i", ARM_PROC::I)
3807 .Case("f", ARM_PROC::F)
3808 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003809
Owen Anderson10c5b122011-10-05 17:16:40 +00003810 // If some specific iflag is already set, it means that some letter is
3811 // present more than once, this is not acceptable.
3812 if (Flag == ~0U || (IFlags & Flag))
3813 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003814
Owen Anderson10c5b122011-10-05 17:16:40 +00003815 IFlags |= Flag;
3816 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003817 }
3818
3819 Parser.Lex(); // Eat identifier token.
3820 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3821 return MatchOperand_Success;
3822}
3823
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003824/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003825ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003826parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003827 SMLoc S = Parser.getTok().getLoc();
3828 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003829 if (!Tok.is(AsmToken::Identifier))
3830 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003831 StringRef Mask = Tok.getString();
3832
James Molloy21efa7d2011-09-28 14:21:38 +00003833 if (isMClass()) {
3834 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003835 std::string Name = Mask.lower();
3836 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003837 // Note: in the documentation:
3838 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3839 // for MSR APSR_nzcvq.
3840 // but we do make it an alias here. This is so to get the "mask encoding"
3841 // bits correct on MSR APSR writes.
3842 //
3843 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3844 // should really only be allowed when writing a special register. Note
3845 // they get dropped in the MRS instruction reading a special register as
3846 // the SYSm field is only 8 bits.
3847 //
3848 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3849 // includes the DSP extension but that is not checked.
3850 .Case("apsr", 0x800)
3851 .Case("apsr_nzcvq", 0x800)
3852 .Case("apsr_g", 0x400)
3853 .Case("apsr_nzcvqg", 0xc00)
3854 .Case("iapsr", 0x801)
3855 .Case("iapsr_nzcvq", 0x801)
3856 .Case("iapsr_g", 0x401)
3857 .Case("iapsr_nzcvqg", 0xc01)
3858 .Case("eapsr", 0x802)
3859 .Case("eapsr_nzcvq", 0x802)
3860 .Case("eapsr_g", 0x402)
3861 .Case("eapsr_nzcvqg", 0xc02)
3862 .Case("xpsr", 0x803)
3863 .Case("xpsr_nzcvq", 0x803)
3864 .Case("xpsr_g", 0x403)
3865 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003866 .Case("ipsr", 0x805)
3867 .Case("epsr", 0x806)
3868 .Case("iepsr", 0x807)
3869 .Case("msp", 0x808)
3870 .Case("psp", 0x809)
3871 .Case("primask", 0x810)
3872 .Case("basepri", 0x811)
3873 .Case("basepri_max", 0x812)
3874 .Case("faultmask", 0x813)
3875 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003876 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003877
James Molloy21efa7d2011-09-28 14:21:38 +00003878 if (FlagsVal == ~0U)
3879 return MatchOperand_NoMatch;
3880
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003881 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003882 // basepri, basepri_max and faultmask only valid for V7m.
3883 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003884
James Molloy21efa7d2011-09-28 14:21:38 +00003885 Parser.Lex(); // Eat identifier token.
3886 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3887 return MatchOperand_Success;
3888 }
3889
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003890 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3891 size_t Start = 0, Next = Mask.find('_');
3892 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003893 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003894 if (Next != StringRef::npos)
3895 Flags = Mask.slice(Next+1, Mask.size());
3896
3897 // FlagsVal contains the complete mask:
3898 // 3-0: Mask
3899 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3900 unsigned FlagsVal = 0;
3901
3902 if (SpecReg == "apsr") {
3903 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003904 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003905 .Case("g", 0x4) // same as CPSR_s
3906 .Case("nzcvqg", 0xc) // same as CPSR_fs
3907 .Default(~0U);
3908
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003909 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003910 if (!Flags.empty())
3911 return MatchOperand_NoMatch;
3912 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003913 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003914 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003915 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003916 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3917 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003918 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003919 for (int i = 0, e = Flags.size(); i != e; ++i) {
3920 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3921 .Case("c", 1)
3922 .Case("x", 2)
3923 .Case("s", 4)
3924 .Case("f", 8)
3925 .Default(~0U);
3926
3927 // If some specific flag is already set, it means that some letter is
3928 // present more than once, this is not acceptable.
3929 if (FlagsVal == ~0U || (FlagsVal & Flag))
3930 return MatchOperand_NoMatch;
3931 FlagsVal |= Flag;
3932 }
3933 } else // No match for special register.
3934 return MatchOperand_NoMatch;
3935
Owen Anderson03a173e2011-10-21 18:43:28 +00003936 // Special register without flags is NOT equivalent to "fc" flags.
3937 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3938 // two lines would enable gas compatibility at the expense of breaking
3939 // round-tripping.
3940 //
3941 // if (!FlagsVal)
3942 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003943
3944 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3945 if (SpecReg == "spsr")
3946 FlagsVal |= 16;
3947
3948 Parser.Lex(); // Eat identifier token.
3949 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3950 return MatchOperand_Success;
3951}
3952
Jim Grosbach27c1e252011-07-21 17:23:04 +00003953ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3954parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3955 int Low, int High) {
3956 const AsmToken &Tok = Parser.getTok();
3957 if (Tok.isNot(AsmToken::Identifier)) {
3958 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3959 return MatchOperand_ParseFail;
3960 }
3961 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003962 std::string LowerOp = Op.lower();
3963 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003964 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3965 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3966 return MatchOperand_ParseFail;
3967 }
3968 Parser.Lex(); // Eat shift type token.
3969
3970 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003971 if (Parser.getTok().isNot(AsmToken::Hash) &&
3972 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003973 Error(Parser.getTok().getLoc(), "'#' expected");
3974 return MatchOperand_ParseFail;
3975 }
3976 Parser.Lex(); // Eat hash token.
3977
3978 const MCExpr *ShiftAmount;
3979 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003980 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003981 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003982 Error(Loc, "illegal expression");
3983 return MatchOperand_ParseFail;
3984 }
3985 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3986 if (!CE) {
3987 Error(Loc, "constant expression expected");
3988 return MatchOperand_ParseFail;
3989 }
3990 int Val = CE->getValue();
3991 if (Val < Low || Val > High) {
3992 Error(Loc, "immediate value out of range");
3993 return MatchOperand_ParseFail;
3994 }
3995
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003996 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003997
3998 return MatchOperand_Success;
3999}
4000
Jim Grosbach0a547702011-07-22 17:44:50 +00004001ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4002parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4003 const AsmToken &Tok = Parser.getTok();
4004 SMLoc S = Tok.getLoc();
4005 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004006 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004007 return MatchOperand_ParseFail;
4008 }
Tim Northover4d141442013-05-31 15:58:45 +00004009 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00004010 .Case("be", 1)
4011 .Case("le", 0)
4012 .Default(-1);
4013 Parser.Lex(); // Eat the token.
4014
4015 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004016 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004017 return MatchOperand_ParseFail;
4018 }
4019 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4020 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004021 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00004022 return MatchOperand_Success;
4023}
4024
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004025/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
4026/// instructions. Legal values are:
4027/// lsl #n 'n' in [0,31]
4028/// asr #n 'n' in [1,32]
4029/// n == 32 encoded as n == 0.
4030ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4031parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4032 const AsmToken &Tok = Parser.getTok();
4033 SMLoc S = Tok.getLoc();
4034 if (Tok.isNot(AsmToken::Identifier)) {
4035 Error(S, "shift operator 'asr' or 'lsl' expected");
4036 return MatchOperand_ParseFail;
4037 }
4038 StringRef ShiftName = Tok.getString();
4039 bool isASR;
4040 if (ShiftName == "lsl" || ShiftName == "LSL")
4041 isASR = false;
4042 else if (ShiftName == "asr" || ShiftName == "ASR")
4043 isASR = true;
4044 else {
4045 Error(S, "shift operator 'asr' or 'lsl' expected");
4046 return MatchOperand_ParseFail;
4047 }
4048 Parser.Lex(); // Eat the operator.
4049
4050 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004051 if (Parser.getTok().isNot(AsmToken::Hash) &&
4052 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004053 Error(Parser.getTok().getLoc(), "'#' expected");
4054 return MatchOperand_ParseFail;
4055 }
4056 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004057 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004058
4059 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004060 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004061 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004062 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004063 return MatchOperand_ParseFail;
4064 }
4065 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4066 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004067 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004068 return MatchOperand_ParseFail;
4069 }
4070
4071 int64_t Val = CE->getValue();
4072 if (isASR) {
4073 // Shift amount must be in [1,32]
4074 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004075 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004076 return MatchOperand_ParseFail;
4077 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00004078 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4079 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004080 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00004081 return MatchOperand_ParseFail;
4082 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004083 if (Val == 32) Val = 0;
4084 } else {
4085 // Shift amount must be in [1,32]
4086 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004087 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004088 return MatchOperand_ParseFail;
4089 }
4090 }
4091
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004092 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004093
4094 return MatchOperand_Success;
4095}
4096
Jim Grosbach833b9d32011-07-27 20:15:40 +00004097/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4098/// of instructions. Legal values are:
4099/// ror #n 'n' in {0, 8, 16, 24}
4100ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4101parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4102 const AsmToken &Tok = Parser.getTok();
4103 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00004104 if (Tok.isNot(AsmToken::Identifier))
4105 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004106 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00004107 if (ShiftName != "ror" && ShiftName != "ROR")
4108 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004109 Parser.Lex(); // Eat the operator.
4110
4111 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004112 if (Parser.getTok().isNot(AsmToken::Hash) &&
4113 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004114 Error(Parser.getTok().getLoc(), "'#' expected");
4115 return MatchOperand_ParseFail;
4116 }
4117 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004118 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004119
4120 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004121 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004122 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004123 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004124 return MatchOperand_ParseFail;
4125 }
4126 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4127 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004128 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004129 return MatchOperand_ParseFail;
4130 }
4131
4132 int64_t Val = CE->getValue();
4133 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4134 // normally, zero is represented in asm by omitting the rotate operand
4135 // entirely.
4136 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004137 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004138 return MatchOperand_ParseFail;
4139 }
4140
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004141 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004142
4143 return MatchOperand_Success;
4144}
4145
Jim Grosbach864b6092011-07-28 21:34:26 +00004146ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4147parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4148 SMLoc S = Parser.getTok().getLoc();
4149 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004150 if (Parser.getTok().isNot(AsmToken::Hash) &&
4151 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004152 Error(Parser.getTok().getLoc(), "'#' expected");
4153 return MatchOperand_ParseFail;
4154 }
4155 Parser.Lex(); // Eat hash token.
4156
4157 const MCExpr *LSBExpr;
4158 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004159 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004160 Error(E, "malformed immediate expression");
4161 return MatchOperand_ParseFail;
4162 }
4163 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4164 if (!CE) {
4165 Error(E, "'lsb' operand must be an immediate");
4166 return MatchOperand_ParseFail;
4167 }
4168
4169 int64_t LSB = CE->getValue();
4170 // The LSB must be in the range [0,31]
4171 if (LSB < 0 || LSB > 31) {
4172 Error(E, "'lsb' operand must be in the range [0,31]");
4173 return MatchOperand_ParseFail;
4174 }
4175 E = Parser.getTok().getLoc();
4176
4177 // Expect another immediate operand.
4178 if (Parser.getTok().isNot(AsmToken::Comma)) {
4179 Error(Parser.getTok().getLoc(), "too few operands");
4180 return MatchOperand_ParseFail;
4181 }
4182 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004183 if (Parser.getTok().isNot(AsmToken::Hash) &&
4184 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004185 Error(Parser.getTok().getLoc(), "'#' expected");
4186 return MatchOperand_ParseFail;
4187 }
4188 Parser.Lex(); // Eat hash token.
4189
4190 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004191 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004192 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004193 Error(E, "malformed immediate expression");
4194 return MatchOperand_ParseFail;
4195 }
4196 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4197 if (!CE) {
4198 Error(E, "'width' operand must be an immediate");
4199 return MatchOperand_ParseFail;
4200 }
4201
4202 int64_t Width = CE->getValue();
4203 // The LSB must be in the range [1,32-lsb]
4204 if (Width < 1 || Width > 32 - LSB) {
4205 Error(E, "'width' operand must be in the range [1,32-lsb]");
4206 return MatchOperand_ParseFail;
4207 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004208
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004209 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004210
4211 return MatchOperand_Success;
4212}
4213
Jim Grosbachd3595712011-08-03 23:50:40 +00004214ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4215parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4216 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004217 // postidx_reg := '+' register {, shift}
4218 // | '-' register {, shift}
4219 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004220
4221 // This method must return MatchOperand_NoMatch without consuming any tokens
4222 // in the case where there is no match, as other alternatives take other
4223 // parse methods.
4224 AsmToken Tok = Parser.getTok();
4225 SMLoc S = Tok.getLoc();
4226 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004227 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004228 if (Tok.is(AsmToken::Plus)) {
4229 Parser.Lex(); // Eat the '+' token.
4230 haveEaten = true;
4231 } else if (Tok.is(AsmToken::Minus)) {
4232 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004233 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004234 haveEaten = true;
4235 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004236
4237 SMLoc E = Parser.getTok().getEndLoc();
4238 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004239 if (Reg == -1) {
4240 if (!haveEaten)
4241 return MatchOperand_NoMatch;
4242 Error(Parser.getTok().getLoc(), "register expected");
4243 return MatchOperand_ParseFail;
4244 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004245
Jim Grosbachc320c852011-08-05 21:28:30 +00004246 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4247 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004248 if (Parser.getTok().is(AsmToken::Comma)) {
4249 Parser.Lex(); // Eat the ','.
4250 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4251 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004252
4253 // FIXME: Only approximates end...may include intervening whitespace.
4254 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004255 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004256
4257 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4258 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004259
4260 return MatchOperand_Success;
4261}
4262
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004263ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4264parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4265 // Check for a post-index addressing register operand. Specifically:
4266 // am3offset := '+' register
4267 // | '-' register
4268 // | register
4269 // | # imm
4270 // | # + imm
4271 // | # - imm
4272
4273 // This method must return MatchOperand_NoMatch without consuming any tokens
4274 // in the case where there is no match, as other alternatives take other
4275 // parse methods.
4276 AsmToken Tok = Parser.getTok();
4277 SMLoc S = Tok.getLoc();
4278
4279 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004280 if (Parser.getTok().is(AsmToken::Hash) ||
4281 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004282 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004283 // Explicitly look for a '-', as we need to encode negative zero
4284 // differently.
4285 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4286 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004287 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004288 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004289 return MatchOperand_ParseFail;
4290 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4291 if (!CE) {
4292 Error(S, "constant expression expected");
4293 return MatchOperand_ParseFail;
4294 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004295 // Negative zero is encoded as the flag value INT32_MIN.
4296 int32_t Val = CE->getValue();
4297 if (isNegative && Val == 0)
4298 Val = INT32_MIN;
4299
4300 Operands.push_back(
4301 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4302
4303 return MatchOperand_Success;
4304 }
4305
4306
4307 bool haveEaten = false;
4308 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004309 if (Tok.is(AsmToken::Plus)) {
4310 Parser.Lex(); // Eat the '+' token.
4311 haveEaten = true;
4312 } else if (Tok.is(AsmToken::Minus)) {
4313 Parser.Lex(); // Eat the '-' token.
4314 isAdd = false;
4315 haveEaten = true;
4316 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004317
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004318 Tok = Parser.getTok();
4319 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004320 if (Reg == -1) {
4321 if (!haveEaten)
4322 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004323 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004324 return MatchOperand_ParseFail;
4325 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004326
4327 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004328 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004329
4330 return MatchOperand_Success;
4331}
4332
Tim Northovereb5e4d52013-07-22 09:06:12 +00004333/// Convert parsed operands to MCInst. Needed here because this instruction
4334/// only has two register operands, but multiplication is commutative so
4335/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004336void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004337cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004338 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004339 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4340 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004341 // If we have a three-operand form, make sure to set Rn to be the operand
4342 // that isn't the same as Rd.
4343 unsigned RegOp = 4;
4344 if (Operands.size() == 6 &&
4345 ((ARMOperand*)Operands[4])->getReg() ==
4346 ((ARMOperand*)Operands[3])->getReg())
4347 RegOp = 5;
4348 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4349 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004350 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004351}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004352
Mihai Popaad18d3c2013-08-09 10:38:32 +00004353void ARMAsmParser::
4354cvtThumbBranches(MCInst &Inst,
4355 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4356 int CondOp = -1, ImmOp = -1;
4357 switch(Inst.getOpcode()) {
4358 case ARM::tB:
4359 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4360
4361 case ARM::t2B:
4362 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4363
4364 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4365 }
4366 // first decide whether or not the branch should be conditional
4367 // by looking at it's location relative to an IT block
4368 if(inITBlock()) {
4369 // inside an IT block we cannot have any conditional branches. any
4370 // such instructions needs to be converted to unconditional form
4371 switch(Inst.getOpcode()) {
4372 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4373 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4374 }
4375 } else {
4376 // outside IT blocks we can only have unconditional branches with AL
4377 // condition code or conditional branches with non-AL condition code
4378 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4379 switch(Inst.getOpcode()) {
4380 case ARM::tB:
4381 case ARM::tBcc:
4382 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4383 break;
4384 case ARM::t2B:
4385 case ARM::t2Bcc:
4386 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4387 break;
4388 }
4389 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004390
Mihai Popaad18d3c2013-08-09 10:38:32 +00004391 // now decide on encoding size based on branch target range
4392 switch(Inst.getOpcode()) {
4393 // classify tB as either t2B or t1B based on range of immediate operand
4394 case ARM::tB: {
4395 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4396 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4397 Inst.setOpcode(ARM::t2B);
4398 break;
4399 }
4400 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4401 case ARM::tBcc: {
4402 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4403 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4404 Inst.setOpcode(ARM::t2Bcc);
4405 break;
4406 }
4407 }
4408 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4409 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4410}
4411
Bill Wendlinge18980a2010-11-06 22:36:58 +00004412/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004413/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004414bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004415parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004416 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004417 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004418 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004419 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004420 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004421
Sean Callanan936b0d32010-01-19 21:44:56 +00004422 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004423 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004424 if (BaseRegNum == -1)
4425 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004426
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004427 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004428 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004429 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4430 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004431 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004432
Jim Grosbachd3595712011-08-03 23:50:40 +00004433 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004434 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004435 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004436
Jim Grosbachd3595712011-08-03 23:50:40 +00004437 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004438 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004439
Jim Grosbach40700e02011-09-19 18:42:21 +00004440 // If there's a pre-indexing writeback marker, '!', just add it as a token
4441 // operand. It's rather odd, but syntactically valid.
4442 if (Parser.getTok().is(AsmToken::Exclaim)) {
4443 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4444 Parser.Lex(); // Eat the '!'.
4445 }
4446
Jim Grosbachd3595712011-08-03 23:50:40 +00004447 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004448 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004449
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004450 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4451 "Lost colon or comma in memory operand?!");
4452 if (Tok.is(AsmToken::Comma)) {
4453 Parser.Lex(); // Eat the comma.
4454 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004455
Jim Grosbacha95ec992011-10-11 17:29:55 +00004456 // If we have a ':', it's an alignment specifier.
4457 if (Parser.getTok().is(AsmToken::Colon)) {
4458 Parser.Lex(); // Eat the ':'.
4459 E = Parser.getTok().getLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00004460 SMLoc AlignmentLoc = Tok.getLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004461
4462 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004463 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004464 return true;
4465
4466 // The expression has to be a constant. Memory references with relocations
4467 // don't come through here, as they use the <label> forms of the relevant
4468 // instructions.
4469 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4470 if (!CE)
4471 return Error (E, "constant expression expected");
4472
4473 unsigned Align = 0;
4474 switch (CE->getValue()) {
4475 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004476 return Error(E,
4477 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4478 case 16: Align = 2; break;
4479 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004480 case 64: Align = 8; break;
4481 case 128: Align = 16; break;
4482 case 256: Align = 32; break;
4483 }
4484
4485 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004486 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004487 return Error(Parser.getTok().getLoc(), "']' expected");
4488 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004489 Parser.Lex(); // Eat right bracket token.
4490
4491 // Don't worry about range checking the value here. That's handled by
4492 // the is*() predicates.
4493 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4494 ARM_AM::no_shift, 0, Align,
Kevin Enderby488f20b2014-04-10 20:18:58 +00004495 false, S, E, AlignmentLoc));
Jim Grosbacha95ec992011-10-11 17:29:55 +00004496
4497 // If there's a pre-indexing writeback marker, '!', just add it as a token
4498 // operand.
4499 if (Parser.getTok().is(AsmToken::Exclaim)) {
4500 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4501 Parser.Lex(); // Eat the '!'.
4502 }
4503
4504 return false;
4505 }
4506
4507 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004508 // offset. Be friendly and also accept a plain integer (without a leading
4509 // hash) for gas compatibility.
4510 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004511 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004512 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004513 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004514 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004515 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004516
Owen Anderson967674d2011-08-29 19:36:44 +00004517 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004518 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004519 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004520 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004521
4522 // The expression has to be a constant. Memory references with relocations
4523 // don't come through here, as they use the <label> forms of the relevant
4524 // instructions.
4525 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4526 if (!CE)
4527 return Error (E, "constant expression expected");
4528
Owen Anderson967674d2011-08-29 19:36:44 +00004529 // If the constant was #-0, represent it as INT32_MIN.
4530 int32_t Val = CE->getValue();
4531 if (isNegative && Val == 0)
4532 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4533
Jim Grosbachd3595712011-08-03 23:50:40 +00004534 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004535 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004536 return Error(Parser.getTok().getLoc(), "']' expected");
4537 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004538 Parser.Lex(); // Eat right bracket token.
4539
4540 // Don't worry about range checking the value here. That's handled by
4541 // the is*() predicates.
4542 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004543 ARM_AM::no_shift, 0, 0,
4544 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004545
4546 // If there's a pre-indexing writeback marker, '!', just add it as a token
4547 // operand.
4548 if (Parser.getTok().is(AsmToken::Exclaim)) {
4549 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4550 Parser.Lex(); // Eat the '!'.
4551 }
4552
4553 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004554 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004555
4556 // The register offset is optionally preceded by a '+' or '-'
4557 bool isNegative = false;
4558 if (Parser.getTok().is(AsmToken::Minus)) {
4559 isNegative = true;
4560 Parser.Lex(); // Eat the '-'.
4561 } else if (Parser.getTok().is(AsmToken::Plus)) {
4562 // Nothing to do.
4563 Parser.Lex(); // Eat the '+'.
4564 }
4565
4566 E = Parser.getTok().getLoc();
4567 int OffsetRegNum = tryParseRegister();
4568 if (OffsetRegNum == -1)
4569 return Error(E, "register expected");
4570
4571 // If there's a shift operator, handle it.
4572 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004573 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004574 if (Parser.getTok().is(AsmToken::Comma)) {
4575 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004576 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004577 return true;
4578 }
4579
4580 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004581 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004582 return Error(Parser.getTok().getLoc(), "']' expected");
4583 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004584 Parser.Lex(); // Eat right bracket token.
4585
4586 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004587 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004588 S, E));
4589
Jim Grosbachc320c852011-08-05 21:28:30 +00004590 // If there's a pre-indexing writeback marker, '!', just add it as a token
4591 // operand.
4592 if (Parser.getTok().is(AsmToken::Exclaim)) {
4593 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4594 Parser.Lex(); // Eat the '!'.
4595 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004596
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004597 return false;
4598}
4599
Jim Grosbachd3595712011-08-03 23:50:40 +00004600/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004601/// ( lsl | lsr | asr | ror ) , # shift_amount
4602/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004603/// return true if it parses a shift otherwise it returns false.
4604bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4605 unsigned &Amount) {
4606 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004607 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004608 if (Tok.isNot(AsmToken::Identifier))
4609 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004610 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004611 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4612 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004613 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004614 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004615 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004616 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004617 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004618 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004619 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004620 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004621 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004622 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004623 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004624 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004625
Jim Grosbachd3595712011-08-03 23:50:40 +00004626 // rrx stands alone.
4627 Amount = 0;
4628 if (St != ARM_AM::rrx) {
4629 Loc = Parser.getTok().getLoc();
4630 // A '#' and a shift amount.
4631 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004632 if (HashTok.isNot(AsmToken::Hash) &&
4633 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004634 return Error(HashTok.getLoc(), "'#' expected");
4635 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004636
Jim Grosbachd3595712011-08-03 23:50:40 +00004637 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004638 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004639 return true;
4640 // Range check the immediate.
4641 // lsl, ror: 0 <= imm <= 31
4642 // lsr, asr: 0 <= imm <= 32
4643 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4644 if (!CE)
4645 return Error(Loc, "shift amount must be an immediate");
4646 int64_t Imm = CE->getValue();
4647 if (Imm < 0 ||
4648 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4649 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4650 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004651 // If <ShiftTy> #0, turn it into a no_shift.
4652 if (Imm == 0)
4653 St = ARM_AM::lsl;
4654 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4655 if (Imm == 32)
4656 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004657 Amount = Imm;
4658 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004659
4660 return false;
4661}
4662
Jim Grosbache7fbce72011-10-03 23:38:36 +00004663/// parseFPImm - A floating point immediate expression operand.
4664ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4665parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004666 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004667 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004668 // integer only.
4669 //
4670 // This routine still creates a generic Immediate operand, containing
4671 // a bitcast of the 64-bit floating point value. The various operands
4672 // that accept floats can check whether the value is valid for them
4673 // via the standard is*() predicates.
4674
Jim Grosbache7fbce72011-10-03 23:38:36 +00004675 SMLoc S = Parser.getTok().getLoc();
4676
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004677 if (Parser.getTok().isNot(AsmToken::Hash) &&
4678 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004679 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004680
4681 // Disambiguate the VMOV forms that can accept an FP immediate.
4682 // vmov.f32 <sreg>, #imm
4683 // vmov.f64 <dreg>, #imm
4684 // vmov.f32 <dreg>, #imm @ vector f32x2
4685 // vmov.f32 <qreg>, #imm @ vector f32x4
4686 //
4687 // There are also the NEON VMOV instructions which expect an
4688 // integer constant. Make sure we don't try to parse an FPImm
4689 // for these:
4690 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4691 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
David Peixottoa872e0e2014-01-07 18:19:23 +00004692 bool isVmovf = TyOp->isToken() && (TyOp->getToken() == ".f32" ||
4693 TyOp->getToken() == ".f64");
4694 ARMOperand *Mnemonic = static_cast<ARMOperand*>(Operands[0]);
4695 bool isFconst = Mnemonic->isToken() && (Mnemonic->getToken() == "fconstd" ||
4696 Mnemonic->getToken() == "fconsts");
4697 if (!(isVmovf || isFconst))
Jim Grosbach741cd732011-10-17 22:26:03 +00004698 return MatchOperand_NoMatch;
4699
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004700 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004701
4702 // Handle negation, as that still comes through as a separate token.
4703 bool isNegative = false;
4704 if (Parser.getTok().is(AsmToken::Minus)) {
4705 isNegative = true;
4706 Parser.Lex();
4707 }
4708 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004709 SMLoc Loc = Tok.getLoc();
David Peixottoa872e0e2014-01-07 18:19:23 +00004710 if (Tok.is(AsmToken::Real) && isVmovf) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004711 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004712 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4713 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004714 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004715 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004716 Operands.push_back(ARMOperand::CreateImm(
4717 MCConstantExpr::Create(IntVal, getContext()),
4718 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004719 return MatchOperand_Success;
4720 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004721 // Also handle plain integers. Instructions which allow floating point
4722 // immediates also allow a raw encoded 8-bit value.
David Peixottoa872e0e2014-01-07 18:19:23 +00004723 if (Tok.is(AsmToken::Integer) && isFconst) {
Jim Grosbache7fbce72011-10-03 23:38:36 +00004724 int64_t Val = Tok.getIntVal();
4725 Parser.Lex(); // Eat the token.
4726 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004727 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004728 return MatchOperand_ParseFail;
4729 }
David Peixottoa872e0e2014-01-07 18:19:23 +00004730 float RealVal = ARM_AM::getFPImmFloat(Val);
4731 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
4732
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004733 Operands.push_back(ARMOperand::CreateImm(
4734 MCConstantExpr::Create(Val, getContext()), S,
4735 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004736 return MatchOperand_Success;
4737 }
4738
Jim Grosbach235c8d22012-01-19 02:47:30 +00004739 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004740 return MatchOperand_ParseFail;
4741}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004742
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004743/// Parse a arm instruction operand. For now this parses the operand regardless
4744/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004745bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004746 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004747 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004748
4749 // Check if the current operand has a custom associated parser, if so, try to
4750 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004751 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4752 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004753 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004754 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4755 // there was a match, but an error occurred, in which case, just return that
4756 // the operand parsing failed.
4757 if (ResTy == MatchOperand_ParseFail)
4758 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004759
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004760 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004761 default:
4762 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004763 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004764 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004765 // If we've seen a branch mnemonic, the next operand must be a label. This
4766 // is true even if the label is a register name. So "br r1" means branch to
4767 // label "r1".
4768 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4769 if (!ExpectLabel) {
4770 if (!tryParseRegisterWithWriteBack(Operands))
4771 return false;
4772 int Res = tryParseShiftRegister(Operands);
4773 if (Res == 0) // success
4774 return false;
4775 else if (Res == -1) // irrecoverable error
4776 return true;
4777 // If this is VMRS, check for the apsr_nzcv operand.
4778 if (Mnemonic == "vmrs" &&
4779 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4780 S = Parser.getTok().getLoc();
4781 Parser.Lex();
4782 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4783 return false;
4784 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004785 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004786
4787 // Fall though for the Identifier case that is not a register or a
4788 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004789 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004790 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004791 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004792 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004793 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004794 // This was not a register so parse other operands that start with an
4795 // identifier (like labels) as expressions and create them as immediates.
4796 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004797 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004798 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004799 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004800 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004801 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4802 return false;
4803 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004804 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004805 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004806 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004807 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004808 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004809 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004810 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004811 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004812 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004813
4814 if (Parser.getTok().isNot(AsmToken::Colon)) {
4815 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4816 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004817 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004818 return true;
4819 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4820 if (CE) {
4821 int32_t Val = CE->getValue();
4822 if (isNegative && Val == 0)
4823 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4824 }
4825 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4826 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004827
4828 // There can be a trailing '!' on operands that we want as a separate
Saleem Abdulrasool83e37702013-12-28 03:07:12 +00004829 // '!' Token operand. Handle that here. For example, the compatibility
Jim Grosbach9be2d712013-02-23 00:52:09 +00004830 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4831 if (Parser.getTok().is(AsmToken::Exclaim)) {
4832 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4833 Parser.getTok().getLoc()));
4834 Parser.Lex(); // Eat exclaim token
4835 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004836 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004837 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004838 // w/ a ':' after the '#', it's just like a plain ':'.
4839 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004840 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004841 case AsmToken::Colon: {
4842 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004843 // FIXME: Check it's an expression prefix,
4844 // e.g. (FOO - :lower16:BAR) isn't legal.
4845 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004846 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004847 return true;
4848
Evan Cheng965b3c72011-01-13 07:58:56 +00004849 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004850 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004851 return true;
4852
Evan Cheng965b3c72011-01-13 07:58:56 +00004853 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004854 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004855 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004856 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004857 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004858 }
David Peixottoe407d092013-12-19 18:12:36 +00004859 case AsmToken::Equal: {
4860 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4861 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4862
David Peixottoe407d092013-12-19 18:12:36 +00004863 Parser.Lex(); // Eat '='
4864 const MCExpr *SubExprVal;
4865 if (getParser().parseExpression(SubExprVal))
4866 return true;
4867 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4868
David Peixottob9b73622014-02-04 17:22:40 +00004869 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
David Peixottoe407d092013-12-19 18:12:36 +00004870 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4871 return false;
4872 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004873 }
4874}
4875
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004876// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004877// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004878bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004879 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004880
Saleem Abdulrasool435f4562014-01-10 04:38:40 +00004881 // consume an optional '#' (GNU compatibility)
4882 if (getLexer().is(AsmToken::Hash))
4883 Parser.Lex();
4884
Jason W Kim1f7bc072011-01-11 23:53:41 +00004885 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004886 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004887 Parser.Lex(); // Eat ':'
4888
4889 if (getLexer().isNot(AsmToken::Identifier)) {
4890 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4891 return true;
4892 }
4893
4894 StringRef IDVal = Parser.getTok().getIdentifier();
4895 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004896 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004897 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004898 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004899 } else {
4900 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4901 return true;
4902 }
4903 Parser.Lex();
4904
4905 if (getLexer().isNot(AsmToken::Colon)) {
4906 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4907 return true;
4908 }
4909 Parser.Lex(); // Eat the last ':'
4910 return false;
4911}
4912
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004913/// \brief Given a mnemonic, split out possible predication code and carry
4914/// setting letters to form a canonical mnemonic and flags.
4915//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004916// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004917// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004918StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004919 unsigned &PredicationCode,
4920 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004921 unsigned &ProcessorIMod,
4922 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004923 PredicationCode = ARMCC::AL;
4924 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004925 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004926
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004927 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004928 //
4929 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004930 if ((Mnemonic == "movs" && isThumb()) ||
4931 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4932 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4933 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4934 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004935 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004936 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4937 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004938 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004939 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004940 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4941 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4942 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004943 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004944
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004945 // First, split out any predication code. Ignore mnemonics we know aren't
4946 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004947 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004948 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004949 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004950 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004951 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4952 .Case("eq", ARMCC::EQ)
4953 .Case("ne", ARMCC::NE)
4954 .Case("hs", ARMCC::HS)
4955 .Case("cs", ARMCC::HS)
4956 .Case("lo", ARMCC::LO)
4957 .Case("cc", ARMCC::LO)
4958 .Case("mi", ARMCC::MI)
4959 .Case("pl", ARMCC::PL)
4960 .Case("vs", ARMCC::VS)
4961 .Case("vc", ARMCC::VC)
4962 .Case("hi", ARMCC::HI)
4963 .Case("ls", ARMCC::LS)
4964 .Case("ge", ARMCC::GE)
4965 .Case("lt", ARMCC::LT)
4966 .Case("gt", ARMCC::GT)
4967 .Case("le", ARMCC::LE)
4968 .Case("al", ARMCC::AL)
4969 .Default(~0U);
4970 if (CC != ~0U) {
4971 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4972 PredicationCode = CC;
4973 }
Bill Wendling193961b2010-10-29 23:50:21 +00004974 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004975
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004976 // Next, determine if we have a carry setting bit. We explicitly ignore all
4977 // the instructions we know end in 's'.
4978 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004979 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004980 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4981 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4982 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004983 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004984 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004985 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004986 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
David Peixottoa872e0e2014-01-07 18:19:23 +00004987 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004988 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004989 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4990 CarrySetting = true;
4991 }
4992
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004993 // The "cps" instruction can have a interrupt mode operand which is glued into
4994 // the mnemonic. Check if this is the case, split it and parse the imod op
4995 if (Mnemonic.startswith("cps")) {
4996 // Split out any imod code.
4997 unsigned IMod =
4998 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4999 .Case("ie", ARM_PROC::IE)
5000 .Case("id", ARM_PROC::ID)
5001 .Default(~0U);
5002 if (IMod != ~0U) {
5003 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5004 ProcessorIMod = IMod;
5005 }
5006 }
5007
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005008 // The "it" instruction has the condition mask on the end of the mnemonic.
5009 if (Mnemonic.startswith("it")) {
5010 ITMask = Mnemonic.slice(2, Mnemonic.size());
5011 Mnemonic = Mnemonic.slice(0, 2);
5012 }
5013
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005014 return Mnemonic;
5015}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005016
5017/// \brief Given a canonical mnemonic, determine if the instruction ever allows
5018/// inclusion of carry set or predication code operands.
5019//
5020// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00005021void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00005022getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5023 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005024 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5025 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005026 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005027 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005028 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005029 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005030 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00005031 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005032 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005033 Mnemonic == "mla" || Mnemonic == "smlal" ||
5034 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005035 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00005036 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00005037 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005038
Tim Northover2c45a382013-06-26 16:52:40 +00005039 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5040 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Joey Gouly2f8890e2013-09-18 09:45:55 +00005041 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00005042 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
5043 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005044 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
5045 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00005046 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
5047 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5048 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00005049 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005050 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005051 } else if (!isThumb()) {
5052 // Some instructions are only predicable in Thumb mode
5053 CanAcceptPredicationCode
5054 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5055 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5056 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5057 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5058 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5059 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5060 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5061 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00005062 if (hasV6MOps())
5063 CanAcceptPredicationCode = Mnemonic != "movs";
5064 else
5065 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005066 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005067 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005068}
5069
Jim Grosbach7283da92011-08-16 21:12:37 +00005070bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
5071 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005072 // FIXME: This is all horribly hacky. We really need a better way to deal
5073 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005074
5075 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5076 // another does not. Specifically, the MOVW instruction does not. So we
5077 // special case it here and remove the defaulted (non-setting) cc_out
5078 // operand if that's the instruction we're trying to match.
5079 //
5080 // We do this as post-processing of the explicit operands rather than just
5081 // conditionally adding the cc_out in the first place because we need
5082 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005083 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00005084 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
5085 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
5086 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5087 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005088
5089 // Register-register 'add' for thumb does not have a cc_out operand
5090 // when there are only two register operands.
5091 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
5092 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5093 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5094 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5095 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005096 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005097 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5098 // have to check the immediate range here since Thumb2 has a variant
5099 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005100 if (((isThumb() && Mnemonic == "add") ||
5101 (isThumbTwo() && Mnemonic == "sub")) &&
5102 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005103 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5104 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5105 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005106 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005107 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005108 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005109 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005110 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5111 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005112 // selecting via the generic "add" mnemonic, so to know that we
5113 // should remove the cc_out operand, we have to explicitly check that
5114 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005115 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
5116 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005117 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5118 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5119 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5120 // Nest conditions rather than one big 'if' statement for readability.
5121 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005122 // If both registers are low, we're in an IT block, and the immediate is
5123 // in range, we should use encoding T1 instead, which has a cc_out.
5124 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005125 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005126 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5127 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5128 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005129 // Check against T3. If the second register is the PC, this is an
5130 // alternate form of ADR, which uses encoding T4, so check for that too.
5131 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5132 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5133 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005134
5135 // Otherwise, we use encoding T4, which does not have a cc_out
5136 // operand.
5137 return true;
5138 }
5139
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005140 // The thumb2 multiply instruction doesn't have a CCOut register, so
5141 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5142 // use the 16-bit encoding or not.
5143 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5144 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5145 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5146 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5147 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5148 // If the registers aren't low regs, the destination reg isn't the
5149 // same as one of the source regs, or the cc_out operand is zero
5150 // outside of an IT block, we have to use the 32-bit encoding, so
5151 // remove the cc_out operand.
5152 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5153 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00005154 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005155 !inITBlock() ||
5156 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5157 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5158 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5159 static_cast<ARMOperand*>(Operands[4])->getReg())))
5160 return true;
5161
Jim Grosbachefa7e952011-11-15 19:55:16 +00005162 // Also check the 'mul' syntax variant that doesn't specify an explicit
5163 // destination register.
5164 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5165 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5166 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5167 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5168 // If the registers aren't low regs or the cc_out operand is zero
5169 // outside of an IT block, we have to use the 32-bit encoding, so
5170 // remove the cc_out operand.
5171 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5172 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5173 !inITBlock()))
5174 return true;
5175
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005176
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005177
Jim Grosbach4b701af2011-08-24 21:42:27 +00005178 // Register-register 'add/sub' for thumb does not have a cc_out operand
5179 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5180 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5181 // right, this will result in better diagnostics (which operand is off)
5182 // anyway.
5183 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5184 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005185 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5186 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005187 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5188 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5189 (Operands.size() == 6 &&
5190 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005191 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005192
Jim Grosbach7283da92011-08-16 21:12:37 +00005193 return false;
5194}
5195
Joey Goulye8602552013-07-19 16:34:16 +00005196bool ARMAsmParser::shouldOmitPredicateOperand(
5197 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
5198 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5199 unsigned RegIdx = 3;
5200 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5201 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
5202 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
5203 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
5204 RegIdx = 4;
5205
5206 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
5207 (ARMMCRegisterClasses[ARM::DPRRegClassID]
5208 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
5209 ARMMCRegisterClasses[ARM::QPRRegClassID]
5210 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
5211 return true;
5212 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005213 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005214}
5215
Jim Grosbach12952fe2011-11-11 23:08:10 +00005216static bool isDataTypeToken(StringRef Tok) {
5217 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5218 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5219 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5220 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5221 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5222 Tok == ".f" || Tok == ".d";
5223}
5224
5225// FIXME: This bit should probably be handled via an explicit match class
5226// in the .td files that matches the suffix instead of having it be
5227// a literal string token the way it is now.
5228static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5229 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5230}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005231static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5232 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005233
5234static bool RequiresVFPRegListValidation(StringRef Inst,
5235 bool &AcceptSinglePrecisionOnly,
5236 bool &AcceptDoublePrecisionOnly) {
5237 if (Inst.size() < 7)
5238 return false;
5239
5240 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5241 StringRef AddressingMode = Inst.substr(4, 2);
5242 if (AddressingMode == "ia" || AddressingMode == "db" ||
5243 AddressingMode == "ea" || AddressingMode == "fd") {
5244 AcceptSinglePrecisionOnly = Inst[6] == 's';
5245 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5246 return true;
5247 }
5248 }
5249
5250 return false;
5251}
5252
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005253/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005254bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5255 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005256 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005257 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005258 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005259 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005260 bool AcceptDoublePrecisionOnly;
5261 RequireVFPRegisterListCheck =
5262 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5263 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005264
Jim Grosbach8be2f652011-12-09 23:34:09 +00005265 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005266 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005267 // The generic tblgen'erated code does this later, at the start of
5268 // MatchInstructionImpl(), but that's too late for aliases that include
5269 // any sort of suffix.
5270 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005271 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5272 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005273
Jim Grosbachab5830e2011-12-14 02:16:11 +00005274 // First check for the ARM-specific .req directive.
5275 if (Parser.getTok().is(AsmToken::Identifier) &&
5276 Parser.getTok().getIdentifier() == ".req") {
5277 parseDirectiveReq(Name, NameLoc);
5278 // We always return 'error' for this, as we're done with this
5279 // statement and don't need to match the 'instruction."
5280 return true;
5281 }
5282
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005283 // Create the leading tokens for the mnemonic, split by '.' characters.
5284 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005285 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005286
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005287 // Split out the predication code and carry setting flag from the mnemonic.
5288 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005289 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005290 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005291 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005292 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005293 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005294
Jim Grosbach1c171b12011-08-25 17:23:55 +00005295 // In Thumb1, only the branch (B) instruction can be predicated.
5296 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005297 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005298 return Error(NameLoc, "conditional execution not supported in Thumb1");
5299 }
5300
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005301 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5302
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005303 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5304 // is the mask as it will be for the IT encoding if the conditional
5305 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5306 // where the conditional bit0 is zero, the instruction post-processing
5307 // will adjust the mask accordingly.
5308 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005309 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5310 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005311 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005312 return Error(Loc, "too many conditions on IT instruction");
5313 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005314 unsigned Mask = 8;
5315 for (unsigned i = ITMask.size(); i != 0; --i) {
5316 char pos = ITMask[i - 1];
5317 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005318 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005319 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005320 }
5321 Mask >>= 1;
5322 if (ITMask[i - 1] == 't')
5323 Mask |= 8;
5324 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005325 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005326 }
5327
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005328 // FIXME: This is all a pretty gross hack. We should automatically handle
5329 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005330
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005331 // Next, add the CCOut and ConditionCode operands, if needed.
5332 //
5333 // For mnemonics which can ever incorporate a carry setting bit or predication
5334 // code, our matching model involves us always generating CCOut and
5335 // ConditionCode operands to match the mnemonic "as written" and then we let
5336 // the matcher deal with finding the right instruction or generating an
5337 // appropriate error.
5338 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005339 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005340
Jim Grosbach03a8a162011-07-14 22:04:21 +00005341 // If we had a carry-set on an instruction that can't do that, issue an
5342 // error.
5343 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005344 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005345 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005346 "' can not set flags, but 's' suffix specified");
5347 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005348 // If we had a predication code on an instruction that can't do that, issue an
5349 // error.
5350 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005351 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005352 return Error(NameLoc, "instruction '" + Mnemonic +
5353 "' is not predicable, but condition code specified");
5354 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005355
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005356 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005357 if (CanAcceptCarrySet) {
5358 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005359 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005360 Loc));
5361 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005362
5363 // Add the predication code operand, if necessary.
5364 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005365 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5366 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005367 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005368 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005369 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005370
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005371 // Add the processor imod operand, if necessary.
5372 if (ProcessorIMod) {
5373 Operands.push_back(ARMOperand::CreateImm(
5374 MCConstantExpr::Create(ProcessorIMod, getContext()),
5375 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005376 }
5377
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005378 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005379 while (Next != StringRef::npos) {
5380 Start = Next;
5381 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005382 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005383
Jim Grosbach12952fe2011-11-11 23:08:10 +00005384 // Some NEON instructions have an optional datatype suffix that is
5385 // completely ignored. Check for that.
5386 if (isDataTypeToken(ExtraToken) &&
5387 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5388 continue;
5389
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005390 // For for ARM mode generate an error if the .n qualifier is used.
5391 if (ExtraToken == ".n" && !isThumb()) {
5392 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005393 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005394 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5395 "arm mode");
5396 }
5397
5398 // The .n qualifier is always discarded as that is what the tables
5399 // and matcher expect. In ARM mode the .w qualifier has no effect,
5400 // so discard it to avoid errors that can be caused by the matcher.
5401 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005402 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5403 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5404 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005405 }
5406
5407 // Read the remaining operands.
5408 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005409 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005410 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005411 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005412 return true;
5413 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005414
5415 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005416 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005417
5418 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005419 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005420 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005421 return true;
5422 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005423 }
5424 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005425
Chris Lattnera2a9d162010-09-11 16:18:25 +00005426 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005427 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005428 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005429 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005430 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005431
Chris Lattner91689c12010-09-08 05:10:46 +00005432 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005433
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005434 if (RequireVFPRegisterListCheck) {
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005435 ARMOperand *Op = static_cast<ARMOperand*>(Operands.back());
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005436 if (AcceptSinglePrecisionOnly && !Op->isSPRRegList())
5437 return Error(Op->getStartLoc(),
5438 "VFP/Neon single precision register expected");
5439 if (AcceptDoublePrecisionOnly && !Op->isDPRRegList())
5440 return Error(Op->getStartLoc(),
5441 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005442 }
5443
Jim Grosbach7283da92011-08-16 21:12:37 +00005444 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5445 // do and don't have a cc_out optional-def operand. With some spot-checks
5446 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005447 // parse and adjust accordingly before actually matching. We shouldn't ever
5448 // try to remove a cc_out operand that was explicitly set on the the
5449 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5450 // table driven matcher doesn't fit well with the ARM instruction set.
5451 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005452 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5453 Operands.erase(Operands.begin() + 1);
5454 delete Op;
5455 }
5456
Joey Goulye8602552013-07-19 16:34:16 +00005457 // Some instructions have the same mnemonic, but don't always
5458 // have a predicate. Distinguish them here and delete the
5459 // predicate if needed.
5460 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5461 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5462 Operands.erase(Operands.begin() + 1);
5463 delete Op;
5464 }
5465
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005466 // ARM mode 'blx' need special handling, as the register operand version
5467 // is predicable, but the label operand version is not. So, we can't rely
5468 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005469 // a k_CondCode operand in the list. If we're trying to match the label
5470 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005471 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5472 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5473 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5474 Operands.erase(Operands.begin() + 1);
5475 delete Op;
5476 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005477
Weiming Zhao8f56f882012-11-16 21:55:34 +00005478 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5479 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5480 // a single GPRPair reg operand is used in the .td file to replace the two
5481 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5482 // expressed as a GPRPair, so we have to manually merge them.
5483 // FIXME: We would really like to be able to tablegen'erate this.
5484 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005485 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5486 Mnemonic == "stlexd")) {
5487 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005488 unsigned Idx = isLoad ? 2 : 3;
5489 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5490 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5491
5492 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5493 // Adjust only if Op1 and Op2 are GPRs.
5494 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5495 MRC.contains(Op2->getReg())) {
5496 unsigned Reg1 = Op1->getReg();
5497 unsigned Reg2 = Op2->getReg();
5498 unsigned Rt = MRI->getEncodingValue(Reg1);
5499 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5500
5501 // Rt2 must be Rt + 1 and Rt must be even.
5502 if (Rt + 1 != Rt2 || (Rt & 1)) {
5503 Error(Op2->getStartLoc(), isLoad ?
5504 "destination operands must be sequential" :
5505 "source operands must be sequential");
5506 return true;
5507 }
5508 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5509 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5510 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5511 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5512 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5513 delete Op1;
5514 delete Op2;
5515 }
5516 }
5517
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005518 // GNU Assembler extension (compatibility)
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005519 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
5520 ARMOperand *Op2 = static_cast<ARMOperand *>(Operands[2]);
5521 ARMOperand *Op3 = static_cast<ARMOperand *>(Operands[3]);
5522 if (Op3->isMem()) {
5523 assert(Op2->isReg() && "expected register argument");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005524
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005525 unsigned SuperReg = MRI->getMatchingSuperReg(
5526 Op2->getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005527
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005528 assert(SuperReg && "expected register pair");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005529
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005530 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005531
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005532 Operands.insert(Operands.begin() + 3,
5533 ARMOperand::CreateReg(PairedReg,
5534 Op2->getStartLoc(),
5535 Op2->getEndLoc()));
5536 }
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005537 }
5538
Kevin Enderby78f95722013-07-31 21:05:30 +00005539 // FIXME: As said above, this is all a pretty gross hack. This instruction
5540 // does not fit with other "subs" and tblgen.
5541 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5542 // so the Mnemonic is the original name "subs" and delete the predicate
5543 // operand so it will match the table entry.
5544 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5545 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5546 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5547 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5548 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5549 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5550 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5551 Operands.erase(Operands.begin());
5552 delete Op0;
5553 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5554
5555 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5556 Operands.erase(Operands.begin() + 1);
5557 delete Op1;
5558 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005559 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005560}
5561
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005562// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005563
5564// return 'true' if register list contains non-low GPR registers,
5565// 'false' otherwise. If Reg is in the register list or is HiReg, set
5566// 'containsReg' to true.
5567static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5568 unsigned HiReg, bool &containsReg) {
5569 containsReg = false;
5570 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5571 unsigned OpReg = Inst.getOperand(i).getReg();
5572 if (OpReg == Reg)
5573 containsReg = true;
5574 // Anything other than a low register isn't legal here.
5575 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5576 return true;
5577 }
5578 return false;
5579}
5580
Jim Grosbacha31f2232011-09-07 18:05:34 +00005581// Check if the specified regisgter is in the register list of the inst,
5582// starting at the indicated operand number.
5583static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5584 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5585 unsigned OpReg = Inst.getOperand(i).getReg();
5586 if (OpReg == Reg)
5587 return true;
5588 }
5589 return false;
5590}
5591
Richard Barton8d519fe2013-09-05 14:14:19 +00005592// Return true if instruction has the interesting property of being
5593// allowed in IT blocks, but not being predicable.
5594static bool instIsBreakpoint(const MCInst &Inst) {
5595 return Inst.getOpcode() == ARM::tBKPT ||
5596 Inst.getOpcode() == ARM::BKPT ||
5597 Inst.getOpcode() == ARM::tHLT ||
5598 Inst.getOpcode() == ARM::HLT;
5599
5600}
5601
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005602// FIXME: We would really like to be able to tablegen'erate this.
5603bool ARMAsmParser::
5604validateInstruction(MCInst &Inst,
5605 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005606 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005607 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005608
Jim Grosbached16ec42011-08-29 22:24:09 +00005609 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005610 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005611 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005612 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005613 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005614 if (ITState.FirstCond)
5615 ITState.FirstCond = false;
5616 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005617 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005618 // The instruction must be predicable.
5619 if (!MCID.isPredicable())
5620 return Error(Loc, "instructions in IT block must be predicable");
5621 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005622 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005623 ARMCC::getOppositeCondition(ITState.Cond);
5624 if (Cond != ITCond) {
5625 // Find the condition code Operand to get its SMLoc information.
5626 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005627 for (unsigned I = 1; I < Operands.size(); ++I)
5628 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5629 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005630 return Error(CondLoc, "incorrect condition in IT block; got '" +
5631 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5632 "', but expected '" +
5633 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5634 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005635 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005636 } else if (isThumbTwo() && MCID.isPredicable() &&
5637 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005638 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5639 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005640 return Error(Loc, "predicated instructions must be in IT block");
5641
Tilmann Scheller255722b2013-09-30 16:11:48 +00005642 const unsigned Opcode = Inst.getOpcode();
5643 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005644 case ARM::LDRD:
5645 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005646 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005647 const unsigned RtReg = Inst.getOperand(0).getReg();
5648
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005649 // Rt can't be R14.
5650 if (RtReg == ARM::LR)
5651 return Error(Operands[3]->getStartLoc(),
5652 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005653
5654 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005655 // Rt must be even-numbered.
5656 if ((Rt & 1) == 1)
5657 return Error(Operands[3]->getStartLoc(),
5658 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005659
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005660 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005661 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005662 if (Rt2 != Rt + 1)
5663 return Error(Operands[3]->getStartLoc(),
5664 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005665
5666 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5667 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5668 // For addressing modes with writeback, the base register needs to be
5669 // different from the destination registers.
5670 if (Rn == Rt || Rn == Rt2)
5671 return Error(Operands[3]->getStartLoc(),
5672 "base register needs to be different from destination "
5673 "registers");
5674 }
5675
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005676 return false;
5677 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005678 case ARM::t2LDRDi8:
5679 case ARM::t2LDRD_PRE:
5680 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005681 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005682 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5683 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5684 if (Rt2 == Rt)
5685 return Error(Operands[3]->getStartLoc(),
5686 "destination operands can't be identical");
5687 return false;
5688 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005689 case ARM::STRD: {
5690 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005691 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5692 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005693 if (Rt2 != Rt + 1)
5694 return Error(Operands[3]->getStartLoc(),
5695 "source operands must be sequential");
5696 return false;
5697 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005698 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005699 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005700 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005701 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5702 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005703 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005704 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005705 "source operands must be sequential");
5706 return false;
5707 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005708 case ARM::SBFX:
5709 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005710 // Width must be in range [1, 32-lsb].
5711 unsigned LSB = Inst.getOperand(2).getImm();
5712 unsigned Widthm1 = Inst.getOperand(3).getImm();
5713 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005714 return Error(Operands[5]->getStartLoc(),
5715 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005716 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005717 }
Tim Northover08a86602013-10-22 19:00:39 +00005718 // Notionally handles ARM::tLDMIA_UPD too.
Jim Grosbach90103cc2011-08-18 21:50:53 +00005719 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005720 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005721 // most cases that are normally illegal for a Thumb1 LDM instruction.
5722 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005723 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005724 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005725 // in the register list.
5726 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005727 bool HasWritebackToken =
Jim Grosbach139acd22011-08-22 23:01:07 +00005728 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5729 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005730 bool ListContainsBase;
5731 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5732 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005733 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005734 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005735 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005736 return Error(Operands[2]->getStartLoc(),
5737 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005738 // If we should not have writeback, there must not be a '!'. This is
5739 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005740 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005741 return Error(Operands[3]->getStartLoc(),
5742 "writeback operator '!' not allowed when base register "
5743 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005744
5745 break;
5746 }
Tim Northover08a86602013-10-22 19:00:39 +00005747 case ARM::LDMIA_UPD:
5748 case ARM::LDMDB_UPD:
5749 case ARM::LDMIB_UPD:
5750 case ARM::LDMDA_UPD:
5751 // ARM variants loading and updating the same register are only officially
5752 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5753 if (!hasV7Ops())
5754 break;
5755 // Fallthrough
5756 case ARM::t2LDMIA_UPD:
5757 case ARM::t2LDMDB_UPD:
5758 case ARM::t2STMIA_UPD:
5759 case ARM::t2STMDB_UPD: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005760 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
Tim Northover741e6ef2013-10-24 09:37:18 +00005761 return Error(Operands.back()->getStartLoc(),
5762 "writeback register not allowed in register list");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005763 break;
5764 }
Tim Northover8eaf1542013-11-12 21:32:41 +00005765 case ARM::sysLDMIA_UPD:
5766 case ARM::sysLDMDA_UPD:
5767 case ARM::sysLDMDB_UPD:
5768 case ARM::sysLDMIB_UPD:
5769 if (!listContainsReg(Inst, 3, ARM::PC))
5770 return Error(Operands[4]->getStartLoc(),
5771 "writeback register only allowed on system LDM "
5772 "if PC in register-list");
5773 break;
5774 case ARM::sysSTMIA_UPD:
5775 case ARM::sysSTMDA_UPD:
5776 case ARM::sysSTMDB_UPD:
5777 case ARM::sysSTMIB_UPD:
5778 return Error(Operands[2]->getStartLoc(),
5779 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005780 case ARM::tMUL: {
5781 // The second source operand must be the same register as the destination
5782 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005783 //
5784 // In this case, we must directly check the parsed operands because the
5785 // cvtThumbMultiply() function is written in such a way that it guarantees
5786 // this first statement is always true for the new Inst. Essentially, the
5787 // destination is unconditionally copied into the second source operand
5788 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005789 if (Operands.size() == 6 &&
5790 (((ARMOperand*)Operands[3])->getReg() !=
5791 ((ARMOperand*)Operands[5])->getReg()) &&
5792 (((ARMOperand*)Operands[3])->getReg() !=
5793 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005794 return Error(Operands[3]->getStartLoc(),
5795 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005796 }
5797 break;
5798 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005799 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5800 // so only issue a diagnostic for thumb1. The instructions will be
5801 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005802 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005803 bool ListContainsBase;
5804 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005805 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005806 return Error(Operands[2]->getStartLoc(),
5807 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005808 break;
5809 }
5810 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005811 bool ListContainsBase;
5812 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005813 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005814 return Error(Operands[2]->getStartLoc(),
5815 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005816 break;
5817 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005818 case ARM::tSTMIA_UPD: {
Tim Northover08a86602013-10-22 19:00:39 +00005819 bool ListContainsBase, InvalidLowList;
5820 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5821 0, ListContainsBase);
5822 if (InvalidLowList && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005823 return Error(Operands[4]->getStartLoc(),
5824 "registers must be in range r0-r7");
Tim Northover08a86602013-10-22 19:00:39 +00005825
5826 // This would be converted to a 32-bit stm, but that's not valid if the
5827 // writeback register is in the list.
5828 if (InvalidLowList && ListContainsBase)
5829 return Error(Operands[4]->getStartLoc(),
5830 "writeback operator '!' not allowed when base register "
5831 "in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00005832 break;
5833 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005834 case ARM::tADDrSP: {
5835 // If the non-SP source operand and the destination operand are not the
5836 // same, we need thumb2 (for the wide encoding), or we have an error.
5837 if (!isThumbTwo() &&
5838 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5839 return Error(Operands[4]->getStartLoc(),
5840 "source register must be the same as destination");
5841 }
5842 break;
5843 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005844 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005845 case ARM::tB:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005846 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5847 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005848 break;
5849 case ARM::t2B: {
5850 int op = (Operands[2]->isImm()) ? 2 : 3;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005851 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5852 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005853 break;
5854 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005855 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005856 case ARM::tBcc:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005857 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5858 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005859 break;
5860 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005861 int Op = (Operands[2]->isImm()) ? 2 : 3;
5862 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5863 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005864 break;
5865 }
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00005866 case ARM::MOVi16:
5867 case ARM::t2MOVi16:
5868 case ARM::t2MOVTi16:
5869 {
5870 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
5871 // especially when we turn it into a movw and the expression <symbol> does
5872 // not have a :lower16: or :upper16 as part of the expression. We don't
5873 // want the behavior of silently truncating, which can be unexpected and
5874 // lead to bugs that are difficult to find since this is an easy mistake
5875 // to make.
5876 int i = (Operands[3]->isImm()) ? 3 : 4;
5877 ARMOperand *Op = static_cast<ARMOperand*>(Operands[i]);
5878 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5879 if (CE) break;
5880 const MCExpr *E = dyn_cast<MCExpr>(Op->getImm());
5881 if (!E) break;
5882 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
5883 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
5884 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16)) {
5885 return Error(Op->getStartLoc(),
5886 "immediate expression for mov requires :lower16: or :upper16");
5887 break;
5888 }
5889 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005890 }
5891
5892 return false;
5893}
5894
Jim Grosbach1a747242012-01-23 23:45:44 +00005895static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005896 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005897 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005898 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005899 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5900 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5901 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5902 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5903 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5904 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5905 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5906 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5907 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005908
5909 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005910 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5911 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5912 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5913 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5914 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005915
Jim Grosbach1e946a42012-01-24 00:43:12 +00005916 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5917 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5918 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5919 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5920 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005921
Jim Grosbach1e946a42012-01-24 00:43:12 +00005922 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5923 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5924 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5925 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5926 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005927
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005928 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005929 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5930 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5931 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5932 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5933 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5934 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5935 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5936 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5937 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5938 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5939 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5940 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5941 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5942 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5943 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005944
Jim Grosbach1a747242012-01-23 23:45:44 +00005945 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005946 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5947 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5948 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5949 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5950 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5951 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5952 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5953 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5954 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5955 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5956 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5957 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5958 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5959 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5960 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5961 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5962 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5963 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005964
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005965 // VST4LN
5966 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5967 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5968 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5969 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5970 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5971 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5972 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5973 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5974 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5975 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5976 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5977 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5978 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5979 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5980 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5981
Jim Grosbachda70eac2012-01-24 00:58:13 +00005982 // VST4
5983 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5984 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5985 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5986 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5987 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5988 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5989 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5990 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5991 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5992 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5993 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5994 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5995 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5996 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5997 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5998 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5999 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6000 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00006001 }
6002}
6003
Jim Grosbach1a747242012-01-23 23:45:44 +00006004static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00006005 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006006 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006007 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006008 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6009 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6010 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6011 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6012 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6013 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6014 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6015 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6016 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006017
6018 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006019 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6020 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6021 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6022 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6023 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6024 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6025 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6026 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6027 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6028 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6029 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6030 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6031 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6032 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6033 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006034
Jim Grosbachb78403c2012-01-24 23:47:04 +00006035 // VLD3DUP
6036 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6037 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6038 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6039 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
Kevin Enderbyd88fec32014-04-08 18:00:52 +00006040 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
Jim Grosbachb78403c2012-01-24 23:47:04 +00006041 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6042 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6043 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6044 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6045 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6046 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6047 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6048 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6049 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6050 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6051 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6052 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6053 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6054
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006055 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006056 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6057 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6058 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6059 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6060 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6061 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6062 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6063 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6064 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6065 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6066 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6067 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6068 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6069 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6070 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006071
6072 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006073 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6074 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6075 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6076 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6077 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6078 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6079 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6080 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6081 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6082 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6083 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6084 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6085 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6086 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6087 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6088 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6089 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6090 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00006091
Jim Grosbach14952a02012-01-24 18:37:25 +00006092 // VLD4LN
6093 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6094 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6095 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00006096 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00006097 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6098 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6099 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6100 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6101 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6102 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6103 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6104 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6105 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6106 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6107 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6108
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006109 // VLD4DUP
6110 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6111 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6112 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6113 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6114 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6115 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6116 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6117 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6118 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6119 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6120 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6121 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6122 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6123 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6124 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6125 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6126 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6127 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6128
Jim Grosbached561fc2012-01-24 00:43:17 +00006129 // VLD4
6130 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6131 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6132 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6133 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6134 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6135 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6136 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6137 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6138 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6139 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6140 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6141 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6142 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6143 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6144 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6145 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6146 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6147 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006148 }
6149}
6150
Jim Grosbachafad0532011-11-10 23:42:14 +00006151bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006152processInstruction(MCInst &Inst,
6153 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
6154 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006155 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6156 case ARM::LDRT_POST:
6157 case ARM::LDRBT_POST: {
6158 const unsigned Opcode =
6159 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6160 : ARM::LDRBT_POST_IMM;
6161 MCInst TmpInst;
6162 TmpInst.setOpcode(Opcode);
6163 TmpInst.addOperand(Inst.getOperand(0));
6164 TmpInst.addOperand(Inst.getOperand(1));
6165 TmpInst.addOperand(Inst.getOperand(1));
6166 TmpInst.addOperand(MCOperand::CreateReg(0));
6167 TmpInst.addOperand(MCOperand::CreateImm(0));
6168 TmpInst.addOperand(Inst.getOperand(2));
6169 TmpInst.addOperand(Inst.getOperand(3));
6170 Inst = TmpInst;
6171 return true;
6172 }
6173 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6174 case ARM::STRT_POST:
6175 case ARM::STRBT_POST: {
6176 const unsigned Opcode =
6177 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6178 : ARM::STRBT_POST_IMM;
6179 MCInst TmpInst;
6180 TmpInst.setOpcode(Opcode);
6181 TmpInst.addOperand(Inst.getOperand(1));
6182 TmpInst.addOperand(Inst.getOperand(0));
6183 TmpInst.addOperand(Inst.getOperand(1));
6184 TmpInst.addOperand(MCOperand::CreateReg(0));
6185 TmpInst.addOperand(MCOperand::CreateImm(0));
6186 TmpInst.addOperand(Inst.getOperand(2));
6187 TmpInst.addOperand(Inst.getOperand(3));
6188 Inst = TmpInst;
6189 return true;
6190 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006191 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6192 case ARM::ADDri: {
6193 if (Inst.getOperand(1).getReg() != ARM::PC ||
6194 Inst.getOperand(5).getReg() != 0)
6195 return false;
6196 MCInst TmpInst;
6197 TmpInst.setOpcode(ARM::ADR);
6198 TmpInst.addOperand(Inst.getOperand(0));
6199 TmpInst.addOperand(Inst.getOperand(2));
6200 TmpInst.addOperand(Inst.getOperand(3));
6201 TmpInst.addOperand(Inst.getOperand(4));
6202 Inst = TmpInst;
6203 return true;
6204 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006205 // Aliases for alternate PC+imm syntax of LDR instructions.
6206 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006207 // Select the narrow version if the immediate will fit.
6208 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006209 Inst.getOperand(1).getImm() <= 0xff &&
6210 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
6211 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006212 Inst.setOpcode(ARM::tLDRpci);
6213 else
6214 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006215 return true;
6216 case ARM::t2LDRBpcrel:
6217 Inst.setOpcode(ARM::t2LDRBpci);
6218 return true;
6219 case ARM::t2LDRHpcrel:
6220 Inst.setOpcode(ARM::t2LDRHpci);
6221 return true;
6222 case ARM::t2LDRSBpcrel:
6223 Inst.setOpcode(ARM::t2LDRSBpci);
6224 return true;
6225 case ARM::t2LDRSHpcrel:
6226 Inst.setOpcode(ARM::t2LDRSHpci);
6227 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006228 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006229 case ARM::VST1LNdWB_register_Asm_8:
6230 case ARM::VST1LNdWB_register_Asm_16:
6231 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006232 MCInst TmpInst;
6233 // Shuffle the operands around so the lane index operand is in the
6234 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006235 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006236 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006237 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6238 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6239 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6240 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6241 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6242 TmpInst.addOperand(Inst.getOperand(1)); // lane
6243 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6244 TmpInst.addOperand(Inst.getOperand(6));
6245 Inst = TmpInst;
6246 return true;
6247 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006248
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006249 case ARM::VST2LNdWB_register_Asm_8:
6250 case ARM::VST2LNdWB_register_Asm_16:
6251 case ARM::VST2LNdWB_register_Asm_32:
6252 case ARM::VST2LNqWB_register_Asm_16:
6253 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006254 MCInst TmpInst;
6255 // Shuffle the operands around so the lane index operand is in the
6256 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006257 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006258 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006259 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6260 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6261 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6262 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6263 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006264 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6265 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006266 TmpInst.addOperand(Inst.getOperand(1)); // lane
6267 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6268 TmpInst.addOperand(Inst.getOperand(6));
6269 Inst = TmpInst;
6270 return true;
6271 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006272
6273 case ARM::VST3LNdWB_register_Asm_8:
6274 case ARM::VST3LNdWB_register_Asm_16:
6275 case ARM::VST3LNdWB_register_Asm_32:
6276 case ARM::VST3LNqWB_register_Asm_16:
6277 case ARM::VST3LNqWB_register_Asm_32: {
6278 MCInst TmpInst;
6279 // Shuffle the operands around so the lane index operand is in the
6280 // right place.
6281 unsigned Spacing;
6282 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6283 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6284 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6285 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6286 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6287 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6288 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6289 Spacing));
6290 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6291 Spacing * 2));
6292 TmpInst.addOperand(Inst.getOperand(1)); // lane
6293 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6294 TmpInst.addOperand(Inst.getOperand(6));
6295 Inst = TmpInst;
6296 return true;
6297 }
6298
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006299 case ARM::VST4LNdWB_register_Asm_8:
6300 case ARM::VST4LNdWB_register_Asm_16:
6301 case ARM::VST4LNdWB_register_Asm_32:
6302 case ARM::VST4LNqWB_register_Asm_16:
6303 case ARM::VST4LNqWB_register_Asm_32: {
6304 MCInst TmpInst;
6305 // Shuffle the operands around so the lane index operand is in the
6306 // right place.
6307 unsigned Spacing;
6308 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6309 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6310 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6311 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6312 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6313 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6314 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6315 Spacing));
6316 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6317 Spacing * 2));
6318 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6319 Spacing * 3));
6320 TmpInst.addOperand(Inst.getOperand(1)); // lane
6321 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6322 TmpInst.addOperand(Inst.getOperand(6));
6323 Inst = TmpInst;
6324 return true;
6325 }
6326
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006327 case ARM::VST1LNdWB_fixed_Asm_8:
6328 case ARM::VST1LNdWB_fixed_Asm_16:
6329 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006330 MCInst TmpInst;
6331 // Shuffle the operands around so the lane index operand is in the
6332 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006333 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006334 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006335 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6336 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6337 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6338 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6339 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6340 TmpInst.addOperand(Inst.getOperand(1)); // lane
6341 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6342 TmpInst.addOperand(Inst.getOperand(5));
6343 Inst = TmpInst;
6344 return true;
6345 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006346
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006347 case ARM::VST2LNdWB_fixed_Asm_8:
6348 case ARM::VST2LNdWB_fixed_Asm_16:
6349 case ARM::VST2LNdWB_fixed_Asm_32:
6350 case ARM::VST2LNqWB_fixed_Asm_16:
6351 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006352 MCInst TmpInst;
6353 // Shuffle the operands around so the lane index operand is in the
6354 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006355 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006356 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006357 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6358 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6359 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6360 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6361 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006362 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6363 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006364 TmpInst.addOperand(Inst.getOperand(1)); // lane
6365 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6366 TmpInst.addOperand(Inst.getOperand(5));
6367 Inst = TmpInst;
6368 return true;
6369 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006370
6371 case ARM::VST3LNdWB_fixed_Asm_8:
6372 case ARM::VST3LNdWB_fixed_Asm_16:
6373 case ARM::VST3LNdWB_fixed_Asm_32:
6374 case ARM::VST3LNqWB_fixed_Asm_16:
6375 case ARM::VST3LNqWB_fixed_Asm_32: {
6376 MCInst TmpInst;
6377 // Shuffle the operands around so the lane index operand is in the
6378 // right place.
6379 unsigned Spacing;
6380 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6381 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6382 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6383 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6384 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6385 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6386 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6387 Spacing));
6388 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6389 Spacing * 2));
6390 TmpInst.addOperand(Inst.getOperand(1)); // lane
6391 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6392 TmpInst.addOperand(Inst.getOperand(5));
6393 Inst = TmpInst;
6394 return true;
6395 }
6396
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006397 case ARM::VST4LNdWB_fixed_Asm_8:
6398 case ARM::VST4LNdWB_fixed_Asm_16:
6399 case ARM::VST4LNdWB_fixed_Asm_32:
6400 case ARM::VST4LNqWB_fixed_Asm_16:
6401 case ARM::VST4LNqWB_fixed_Asm_32: {
6402 MCInst TmpInst;
6403 // Shuffle the operands around so the lane index operand is in the
6404 // right place.
6405 unsigned Spacing;
6406 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6407 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6408 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6409 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6410 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6411 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6412 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6413 Spacing));
6414 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6415 Spacing * 2));
6416 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6417 Spacing * 3));
6418 TmpInst.addOperand(Inst.getOperand(1)); // lane
6419 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6420 TmpInst.addOperand(Inst.getOperand(5));
6421 Inst = TmpInst;
6422 return true;
6423 }
6424
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006425 case ARM::VST1LNdAsm_8:
6426 case ARM::VST1LNdAsm_16:
6427 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006428 MCInst TmpInst;
6429 // Shuffle the operands around so the lane index operand is in the
6430 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006431 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006432 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006433 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6434 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6435 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6436 TmpInst.addOperand(Inst.getOperand(1)); // lane
6437 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6438 TmpInst.addOperand(Inst.getOperand(5));
6439 Inst = TmpInst;
6440 return true;
6441 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006442
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006443 case ARM::VST2LNdAsm_8:
6444 case ARM::VST2LNdAsm_16:
6445 case ARM::VST2LNdAsm_32:
6446 case ARM::VST2LNqAsm_16:
6447 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006448 MCInst TmpInst;
6449 // Shuffle the operands around so the lane index operand is in the
6450 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006451 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006452 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006453 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6454 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6455 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006456 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6457 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006458 TmpInst.addOperand(Inst.getOperand(1)); // lane
6459 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6460 TmpInst.addOperand(Inst.getOperand(5));
6461 Inst = TmpInst;
6462 return true;
6463 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006464
6465 case ARM::VST3LNdAsm_8:
6466 case ARM::VST3LNdAsm_16:
6467 case ARM::VST3LNdAsm_32:
6468 case ARM::VST3LNqAsm_16:
6469 case ARM::VST3LNqAsm_32: {
6470 MCInst TmpInst;
6471 // Shuffle the operands around so the lane index operand is in the
6472 // right place.
6473 unsigned Spacing;
6474 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6475 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6476 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6477 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6478 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6479 Spacing));
6480 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6481 Spacing * 2));
6482 TmpInst.addOperand(Inst.getOperand(1)); // lane
6483 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6484 TmpInst.addOperand(Inst.getOperand(5));
6485 Inst = TmpInst;
6486 return true;
6487 }
6488
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006489 case ARM::VST4LNdAsm_8:
6490 case ARM::VST4LNdAsm_16:
6491 case ARM::VST4LNdAsm_32:
6492 case ARM::VST4LNqAsm_16:
6493 case ARM::VST4LNqAsm_32: {
6494 MCInst TmpInst;
6495 // Shuffle the operands around so the lane index operand is in the
6496 // right place.
6497 unsigned Spacing;
6498 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6499 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6500 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6501 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6502 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6503 Spacing));
6504 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6505 Spacing * 2));
6506 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6507 Spacing * 3));
6508 TmpInst.addOperand(Inst.getOperand(1)); // lane
6509 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6510 TmpInst.addOperand(Inst.getOperand(5));
6511 Inst = TmpInst;
6512 return true;
6513 }
6514
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006515 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006516 case ARM::VLD1LNdWB_register_Asm_8:
6517 case ARM::VLD1LNdWB_register_Asm_16:
6518 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006519 MCInst TmpInst;
6520 // Shuffle the operands around so the lane index operand is in the
6521 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006522 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006523 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006524 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6525 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6526 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6527 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6528 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6529 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6530 TmpInst.addOperand(Inst.getOperand(1)); // lane
6531 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6532 TmpInst.addOperand(Inst.getOperand(6));
6533 Inst = TmpInst;
6534 return true;
6535 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006536
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006537 case ARM::VLD2LNdWB_register_Asm_8:
6538 case ARM::VLD2LNdWB_register_Asm_16:
6539 case ARM::VLD2LNdWB_register_Asm_32:
6540 case ARM::VLD2LNqWB_register_Asm_16:
6541 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006542 MCInst TmpInst;
6543 // Shuffle the operands around so the lane index operand is in the
6544 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006545 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006546 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006547 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6549 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006550 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6551 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6552 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6553 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6554 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006555 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6556 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006557 TmpInst.addOperand(Inst.getOperand(1)); // lane
6558 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6559 TmpInst.addOperand(Inst.getOperand(6));
6560 Inst = TmpInst;
6561 return true;
6562 }
6563
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006564 case ARM::VLD3LNdWB_register_Asm_8:
6565 case ARM::VLD3LNdWB_register_Asm_16:
6566 case ARM::VLD3LNdWB_register_Asm_32:
6567 case ARM::VLD3LNqWB_register_Asm_16:
6568 case ARM::VLD3LNqWB_register_Asm_32: {
6569 MCInst TmpInst;
6570 // Shuffle the operands around so the lane index operand is in the
6571 // right place.
6572 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006573 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006574 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6575 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6576 Spacing));
6577 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006578 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006579 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6580 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6581 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6582 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6583 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6584 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6585 Spacing));
6586 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006587 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006588 TmpInst.addOperand(Inst.getOperand(1)); // lane
6589 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6590 TmpInst.addOperand(Inst.getOperand(6));
6591 Inst = TmpInst;
6592 return true;
6593 }
6594
Jim Grosbach14952a02012-01-24 18:37:25 +00006595 case ARM::VLD4LNdWB_register_Asm_8:
6596 case ARM::VLD4LNdWB_register_Asm_16:
6597 case ARM::VLD4LNdWB_register_Asm_32:
6598 case ARM::VLD4LNqWB_register_Asm_16:
6599 case ARM::VLD4LNqWB_register_Asm_32: {
6600 MCInst TmpInst;
6601 // Shuffle the operands around so the lane index operand is in the
6602 // right place.
6603 unsigned Spacing;
6604 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6605 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6606 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6607 Spacing));
6608 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6609 Spacing * 2));
6610 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6611 Spacing * 3));
6612 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6613 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6614 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6615 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6616 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6617 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6618 Spacing));
6619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6620 Spacing * 2));
6621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6622 Spacing * 3));
6623 TmpInst.addOperand(Inst.getOperand(1)); // lane
6624 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6625 TmpInst.addOperand(Inst.getOperand(6));
6626 Inst = TmpInst;
6627 return true;
6628 }
6629
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006630 case ARM::VLD1LNdWB_fixed_Asm_8:
6631 case ARM::VLD1LNdWB_fixed_Asm_16:
6632 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006633 MCInst TmpInst;
6634 // Shuffle the operands around so the lane index operand is in the
6635 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006636 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006637 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006638 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6639 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6640 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6641 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6642 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6643 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6644 TmpInst.addOperand(Inst.getOperand(1)); // lane
6645 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6646 TmpInst.addOperand(Inst.getOperand(5));
6647 Inst = TmpInst;
6648 return true;
6649 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006650
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006651 case ARM::VLD2LNdWB_fixed_Asm_8:
6652 case ARM::VLD2LNdWB_fixed_Asm_16:
6653 case ARM::VLD2LNdWB_fixed_Asm_32:
6654 case ARM::VLD2LNqWB_fixed_Asm_16:
6655 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006656 MCInst TmpInst;
6657 // Shuffle the operands around so the lane index operand is in the
6658 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006659 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006660 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006661 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006662 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6663 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006664 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6665 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6666 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6667 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6668 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006669 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6670 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006671 TmpInst.addOperand(Inst.getOperand(1)); // lane
6672 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6673 TmpInst.addOperand(Inst.getOperand(5));
6674 Inst = TmpInst;
6675 return true;
6676 }
6677
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006678 case ARM::VLD3LNdWB_fixed_Asm_8:
6679 case ARM::VLD3LNdWB_fixed_Asm_16:
6680 case ARM::VLD3LNdWB_fixed_Asm_32:
6681 case ARM::VLD3LNqWB_fixed_Asm_16:
6682 case ARM::VLD3LNqWB_fixed_Asm_32: {
6683 MCInst TmpInst;
6684 // Shuffle the operands around so the lane index operand is in the
6685 // right place.
6686 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006687 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006688 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6689 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6690 Spacing));
6691 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006692 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006693 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6694 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6695 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6696 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6697 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6699 Spacing));
6700 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006701 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006702 TmpInst.addOperand(Inst.getOperand(1)); // lane
6703 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6704 TmpInst.addOperand(Inst.getOperand(5));
6705 Inst = TmpInst;
6706 return true;
6707 }
6708
Jim Grosbach14952a02012-01-24 18:37:25 +00006709 case ARM::VLD4LNdWB_fixed_Asm_8:
6710 case ARM::VLD4LNdWB_fixed_Asm_16:
6711 case ARM::VLD4LNdWB_fixed_Asm_32:
6712 case ARM::VLD4LNqWB_fixed_Asm_16:
6713 case ARM::VLD4LNqWB_fixed_Asm_32: {
6714 MCInst TmpInst;
6715 // Shuffle the operands around so the lane index operand is in the
6716 // right place.
6717 unsigned Spacing;
6718 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6719 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6720 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6721 Spacing));
6722 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6723 Spacing * 2));
6724 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6725 Spacing * 3));
6726 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6727 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6728 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6729 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6730 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6731 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6732 Spacing));
6733 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6734 Spacing * 2));
6735 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6736 Spacing * 3));
6737 TmpInst.addOperand(Inst.getOperand(1)); // lane
6738 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6739 TmpInst.addOperand(Inst.getOperand(5));
6740 Inst = TmpInst;
6741 return true;
6742 }
6743
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006744 case ARM::VLD1LNdAsm_8:
6745 case ARM::VLD1LNdAsm_16:
6746 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006747 MCInst TmpInst;
6748 // Shuffle the operands around so the lane index operand is in the
6749 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006750 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006751 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006752 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6753 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6754 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6755 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6756 TmpInst.addOperand(Inst.getOperand(1)); // lane
6757 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6758 TmpInst.addOperand(Inst.getOperand(5));
6759 Inst = TmpInst;
6760 return true;
6761 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006762
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006763 case ARM::VLD2LNdAsm_8:
6764 case ARM::VLD2LNdAsm_16:
6765 case ARM::VLD2LNdAsm_32:
6766 case ARM::VLD2LNqAsm_16:
6767 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006768 MCInst TmpInst;
6769 // Shuffle the operands around so the lane index operand is in the
6770 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006771 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006772 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006773 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006774 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6775 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006776 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6777 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6778 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6780 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006781 TmpInst.addOperand(Inst.getOperand(1)); // lane
6782 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6783 TmpInst.addOperand(Inst.getOperand(5));
6784 Inst = TmpInst;
6785 return true;
6786 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006787
6788 case ARM::VLD3LNdAsm_8:
6789 case ARM::VLD3LNdAsm_16:
6790 case ARM::VLD3LNdAsm_32:
6791 case ARM::VLD3LNqAsm_16:
6792 case ARM::VLD3LNqAsm_32: {
6793 MCInst TmpInst;
6794 // Shuffle the operands around so the lane index operand is in the
6795 // right place.
6796 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006797 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006798 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6799 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6800 Spacing));
6801 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006802 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006803 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6804 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6805 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6806 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6807 Spacing));
6808 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006809 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006810 TmpInst.addOperand(Inst.getOperand(1)); // lane
6811 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6812 TmpInst.addOperand(Inst.getOperand(5));
6813 Inst = TmpInst;
6814 return true;
6815 }
6816
Jim Grosbach14952a02012-01-24 18:37:25 +00006817 case ARM::VLD4LNdAsm_8:
6818 case ARM::VLD4LNdAsm_16:
6819 case ARM::VLD4LNdAsm_32:
6820 case ARM::VLD4LNqAsm_16:
6821 case ARM::VLD4LNqAsm_32: {
6822 MCInst TmpInst;
6823 // Shuffle the operands around so the lane index operand is in the
6824 // right place.
6825 unsigned Spacing;
6826 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6827 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6828 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6829 Spacing));
6830 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6831 Spacing * 2));
6832 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6833 Spacing * 3));
6834 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6835 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6836 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6837 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6838 Spacing));
6839 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6840 Spacing * 2));
6841 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6842 Spacing * 3));
6843 TmpInst.addOperand(Inst.getOperand(1)); // lane
6844 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6845 TmpInst.addOperand(Inst.getOperand(5));
6846 Inst = TmpInst;
6847 return true;
6848 }
6849
Jim Grosbachb78403c2012-01-24 23:47:04 +00006850 // VLD3DUP single 3-element structure to all lanes instructions.
6851 case ARM::VLD3DUPdAsm_8:
6852 case ARM::VLD3DUPdAsm_16:
6853 case ARM::VLD3DUPdAsm_32:
6854 case ARM::VLD3DUPqAsm_8:
6855 case ARM::VLD3DUPqAsm_16:
6856 case ARM::VLD3DUPqAsm_32: {
6857 MCInst TmpInst;
6858 unsigned Spacing;
6859 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6860 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6861 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6862 Spacing));
6863 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6864 Spacing * 2));
6865 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6866 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6867 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6868 TmpInst.addOperand(Inst.getOperand(4));
6869 Inst = TmpInst;
6870 return true;
6871 }
6872
6873 case ARM::VLD3DUPdWB_fixed_Asm_8:
6874 case ARM::VLD3DUPdWB_fixed_Asm_16:
6875 case ARM::VLD3DUPdWB_fixed_Asm_32:
6876 case ARM::VLD3DUPqWB_fixed_Asm_8:
6877 case ARM::VLD3DUPqWB_fixed_Asm_16:
6878 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6879 MCInst TmpInst;
6880 unsigned Spacing;
6881 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6882 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6883 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6884 Spacing));
6885 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6886 Spacing * 2));
6887 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6888 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6889 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6890 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6891 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6892 TmpInst.addOperand(Inst.getOperand(4));
6893 Inst = TmpInst;
6894 return true;
6895 }
6896
6897 case ARM::VLD3DUPdWB_register_Asm_8:
6898 case ARM::VLD3DUPdWB_register_Asm_16:
6899 case ARM::VLD3DUPdWB_register_Asm_32:
6900 case ARM::VLD3DUPqWB_register_Asm_8:
6901 case ARM::VLD3DUPqWB_register_Asm_16:
6902 case ARM::VLD3DUPqWB_register_Asm_32: {
6903 MCInst TmpInst;
6904 unsigned Spacing;
6905 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6906 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6907 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6908 Spacing));
6909 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6910 Spacing * 2));
6911 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6912 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6913 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6914 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6915 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6916 TmpInst.addOperand(Inst.getOperand(5));
6917 Inst = TmpInst;
6918 return true;
6919 }
6920
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006921 // VLD3 multiple 3-element structure instructions.
6922 case ARM::VLD3dAsm_8:
6923 case ARM::VLD3dAsm_16:
6924 case ARM::VLD3dAsm_32:
6925 case ARM::VLD3qAsm_8:
6926 case ARM::VLD3qAsm_16:
6927 case ARM::VLD3qAsm_32: {
6928 MCInst TmpInst;
6929 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006930 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006931 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6932 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6933 Spacing));
6934 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6935 Spacing * 2));
6936 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6937 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6938 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6939 TmpInst.addOperand(Inst.getOperand(4));
6940 Inst = TmpInst;
6941 return true;
6942 }
6943
6944 case ARM::VLD3dWB_fixed_Asm_8:
6945 case ARM::VLD3dWB_fixed_Asm_16:
6946 case ARM::VLD3dWB_fixed_Asm_32:
6947 case ARM::VLD3qWB_fixed_Asm_8:
6948 case ARM::VLD3qWB_fixed_Asm_16:
6949 case ARM::VLD3qWB_fixed_Asm_32: {
6950 MCInst TmpInst;
6951 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006952 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006953 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6954 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6955 Spacing));
6956 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6957 Spacing * 2));
6958 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6959 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6960 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6961 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6962 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6963 TmpInst.addOperand(Inst.getOperand(4));
6964 Inst = TmpInst;
6965 return true;
6966 }
6967
6968 case ARM::VLD3dWB_register_Asm_8:
6969 case ARM::VLD3dWB_register_Asm_16:
6970 case ARM::VLD3dWB_register_Asm_32:
6971 case ARM::VLD3qWB_register_Asm_8:
6972 case ARM::VLD3qWB_register_Asm_16:
6973 case ARM::VLD3qWB_register_Asm_32: {
6974 MCInst TmpInst;
6975 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006976 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006977 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6978 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6979 Spacing));
6980 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6981 Spacing * 2));
6982 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6983 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6984 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6985 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6986 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6987 TmpInst.addOperand(Inst.getOperand(5));
6988 Inst = TmpInst;
6989 return true;
6990 }
6991
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006992 // VLD4DUP single 3-element structure to all lanes instructions.
6993 case ARM::VLD4DUPdAsm_8:
6994 case ARM::VLD4DUPdAsm_16:
6995 case ARM::VLD4DUPdAsm_32:
6996 case ARM::VLD4DUPqAsm_8:
6997 case ARM::VLD4DUPqAsm_16:
6998 case ARM::VLD4DUPqAsm_32: {
6999 MCInst TmpInst;
7000 unsigned Spacing;
7001 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7002 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7003 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7004 Spacing));
7005 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7006 Spacing * 2));
7007 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7008 Spacing * 3));
7009 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7010 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7011 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7012 TmpInst.addOperand(Inst.getOperand(4));
7013 Inst = TmpInst;
7014 return true;
7015 }
7016
7017 case ARM::VLD4DUPdWB_fixed_Asm_8:
7018 case ARM::VLD4DUPdWB_fixed_Asm_16:
7019 case ARM::VLD4DUPdWB_fixed_Asm_32:
7020 case ARM::VLD4DUPqWB_fixed_Asm_8:
7021 case ARM::VLD4DUPqWB_fixed_Asm_16:
7022 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7023 MCInst TmpInst;
7024 unsigned Spacing;
7025 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7026 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7027 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7028 Spacing));
7029 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7030 Spacing * 2));
7031 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7032 Spacing * 3));
7033 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7034 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7035 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7036 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7037 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7038 TmpInst.addOperand(Inst.getOperand(4));
7039 Inst = TmpInst;
7040 return true;
7041 }
7042
7043 case ARM::VLD4DUPdWB_register_Asm_8:
7044 case ARM::VLD4DUPdWB_register_Asm_16:
7045 case ARM::VLD4DUPdWB_register_Asm_32:
7046 case ARM::VLD4DUPqWB_register_Asm_8:
7047 case ARM::VLD4DUPqWB_register_Asm_16:
7048 case ARM::VLD4DUPqWB_register_Asm_32: {
7049 MCInst TmpInst;
7050 unsigned Spacing;
7051 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7052 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7053 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7054 Spacing));
7055 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7056 Spacing * 2));
7057 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7058 Spacing * 3));
7059 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7060 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7061 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7062 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7063 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7064 TmpInst.addOperand(Inst.getOperand(5));
7065 Inst = TmpInst;
7066 return true;
7067 }
7068
7069 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00007070 case ARM::VLD4dAsm_8:
7071 case ARM::VLD4dAsm_16:
7072 case ARM::VLD4dAsm_32:
7073 case ARM::VLD4qAsm_8:
7074 case ARM::VLD4qAsm_16:
7075 case ARM::VLD4qAsm_32: {
7076 MCInst TmpInst;
7077 unsigned Spacing;
7078 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7079 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7081 Spacing));
7082 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7083 Spacing * 2));
7084 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7085 Spacing * 3));
7086 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7087 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7088 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7089 TmpInst.addOperand(Inst.getOperand(4));
7090 Inst = TmpInst;
7091 return true;
7092 }
7093
7094 case ARM::VLD4dWB_fixed_Asm_8:
7095 case ARM::VLD4dWB_fixed_Asm_16:
7096 case ARM::VLD4dWB_fixed_Asm_32:
7097 case ARM::VLD4qWB_fixed_Asm_8:
7098 case ARM::VLD4qWB_fixed_Asm_16:
7099 case ARM::VLD4qWB_fixed_Asm_32: {
7100 MCInst TmpInst;
7101 unsigned Spacing;
7102 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7103 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7104 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7105 Spacing));
7106 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7107 Spacing * 2));
7108 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7109 Spacing * 3));
7110 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7111 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7112 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7113 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7114 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7115 TmpInst.addOperand(Inst.getOperand(4));
7116 Inst = TmpInst;
7117 return true;
7118 }
7119
7120 case ARM::VLD4dWB_register_Asm_8:
7121 case ARM::VLD4dWB_register_Asm_16:
7122 case ARM::VLD4dWB_register_Asm_32:
7123 case ARM::VLD4qWB_register_Asm_8:
7124 case ARM::VLD4qWB_register_Asm_16:
7125 case ARM::VLD4qWB_register_Asm_32: {
7126 MCInst TmpInst;
7127 unsigned Spacing;
7128 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7129 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7130 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7131 Spacing));
7132 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7133 Spacing * 2));
7134 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7135 Spacing * 3));
7136 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7137 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7138 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7139 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7140 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7141 TmpInst.addOperand(Inst.getOperand(5));
7142 Inst = TmpInst;
7143 return true;
7144 }
7145
Jim Grosbach1a747242012-01-23 23:45:44 +00007146 // VST3 multiple 3-element structure instructions.
7147 case ARM::VST3dAsm_8:
7148 case ARM::VST3dAsm_16:
7149 case ARM::VST3dAsm_32:
7150 case ARM::VST3qAsm_8:
7151 case ARM::VST3qAsm_16:
7152 case ARM::VST3qAsm_32: {
7153 MCInst TmpInst;
7154 unsigned Spacing;
7155 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7156 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7157 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7158 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7159 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7160 Spacing));
7161 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7162 Spacing * 2));
7163 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7164 TmpInst.addOperand(Inst.getOperand(4));
7165 Inst = TmpInst;
7166 return true;
7167 }
7168
7169 case ARM::VST3dWB_fixed_Asm_8:
7170 case ARM::VST3dWB_fixed_Asm_16:
7171 case ARM::VST3dWB_fixed_Asm_32:
7172 case ARM::VST3qWB_fixed_Asm_8:
7173 case ARM::VST3qWB_fixed_Asm_16:
7174 case ARM::VST3qWB_fixed_Asm_32: {
7175 MCInst TmpInst;
7176 unsigned Spacing;
7177 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7178 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7179 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7180 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7181 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7182 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7183 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7184 Spacing));
7185 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7186 Spacing * 2));
7187 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7188 TmpInst.addOperand(Inst.getOperand(4));
7189 Inst = TmpInst;
7190 return true;
7191 }
7192
7193 case ARM::VST3dWB_register_Asm_8:
7194 case ARM::VST3dWB_register_Asm_16:
7195 case ARM::VST3dWB_register_Asm_32:
7196 case ARM::VST3qWB_register_Asm_8:
7197 case ARM::VST3qWB_register_Asm_16:
7198 case ARM::VST3qWB_register_Asm_32: {
7199 MCInst TmpInst;
7200 unsigned Spacing;
7201 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7202 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7203 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7204 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7205 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7206 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7207 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7208 Spacing));
7209 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7210 Spacing * 2));
7211 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7212 TmpInst.addOperand(Inst.getOperand(5));
7213 Inst = TmpInst;
7214 return true;
7215 }
7216
Jim Grosbachda70eac2012-01-24 00:58:13 +00007217 // VST4 multiple 3-element structure instructions.
7218 case ARM::VST4dAsm_8:
7219 case ARM::VST4dAsm_16:
7220 case ARM::VST4dAsm_32:
7221 case ARM::VST4qAsm_8:
7222 case ARM::VST4qAsm_16:
7223 case ARM::VST4qAsm_32: {
7224 MCInst TmpInst;
7225 unsigned Spacing;
7226 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7227 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7228 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7229 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7230 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7231 Spacing));
7232 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7233 Spacing * 2));
7234 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7235 Spacing * 3));
7236 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7237 TmpInst.addOperand(Inst.getOperand(4));
7238 Inst = TmpInst;
7239 return true;
7240 }
7241
7242 case ARM::VST4dWB_fixed_Asm_8:
7243 case ARM::VST4dWB_fixed_Asm_16:
7244 case ARM::VST4dWB_fixed_Asm_32:
7245 case ARM::VST4qWB_fixed_Asm_8:
7246 case ARM::VST4qWB_fixed_Asm_16:
7247 case ARM::VST4qWB_fixed_Asm_32: {
7248 MCInst TmpInst;
7249 unsigned Spacing;
7250 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7251 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7252 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7253 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7254 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7255 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7256 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7257 Spacing));
7258 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7259 Spacing * 2));
7260 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7261 Spacing * 3));
7262 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7263 TmpInst.addOperand(Inst.getOperand(4));
7264 Inst = TmpInst;
7265 return true;
7266 }
7267
7268 case ARM::VST4dWB_register_Asm_8:
7269 case ARM::VST4dWB_register_Asm_16:
7270 case ARM::VST4dWB_register_Asm_32:
7271 case ARM::VST4qWB_register_Asm_8:
7272 case ARM::VST4qWB_register_Asm_16:
7273 case ARM::VST4qWB_register_Asm_32: {
7274 MCInst TmpInst;
7275 unsigned Spacing;
7276 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7277 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7278 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7279 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7280 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7281 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7282 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7283 Spacing));
7284 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7285 Spacing * 2));
7286 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7287 Spacing * 3));
7288 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7289 TmpInst.addOperand(Inst.getOperand(5));
7290 Inst = TmpInst;
7291 return true;
7292 }
7293
Jim Grosbachad66de12012-04-11 00:15:16 +00007294 // Handle encoding choice for the shift-immediate instructions.
7295 case ARM::t2LSLri:
7296 case ARM::t2LSRri:
7297 case ARM::t2ASRri: {
7298 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7299 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7300 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7301 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
7302 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
7303 unsigned NewOpc;
7304 switch (Inst.getOpcode()) {
7305 default: llvm_unreachable("unexpected opcode");
7306 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7307 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7308 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7309 }
7310 // The Thumb1 operands aren't in the same order. Awesome, eh?
7311 MCInst TmpInst;
7312 TmpInst.setOpcode(NewOpc);
7313 TmpInst.addOperand(Inst.getOperand(0));
7314 TmpInst.addOperand(Inst.getOperand(5));
7315 TmpInst.addOperand(Inst.getOperand(1));
7316 TmpInst.addOperand(Inst.getOperand(2));
7317 TmpInst.addOperand(Inst.getOperand(3));
7318 TmpInst.addOperand(Inst.getOperand(4));
7319 Inst = TmpInst;
7320 return true;
7321 }
7322 return false;
7323 }
7324
Jim Grosbach485e5622011-12-13 22:45:11 +00007325 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007326 case ARM::t2MOVsr:
7327 case ARM::t2MOVSsr: {
7328 // Which instruction to expand to depends on the CCOut operand and
7329 // whether we're in an IT block if the register operands are low
7330 // registers.
7331 bool isNarrow = false;
7332 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7333 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7334 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7335 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7336 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7337 isNarrow = true;
7338 MCInst TmpInst;
7339 unsigned newOpc;
7340 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7341 default: llvm_unreachable("unexpected opcode!");
7342 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7343 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7344 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7345 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7346 }
7347 TmpInst.setOpcode(newOpc);
7348 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7349 if (isNarrow)
7350 TmpInst.addOperand(MCOperand::CreateReg(
7351 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7352 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7353 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7354 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7355 TmpInst.addOperand(Inst.getOperand(5));
7356 if (!isNarrow)
7357 TmpInst.addOperand(MCOperand::CreateReg(
7358 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7359 Inst = TmpInst;
7360 return true;
7361 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007362 case ARM::t2MOVsi:
7363 case ARM::t2MOVSsi: {
7364 // Which instruction to expand to depends on the CCOut operand and
7365 // whether we're in an IT block if the register operands are low
7366 // registers.
7367 bool isNarrow = false;
7368 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7369 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7370 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7371 isNarrow = true;
7372 MCInst TmpInst;
7373 unsigned newOpc;
7374 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7375 default: llvm_unreachable("unexpected opcode!");
7376 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7377 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7378 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7379 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007380 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007381 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007382 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7383 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007384 TmpInst.setOpcode(newOpc);
7385 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7386 if (isNarrow)
7387 TmpInst.addOperand(MCOperand::CreateReg(
7388 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7389 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007390 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007391 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007392 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7393 TmpInst.addOperand(Inst.getOperand(4));
7394 if (!isNarrow)
7395 TmpInst.addOperand(MCOperand::CreateReg(
7396 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7397 Inst = TmpInst;
7398 return true;
7399 }
7400 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007401 case ARM::ASRr:
7402 case ARM::LSRr:
7403 case ARM::LSLr:
7404 case ARM::RORr: {
7405 ARM_AM::ShiftOpc ShiftTy;
7406 switch(Inst.getOpcode()) {
7407 default: llvm_unreachable("unexpected opcode!");
7408 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7409 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7410 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7411 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7412 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007413 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7414 MCInst TmpInst;
7415 TmpInst.setOpcode(ARM::MOVsr);
7416 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7417 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7418 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7419 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7420 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7421 TmpInst.addOperand(Inst.getOperand(4));
7422 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7423 Inst = TmpInst;
7424 return true;
7425 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007426 case ARM::ASRi:
7427 case ARM::LSRi:
7428 case ARM::LSLi:
7429 case ARM::RORi: {
7430 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007431 switch(Inst.getOpcode()) {
7432 default: llvm_unreachable("unexpected opcode!");
7433 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7434 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7435 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7436 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7437 }
7438 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007439 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007440 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007441 // A shift by 32 should be encoded as 0 when permitted
7442 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7443 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007444 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007445 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007446 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007447 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7448 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007449 if (Opc == ARM::MOVsi)
7450 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007451 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7452 TmpInst.addOperand(Inst.getOperand(4));
7453 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7454 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007455 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007456 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007457 case ARM::RRXi: {
7458 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7459 MCInst TmpInst;
7460 TmpInst.setOpcode(ARM::MOVsi);
7461 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7462 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7463 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7464 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7465 TmpInst.addOperand(Inst.getOperand(3));
7466 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7467 Inst = TmpInst;
7468 return true;
7469 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007470 case ARM::t2LDMIA_UPD: {
7471 // If this is a load of a single register, then we should use
7472 // a post-indexed LDR instruction instead, per the ARM ARM.
7473 if (Inst.getNumOperands() != 5)
7474 return false;
7475 MCInst TmpInst;
7476 TmpInst.setOpcode(ARM::t2LDR_POST);
7477 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7478 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7479 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7480 TmpInst.addOperand(MCOperand::CreateImm(4));
7481 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7482 TmpInst.addOperand(Inst.getOperand(3));
7483 Inst = TmpInst;
7484 return true;
7485 }
7486 case ARM::t2STMDB_UPD: {
7487 // If this is a store of a single register, then we should use
7488 // a pre-indexed STR instruction instead, per the ARM ARM.
7489 if (Inst.getNumOperands() != 5)
7490 return false;
7491 MCInst TmpInst;
7492 TmpInst.setOpcode(ARM::t2STR_PRE);
7493 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7494 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7495 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7496 TmpInst.addOperand(MCOperand::CreateImm(-4));
7497 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7498 TmpInst.addOperand(Inst.getOperand(3));
7499 Inst = TmpInst;
7500 return true;
7501 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007502 case ARM::LDMIA_UPD:
7503 // If this is a load of a single register via a 'pop', then we should use
7504 // a post-indexed LDR instruction instead, per the ARM ARM.
7505 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7506 Inst.getNumOperands() == 5) {
7507 MCInst TmpInst;
7508 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7509 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7510 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7511 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7512 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7513 TmpInst.addOperand(MCOperand::CreateImm(4));
7514 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7515 TmpInst.addOperand(Inst.getOperand(3));
7516 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007517 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007518 }
7519 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007520 case ARM::STMDB_UPD:
7521 // If this is a store of a single register via a 'push', then we should use
7522 // a pre-indexed STR instruction instead, per the ARM ARM.
7523 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7524 Inst.getNumOperands() == 5) {
7525 MCInst TmpInst;
7526 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7527 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7528 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7529 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7530 TmpInst.addOperand(MCOperand::CreateImm(-4));
7531 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7532 TmpInst.addOperand(Inst.getOperand(3));
7533 Inst = TmpInst;
7534 }
7535 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007536 case ARM::t2ADDri12:
7537 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7538 // mnemonic was used (not "addw"), encoding T3 is preferred.
7539 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7540 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7541 break;
7542 Inst.setOpcode(ARM::t2ADDri);
7543 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7544 break;
7545 case ARM::t2SUBri12:
7546 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7547 // mnemonic was used (not "subw"), encoding T3 is preferred.
7548 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7549 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7550 break;
7551 Inst.setOpcode(ARM::t2SUBri);
7552 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7553 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007554 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007555 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007556 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7557 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7558 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007559 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007560 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007561 return true;
7562 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007563 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007564 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007565 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007566 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7567 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7568 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007569 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007570 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007571 return true;
7572 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007573 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007574 case ARM::t2ADDri:
7575 case ARM::t2SUBri: {
7576 // If the destination and first source operand are the same, and
7577 // the flags are compatible with the current IT status, use encoding T2
7578 // instead of T3. For compatibility with the system 'as'. Make sure the
7579 // wide encoding wasn't explicit.
7580 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007581 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007582 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7583 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7584 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7585 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7586 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7587 break;
7588 MCInst TmpInst;
7589 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7590 ARM::tADDi8 : ARM::tSUBi8);
7591 TmpInst.addOperand(Inst.getOperand(0));
7592 TmpInst.addOperand(Inst.getOperand(5));
7593 TmpInst.addOperand(Inst.getOperand(0));
7594 TmpInst.addOperand(Inst.getOperand(2));
7595 TmpInst.addOperand(Inst.getOperand(3));
7596 TmpInst.addOperand(Inst.getOperand(4));
7597 Inst = TmpInst;
7598 return true;
7599 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007600 case ARM::t2ADDrr: {
7601 // If the destination and first source operand are the same, and
7602 // there's no setting of the flags, use encoding T2 instead of T3.
7603 // Note that this is only for ADD, not SUB. This mirrors the system
7604 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7605 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7606 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007607 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7608 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007609 break;
7610 MCInst TmpInst;
7611 TmpInst.setOpcode(ARM::tADDhirr);
7612 TmpInst.addOperand(Inst.getOperand(0));
7613 TmpInst.addOperand(Inst.getOperand(0));
7614 TmpInst.addOperand(Inst.getOperand(2));
7615 TmpInst.addOperand(Inst.getOperand(3));
7616 TmpInst.addOperand(Inst.getOperand(4));
7617 Inst = TmpInst;
7618 return true;
7619 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007620 case ARM::tADDrSP: {
7621 // If the non-SP source operand and the destination operand are not the
7622 // same, we need to use the 32-bit encoding if it's available.
7623 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7624 Inst.setOpcode(ARM::t2ADDrr);
7625 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7626 return true;
7627 }
7628 break;
7629 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007630 case ARM::tB:
7631 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007632 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007633 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007634 return true;
7635 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007636 break;
7637 case ARM::t2B:
7638 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007639 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007640 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007641 return true;
7642 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007643 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007644 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007645 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007646 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007647 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007648 return true;
7649 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007650 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007651 case ARM::tBcc:
7652 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007653 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007654 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007655 return true;
7656 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007657 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007658 case ARM::tLDMIA: {
7659 // If the register list contains any high registers, or if the writeback
7660 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7661 // instead if we're in Thumb2. Otherwise, this should have generated
7662 // an error in validateInstruction().
7663 unsigned Rn = Inst.getOperand(0).getReg();
7664 bool hasWritebackToken =
7665 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7666 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7667 bool listContainsBase;
7668 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7669 (!listContainsBase && !hasWritebackToken) ||
7670 (listContainsBase && hasWritebackToken)) {
7671 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7672 assert (isThumbTwo());
7673 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7674 // If we're switching to the updating version, we need to insert
7675 // the writeback tied operand.
7676 if (hasWritebackToken)
7677 Inst.insert(Inst.begin(),
7678 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007679 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007680 }
7681 break;
7682 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007683 case ARM::tSTMIA_UPD: {
7684 // If the register list contains any high registers, we need to use
7685 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7686 // should have generated an error in validateInstruction().
7687 unsigned Rn = Inst.getOperand(0).getReg();
7688 bool listContainsBase;
7689 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7690 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7691 assert (isThumbTwo());
7692 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007693 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007694 }
7695 break;
7696 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007697 case ARM::tPOP: {
7698 bool listContainsBase;
7699 // If the register list contains any high registers, we need to use
7700 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7701 // should have generated an error in validateInstruction().
7702 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007703 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007704 assert (isThumbTwo());
7705 Inst.setOpcode(ARM::t2LDMIA_UPD);
7706 // Add the base register and writeback operands.
7707 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7708 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007709 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007710 }
7711 case ARM::tPUSH: {
7712 bool listContainsBase;
7713 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007714 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007715 assert (isThumbTwo());
7716 Inst.setOpcode(ARM::t2STMDB_UPD);
7717 // Add the base register and writeback operands.
7718 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7719 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007720 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007721 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007722 case ARM::t2MOVi: {
7723 // If we can use the 16-bit encoding and the user didn't explicitly
7724 // request the 32-bit variant, transform it here.
7725 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007726 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007727 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7728 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7729 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007730 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7731 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7732 // The operands aren't in the same order for tMOVi8...
7733 MCInst TmpInst;
7734 TmpInst.setOpcode(ARM::tMOVi8);
7735 TmpInst.addOperand(Inst.getOperand(0));
7736 TmpInst.addOperand(Inst.getOperand(4));
7737 TmpInst.addOperand(Inst.getOperand(1));
7738 TmpInst.addOperand(Inst.getOperand(2));
7739 TmpInst.addOperand(Inst.getOperand(3));
7740 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007741 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007742 }
7743 break;
7744 }
7745 case ARM::t2MOVr: {
7746 // If we can use the 16-bit encoding and the user didn't explicitly
7747 // request the 32-bit variant, transform it here.
7748 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7749 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7750 Inst.getOperand(2).getImm() == ARMCC::AL &&
7751 Inst.getOperand(4).getReg() == ARM::CPSR &&
7752 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7753 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7754 // The operands aren't the same for tMOV[S]r... (no cc_out)
7755 MCInst TmpInst;
7756 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7757 TmpInst.addOperand(Inst.getOperand(0));
7758 TmpInst.addOperand(Inst.getOperand(1));
7759 TmpInst.addOperand(Inst.getOperand(2));
7760 TmpInst.addOperand(Inst.getOperand(3));
7761 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007762 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007763 }
7764 break;
7765 }
Jim Grosbach82213192011-09-19 20:29:33 +00007766 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007767 case ARM::t2SXTB:
7768 case ARM::t2UXTH:
7769 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007770 // If we can use the 16-bit encoding and the user didn't explicitly
7771 // request the 32-bit variant, transform it here.
7772 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7773 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7774 Inst.getOperand(2).getImm() == 0 &&
7775 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7776 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007777 unsigned NewOpc;
7778 switch (Inst.getOpcode()) {
7779 default: llvm_unreachable("Illegal opcode!");
7780 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7781 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7782 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7783 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7784 }
Jim Grosbach82213192011-09-19 20:29:33 +00007785 // The operands aren't the same for thumb1 (no rotate operand).
7786 MCInst TmpInst;
7787 TmpInst.setOpcode(NewOpc);
7788 TmpInst.addOperand(Inst.getOperand(0));
7789 TmpInst.addOperand(Inst.getOperand(1));
7790 TmpInst.addOperand(Inst.getOperand(3));
7791 TmpInst.addOperand(Inst.getOperand(4));
7792 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007793 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007794 }
7795 break;
7796 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007797 case ARM::MOVsi: {
7798 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007799 // rrx shifts and asr/lsr of #32 is encoded as 0
7800 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7801 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007802 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7803 // Shifting by zero is accepted as a vanilla 'MOVr'
7804 MCInst TmpInst;
7805 TmpInst.setOpcode(ARM::MOVr);
7806 TmpInst.addOperand(Inst.getOperand(0));
7807 TmpInst.addOperand(Inst.getOperand(1));
7808 TmpInst.addOperand(Inst.getOperand(3));
7809 TmpInst.addOperand(Inst.getOperand(4));
7810 TmpInst.addOperand(Inst.getOperand(5));
7811 Inst = TmpInst;
7812 return true;
7813 }
7814 return false;
7815 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007816 case ARM::ANDrsi:
7817 case ARM::ORRrsi:
7818 case ARM::EORrsi:
7819 case ARM::BICrsi:
7820 case ARM::SUBrsi:
7821 case ARM::ADDrsi: {
7822 unsigned newOpc;
7823 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7824 if (SOpc == ARM_AM::rrx) return false;
7825 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007826 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007827 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7828 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7829 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7830 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7831 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7832 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7833 }
7834 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007835 // The exception is for right shifts, where 0 == 32
7836 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7837 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007838 MCInst TmpInst;
7839 TmpInst.setOpcode(newOpc);
7840 TmpInst.addOperand(Inst.getOperand(0));
7841 TmpInst.addOperand(Inst.getOperand(1));
7842 TmpInst.addOperand(Inst.getOperand(2));
7843 TmpInst.addOperand(Inst.getOperand(4));
7844 TmpInst.addOperand(Inst.getOperand(5));
7845 TmpInst.addOperand(Inst.getOperand(6));
7846 Inst = TmpInst;
7847 return true;
7848 }
7849 return false;
7850 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007851 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007852 case ARM::t2IT: {
7853 // The mask bits for all but the first condition are represented as
7854 // the low bit of the condition code value implies 't'. We currently
7855 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007856 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007857 MCOperand &MO = Inst.getOperand(1);
7858 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007859 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007860 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007861 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007862 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007863 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007864 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007865 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007866
7867 // Set up the IT block state according to the IT instruction we just
7868 // matched.
7869 assert(!inITBlock() && "nested IT blocks?!");
7870 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7871 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7872 ITState.CurPosition = 0;
7873 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007874 break;
7875 }
Richard Bartona39625e2012-07-09 16:12:24 +00007876 case ARM::t2LSLrr:
7877 case ARM::t2LSRrr:
7878 case ARM::t2ASRrr:
7879 case ARM::t2SBCrr:
7880 case ARM::t2RORrr:
7881 case ARM::t2BICrr:
7882 {
Richard Bartond5660372012-07-09 16:14:28 +00007883 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007884 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7885 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7886 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007887 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7888 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007889 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7890 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7891 unsigned NewOpc;
7892 switch (Inst.getOpcode()) {
7893 default: llvm_unreachable("unexpected opcode");
7894 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7895 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7896 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7897 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7898 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7899 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7900 }
7901 MCInst TmpInst;
7902 TmpInst.setOpcode(NewOpc);
7903 TmpInst.addOperand(Inst.getOperand(0));
7904 TmpInst.addOperand(Inst.getOperand(5));
7905 TmpInst.addOperand(Inst.getOperand(1));
7906 TmpInst.addOperand(Inst.getOperand(2));
7907 TmpInst.addOperand(Inst.getOperand(3));
7908 TmpInst.addOperand(Inst.getOperand(4));
7909 Inst = TmpInst;
7910 return true;
7911 }
7912 return false;
7913 }
7914 case ARM::t2ANDrr:
7915 case ARM::t2EORrr:
7916 case ARM::t2ADCrr:
7917 case ARM::t2ORRrr:
7918 {
Richard Bartond5660372012-07-09 16:14:28 +00007919 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007920 // These instructions are special in that they are commutable, so shorter encodings
7921 // are available more often.
7922 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7923 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7924 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7925 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007926 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7927 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007928 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7929 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7930 unsigned NewOpc;
7931 switch (Inst.getOpcode()) {
7932 default: llvm_unreachable("unexpected opcode");
7933 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7934 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7935 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7936 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7937 }
7938 MCInst TmpInst;
7939 TmpInst.setOpcode(NewOpc);
7940 TmpInst.addOperand(Inst.getOperand(0));
7941 TmpInst.addOperand(Inst.getOperand(5));
7942 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7943 TmpInst.addOperand(Inst.getOperand(1));
7944 TmpInst.addOperand(Inst.getOperand(2));
7945 } else {
7946 TmpInst.addOperand(Inst.getOperand(2));
7947 TmpInst.addOperand(Inst.getOperand(1));
7948 }
7949 TmpInst.addOperand(Inst.getOperand(3));
7950 TmpInst.addOperand(Inst.getOperand(4));
7951 Inst = TmpInst;
7952 return true;
7953 }
7954 return false;
7955 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007956 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007957 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007958}
7959
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007960unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7961 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7962 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007963 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007964 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007965 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7966 assert(MCID.hasOptionalDef() &&
7967 "optionally flag setting instruction missing optional def operand");
7968 assert(MCID.NumOperands == Inst.getNumOperands() &&
7969 "operand count mismatch!");
7970 // Find the optional-def operand (cc_out).
7971 unsigned OpNo;
7972 for (OpNo = 0;
7973 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7974 ++OpNo)
7975 ;
7976 // If we're parsing Thumb1, reject it completely.
7977 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7978 return Match_MnemonicFail;
7979 // If we're parsing Thumb2, which form is legal depends on whether we're
7980 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007981 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7982 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007983 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007984 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7985 inITBlock())
7986 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007987 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007988 // Some high-register supporting Thumb1 encodings only allow both registers
7989 // to be from r0-r7 when in Thumb2.
7990 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7991 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7992 isARMLowRegister(Inst.getOperand(2).getReg()))
7993 return Match_RequiresThumb2;
7994 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007995 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007996 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7997 isARMLowRegister(Inst.getOperand(1).getReg()))
7998 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007999 return Match_Success;
8000}
8001
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008002namespace llvm {
8003template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008004 return true; // In an assembly source, no need to second-guess
8005}
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008006}
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008007
Jim Grosbach5117ef72012-04-24 22:40:08 +00008008static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00008009bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00008010MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00008011 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00008012 MCStreamer &Out, unsigned &ErrorInfo,
8013 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00008014 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00008015 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00008016
Chad Rosier2f480a82012-10-12 22:53:36 +00008017 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00008018 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00008019 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00008020 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008021 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008022 // Context sensitive operand constraints aren't handled by the matcher,
8023 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008024 if (validateInstruction(Inst, Operands)) {
8025 // Still progress the IT block, otherwise one wrong condition causes
8026 // nasty cascading errors.
8027 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008028 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008029 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008030
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008031 { // processInstruction() updates inITBlock state, we need to save it away
8032 bool wasInITBlock = inITBlock();
8033
8034 // Some instructions need post-processing to, for example, tweak which
8035 // encoding is selected. Loop on it while changes happen so the
8036 // individual transformations can chain off each other. E.g.,
8037 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
8038 while (processInstruction(Inst, Operands))
8039 ;
8040
8041 // Only after the instruction is fully processed, we can validate it
8042 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00008043 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008044 Warning(IDLoc, "deprecated instruction in IT block");
8045 }
8046 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008047
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008048 // Only move forward at the very end so that everything in validate
8049 // and process gets a consistent answer about whether we're in an IT
8050 // block.
8051 forwardITPosition();
8052
Jim Grosbach82f76d12012-01-25 19:52:01 +00008053 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8054 // doesn't actually encode.
8055 if (Inst.getOpcode() == ARM::ITasm)
8056 return false;
8057
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00008058 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00008059 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00008060 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008061 case Match_MissingFeature: {
8062 assert(ErrorInfo && "Unknown missing feature!");
8063 // Special case the error message for the very common case where only
8064 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8065 std::string Msg = "instruction requires:";
8066 unsigned Mask = 1;
8067 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8068 if (ErrorInfo & Mask) {
8069 Msg += " ";
8070 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8071 }
8072 Mask <<= 1;
8073 }
8074 return Error(IDLoc, Msg);
8075 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008076 case Match_InvalidOperand: {
8077 SMLoc ErrorLoc = IDLoc;
8078 if (ErrorInfo != ~0U) {
8079 if (ErrorInfo >= Operands.size())
8080 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00008081
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008082 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
8083 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8084 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008085
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008086 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00008087 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008088 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00008089 return Error(IDLoc, "invalid instruction",
8090 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00008091 case Match_RequiresNotITBlock:
8092 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008093 case Match_RequiresITBlock:
8094 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008095 case Match_RequiresV6:
8096 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8097 case Match_RequiresThumb2:
8098 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00008099 case Match_ImmRange0_15: {
8100 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
8101 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8102 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8103 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008104 case Match_ImmRange0_239: {
8105 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
8106 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8107 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8108 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00008109 case Match_AlignedMemoryRequiresNone:
8110 case Match_DupAlignedMemoryRequiresNone:
8111 case Match_AlignedMemoryRequires16:
8112 case Match_DupAlignedMemoryRequires16:
8113 case Match_AlignedMemoryRequires32:
8114 case Match_DupAlignedMemoryRequires32:
8115 case Match_AlignedMemoryRequires64:
8116 case Match_DupAlignedMemoryRequires64:
8117 case Match_AlignedMemoryRequires64or128:
8118 case Match_DupAlignedMemoryRequires64or128:
8119 case Match_AlignedMemoryRequires64or128or256:
8120 {
8121 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getAlignmentLoc();
8122 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8123 switch (MatchResult) {
8124 default:
8125 llvm_unreachable("Missing Match_Aligned type");
8126 case Match_AlignedMemoryRequiresNone:
8127 case Match_DupAlignedMemoryRequiresNone:
8128 return Error(ErrorLoc, "alignment must be omitted");
8129 case Match_AlignedMemoryRequires16:
8130 case Match_DupAlignedMemoryRequires16:
8131 return Error(ErrorLoc, "alignment must be 16 or omitted");
8132 case Match_AlignedMemoryRequires32:
8133 case Match_DupAlignedMemoryRequires32:
8134 return Error(ErrorLoc, "alignment must be 32 or omitted");
8135 case Match_AlignedMemoryRequires64:
8136 case Match_DupAlignedMemoryRequires64:
8137 return Error(ErrorLoc, "alignment must be 64 or omitted");
8138 case Match_AlignedMemoryRequires64or128:
8139 case Match_DupAlignedMemoryRequires64or128:
8140 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8141 case Match_AlignedMemoryRequires64or128or256:
8142 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8143 }
8144 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008145 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008146
Eric Christopher91d7b902010-10-29 09:26:59 +00008147 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00008148}
8149
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008150/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00008151bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008152 const MCObjectFileInfo::Environment Format =
8153 getContext().getObjectFileInfo()->getObjectFileType();
8154 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
8155
Kevin Enderbyccab3172009-09-15 00:27:25 +00008156 StringRef IDVal = DirectiveID.getIdentifier();
8157 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008158 return parseLiteralValues(4, DirectiveID.getLoc());
8159 else if (IDVal == ".short" || IDVal == ".hword")
8160 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008161 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008162 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00008163 else if (IDVal == ".arm")
8164 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008165 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008166 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008167 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008168 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008169 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008170 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008171 else if (IDVal == ".unreq")
8172 return parseDirectiveUnreq(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00008173 else if (IDVal == ".fnend")
8174 return parseDirectiveFnEnd(DirectiveID.getLoc());
8175 else if (IDVal == ".cantunwind")
8176 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8177 else if (IDVal == ".personality")
8178 return parseDirectivePersonality(DirectiveID.getLoc());
8179 else if (IDVal == ".handlerdata")
8180 return parseDirectiveHandlerData(DirectiveID.getLoc());
8181 else if (IDVal == ".setfp")
8182 return parseDirectiveSetFP(DirectiveID.getLoc());
8183 else if (IDVal == ".pad")
8184 return parseDirectivePad(DirectiveID.getLoc());
8185 else if (IDVal == ".save")
8186 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8187 else if (IDVal == ".vsave")
8188 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008189 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008190 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008191 else if (IDVal == ".even")
8192 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008193 else if (IDVal == ".personalityindex")
8194 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008195 else if (IDVal == ".unwind_raw")
8196 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008197 else if (IDVal == ".movsp")
8198 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008199 else if (IDVal == ".arch_extension")
8200 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008201 else if (IDVal == ".align")
8202 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008203 else if (IDVal == ".thumb_set")
8204 return parseDirectiveThumbSet(DirectiveID.getLoc());
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008205
8206 if (!IsMachO) {
8207 if (IDVal == ".arch")
8208 return parseDirectiveArch(DirectiveID.getLoc());
8209 else if (IDVal == ".cpu")
8210 return parseDirectiveCPU(DirectiveID.getLoc());
8211 else if (IDVal == ".eabi_attribute")
8212 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8213 else if (IDVal == ".fpu")
8214 return parseDirectiveFPU(DirectiveID.getLoc());
8215 else if (IDVal == ".fnstart")
8216 return parseDirectiveFnStart(DirectiveID.getLoc());
8217 else if (IDVal == ".inst")
8218 return parseDirectiveInst(DirectiveID.getLoc());
8219 else if (IDVal == ".inst.n")
8220 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8221 else if (IDVal == ".inst.w")
8222 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8223 else if (IDVal == ".object_arch")
8224 return parseDirectiveObjectArch(DirectiveID.getLoc());
8225 else if (IDVal == ".tlsdescseq")
8226 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8227 }
8228
Kevin Enderbyccab3172009-09-15 00:27:25 +00008229 return true;
8230}
8231
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008232/// parseLiteralValues
8233/// ::= .hword expression [, expression]*
8234/// ::= .short expression [, expression]*
8235/// ::= .word expression [, expression]*
8236bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00008237 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8238 for (;;) {
8239 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008240 if (getParser().parseExpression(Value)) {
8241 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008242 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008243 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008244
Eric Christopherbf7bc492013-01-09 03:52:05 +00008245 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008246
8247 if (getLexer().is(AsmToken::EndOfStatement))
8248 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008249
Kevin Enderbyccab3172009-09-15 00:27:25 +00008250 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008251 if (getLexer().isNot(AsmToken::Comma)) {
8252 Error(L, "unexpected token in directive");
8253 return false;
8254 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008255 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008256 }
8257 }
8258
Sean Callanana83fd7d2010-01-19 20:27:46 +00008259 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008260 return false;
8261}
8262
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008263/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008264/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008265bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008266 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8267 Error(L, "unexpected token in directive");
8268 return false;
8269 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008270 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008271
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008272 if (!hasThumb()) {
8273 Error(L, "target does not support Thumb mode");
8274 return false;
8275 }
Tim Northovera2292d02013-06-10 23:20:58 +00008276
Jim Grosbach7f882392011-12-07 18:04:19 +00008277 if (!isThumb())
8278 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008279
Jim Grosbach7f882392011-12-07 18:04:19 +00008280 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8281 return false;
8282}
8283
8284/// parseDirectiveARM
8285/// ::= .arm
8286bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008287 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8288 Error(L, "unexpected token in directive");
8289 return false;
8290 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008291 Parser.Lex();
8292
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008293 if (!hasARM()) {
8294 Error(L, "target does not support ARM mode");
8295 return false;
8296 }
Tim Northovera2292d02013-06-10 23:20:58 +00008297
Jim Grosbach7f882392011-12-07 18:04:19 +00008298 if (isThumb())
8299 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008300
Jim Grosbach7f882392011-12-07 18:04:19 +00008301 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008302 return false;
8303}
8304
Tim Northover1744d0a2013-10-25 12:49:50 +00008305void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8306 if (NextSymbolIsThumb) {
8307 getParser().getStreamer().EmitThumbFunc(Symbol);
8308 NextSymbolIsThumb = false;
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008309 return;
8310 }
8311
8312 if (!isThumb())
8313 return;
8314
8315 const MCObjectFileInfo::Environment Format =
8316 getContext().getObjectFileInfo()->getObjectFileType();
8317 switch (Format) {
8318 case MCObjectFileInfo::IsCOFF: {
8319 const MCSymbolData &SD =
8320 getParser().getStreamer().getOrCreateSymbolData(Symbol);
8321 char Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
8322 if (SD.getFlags() & (Type << COFF::SF_TypeShift))
8323 getParser().getStreamer().EmitThumbFunc(Symbol);
8324 break;
8325 }
8326 case MCObjectFileInfo::IsELF: {
8327 const MCSymbolData &SD =
8328 getParser().getStreamer().getOrCreateSymbolData(Symbol);
8329 if (MCELF::GetType(SD) & (ELF::STT_FUNC << ELF_STT_Shift))
8330 getParser().getStreamer().EmitThumbFunc(Symbol);
8331 break;
8332 }
8333 case MCObjectFileInfo::IsMachO:
8334 break;
Tim Northover1744d0a2013-10-25 12:49:50 +00008335 }
8336}
8337
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008338/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008339/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008340bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00008341 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8342 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008343
Jim Grosbach1152cc02011-12-21 22:30:16 +00008344 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008345 // ELF doesn't
8346 if (isMachO) {
8347 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008348 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008349 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8350 Error(L, "unexpected token in .thumb_func directive");
8351 return false;
8352 }
8353
Tim Northover1744d0a2013-10-25 12:49:50 +00008354 MCSymbol *Func =
8355 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8356 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008357 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008358 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008359 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008360 }
8361
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008362 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8363 Error(L, "unexpected token in directive");
8364 return false;
8365 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008366
Tim Northover1744d0a2013-10-25 12:49:50 +00008367 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008368 return false;
8369}
8370
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008371/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008372/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008373bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008374 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008375 if (Tok.isNot(AsmToken::Identifier)) {
8376 Error(L, "unexpected token in .syntax directive");
8377 return false;
8378 }
8379
Benjamin Kramer92d89982010-07-14 22:38:02 +00008380 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008381 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008382 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008383 } else if (Mode == "divided" || Mode == "DIVIDED") {
8384 Error(L, "'.syntax divided' arm asssembly not supported");
8385 return false;
8386 } else {
8387 Error(L, "unrecognized syntax mode in .syntax directive");
8388 return false;
8389 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008390
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008391 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8392 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8393 return false;
8394 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008395 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008396
8397 // TODO tell the MC streamer the mode
8398 // getParser().getStreamer().Emit???();
8399 return false;
8400}
8401
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008402/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008403/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008404bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008405 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008406 if (Tok.isNot(AsmToken::Integer)) {
8407 Error(L, "unexpected token in .code directive");
8408 return false;
8409 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008410 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008411 if (Val != 16 && Val != 32) {
8412 Error(L, "invalid operand to .code directive");
8413 return false;
8414 }
8415 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008416
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008417 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8418 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8419 return false;
8420 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008421 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008422
Evan Cheng284b4672011-07-08 22:36:29 +00008423 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008424 if (!hasThumb()) {
8425 Error(L, "target does not support Thumb mode");
8426 return false;
8427 }
Tim Northovera2292d02013-06-10 23:20:58 +00008428
Jim Grosbachf471ac32011-09-06 18:46:23 +00008429 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008430 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008431 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008432 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008433 if (!hasARM()) {
8434 Error(L, "target does not support ARM mode");
8435 return false;
8436 }
Tim Northovera2292d02013-06-10 23:20:58 +00008437
Jim Grosbachf471ac32011-09-06 18:46:23 +00008438 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008439 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008440 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008441 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008442
Kevin Enderby146dcf22009-10-15 20:48:48 +00008443 return false;
8444}
8445
Jim Grosbachab5830e2011-12-14 02:16:11 +00008446/// parseDirectiveReq
8447/// ::= name .req registername
8448bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8449 Parser.Lex(); // Eat the '.req' token.
8450 unsigned Reg;
8451 SMLoc SRegLoc, ERegLoc;
8452 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008453 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008454 Error(SRegLoc, "register name expected");
8455 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008456 }
8457
8458 // Shouldn't be anything else.
8459 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008460 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008461 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8462 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008463 }
8464
8465 Parser.Lex(); // Consume the EndOfStatement
8466
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008467 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) {
8468 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8469 return false;
8470 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00008471
8472 return false;
8473}
8474
8475/// parseDirectiveUneq
8476/// ::= .unreq registername
8477bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8478 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008479 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008480 Error(L, "unexpected input in .unreq directive.");
8481 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008482 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00008483 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008484 Parser.Lex(); // Eat the identifier.
8485 return false;
8486}
8487
Jason W Kim135d2442011-12-20 17:38:12 +00008488/// parseDirectiveArch
8489/// ::= .arch token
8490bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00008491 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8492
8493 unsigned ID = StringSwitch<unsigned>(Arch)
8494#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8495 .Case(NAME, ARM::ID)
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +00008496#define ARM_ARCH_ALIAS(NAME, ID) \
8497 .Case(NAME, ARM::ID)
Logan Chien439e8f92013-12-11 17:16:25 +00008498#include "MCTargetDesc/ARMArchName.def"
8499 .Default(ARM::INVALID_ARCH);
8500
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008501 if (ID == ARM::INVALID_ARCH) {
8502 Error(L, "Unknown arch name");
8503 return false;
8504 }
Logan Chien439e8f92013-12-11 17:16:25 +00008505
8506 getTargetStreamer().emitArch(ID);
8507 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008508}
8509
8510/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008511/// ::= .eabi_attribute int, int [, "str"]
8512/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00008513bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008514 int64_t Tag;
8515 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008516 TagLoc = Parser.getTok().getLoc();
8517 if (Parser.getTok().is(AsmToken::Identifier)) {
8518 StringRef Name = Parser.getTok().getIdentifier();
8519 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
8520 if (Tag == -1) {
8521 Error(TagLoc, "attribute name not recognised: " + Name);
8522 Parser.eatToEndOfStatement();
8523 return false;
8524 }
8525 Parser.Lex();
8526 } else {
8527 const MCExpr *AttrExpr;
8528
8529 TagLoc = Parser.getTok().getLoc();
8530 if (Parser.parseExpression(AttrExpr)) {
8531 Parser.eatToEndOfStatement();
8532 return false;
8533 }
8534
8535 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
8536 if (!CE) {
8537 Error(TagLoc, "expected numeric constant");
8538 Parser.eatToEndOfStatement();
8539 return false;
8540 }
8541
8542 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008543 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008544
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008545 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008546 Error(Parser.getTok().getLoc(), "comma expected");
8547 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008548 return false;
8549 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008550 Parser.Lex(); // skip comma
8551
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008552 StringRef StringValue = "";
8553 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00008554
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008555 int64_t IntegerValue = 0;
8556 bool IsIntegerValue = false;
8557
8558 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
8559 IsStringValue = true;
8560 else if (Tag == ARMBuildAttrs::compatibility) {
8561 IsStringValue = true;
8562 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00008563 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00008564 IsIntegerValue = true;
8565 else if (Tag % 2 == 1)
8566 IsStringValue = true;
8567 else
8568 llvm_unreachable("invalid tag type");
8569
8570 if (IsIntegerValue) {
8571 const MCExpr *ValueExpr;
8572 SMLoc ValueExprLoc = Parser.getTok().getLoc();
8573 if (Parser.parseExpression(ValueExpr)) {
8574 Parser.eatToEndOfStatement();
8575 return false;
8576 }
8577
8578 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
8579 if (!CE) {
8580 Error(ValueExprLoc, "expected numeric constant");
8581 Parser.eatToEndOfStatement();
8582 return false;
8583 }
8584
8585 IntegerValue = CE->getValue();
8586 }
8587
8588 if (Tag == ARMBuildAttrs::compatibility) {
8589 if (Parser.getTok().isNot(AsmToken::Comma))
8590 IsStringValue = false;
8591 else
8592 Parser.Lex();
8593 }
8594
8595 if (IsStringValue) {
8596 if (Parser.getTok().isNot(AsmToken::String)) {
8597 Error(Parser.getTok().getLoc(), "bad string constant");
8598 Parser.eatToEndOfStatement();
8599 return false;
8600 }
8601
8602 StringValue = Parser.getTok().getStringContents();
8603 Parser.Lex();
8604 }
8605
8606 if (IsIntegerValue && IsStringValue) {
8607 assert(Tag == ARMBuildAttrs::compatibility);
8608 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
8609 } else if (IsIntegerValue)
8610 getTargetStreamer().emitAttribute(Tag, IntegerValue);
8611 else if (IsStringValue)
8612 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00008613 return false;
8614}
8615
8616/// parseDirectiveCPU
8617/// ::= .cpu str
8618bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8619 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8620 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8621 return false;
8622}
8623
8624/// parseDirectiveFPU
8625/// ::= .fpu str
8626bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8627 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8628
8629 unsigned ID = StringSwitch<unsigned>(FPU)
8630#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8631#include "ARMFPUName.def"
8632 .Default(ARM::INVALID_FPU);
8633
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008634 if (ID == ARM::INVALID_FPU) {
8635 Error(L, "Unknown FPU name");
8636 return false;
8637 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00008638
8639 getTargetStreamer().emitFPU(ID);
8640 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008641}
8642
Logan Chien4ea23b52013-05-10 16:17:24 +00008643/// parseDirectiveFnStart
8644/// ::= .fnstart
8645bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008646 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008647 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008648 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008649 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008650 }
8651
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008652 // Reset the unwind directives parser state
8653 UC.reset();
8654
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008655 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008656
8657 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00008658 return false;
8659}
8660
8661/// parseDirectiveFnEnd
8662/// ::= .fnend
8663bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8664 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008665 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008666 Error(L, ".fnstart must precede .fnend directive");
8667 return false;
8668 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008669
8670 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008671 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008672
8673 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00008674 return false;
8675}
8676
8677/// parseDirectiveCantUnwind
8678/// ::= .cantunwind
8679bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008680 UC.recordCantUnwind(L);
8681
Logan Chien4ea23b52013-05-10 16:17:24 +00008682 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008683 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008684 Error(L, ".fnstart must precede .cantunwind directive");
8685 return false;
8686 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008687 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008688 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008689 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008690 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008691 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008692 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008693 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008694 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008695 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008696 }
8697
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008698 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00008699 return false;
8700}
8701
8702/// parseDirectivePersonality
8703/// ::= .personality name
8704bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008705 bool HasExistingPersonality = UC.hasPersonality();
8706
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008707 UC.recordPersonality(L);
8708
Logan Chien4ea23b52013-05-10 16:17:24 +00008709 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008710 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008711 Error(L, ".fnstart must precede .personality directive");
8712 return false;
8713 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008714 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008715 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008716 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008717 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008718 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008719 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008720 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008721 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008722 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008723 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008724 if (HasExistingPersonality) {
8725 Parser.eatToEndOfStatement();
8726 Error(L, "multiple personality directives");
8727 UC.emitPersonalityLocNotes();
8728 return false;
8729 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008730
8731 // Parse the name of the personality routine
8732 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8733 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008734 Error(L, "unexpected input in .personality directive.");
8735 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008736 }
8737 StringRef Name(Parser.getTok().getIdentifier());
8738 Parser.Lex();
8739
8740 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008741 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00008742 return false;
8743}
8744
8745/// parseDirectiveHandlerData
8746/// ::= .handlerdata
8747bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008748 UC.recordHandlerData(L);
8749
Logan Chien4ea23b52013-05-10 16:17:24 +00008750 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008751 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008752 Error(L, ".fnstart must precede .personality directive");
8753 return false;
8754 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008755 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00008756 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008757 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008758 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008759 }
8760
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008761 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00008762 return false;
8763}
8764
8765/// parseDirectiveSetFP
8766/// ::= .setfp fpreg, spreg [, offset]
8767bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8768 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008769 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008770 Error(L, ".fnstart must precede .setfp directive");
8771 return false;
8772 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008773 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008774 Error(L, ".setfp must precede .handlerdata directive");
8775 return false;
8776 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008777
8778 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008779 SMLoc FPRegLoc = Parser.getTok().getLoc();
8780 int FPReg = tryParseRegister();
8781 if (FPReg == -1) {
8782 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008783 return false;
8784 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008785
8786 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008787 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008788 Error(Parser.getTok().getLoc(), "comma expected");
8789 return false;
8790 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008791 Parser.Lex(); // skip comma
8792
8793 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008794 SMLoc SPRegLoc = Parser.getTok().getLoc();
8795 int SPReg = tryParseRegister();
8796 if (SPReg == -1) {
8797 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008798 return false;
8799 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008800
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008801 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
8802 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008803 return false;
8804 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008805
8806 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008807 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00008808
8809 // Parse offset
8810 int64_t Offset = 0;
8811 if (Parser.getTok().is(AsmToken::Comma)) {
8812 Parser.Lex(); // skip comma
8813
8814 if (Parser.getTok().isNot(AsmToken::Hash) &&
8815 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008816 Error(Parser.getTok().getLoc(), "'#' expected");
8817 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008818 }
8819 Parser.Lex(); // skip hash token.
8820
8821 const MCExpr *OffsetExpr;
8822 SMLoc ExLoc = Parser.getTok().getLoc();
8823 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008824 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8825 Error(ExLoc, "malformed setfp offset");
8826 return false;
8827 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008829 if (!CE) {
8830 Error(ExLoc, "setfp offset must be an immediate");
8831 return false;
8832 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008833
8834 Offset = CE->getValue();
8835 }
8836
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008837 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
8838 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00008839 return false;
8840}
8841
8842/// parseDirective
8843/// ::= .pad offset
8844bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8845 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008846 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008847 Error(L, ".fnstart must precede .pad directive");
8848 return false;
8849 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008850 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008851 Error(L, ".pad must precede .handlerdata directive");
8852 return false;
8853 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008854
8855 // Parse the offset
8856 if (Parser.getTok().isNot(AsmToken::Hash) &&
8857 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008858 Error(Parser.getTok().getLoc(), "'#' expected");
8859 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00008860 }
8861 Parser.Lex(); // skip hash token.
8862
8863 const MCExpr *OffsetExpr;
8864 SMLoc ExLoc = Parser.getTok().getLoc();
8865 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008866 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8867 Error(ExLoc, "malformed pad offset");
8868 return false;
8869 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008870 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008871 if (!CE) {
8872 Error(ExLoc, "pad offset must be an immediate");
8873 return false;
8874 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008875
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008876 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00008877 return false;
8878}
8879
8880/// parseDirectiveRegSave
8881/// ::= .save { registers }
8882/// ::= .vsave { registers }
8883bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8884 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008885 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008886 Error(L, ".fnstart must precede .save or .vsave directives");
8887 return false;
8888 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00008889 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008890 Error(L, ".save or .vsave must precede .handlerdata directive");
8891 return false;
8892 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008893
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008894 // RAII object to make sure parsed operands are deleted.
8895 struct CleanupObject {
8896 SmallVector<MCParsedAsmOperand *, 1> Operands;
8897 ~CleanupObject() {
8898 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8899 delete Operands[I];
8900 }
8901 } CO;
8902
Logan Chien4ea23b52013-05-10 16:17:24 +00008903 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008904 if (parseRegisterList(CO.Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008905 return false;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008906 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008907 if (!IsVector && !Op->isRegList()) {
8908 Error(L, ".save expects GPR registers");
8909 return false;
8910 }
8911 if (IsVector && !Op->isDPRRegList()) {
8912 Error(L, ".vsave expects DPR registers");
8913 return false;
8914 }
Logan Chien4ea23b52013-05-10 16:17:24 +00008915
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008916 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00008917 return false;
8918}
8919
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008920/// parseDirectiveInst
8921/// ::= .inst opcode [, ...]
8922/// ::= .inst.n opcode [, ...]
8923/// ::= .inst.w opcode [, ...]
8924bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8925 int Width;
8926
8927 if (isThumb()) {
8928 switch (Suffix) {
8929 case 'n':
8930 Width = 2;
8931 break;
8932 case 'w':
8933 Width = 4;
8934 break;
8935 default:
8936 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008937 Error(Loc, "cannot determine Thumb instruction size, "
8938 "use inst.n/inst.w instead");
8939 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008940 }
8941 } else {
8942 if (Suffix) {
8943 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008944 Error(Loc, "width suffixes are invalid in ARM mode");
8945 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008946 }
8947 Width = 4;
8948 }
8949
8950 if (getLexer().is(AsmToken::EndOfStatement)) {
8951 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008952 Error(Loc, "expected expression following directive");
8953 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008954 }
8955
8956 for (;;) {
8957 const MCExpr *Expr;
8958
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008959 if (getParser().parseExpression(Expr)) {
8960 Error(Loc, "expected expression");
8961 return false;
8962 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008963
8964 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008965 if (!Value) {
8966 Error(Loc, "expected constant expression");
8967 return false;
8968 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008969
8970 switch (Width) {
8971 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008972 if (Value->getValue() > 0xffff) {
8973 Error(Loc, "inst.n operand is too big, use inst.w instead");
8974 return false;
8975 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008976 break;
8977 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008978 if (Value->getValue() > 0xffffffff) {
8979 Error(Loc,
8980 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8981 return false;
8982 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008983 break;
8984 default:
8985 llvm_unreachable("only supported widths are 2 and 4");
8986 }
8987
8988 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8989
8990 if (getLexer().is(AsmToken::EndOfStatement))
8991 break;
8992
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008993 if (getLexer().isNot(AsmToken::Comma)) {
8994 Error(Loc, "unexpected token in directive");
8995 return false;
8996 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008997
8998 Parser.Lex();
8999 }
9000
9001 Parser.Lex();
9002 return false;
9003}
9004
David Peixotto80c083a2013-12-19 18:26:07 +00009005/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00009006/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00009007bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00009008 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00009009 return false;
9010}
9011
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009012bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9013 const MCSection *Section = getStreamer().getCurrentSection().first;
9014
9015 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9016 TokError("unexpected token in directive");
9017 return false;
9018 }
9019
9020 if (!Section) {
Rafael Espindolaf1440342014-01-23 23:14:14 +00009021 getStreamer().InitSections();
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009022 Section = getStreamer().getCurrentSection().first;
9023 }
9024
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00009025 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009026 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00009027 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009028 else
Rafael Espindola7b514962014-02-04 18:34:04 +00009029 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009030
9031 return false;
9032}
9033
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009034/// parseDirectivePersonalityIndex
9035/// ::= .personalityindex index
9036bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
9037 bool HasExistingPersonality = UC.hasPersonality();
9038
9039 UC.recordPersonalityIndex(L);
9040
9041 if (!UC.hasFnStart()) {
9042 Parser.eatToEndOfStatement();
9043 Error(L, ".fnstart must precede .personalityindex directive");
9044 return false;
9045 }
9046 if (UC.cantUnwind()) {
9047 Parser.eatToEndOfStatement();
9048 Error(L, ".personalityindex cannot be used with .cantunwind");
9049 UC.emitCantUnwindLocNotes();
9050 return false;
9051 }
9052 if (UC.hasHandlerData()) {
9053 Parser.eatToEndOfStatement();
9054 Error(L, ".personalityindex must precede .handlerdata directive");
9055 UC.emitHandlerDataLocNotes();
9056 return false;
9057 }
9058 if (HasExistingPersonality) {
9059 Parser.eatToEndOfStatement();
9060 Error(L, "multiple personality directives");
9061 UC.emitPersonalityLocNotes();
9062 return false;
9063 }
9064
9065 const MCExpr *IndexExpression;
9066 SMLoc IndexLoc = Parser.getTok().getLoc();
9067 if (Parser.parseExpression(IndexExpression)) {
9068 Parser.eatToEndOfStatement();
9069 return false;
9070 }
9071
9072 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9073 if (!CE) {
9074 Parser.eatToEndOfStatement();
9075 Error(IndexLoc, "index must be a constant number");
9076 return false;
9077 }
9078 if (CE->getValue() < 0 ||
9079 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9080 Parser.eatToEndOfStatement();
9081 Error(IndexLoc, "personality routine index should be in range [0-3]");
9082 return false;
9083 }
9084
9085 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9086 return false;
9087}
9088
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009089/// parseDirectiveUnwindRaw
9090/// ::= .unwind_raw offset, opcode [, opcode...]
9091bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
9092 if (!UC.hasFnStart()) {
9093 Parser.eatToEndOfStatement();
9094 Error(L, ".fnstart must precede .unwind_raw directives");
9095 return false;
9096 }
9097
9098 int64_t StackOffset;
9099
9100 const MCExpr *OffsetExpr;
9101 SMLoc OffsetLoc = getLexer().getLoc();
9102 if (getLexer().is(AsmToken::EndOfStatement) ||
9103 getParser().parseExpression(OffsetExpr)) {
9104 Error(OffsetLoc, "expected expression");
9105 Parser.eatToEndOfStatement();
9106 return false;
9107 }
9108
9109 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9110 if (!CE) {
9111 Error(OffsetLoc, "offset must be a constant");
9112 Parser.eatToEndOfStatement();
9113 return false;
9114 }
9115
9116 StackOffset = CE->getValue();
9117
9118 if (getLexer().isNot(AsmToken::Comma)) {
9119 Error(getLexer().getLoc(), "expected comma");
9120 Parser.eatToEndOfStatement();
9121 return false;
9122 }
9123 Parser.Lex();
9124
9125 SmallVector<uint8_t, 16> Opcodes;
9126 for (;;) {
9127 const MCExpr *OE;
9128
9129 SMLoc OpcodeLoc = getLexer().getLoc();
9130 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9131 Error(OpcodeLoc, "expected opcode expression");
9132 Parser.eatToEndOfStatement();
9133 return false;
9134 }
9135
9136 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9137 if (!OC) {
9138 Error(OpcodeLoc, "opcode value must be a constant");
9139 Parser.eatToEndOfStatement();
9140 return false;
9141 }
9142
9143 const int64_t Opcode = OC->getValue();
9144 if (Opcode & ~0xff) {
9145 Error(OpcodeLoc, "invalid opcode");
9146 Parser.eatToEndOfStatement();
9147 return false;
9148 }
9149
9150 Opcodes.push_back(uint8_t(Opcode));
9151
9152 if (getLexer().is(AsmToken::EndOfStatement))
9153 break;
9154
9155 if (getLexer().isNot(AsmToken::Comma)) {
9156 Error(getLexer().getLoc(), "unexpected token in directive");
9157 Parser.eatToEndOfStatement();
9158 return false;
9159 }
9160
9161 Parser.Lex();
9162 }
9163
9164 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9165
9166 Parser.Lex();
9167 return false;
9168}
9169
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009170/// parseDirectiveTLSDescSeq
9171/// ::= .tlsdescseq tls-variable
9172bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
9173 if (getLexer().isNot(AsmToken::Identifier)) {
9174 TokError("expected variable after '.tlsdescseq' directive");
9175 Parser.eatToEndOfStatement();
9176 return false;
9177 }
9178
9179 const MCSymbolRefExpr *SRE =
9180 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9181 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9182 Lex();
9183
9184 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9185 Error(Parser.getTok().getLoc(), "unexpected token");
9186 Parser.eatToEndOfStatement();
9187 return false;
9188 }
9189
9190 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9191 return false;
9192}
9193
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009194/// parseDirectiveMovSP
9195/// ::= .movsp reg [, #offset]
9196bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
9197 if (!UC.hasFnStart()) {
9198 Parser.eatToEndOfStatement();
9199 Error(L, ".fnstart must precede .movsp directives");
9200 return false;
9201 }
9202 if (UC.getFPReg() != ARM::SP) {
9203 Parser.eatToEndOfStatement();
9204 Error(L, "unexpected .movsp directive");
9205 return false;
9206 }
9207
9208 SMLoc SPRegLoc = Parser.getTok().getLoc();
9209 int SPReg = tryParseRegister();
9210 if (SPReg == -1) {
9211 Parser.eatToEndOfStatement();
9212 Error(SPRegLoc, "register expected");
9213 return false;
9214 }
9215
9216 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9217 Parser.eatToEndOfStatement();
9218 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9219 return false;
9220 }
9221
9222 int64_t Offset = 0;
9223 if (Parser.getTok().is(AsmToken::Comma)) {
9224 Parser.Lex();
9225
9226 if (Parser.getTok().isNot(AsmToken::Hash)) {
9227 Error(Parser.getTok().getLoc(), "expected #constant");
9228 Parser.eatToEndOfStatement();
9229 return false;
9230 }
9231 Parser.Lex();
9232
9233 const MCExpr *OffsetExpr;
9234 SMLoc OffsetLoc = Parser.getTok().getLoc();
9235 if (Parser.parseExpression(OffsetExpr)) {
9236 Parser.eatToEndOfStatement();
9237 Error(OffsetLoc, "malformed offset expression");
9238 return false;
9239 }
9240
9241 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9242 if (!CE) {
9243 Parser.eatToEndOfStatement();
9244 Error(OffsetLoc, "offset must be an immediate constant");
9245 return false;
9246 }
9247
9248 Offset = CE->getValue();
9249 }
9250
9251 getTargetStreamer().emitMovSP(SPReg, Offset);
9252 UC.saveFPReg(SPReg);
9253
9254 return false;
9255}
9256
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009257/// parseDirectiveObjectArch
9258/// ::= .object_arch name
9259bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
9260 if (getLexer().isNot(AsmToken::Identifier)) {
9261 Error(getLexer().getLoc(), "unexpected token");
9262 Parser.eatToEndOfStatement();
9263 return false;
9264 }
9265
9266 StringRef Arch = Parser.getTok().getString();
9267 SMLoc ArchLoc = Parser.getTok().getLoc();
9268 getLexer().Lex();
9269
9270 unsigned ID = StringSwitch<unsigned>(Arch)
9271#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9272 .Case(NAME, ARM::ID)
9273#define ARM_ARCH_ALIAS(NAME, ID) \
9274 .Case(NAME, ARM::ID)
9275#include "MCTargetDesc/ARMArchName.def"
9276#undef ARM_ARCH_NAME
9277#undef ARM_ARCH_ALIAS
9278 .Default(ARM::INVALID_ARCH);
9279
9280 if (ID == ARM::INVALID_ARCH) {
9281 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9282 Parser.eatToEndOfStatement();
9283 return false;
9284 }
9285
9286 getTargetStreamer().emitObjectArch(ID);
9287
9288 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9289 Error(getLexer().getLoc(), "unexpected token");
9290 Parser.eatToEndOfStatement();
9291 }
9292
9293 return false;
9294}
9295
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009296/// parseDirectiveAlign
9297/// ::= .align
9298bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9299 // NOTE: if this is not the end of the statement, fall back to the target
9300 // agnostic handling for this directive which will correctly handle this.
9301 if (getLexer().isNot(AsmToken::EndOfStatement))
9302 return true;
9303
9304 // '.align' is target specifically handled to mean 2**2 byte alignment.
9305 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9306 getStreamer().EmitCodeAlignment(4, 0);
9307 else
9308 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9309
9310 return false;
9311}
9312
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009313/// parseDirectiveThumbSet
9314/// ::= .thumb_set name, value
9315bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
9316 StringRef Name;
9317 if (Parser.parseIdentifier(Name)) {
9318 TokError("expected identifier after '.thumb_set'");
9319 Parser.eatToEndOfStatement();
9320 return false;
9321 }
9322
9323 if (getLexer().isNot(AsmToken::Comma)) {
9324 TokError("expected comma after name '" + Name + "'");
9325 Parser.eatToEndOfStatement();
9326 return false;
9327 }
9328 Lex();
9329
9330 const MCExpr *Value;
9331 if (Parser.parseExpression(Value)) {
9332 TokError("missing expression");
9333 Parser.eatToEndOfStatement();
9334 return false;
9335 }
9336
9337 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9338 TokError("unexpected token");
9339 Parser.eatToEndOfStatement();
9340 return false;
9341 }
9342 Lex();
9343
9344 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
9345 if (const MCSymbolRefExpr *SRE = dyn_cast<MCSymbolRefExpr>(Value)) {
9346 MCSymbol *Sym = getContext().LookupSymbol(SRE->getSymbol().getName());
9347 if (!Sym->isDefined()) {
9348 getStreamer().EmitSymbolAttribute(Sym, MCSA_Global);
9349 getStreamer().EmitAssignment(Alias, Value);
9350 return false;
9351 }
9352
9353 const MCObjectFileInfo::Environment Format =
9354 getContext().getObjectFileInfo()->getObjectFileType();
9355 switch (Format) {
9356 case MCObjectFileInfo::IsCOFF: {
9357 char Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
9358 getStreamer().EmitCOFFSymbolType(Type);
9359 // .set values are always local in COFF
9360 getStreamer().EmitSymbolAttribute(Alias, MCSA_Local);
9361 break;
9362 }
9363 case MCObjectFileInfo::IsELF:
9364 getStreamer().EmitSymbolAttribute(Alias, MCSA_ELF_TypeFunction);
9365 break;
9366 case MCObjectFileInfo::IsMachO:
9367 break;
9368 }
9369 }
9370
9371 // FIXME: set the function as being a thumb function via the assembler
9372 getStreamer().EmitThumbFunc(Alias);
9373 getStreamer().EmitAssignment(Alias, Value);
9374
9375 return false;
9376}
9377
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009378/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009379extern "C" void LLVMInitializeARMAsmParser() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00009380 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9381 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9382 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9383 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009384}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009385
Chris Lattner3e4582a2010-09-06 19:11:01 +00009386#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009387#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009388#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009389#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009390
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009391static const struct ExtMapEntry {
9392 const char *Extension;
9393 const unsigned ArchCheck;
9394 const uint64_t Features;
9395} Extensions[] = {
9396 { "crc", Feature_HasV8, ARM::FeatureCRC },
9397 { "crypto", Feature_HasV8,
9398 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9399 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
9400 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
9401 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
9402 // FIXME: iWMMXT not supported
9403 { "iwmmxt", Feature_None, 0 },
9404 // FIXME: iWMMXT2 not supported
9405 { "iwmmxt2", Feature_None, 0 },
9406 // FIXME: Maverick not supported
9407 { "maverick", Feature_None, 0 },
9408 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
9409 // FIXME: ARMv6-m OS Extensions feature not checked
9410 { "os", Feature_None, 0 },
9411 // FIXME: Also available in ARMv6-K
9412 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
9413 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9414 // FIXME: Only available in A-class, isel not predicated
9415 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
9416 // FIXME: xscale not supported
9417 { "xscale", Feature_None, 0 },
9418};
9419
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009420/// parseDirectiveArchExtension
9421/// ::= .arch_extension [no]feature
9422bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
9423 if (getLexer().isNot(AsmToken::Identifier)) {
9424 Error(getLexer().getLoc(), "unexpected token");
9425 Parser.eatToEndOfStatement();
9426 return false;
9427 }
9428
9429 StringRef Extension = Parser.getTok().getString();
9430 SMLoc ExtLoc = Parser.getTok().getLoc();
9431 getLexer().Lex();
9432
9433 bool EnableFeature = true;
Benjamin Kramere9391a52014-02-20 17:36:31 +00009434 if (Extension.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009435 EnableFeature = false;
9436 Extension = Extension.substr(2);
9437 }
9438
Benjamin Kramere9391a52014-02-20 17:36:31 +00009439 for (unsigned EI = 0, EE = array_lengthof(Extensions); EI != EE; ++EI) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009440 if (Extensions[EI].Extension != Extension)
9441 continue;
9442
9443 unsigned FB = getAvailableFeatures();
9444 if ((FB & Extensions[EI].ArchCheck) != Extensions[EI].ArchCheck) {
9445 Error(ExtLoc, "architectural extension '" + Extension + "' is not "
9446 "allowed for the current base architecture");
9447 return false;
9448 }
9449
9450 if (!Extensions[EI].Features)
9451 report_fatal_error("unsupported architectural extension: " + Extension);
9452
9453 if (EnableFeature)
9454 FB |= ComputeAvailableFeatures(Extensions[EI].Features);
9455 else
9456 FB &= ~ComputeAvailableFeatures(Extensions[EI].Features);
9457
9458 setAvailableFeatures(FB);
9459 return false;
9460 }
9461
9462 Error(ExtLoc, "unknown architectural extension: " + Extension);
9463 Parser.eatToEndOfStatement();
9464 return false;
9465}
9466
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009467// Define this matcher function after the auto-generated include so we
9468// have the match class enum definitions.
9469unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
9470 unsigned Kind) {
9471 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
9472 // If the kind is a token for a literal immediate, check if our asm
9473 // operand matches. This is for InstAliases which have a fixed-value
9474 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009475 switch (Kind) {
9476 default: break;
9477 case MCK__35_0:
9478 if (Op->isImm())
9479 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm()))
9480 if (CE->getValue() == 0)
9481 return Match_Success;
9482 break;
9483 case MCK_ARMSOImm:
9484 if (Op->isImm()) {
9485 const MCExpr *SOExpr = Op->getImm();
9486 int64_t Value;
9487 if (!SOExpr->EvaluateAsAbsolute(Value))
Stepan Dyatkovskiydf657cc2014-03-29 13:12:40 +00009488 return Match_Success;
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +00009489 assert((Value >= INT32_MIN && Value <= INT32_MAX) &&
9490 "expression value must be representiable in 32 bits");
9491 }
9492 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00009493 case MCK_GPRPair:
9494 if (Op->isReg() &&
9495 MRI->getRegClass(ARM::GPRRegClassID).contains(Op->getReg()))
9496 return Match_Success;
9497 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009498 }
9499 return Match_InvalidOperand;
9500}