blob: 534771b0a21f9369f13ee6ad9c5a1cba27c3851b [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
Amara Emerson52cfb6a2013-10-03 09:31:51 +000010#include "ARMFeatures.h"
Evan Cheng11424442011-07-26 00:24:13 +000011#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000012#include "MCTargetDesc/ARMAddressingModes.h"
13#include "MCTargetDesc/ARMBaseInfo.h"
14#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000015#include "llvm/ADT/BitVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000016#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000017#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000018#include "llvm/ADT/SmallVector.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"
Jack Carter718da0b2013-01-30 02:24:33 +000024#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000025#include "llvm/MC/MCExpr.h"
26#include "llvm/MC/MCInst.h"
27#include "llvm/MC/MCInstrDesc.h"
Joey Gouly0e76fa72013-09-12 10:28:05 +000028#include "llvm/MC/MCInstrInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000029#include "llvm/MC/MCParser/MCAsmLexer.h"
30#include "llvm/MC/MCParser/MCAsmParser.h"
31#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
32#include "llvm/MC/MCRegisterInfo.h"
33#include "llvm/MC/MCStreamer.h"
34#include "llvm/MC/MCSubtargetInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000035#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000036#include "llvm/Support/MathExtras.h"
37#include "llvm/Support/SourceMgr.h"
38#include "llvm/Support/TargetRegistry.h"
39#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000040
Kevin Enderbyccab3172009-09-15 00:27:25 +000041using namespace llvm;
42
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000043namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000044
45class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000046
Jim Grosbach04945c42011-12-02 00:35:16 +000047enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000048
Evan Cheng11424442011-07-26 00:24:13 +000049class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000050 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000051 MCAsmParser &Parser;
Joey Gouly0e76fa72013-09-12 10:28:05 +000052 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000053 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000054
Rafael Espindolaa17151a2013-10-08 13:08:17 +000055 ARMTargetStreamer &getTargetStreamer() {
56 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
57 return static_cast<ARMTargetStreamer &>(TS);
58 }
59
Logan Chien4ea23b52013-05-10 16:17:24 +000060 // Unwind directives state
61 SMLoc FnStartLoc;
62 SMLoc CantUnwindLoc;
63 SMLoc PersonalityLoc;
64 SMLoc HandlerDataLoc;
65 int FPReg;
66 void resetUnwindDirectiveParserState() {
67 FnStartLoc = SMLoc();
68 CantUnwindLoc = SMLoc();
69 PersonalityLoc = SMLoc();
70 HandlerDataLoc = SMLoc();
71 FPReg = -1;
72 }
73
Jim Grosbachab5830e2011-12-14 02:16:11 +000074 // Map of register aliases registers via the .req directive.
75 StringMap<unsigned> RegisterReqs;
76
Jim Grosbached16ec42011-08-29 22:24:09 +000077 struct {
78 ARMCC::CondCodes Cond; // Condition for IT block.
79 unsigned Mask:4; // Condition mask for instructions.
80 // Starting at first 1 (from lsb).
81 // '1' condition as indicated in IT.
82 // '0' inverse of condition (else).
83 // Count of instructions in IT block is
84 // 4 - trailingzeroes(mask)
85
86 bool FirstCond; // Explicit flag for when we're parsing the
87 // First instruction in the IT block. It's
88 // implied in the mask, so needs special
89 // handling.
90
91 unsigned CurPosition; // Current position in parsing of IT
92 // block. In range [0,3]. Initialized
93 // according to count of instructions in block.
94 // ~0U if no active IT block.
95 } ITState;
96 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000097 void forwardITPosition() {
98 if (!inITBlock()) return;
99 // Move to the next instruction in the IT block, if there is one. If not,
100 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000101 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000102 if (++ITState.CurPosition == 5 - TZ)
103 ITState.CurPosition = ~0U; // Done with the IT block after this.
104 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000105
106
Kevin Enderbyccab3172009-09-15 00:27:25 +0000107 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000108 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
109
Benjamin Kramer673824b2012-04-15 17:04:27 +0000110 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000111 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000112 return Parser.Warning(L, Msg, Ranges);
113 }
114 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000115 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000116 return Parser.Error(L, Msg, Ranges);
117 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000118
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000119 int tryParseRegister();
120 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000121 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000122 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000123 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000124 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
125 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000126 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
127 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000128 bool parseDirectiveWord(unsigned Size, SMLoc L);
129 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000130 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000131 bool parseDirectiveThumbFunc(SMLoc L);
132 bool parseDirectiveCode(SMLoc L);
133 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000134 bool parseDirectiveReq(StringRef Name, SMLoc L);
135 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000136 bool parseDirectiveArch(SMLoc L);
137 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000138 bool parseDirectiveFnStart(SMLoc L);
139 bool parseDirectiveFnEnd(SMLoc L);
140 bool parseDirectiveCantUnwind(SMLoc L);
141 bool parseDirectivePersonality(SMLoc L);
142 bool parseDirectiveHandlerData(SMLoc L);
143 bool parseDirectiveSetFP(SMLoc L);
144 bool parseDirectivePad(SMLoc L);
145 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000146
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000147 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000148 bool &CarrySetting, unsigned &ProcessorIMod,
149 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000150 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
151 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000152 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000153
Evan Cheng4d1ca962011-07-08 01:53:10 +0000154 bool isThumb() const {
155 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000156 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000157 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000158 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000159 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000160 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000161 bool isThumbTwo() const {
162 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
163 }
Tim Northovera2292d02013-06-10 23:20:58 +0000164 bool hasThumb() const {
165 return STI.getFeatureBits() & ARM::HasV4TOps;
166 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000167 bool hasV6Ops() const {
168 return STI.getFeatureBits() & ARM::HasV6Ops;
169 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000170 bool hasV6MOps() const {
171 return STI.getFeatureBits() & ARM::HasV6MOps;
172 }
James Molloy21efa7d2011-09-28 14:21:38 +0000173 bool hasV7Ops() const {
174 return STI.getFeatureBits() & ARM::HasV7Ops;
175 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000176 bool hasV8Ops() const {
177 return STI.getFeatureBits() & ARM::HasV8Ops;
178 }
Tim Northovera2292d02013-06-10 23:20:58 +0000179 bool hasARM() const {
180 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
181 }
182
Evan Cheng284b4672011-07-08 22:36:29 +0000183 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000184 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
185 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000186 }
James Molloy21efa7d2011-09-28 14:21:38 +0000187 bool isMClass() const {
188 return STI.getFeatureBits() & ARM::FeatureMClass;
189 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000190
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000191 /// @name Auto-generated Match Functions
192 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000193
Chris Lattner3e4582a2010-09-06 19:11:01 +0000194#define GET_ASSEMBLER_HEADER
195#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000196
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000197 /// }
198
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000199 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000200 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000201 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000202 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000203 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000204 OperandMatchResultTy parseCoprocOptionOperand(
205 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000206 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000207 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000208 OperandMatchResultTy parseInstSyncBarrierOptOperand(
209 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000210 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000211 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000212 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000213 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000214 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
215 StringRef Op, int Low, int High);
216 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
217 return parsePKHImm(O, "lsl", 0, 31);
218 }
219 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
220 return parsePKHImm(O, "asr", 1, 32);
221 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000222 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000223 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000224 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000225 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000226 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000227 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000228 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000229 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000230 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
231 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000232
233 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000234 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000235 const SmallVectorImpl<MCParsedAsmOperand*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000236 void cvtThumbBranches(MCInst &Inst,
237 const SmallVectorImpl<MCParsedAsmOperand*> &);
238
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000239 bool validateInstruction(MCInst &Inst,
240 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000241 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000242 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000243 bool shouldOmitCCOutOperand(StringRef Mnemonic,
244 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000245 bool shouldOmitPredicateOperand(StringRef Mnemonic,
246 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000247public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000248 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000249 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000250 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000251 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000252 Match_RequiresThumb2,
253#define GET_OPERAND_DIAGNOSTIC_TYPES
254#include "ARMGenAsmMatcher.inc"
255
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000256 };
257
Joey Gouly0e76fa72013-09-12 10:28:05 +0000258 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
259 const MCInstrInfo &MII)
260 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000261 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000262
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000263 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000264 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000265
Evan Cheng4d1ca962011-07-08 01:53:10 +0000266 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000267 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000268
269 // Not in an ITBlock to start with.
270 ITState.CurPosition = ~0U;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000271 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000272
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000273 // Implementation of the MCTargetAsmParser interface:
274 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000275 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
276 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000277 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000278 bool ParseDirective(AsmToken DirectiveID);
279
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000280 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000281 unsigned checkTargetMatchPredicate(MCInst &Inst);
282
Chad Rosier49963552012-10-13 00:26:04 +0000283 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000284 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000285 MCStreamer &Out, unsigned &ErrorInfo,
286 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000287};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000288} // end anonymous namespace
289
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000290namespace {
291
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000292/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000293/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000294class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000295 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000296 k_CondCode,
297 k_CCOut,
298 k_ITCondMask,
299 k_CoprocNum,
300 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000301 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000302 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000303 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000304 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000305 k_Memory,
306 k_PostIndexRegister,
307 k_MSRMask,
308 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000309 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000310 k_Register,
311 k_RegisterList,
312 k_DPRRegisterList,
313 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000314 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000315 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000316 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000317 k_ShiftedRegister,
318 k_ShiftedImmediate,
319 k_ShifterImmediate,
320 k_RotateImmediate,
321 k_BitfieldDescriptor,
322 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000323 } Kind;
324
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000325 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000326 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000327
Eric Christopher8996c5d2013-03-15 00:42:55 +0000328 struct CCOp {
329 ARMCC::CondCodes Val;
330 };
331
332 struct CopOp {
333 unsigned Val;
334 };
335
336 struct CoprocOptionOp {
337 unsigned Val;
338 };
339
340 struct ITMaskOp {
341 unsigned Mask:4;
342 };
343
344 struct MBOptOp {
345 ARM_MB::MemBOpt Val;
346 };
347
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000348 struct ISBOptOp {
349 ARM_ISB::InstSyncBOpt Val;
350 };
351
Eric Christopher8996c5d2013-03-15 00:42:55 +0000352 struct IFlagsOp {
353 ARM_PROC::IFlags Val;
354 };
355
356 struct MMaskOp {
357 unsigned Val;
358 };
359
360 struct TokOp {
361 const char *Data;
362 unsigned Length;
363 };
364
365 struct RegOp {
366 unsigned RegNum;
367 };
368
369 // A vector register list is a sequential list of 1 to 4 registers.
370 struct VectorListOp {
371 unsigned RegNum;
372 unsigned Count;
373 unsigned LaneIndex;
374 bool isDoubleSpaced;
375 };
376
377 struct VectorIndexOp {
378 unsigned Val;
379 };
380
381 struct ImmOp {
382 const MCExpr *Val;
383 };
384
385 /// Combined record for all forms of ARM address expressions.
386 struct MemoryOp {
387 unsigned BaseRegNum;
388 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
389 // was specified.
390 const MCConstantExpr *OffsetImm; // Offset immediate value
391 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
392 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
393 unsigned ShiftImm; // shift for OffsetReg.
394 unsigned Alignment; // 0 = no alignment specified
395 // n = alignment in bytes (2, 4, 8, 16, or 32)
396 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
397 };
398
399 struct PostIdxRegOp {
400 unsigned RegNum;
401 bool isAdd;
402 ARM_AM::ShiftOpc ShiftTy;
403 unsigned ShiftImm;
404 };
405
406 struct ShifterImmOp {
407 bool isASR;
408 unsigned Imm;
409 };
410
411 struct RegShiftedRegOp {
412 ARM_AM::ShiftOpc ShiftTy;
413 unsigned SrcReg;
414 unsigned ShiftReg;
415 unsigned ShiftImm;
416 };
417
418 struct RegShiftedImmOp {
419 ARM_AM::ShiftOpc ShiftTy;
420 unsigned SrcReg;
421 unsigned ShiftImm;
422 };
423
424 struct RotImmOp {
425 unsigned Imm;
426 };
427
428 struct BitfieldOp {
429 unsigned LSB;
430 unsigned Width;
431 };
432
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000433 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000434 struct CCOp CC;
435 struct CopOp Cop;
436 struct CoprocOptionOp CoprocOption;
437 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000438 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000439 struct ITMaskOp ITMask;
440 struct IFlagsOp IFlags;
441 struct MMaskOp MMask;
442 struct TokOp Tok;
443 struct RegOp Reg;
444 struct VectorListOp VectorList;
445 struct VectorIndexOp VectorIndex;
446 struct ImmOp Imm;
447 struct MemoryOp Memory;
448 struct PostIdxRegOp PostIdxReg;
449 struct ShifterImmOp ShifterImm;
450 struct RegShiftedRegOp RegShiftedReg;
451 struct RegShiftedImmOp RegShiftedImm;
452 struct RotImmOp RotImm;
453 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000454 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000455
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000456 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
457public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000458 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
459 Kind = o.Kind;
460 StartLoc = o.StartLoc;
461 EndLoc = o.EndLoc;
462 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000463 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000464 CC = o.CC;
465 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000466 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000467 ITMask = o.ITMask;
468 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000469 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000470 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000471 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000472 case k_CCOut:
473 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000474 Reg = o.Reg;
475 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000476 case k_RegisterList:
477 case k_DPRRegisterList:
478 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000479 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000480 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000481 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000482 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000483 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000484 VectorList = o.VectorList;
485 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000486 case k_CoprocNum:
487 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000488 Cop = o.Cop;
489 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000490 case k_CoprocOption:
491 CoprocOption = o.CoprocOption;
492 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000493 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000494 Imm = o.Imm;
495 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000496 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000497 MBOpt = o.MBOpt;
498 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000499 case k_InstSyncBarrierOpt:
500 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000501 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000502 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000503 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000504 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000505 PostIdxReg = o.PostIdxReg;
506 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000507 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000508 MMask = o.MMask;
509 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000510 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000511 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000512 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000513 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000514 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000515 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000516 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000517 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000518 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000519 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000520 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000521 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000522 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000523 RotImm = o.RotImm;
524 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000525 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000526 Bitfield = o.Bitfield;
527 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000528 case k_VectorIndex:
529 VectorIndex = o.VectorIndex;
530 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000531 }
532 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000533
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000534 /// getStartLoc - Get the location of the first token of this operand.
535 SMLoc getStartLoc() const { return StartLoc; }
536 /// getEndLoc - Get the location of the last token of this operand.
537 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000538 /// getLocRange - Get the range between the first and last token of this
539 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000540 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
541
Daniel Dunbard8042b72010-08-11 06:36:53 +0000542 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000543 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000544 return CC.Val;
545 }
546
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000547 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000548 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000549 return Cop.Val;
550 }
551
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000552 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000553 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000554 return StringRef(Tok.Data, Tok.Length);
555 }
556
557 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000558 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000559 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000560 }
561
Bill Wendlingbed94652010-11-09 23:28:44 +0000562 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000563 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
564 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000565 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000566 }
567
Kevin Enderbyf5079942009-10-13 22:19:02 +0000568 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000569 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000570 return Imm.Val;
571 }
572
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000573 unsigned getVectorIndex() const {
574 assert(Kind == k_VectorIndex && "Invalid access!");
575 return VectorIndex.Val;
576 }
577
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000578 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000579 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000580 return MBOpt.Val;
581 }
582
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000583 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
584 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
585 return ISBOpt.Val;
586 }
587
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000588 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000589 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000590 return IFlags.Val;
591 }
592
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000593 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000594 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000595 return MMask.Val;
596 }
597
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000598 bool isCoprocNum() const { return Kind == k_CoprocNum; }
599 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000600 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000601 bool isCondCode() const { return Kind == k_CondCode; }
602 bool isCCOut() const { return Kind == k_CCOut; }
603 bool isITMask() const { return Kind == k_ITCondMask; }
604 bool isITCondCode() const { return Kind == k_CondCode; }
605 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000606 // checks whether this operand is an unsigned offset which fits is a field
607 // of specified width and scaled by a specific number of bits
608 template<unsigned width, unsigned scale>
609 bool isUnsignedOffset() const {
610 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000611 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000612 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
613 int64_t Val = CE->getValue();
614 int64_t Align = 1LL << scale;
615 int64_t Max = Align * ((1LL << width) - 1);
616 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
617 }
618 return false;
619 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000620 // checks whether this operand is an signed offset which fits is a field
621 // of specified width and scaled by a specific number of bits
622 template<unsigned width, unsigned scale>
623 bool isSignedOffset() const {
624 if (!isImm()) return false;
625 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
626 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
627 int64_t Val = CE->getValue();
628 int64_t Align = 1LL << scale;
629 int64_t Max = Align * ((1LL << (width-1)) - 1);
630 int64_t Min = -Align * (1LL << (width-1));
631 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
632 }
633 return false;
634 }
635
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000636 // checks whether this operand is a memory operand computed as an offset
637 // applied to PC. the offset may have 8 bits of magnitude and is represented
638 // with two bits of shift. textually it may be either [pc, #imm], #imm or
639 // relocable expression...
640 bool isThumbMemPC() const {
641 int64_t Val = 0;
642 if (isImm()) {
643 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
644 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
645 if (!CE) return false;
646 Val = CE->getValue();
647 }
648 else if (isMem()) {
649 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
650 if(Memory.BaseRegNum != ARM::PC) return false;
651 Val = Memory.OffsetImm->getValue();
652 }
653 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000654 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000655 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000656 bool isFPImm() const {
657 if (!isImm()) return false;
658 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
659 if (!CE) return false;
660 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
661 return Val != -1;
662 }
Jim Grosbachea231912011-12-22 22:19:05 +0000663 bool isFBits16() const {
664 if (!isImm()) return false;
665 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
666 if (!CE) return false;
667 int64_t Value = CE->getValue();
668 return Value >= 0 && Value <= 16;
669 }
670 bool isFBits32() const {
671 if (!isImm()) return false;
672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
673 if (!CE) return false;
674 int64_t Value = CE->getValue();
675 return Value >= 1 && Value <= 32;
676 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000677 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000678 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000679 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
680 if (!CE) return false;
681 int64_t Value = CE->getValue();
682 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
683 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000684 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000685 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
687 if (!CE) return false;
688 int64_t Value = CE->getValue();
689 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
690 }
691 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000692 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000693 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
694 if (!CE) return false;
695 int64_t Value = CE->getValue();
696 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
697 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000698 bool isImm0_508s4Neg() const {
699 if (!isImm()) return false;
700 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
701 if (!CE) return false;
702 int64_t Value = -CE->getValue();
703 // explicitly exclude zero. we want that to use the normal 0_508 version.
704 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
705 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000706 bool isImm0_239() const {
707 if (!isImm()) return false;
708 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
709 if (!CE) return false;
710 int64_t Value = CE->getValue();
711 return Value >= 0 && Value < 240;
712 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000713 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000714 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000715 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
716 if (!CE) return false;
717 int64_t Value = CE->getValue();
718 return Value >= 0 && Value < 256;
719 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000720 bool isImm0_4095() const {
721 if (!isImm()) return false;
722 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
723 if (!CE) return false;
724 int64_t Value = CE->getValue();
725 return Value >= 0 && Value < 4096;
726 }
727 bool isImm0_4095Neg() const {
728 if (!isImm()) return false;
729 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
730 if (!CE) return false;
731 int64_t Value = -CE->getValue();
732 return Value > 0 && Value < 4096;
733 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000734 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000735 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000736 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
737 if (!CE) return false;
738 int64_t Value = CE->getValue();
739 return Value >= 0 && Value < 2;
740 }
741 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000742 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000743 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
744 if (!CE) return false;
745 int64_t Value = CE->getValue();
746 return Value >= 0 && Value < 4;
747 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000748 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000749 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000750 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
751 if (!CE) return false;
752 int64_t Value = CE->getValue();
753 return Value >= 0 && Value < 8;
754 }
755 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000756 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000757 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
758 if (!CE) return false;
759 int64_t Value = CE->getValue();
760 return Value >= 0 && Value < 16;
761 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000762 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000763 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000764 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
765 if (!CE) return false;
766 int64_t Value = CE->getValue();
767 return Value >= 0 && Value < 32;
768 }
Jim Grosbach00326402011-12-08 01:30:04 +0000769 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000770 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000771 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
772 if (!CE) return false;
773 int64_t Value = CE->getValue();
774 return Value >= 0 && Value < 64;
775 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000776 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000777 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
779 if (!CE) return false;
780 int64_t Value = CE->getValue();
781 return Value == 8;
782 }
783 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000784 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
786 if (!CE) return false;
787 int64_t Value = CE->getValue();
788 return Value == 16;
789 }
790 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000791 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
793 if (!CE) return false;
794 int64_t Value = CE->getValue();
795 return Value == 32;
796 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000797 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000798 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000799 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
800 if (!CE) return false;
801 int64_t Value = CE->getValue();
802 return Value > 0 && Value <= 8;
803 }
804 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000805 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
807 if (!CE) return false;
808 int64_t Value = CE->getValue();
809 return Value > 0 && Value <= 16;
810 }
811 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000812 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000813 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
814 if (!CE) return false;
815 int64_t Value = CE->getValue();
816 return Value > 0 && Value <= 32;
817 }
818 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000819 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
821 if (!CE) return false;
822 int64_t Value = CE->getValue();
823 return Value > 0 && Value <= 64;
824 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000825 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000826 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
828 if (!CE) return false;
829 int64_t Value = CE->getValue();
830 return Value > 0 && Value < 8;
831 }
832 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000833 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
835 if (!CE) return false;
836 int64_t Value = CE->getValue();
837 return Value > 0 && Value < 16;
838 }
839 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000840 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
842 if (!CE) return false;
843 int64_t Value = CE->getValue();
844 return Value > 0 && Value < 32;
845 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000846 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000847 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
849 if (!CE) return false;
850 int64_t Value = CE->getValue();
851 return Value > 0 && Value < 17;
852 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000853 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000854 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
856 if (!CE) return false;
857 int64_t Value = CE->getValue();
858 return Value > 0 && Value < 33;
859 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000860 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000861 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
863 if (!CE) return false;
864 int64_t Value = CE->getValue();
865 return Value >= 0 && Value < 33;
866 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000867 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000868 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
870 if (!CE) return false;
871 int64_t Value = CE->getValue();
872 return Value >= 0 && Value < 65536;
873 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000874 bool isImm256_65535Expr() const {
875 if (!isImm()) return false;
876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
877 // If it's not a constant expression, it'll generate a fixup and be
878 // handled later.
879 if (!CE) return true;
880 int64_t Value = CE->getValue();
881 return Value >= 256 && Value < 65536;
882 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000883 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000884 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000885 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
886 // If it's not a constant expression, it'll generate a fixup and be
887 // handled later.
888 if (!CE) return true;
889 int64_t Value = CE->getValue();
890 return Value >= 0 && Value < 65536;
891 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000892 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000893 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000894 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
895 if (!CE) return false;
896 int64_t Value = CE->getValue();
897 return Value >= 0 && Value <= 0xffffff;
898 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000899 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000900 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000901 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
902 if (!CE) return false;
903 int64_t Value = CE->getValue();
904 return Value > 0 && Value < 33;
905 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000906 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000907 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
909 if (!CE) return false;
910 int64_t Value = CE->getValue();
911 return Value >= 0 && Value < 32;
912 }
913 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000914 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
916 if (!CE) return false;
917 int64_t Value = CE->getValue();
918 return Value > 0 && Value <= 32;
919 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000920 bool isAdrLabel() const {
921 // If we have an immediate that's not a constant, treat it as a label
922 // reference needing a fixup. If it is a constant, but it can't fit
923 // into shift immediate encoding, we reject it.
924 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
925 else return (isARMSOImm() || isARMSOImmNeg());
926 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000927 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000928 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000929 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
930 if (!CE) return false;
931 int64_t Value = CE->getValue();
932 return ARM_AM::getSOImmVal(Value) != -1;
933 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000934 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000935 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000936 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
937 if (!CE) return false;
938 int64_t Value = CE->getValue();
939 return ARM_AM::getSOImmVal(~Value) != -1;
940 }
Jim Grosbach30506252011-12-08 00:31:07 +0000941 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000942 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
944 if (!CE) return false;
945 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000946 // Only use this when not representable as a plain so_imm.
947 return ARM_AM::getSOImmVal(Value) == -1 &&
948 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000949 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000950 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000951 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000952 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
953 if (!CE) return false;
954 int64_t Value = CE->getValue();
955 return ARM_AM::getT2SOImmVal(Value) != -1;
956 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000957 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000958 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000959 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
960 if (!CE) return false;
961 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +0000962 return ARM_AM::getT2SOImmVal(Value) == -1 &&
963 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +0000964 }
Jim Grosbach30506252011-12-08 00:31:07 +0000965 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000966 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000967 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
968 if (!CE) return false;
969 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000970 // Only use this when not representable as a plain so_imm.
971 return ARM_AM::getT2SOImmVal(Value) == -1 &&
972 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000973 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000974 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000975 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000976 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
977 if (!CE) return false;
978 int64_t Value = CE->getValue();
979 return Value == 1 || Value == 0;
980 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000981 bool isReg() const { return Kind == k_Register; }
982 bool isRegList() const { return Kind == k_RegisterList; }
983 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
984 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
985 bool isToken() const { return Kind == k_Token; }
986 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000987 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000988 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000989 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
990 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
991 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
992 bool isRotImm() const { return Kind == k_RotateImmediate; }
993 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
994 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000995 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000996 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000997 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000998 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000999 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001000 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001001 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +00001002 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1003 (alignOK || Memory.Alignment == 0);
1004 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001005 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001006 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001007 return false;
1008 // Base register must be PC.
1009 if (Memory.BaseRegNum != ARM::PC)
1010 return false;
1011 // Immediate offset in range [-4095, 4095].
1012 if (!Memory.OffsetImm) return true;
1013 int64_t Val = Memory.OffsetImm->getValue();
1014 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1015 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001016 bool isAlignedMemory() const {
1017 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001018 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001019 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001020 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001021 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001022 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001023 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001024 if (!Memory.OffsetImm) return true;
1025 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001026 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001027 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001028 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001029 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001030 // Immediate offset in range [-4095, 4095].
1031 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1032 if (!CE) return false;
1033 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001034 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001035 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001036 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001037 // If we have an immediate that's not a constant, treat it as a label
1038 // reference needing a fixup. If it is a constant, it's something else
1039 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001040 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001041 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001042 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001043 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001044 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001045 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001046 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001047 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001048 if (!Memory.OffsetImm) return true;
1049 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001050 // The #-0 offset is encoded as INT32_MIN, and we have to check
1051 // for this too.
1052 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001053 }
1054 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001055 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001056 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001057 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001058 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1059 // Immediate offset in range [-255, 255].
1060 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1061 if (!CE) return false;
1062 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001063 // Special case, #-0 is INT32_MIN.
1064 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001065 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001066 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001067 // If we have an immediate that's not a constant, treat it as a label
1068 // reference needing a fixup. If it is a constant, it's something else
1069 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001070 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001071 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001072 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001073 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001074 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001075 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001076 if (!Memory.OffsetImm) return true;
1077 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001078 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001079 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001080 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001081 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001082 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001083 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001084 return false;
1085 return true;
1086 }
1087 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001088 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001089 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1090 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001091 return false;
1092 return true;
1093 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001094 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001095 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001096 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001097 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001098 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001099 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001100 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001101 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001102 return false;
1103 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001104 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001105 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001106 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001107 return false;
1108 return true;
1109 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001110 bool isMemThumbRR() const {
1111 // Thumb reg+reg addressing is simple. Just two registers, a base and
1112 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001113 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001114 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001115 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001116 return isARMLowRegister(Memory.BaseRegNum) &&
1117 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001118 }
1119 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001120 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001121 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001122 return false;
1123 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001124 if (!Memory.OffsetImm) return true;
1125 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001126 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1127 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001128 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001129 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001130 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001131 return false;
1132 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001133 if (!Memory.OffsetImm) return true;
1134 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001135 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1136 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001137 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001138 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001139 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001140 return false;
1141 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001142 if (!Memory.OffsetImm) return true;
1143 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001144 return Val >= 0 && Val <= 31;
1145 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001146 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001147 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001148 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001149 return false;
1150 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001151 if (!Memory.OffsetImm) return true;
1152 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001153 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001154 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001155 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001156 // If we have an immediate that's not a constant, treat it as a label
1157 // reference needing a fixup. If it is a constant, it's something else
1158 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001159 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001160 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001161 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001162 return false;
1163 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001164 if (!Memory.OffsetImm) return true;
1165 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001166 // Special case, #-0 is INT32_MIN.
1167 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001168 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001169 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001170 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001171 return false;
1172 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001173 if (!Memory.OffsetImm) return true;
1174 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001175 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1176 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001177 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001178 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001179 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001180 // Base reg of PC isn't allowed for these encodings.
1181 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001182 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001183 if (!Memory.OffsetImm) return true;
1184 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001185 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001186 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001187 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001188 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001189 return false;
1190 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001191 if (!Memory.OffsetImm) return true;
1192 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001193 return Val >= 0 && Val < 256;
1194 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001195 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001196 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001197 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001198 // Base reg of PC isn't allowed for these encodings.
1199 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001200 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001201 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001202 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001203 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001204 }
1205 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001206 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001207 return false;
1208 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001209 if (!Memory.OffsetImm) return true;
1210 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001211 return (Val >= 0 && Val < 4096);
1212 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001213 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001214 // If we have an immediate that's not a constant, treat it as a label
1215 // reference needing a fixup. If it is a constant, it's something else
1216 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001217 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001218 return true;
1219
Chad Rosier41099832012-09-11 23:02:35 +00001220 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001221 return false;
1222 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001223 if (!Memory.OffsetImm) return true;
1224 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001225 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001226 }
1227 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001228 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001229 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1230 if (!CE) return false;
1231 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001232 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001233 }
Jim Grosbach93981412011-10-11 21:55:36 +00001234 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001235 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001236 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1237 if (!CE) return false;
1238 int64_t Val = CE->getValue();
1239 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1240 (Val == INT32_MIN);
1241 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001242
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001243 bool isMSRMask() const { return Kind == k_MSRMask; }
1244 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001245
Jim Grosbach741cd732011-10-17 22:26:03 +00001246 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001247 bool isSingleSpacedVectorList() const {
1248 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1249 }
1250 bool isDoubleSpacedVectorList() const {
1251 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1252 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001253 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001254 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001255 return VectorList.Count == 1;
1256 }
1257
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001258 bool isVecListDPair() const {
1259 if (!isSingleSpacedVectorList()) return false;
1260 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1261 .contains(VectorList.RegNum));
1262 }
1263
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001264 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001265 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001266 return VectorList.Count == 3;
1267 }
1268
Jim Grosbach846bcff2011-10-21 20:35:01 +00001269 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001270 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001271 return VectorList.Count == 4;
1272 }
1273
Jim Grosbache5307f92012-03-05 21:43:40 +00001274 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001275 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001276 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1277 .contains(VectorList.RegNum));
1278 }
1279
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001280 bool isVecListThreeQ() const {
1281 if (!isDoubleSpacedVectorList()) return false;
1282 return VectorList.Count == 3;
1283 }
1284
Jim Grosbach1e946a42012-01-24 00:43:12 +00001285 bool isVecListFourQ() const {
1286 if (!isDoubleSpacedVectorList()) return false;
1287 return VectorList.Count == 4;
1288 }
1289
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001290 bool isSingleSpacedVectorAllLanes() const {
1291 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1292 }
1293 bool isDoubleSpacedVectorAllLanes() const {
1294 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1295 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001296 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001297 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001298 return VectorList.Count == 1;
1299 }
1300
Jim Grosbach13a292c2012-03-06 22:01:44 +00001301 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001302 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001303 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1304 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001305 }
1306
Jim Grosbached428bc2012-03-06 23:10:38 +00001307 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001308 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001309 return VectorList.Count == 2;
1310 }
1311
Jim Grosbachb78403c2012-01-24 23:47:04 +00001312 bool isVecListThreeDAllLanes() const {
1313 if (!isSingleSpacedVectorAllLanes()) return false;
1314 return VectorList.Count == 3;
1315 }
1316
1317 bool isVecListThreeQAllLanes() const {
1318 if (!isDoubleSpacedVectorAllLanes()) return false;
1319 return VectorList.Count == 3;
1320 }
1321
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001322 bool isVecListFourDAllLanes() const {
1323 if (!isSingleSpacedVectorAllLanes()) return false;
1324 return VectorList.Count == 4;
1325 }
1326
1327 bool isVecListFourQAllLanes() const {
1328 if (!isDoubleSpacedVectorAllLanes()) return false;
1329 return VectorList.Count == 4;
1330 }
1331
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001332 bool isSingleSpacedVectorIndexed() const {
1333 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1334 }
1335 bool isDoubleSpacedVectorIndexed() const {
1336 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1337 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001338 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001339 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001340 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1341 }
1342
Jim Grosbachda511042011-12-14 23:35:06 +00001343 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001344 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001345 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1346 }
1347
1348 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001349 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001350 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1351 }
1352
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001353 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001354 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001355 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1356 }
1357
Jim Grosbachda511042011-12-14 23:35:06 +00001358 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001359 if (!isSingleSpacedVectorIndexed()) return false;
1360 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1361 }
1362
1363 bool isVecListTwoQWordIndexed() const {
1364 if (!isDoubleSpacedVectorIndexed()) return false;
1365 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1366 }
1367
1368 bool isVecListTwoQHWordIndexed() const {
1369 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001370 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1371 }
1372
1373 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001374 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001375 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1376 }
1377
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001378 bool isVecListThreeDByteIndexed() const {
1379 if (!isSingleSpacedVectorIndexed()) return false;
1380 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1381 }
1382
1383 bool isVecListThreeDHWordIndexed() const {
1384 if (!isSingleSpacedVectorIndexed()) return false;
1385 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1386 }
1387
1388 bool isVecListThreeQWordIndexed() const {
1389 if (!isDoubleSpacedVectorIndexed()) return false;
1390 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1391 }
1392
1393 bool isVecListThreeQHWordIndexed() const {
1394 if (!isDoubleSpacedVectorIndexed()) return false;
1395 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1396 }
1397
1398 bool isVecListThreeDWordIndexed() const {
1399 if (!isSingleSpacedVectorIndexed()) return false;
1400 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1401 }
1402
Jim Grosbach14952a02012-01-24 18:37:25 +00001403 bool isVecListFourDByteIndexed() const {
1404 if (!isSingleSpacedVectorIndexed()) return false;
1405 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1406 }
1407
1408 bool isVecListFourDHWordIndexed() const {
1409 if (!isSingleSpacedVectorIndexed()) return false;
1410 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1411 }
1412
1413 bool isVecListFourQWordIndexed() const {
1414 if (!isDoubleSpacedVectorIndexed()) return false;
1415 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1416 }
1417
1418 bool isVecListFourQHWordIndexed() const {
1419 if (!isDoubleSpacedVectorIndexed()) return false;
1420 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1421 }
1422
1423 bool isVecListFourDWordIndexed() const {
1424 if (!isSingleSpacedVectorIndexed()) return false;
1425 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1426 }
1427
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001428 bool isVectorIndex8() const {
1429 if (Kind != k_VectorIndex) return false;
1430 return VectorIndex.Val < 8;
1431 }
1432 bool isVectorIndex16() const {
1433 if (Kind != k_VectorIndex) return false;
1434 return VectorIndex.Val < 4;
1435 }
1436 bool isVectorIndex32() const {
1437 if (Kind != k_VectorIndex) return false;
1438 return VectorIndex.Val < 2;
1439 }
1440
Jim Grosbach741cd732011-10-17 22:26:03 +00001441 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001442 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001443 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1444 // Must be a constant.
1445 if (!CE) return false;
1446 int64_t Value = CE->getValue();
1447 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1448 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001449 return Value >= 0 && Value < 256;
1450 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001451
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001452 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001453 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001454 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1455 // Must be a constant.
1456 if (!CE) return false;
1457 int64_t Value = CE->getValue();
1458 // i16 value in the range [0,255] or [0x0100, 0xff00]
1459 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1460 }
1461
Jim Grosbach8211c052011-10-18 00:22:00 +00001462 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001463 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001464 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1465 // Must be a constant.
1466 if (!CE) return false;
1467 int64_t Value = CE->getValue();
1468 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1469 return (Value >= 0 && Value < 256) ||
1470 (Value >= 0x0100 && Value <= 0xff00) ||
1471 (Value >= 0x010000 && Value <= 0xff0000) ||
1472 (Value >= 0x01000000 && Value <= 0xff000000);
1473 }
1474
1475 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001476 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001477 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1478 // Must be a constant.
1479 if (!CE) return false;
1480 int64_t Value = CE->getValue();
1481 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1482 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1483 return (Value >= 0 && Value < 256) ||
1484 (Value >= 0x0100 && Value <= 0xff00) ||
1485 (Value >= 0x010000 && Value <= 0xff0000) ||
1486 (Value >= 0x01000000 && Value <= 0xff000000) ||
1487 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1488 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1489 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001490 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001491 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001492 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1493 // Must be a constant.
1494 if (!CE) return false;
1495 int64_t Value = ~CE->getValue();
1496 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1497 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1498 return (Value >= 0 && Value < 256) ||
1499 (Value >= 0x0100 && Value <= 0xff00) ||
1500 (Value >= 0x010000 && Value <= 0xff0000) ||
1501 (Value >= 0x01000000 && Value <= 0xff000000) ||
1502 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1503 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1504 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001505
Jim Grosbache4454e02011-10-18 16:18:11 +00001506 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001507 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001508 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1509 // Must be a constant.
1510 if (!CE) return false;
1511 uint64_t Value = CE->getValue();
1512 // i64 value with each byte being either 0 or 0xff.
1513 for (unsigned i = 0; i < 8; ++i)
1514 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1515 return true;
1516 }
1517
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001518 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001519 // Add as immediates when possible. Null MCExpr = 0.
1520 if (Expr == 0)
1521 Inst.addOperand(MCOperand::CreateImm(0));
1522 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001523 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1524 else
1525 Inst.addOperand(MCOperand::CreateExpr(Expr));
1526 }
1527
Daniel Dunbard8042b72010-08-11 06:36:53 +00001528 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001529 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001530 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001531 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1532 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001533 }
1534
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001535 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1536 assert(N == 1 && "Invalid number of operands!");
1537 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1538 }
1539
Jim Grosbach48399582011-10-12 17:34:41 +00001540 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1541 assert(N == 1 && "Invalid number of operands!");
1542 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1543 }
1544
1545 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1546 assert(N == 1 && "Invalid number of operands!");
1547 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1548 }
1549
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001550 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1551 assert(N == 1 && "Invalid number of operands!");
1552 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1553 }
1554
1555 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1556 assert(N == 1 && "Invalid number of operands!");
1557 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1558 }
1559
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001560 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1561 assert(N == 1 && "Invalid number of operands!");
1562 Inst.addOperand(MCOperand::CreateReg(getReg()));
1563 }
1564
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001565 void addRegOperands(MCInst &Inst, unsigned N) const {
1566 assert(N == 1 && "Invalid number of operands!");
1567 Inst.addOperand(MCOperand::CreateReg(getReg()));
1568 }
1569
Jim Grosbachac798e12011-07-25 20:49:51 +00001570 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001571 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001572 assert(isRegShiftedReg() &&
1573 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001574 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1575 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001576 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001577 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001578 }
1579
Jim Grosbachac798e12011-07-25 20:49:51 +00001580 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001581 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001582 assert(isRegShiftedImm() &&
1583 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001584 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001585 // Shift of #32 is encoded as 0 where permitted
1586 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001587 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001588 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001589 }
1590
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001591 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001592 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001593 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1594 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001595 }
1596
Bill Wendling8d2aa032010-11-08 23:49:57 +00001597 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001598 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001599 const SmallVectorImpl<unsigned> &RegList = getRegList();
1600 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001601 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1602 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001603 }
1604
Bill Wendling9898ac92010-11-17 04:32:08 +00001605 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1606 addRegListOperands(Inst, N);
1607 }
1608
1609 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1610 addRegListOperands(Inst, N);
1611 }
1612
Jim Grosbach833b9d32011-07-27 20:15:40 +00001613 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1614 assert(N == 1 && "Invalid number of operands!");
1615 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1616 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1617 }
1618
Jim Grosbach864b6092011-07-28 21:34:26 +00001619 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1620 assert(N == 1 && "Invalid number of operands!");
1621 // Munge the lsb/width into a bitfield mask.
1622 unsigned lsb = Bitfield.LSB;
1623 unsigned width = Bitfield.Width;
1624 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1625 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1626 (32 - (lsb + width)));
1627 Inst.addOperand(MCOperand::CreateImm(Mask));
1628 }
1629
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001630 void addImmOperands(MCInst &Inst, unsigned N) const {
1631 assert(N == 1 && "Invalid number of operands!");
1632 addExpr(Inst, getImm());
1633 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001634
Jim Grosbachea231912011-12-22 22:19:05 +00001635 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1636 assert(N == 1 && "Invalid number of operands!");
1637 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1638 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1639 }
1640
1641 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1642 assert(N == 1 && "Invalid number of operands!");
1643 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1644 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1645 }
1646
Jim Grosbache7fbce72011-10-03 23:38:36 +00001647 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1648 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1650 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1651 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001652 }
1653
Jim Grosbach7db8d692011-09-08 22:07:06 +00001654 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1655 assert(N == 1 && "Invalid number of operands!");
1656 // FIXME: We really want to scale the value here, but the LDRD/STRD
1657 // instruction don't encode operands that way yet.
1658 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1659 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1660 }
1661
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001662 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1663 assert(N == 1 && "Invalid number of operands!");
1664 // The immediate is scaled by four in the encoding and is stored
1665 // in the MCInst as such. Lop off the low two bits here.
1666 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1667 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1668 }
1669
Jim Grosbach930f2f62012-04-05 20:57:13 +00001670 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1671 assert(N == 1 && "Invalid number of operands!");
1672 // The immediate is scaled by four in the encoding and is stored
1673 // in the MCInst as such. Lop off the low two bits here.
1674 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1675 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1676 }
1677
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001678 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1679 assert(N == 1 && "Invalid number of operands!");
1680 // The immediate is scaled by four in the encoding and is stored
1681 // in the MCInst as such. Lop off the low two bits here.
1682 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1683 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1684 }
1685
Jim Grosbach475c6db2011-07-25 23:09:14 +00001686 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1687 assert(N == 1 && "Invalid number of operands!");
1688 // The constant encodes as the immediate-1, and we store in the instruction
1689 // the bits as encoded, so subtract off one here.
1690 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1691 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1692 }
1693
Jim Grosbach801e0a32011-07-22 23:16:18 +00001694 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1695 assert(N == 1 && "Invalid number of operands!");
1696 // The constant encodes as the immediate-1, and we store in the instruction
1697 // the bits as encoded, so subtract off one here.
1698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1699 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1700 }
1701
Jim Grosbach46dd4132011-08-17 21:51:27 +00001702 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1703 assert(N == 1 && "Invalid number of operands!");
1704 // The constant encodes as the immediate, except for 32, which encodes as
1705 // zero.
1706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1707 unsigned Imm = CE->getValue();
1708 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1709 }
1710
Jim Grosbach27c1e252011-07-21 17:23:04 +00001711 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1712 assert(N == 1 && "Invalid number of operands!");
1713 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1714 // the instruction as well.
1715 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1716 int Val = CE->getValue();
1717 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1718 }
1719
Jim Grosbachb009a872011-10-28 22:36:30 +00001720 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1721 assert(N == 1 && "Invalid number of operands!");
1722 // The operand is actually a t2_so_imm, but we have its bitwise
1723 // negation in the assembly source, so twiddle it here.
1724 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1725 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1726 }
1727
Jim Grosbach30506252011-12-08 00:31:07 +00001728 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1729 assert(N == 1 && "Invalid number of operands!");
1730 // The operand is actually a t2_so_imm, but we have its
1731 // negation in the assembly source, so twiddle it here.
1732 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1733 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1734 }
1735
Jim Grosbach930f2f62012-04-05 20:57:13 +00001736 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1737 assert(N == 1 && "Invalid number of operands!");
1738 // The operand is actually an imm0_4095, but we have its
1739 // negation in the assembly source, so twiddle it here.
1740 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1741 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1742 }
1743
Mihai Popad36cbaa2013-07-03 09:21:44 +00001744 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1745 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1746 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1747 return;
1748 }
1749
1750 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1751 assert(SR && "Unknown value type!");
1752 Inst.addOperand(MCOperand::CreateExpr(SR));
1753 }
1754
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001755 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1756 assert(N == 1 && "Invalid number of operands!");
1757 if (isImm()) {
1758 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1759 if (CE) {
1760 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1761 return;
1762 }
1763
1764 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1765 assert(SR && "Unknown value type!");
1766 Inst.addOperand(MCOperand::CreateExpr(SR));
1767 return;
1768 }
1769
1770 assert(isMem() && "Unknown value type!");
1771 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1772 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1773 }
1774
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001775 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1776 assert(N == 1 && "Invalid number of operands!");
1777 // The operand is actually a so_imm, but we have its bitwise
1778 // negation in the assembly source, so twiddle it here.
1779 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1780 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1781 }
1782
Jim Grosbach30506252011-12-08 00:31:07 +00001783 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1784 assert(N == 1 && "Invalid number of operands!");
1785 // The operand is actually a so_imm, but we have its
1786 // negation in the assembly source, so twiddle it here.
1787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1788 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1789 }
1790
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001791 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1792 assert(N == 1 && "Invalid number of operands!");
1793 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1794 }
1795
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001796 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1797 assert(N == 1 && "Invalid number of operands!");
1798 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1799 }
1800
Jim Grosbachd3595712011-08-03 23:50:40 +00001801 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1802 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001803 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001804 }
1805
Jim Grosbach94298a92012-01-18 22:46:46 +00001806 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1807 assert(N == 1 && "Invalid number of operands!");
1808 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001809 Inst.addOperand(MCOperand::CreateImm(Imm));
1810 }
1811
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001812 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1813 assert(N == 1 && "Invalid number of operands!");
1814 assert(isImm() && "Not an immediate!");
1815
1816 // If we have an immediate that's not a constant, treat it as a label
1817 // reference needing a fixup.
1818 if (!isa<MCConstantExpr>(getImm())) {
1819 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1820 return;
1821 }
1822
1823 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1824 int Val = CE->getValue();
1825 Inst.addOperand(MCOperand::CreateImm(Val));
1826 }
1827
Jim Grosbacha95ec992011-10-11 17:29:55 +00001828 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1829 assert(N == 2 && "Invalid number of operands!");
1830 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1831 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1832 }
1833
Jim Grosbachd3595712011-08-03 23:50:40 +00001834 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1835 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001836 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1837 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001838 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1839 // Special case for #-0
1840 if (Val == INT32_MIN) Val = 0;
1841 if (Val < 0) Val = -Val;
1842 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1843 } else {
1844 // For register offset, we encode the shift type and negation flag
1845 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001846 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1847 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001848 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001849 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1850 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001851 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001852 }
1853
Jim Grosbachcd17c122011-08-04 23:01:30 +00001854 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1855 assert(N == 2 && "Invalid number of operands!");
1856 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1857 assert(CE && "non-constant AM2OffsetImm operand!");
1858 int32_t Val = CE->getValue();
1859 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1860 // Special case for #-0
1861 if (Val == INT32_MIN) Val = 0;
1862 if (Val < 0) Val = -Val;
1863 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1864 Inst.addOperand(MCOperand::CreateReg(0));
1865 Inst.addOperand(MCOperand::CreateImm(Val));
1866 }
1867
Jim Grosbach5b96b802011-08-10 20:29:19 +00001868 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1869 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001870 // If we have an immediate that's not a constant, treat it as a label
1871 // reference needing a fixup. If it is a constant, it's something else
1872 // and we reject it.
1873 if (isImm()) {
1874 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1875 Inst.addOperand(MCOperand::CreateReg(0));
1876 Inst.addOperand(MCOperand::CreateImm(0));
1877 return;
1878 }
1879
Jim Grosbach871dff72011-10-11 15:59:20 +00001880 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1881 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001882 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1883 // Special case for #-0
1884 if (Val == INT32_MIN) Val = 0;
1885 if (Val < 0) Val = -Val;
1886 Val = ARM_AM::getAM3Opc(AddSub, Val);
1887 } else {
1888 // For register offset, we encode the shift type and negation flag
1889 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001890 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001891 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001892 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1893 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001894 Inst.addOperand(MCOperand::CreateImm(Val));
1895 }
1896
1897 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1898 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001899 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001900 int32_t Val =
1901 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1902 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1903 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001904 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001905 }
1906
1907 // Constant offset.
1908 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1909 int32_t Val = CE->getValue();
1910 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1911 // Special case for #-0
1912 if (Val == INT32_MIN) Val = 0;
1913 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001914 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001915 Inst.addOperand(MCOperand::CreateReg(0));
1916 Inst.addOperand(MCOperand::CreateImm(Val));
1917 }
1918
Jim Grosbachd3595712011-08-03 23:50:40 +00001919 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1920 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001921 // If we have an immediate that's not a constant, treat it as a label
1922 // reference needing a fixup. If it is a constant, it's something else
1923 // and we reject it.
1924 if (isImm()) {
1925 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1926 Inst.addOperand(MCOperand::CreateImm(0));
1927 return;
1928 }
1929
Jim Grosbachd3595712011-08-03 23:50:40 +00001930 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001931 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001932 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1933 // Special case for #-0
1934 if (Val == INT32_MIN) Val = 0;
1935 if (Val < 0) Val = -Val;
1936 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001937 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001938 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001939 }
1940
Jim Grosbach7db8d692011-09-08 22:07:06 +00001941 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1942 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001943 // If we have an immediate that's not a constant, treat it as a label
1944 // reference needing a fixup. If it is a constant, it's something else
1945 // and we reject it.
1946 if (isImm()) {
1947 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1948 Inst.addOperand(MCOperand::CreateImm(0));
1949 return;
1950 }
1951
Jim Grosbach871dff72011-10-11 15:59:20 +00001952 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1953 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001954 Inst.addOperand(MCOperand::CreateImm(Val));
1955 }
1956
Jim Grosbacha05627e2011-09-09 18:37:27 +00001957 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1958 assert(N == 2 && "Invalid number of operands!");
1959 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001960 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1961 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001962 Inst.addOperand(MCOperand::CreateImm(Val));
1963 }
1964
Jim Grosbachd3595712011-08-03 23:50:40 +00001965 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1966 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001967 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1968 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001969 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001970 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001971
Jim Grosbach2392c532011-09-07 23:39:14 +00001972 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1973 addMemImm8OffsetOperands(Inst, N);
1974 }
1975
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001976 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001977 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001978 }
1979
1980 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1981 assert(N == 2 && "Invalid number of operands!");
1982 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001983 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001984 addExpr(Inst, getImm());
1985 Inst.addOperand(MCOperand::CreateImm(0));
1986 return;
1987 }
1988
1989 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001990 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1991 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001992 Inst.addOperand(MCOperand::CreateImm(Val));
1993 }
1994
Jim Grosbachd3595712011-08-03 23:50:40 +00001995 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1996 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001997 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001998 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001999 addExpr(Inst, getImm());
2000 Inst.addOperand(MCOperand::CreateImm(0));
2001 return;
2002 }
2003
2004 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002005 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2006 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002007 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002008 }
Bill Wendling811c9362010-11-30 07:44:32 +00002009
Jim Grosbach05541f42011-09-19 22:21:13 +00002010 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2011 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002012 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2013 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002014 }
2015
2016 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2017 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002018 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2019 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002020 }
2021
Jim Grosbachd3595712011-08-03 23:50:40 +00002022 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2023 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002024 unsigned Val =
2025 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2026 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002027 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2028 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002029 Inst.addOperand(MCOperand::CreateImm(Val));
2030 }
2031
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002032 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2033 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002034 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2035 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2036 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002037 }
2038
Jim Grosbachd3595712011-08-03 23:50:40 +00002039 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2040 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002041 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2042 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002043 }
2044
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002045 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2046 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002047 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2048 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002049 Inst.addOperand(MCOperand::CreateImm(Val));
2050 }
2051
Jim Grosbach26d35872011-08-19 18:55:51 +00002052 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2053 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002054 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2055 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002056 Inst.addOperand(MCOperand::CreateImm(Val));
2057 }
2058
Jim Grosbacha32c7532011-08-19 18:49:59 +00002059 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2060 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002061 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2062 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002063 Inst.addOperand(MCOperand::CreateImm(Val));
2064 }
2065
Jim Grosbach23983d62011-08-19 18:13:48 +00002066 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2067 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002068 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2069 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002070 Inst.addOperand(MCOperand::CreateImm(Val));
2071 }
2072
Jim Grosbachd3595712011-08-03 23:50:40 +00002073 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2074 assert(N == 1 && "Invalid number of operands!");
2075 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2076 assert(CE && "non-constant post-idx-imm8 operand!");
2077 int Imm = CE->getValue();
2078 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002079 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002080 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2081 Inst.addOperand(MCOperand::CreateImm(Imm));
2082 }
2083
Jim Grosbach93981412011-10-11 21:55:36 +00002084 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2085 assert(N == 1 && "Invalid number of operands!");
2086 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2087 assert(CE && "non-constant post-idx-imm8s4 operand!");
2088 int Imm = CE->getValue();
2089 bool isAdd = Imm >= 0;
2090 if (Imm == INT32_MIN) Imm = 0;
2091 // Immediate is scaled by 4.
2092 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2093 Inst.addOperand(MCOperand::CreateImm(Imm));
2094 }
2095
Jim Grosbachd3595712011-08-03 23:50:40 +00002096 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2097 assert(N == 2 && "Invalid number of operands!");
2098 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002099 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2100 }
2101
2102 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2103 assert(N == 2 && "Invalid number of operands!");
2104 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2105 // The sign, shift type, and shift amount are encoded in a single operand
2106 // using the AM2 encoding helpers.
2107 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2108 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2109 PostIdxReg.ShiftTy);
2110 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002111 }
2112
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002113 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2114 assert(N == 1 && "Invalid number of operands!");
2115 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2116 }
2117
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002118 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2119 assert(N == 1 && "Invalid number of operands!");
2120 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2121 }
2122
Jim Grosbach182b6a02011-11-29 23:51:09 +00002123 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002124 assert(N == 1 && "Invalid number of operands!");
2125 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2126 }
2127
Jim Grosbach04945c42011-12-02 00:35:16 +00002128 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2129 assert(N == 2 && "Invalid number of operands!");
2130 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2131 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2132 }
2133
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002134 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2135 assert(N == 1 && "Invalid number of operands!");
2136 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2137 }
2138
2139 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2140 assert(N == 1 && "Invalid number of operands!");
2141 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2142 }
2143
2144 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2145 assert(N == 1 && "Invalid number of operands!");
2146 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2147 }
2148
Jim Grosbach741cd732011-10-17 22:26:03 +00002149 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2150 assert(N == 1 && "Invalid number of operands!");
2151 // The immediate encodes the type of constant as well as the value.
2152 // Mask in that this is an i8 splat.
2153 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2154 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2155 }
2156
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002157 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2158 assert(N == 1 && "Invalid number of operands!");
2159 // The immediate encodes the type of constant as well as the value.
2160 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2161 unsigned Value = CE->getValue();
2162 if (Value >= 256)
2163 Value = (Value >> 8) | 0xa00;
2164 else
2165 Value |= 0x800;
2166 Inst.addOperand(MCOperand::CreateImm(Value));
2167 }
2168
Jim Grosbach8211c052011-10-18 00:22:00 +00002169 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2170 assert(N == 1 && "Invalid number of operands!");
2171 // The immediate encodes the type of constant as well as the value.
2172 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2173 unsigned Value = CE->getValue();
2174 if (Value >= 256 && Value <= 0xff00)
2175 Value = (Value >> 8) | 0x200;
2176 else if (Value > 0xffff && Value <= 0xff0000)
2177 Value = (Value >> 16) | 0x400;
2178 else if (Value > 0xffffff)
2179 Value = (Value >> 24) | 0x600;
2180 Inst.addOperand(MCOperand::CreateImm(Value));
2181 }
2182
2183 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2184 assert(N == 1 && "Invalid number of operands!");
2185 // The immediate encodes the type of constant as well as the value.
2186 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2187 unsigned Value = CE->getValue();
2188 if (Value >= 256 && Value <= 0xffff)
2189 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2190 else if (Value > 0xffff && Value <= 0xffffff)
2191 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2192 else if (Value > 0xffffff)
2193 Value = (Value >> 24) | 0x600;
2194 Inst.addOperand(MCOperand::CreateImm(Value));
2195 }
2196
Jim Grosbach045b6c72011-12-19 23:51:07 +00002197 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2198 assert(N == 1 && "Invalid number of operands!");
2199 // The immediate encodes the type of constant as well as the value.
2200 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2201 unsigned Value = ~CE->getValue();
2202 if (Value >= 256 && Value <= 0xffff)
2203 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2204 else if (Value > 0xffff && Value <= 0xffffff)
2205 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2206 else if (Value > 0xffffff)
2207 Value = (Value >> 24) | 0x600;
2208 Inst.addOperand(MCOperand::CreateImm(Value));
2209 }
2210
Jim Grosbache4454e02011-10-18 16:18:11 +00002211 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2212 assert(N == 1 && "Invalid number of operands!");
2213 // The immediate encodes the type of constant as well as the value.
2214 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2215 uint64_t Value = CE->getValue();
2216 unsigned Imm = 0;
2217 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2218 Imm |= (Value & 1) << i;
2219 }
2220 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2221 }
2222
Jim Grosbach602aa902011-07-13 15:34:57 +00002223 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002224
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002225 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002226 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002227 Op->ITMask.Mask = Mask;
2228 Op->StartLoc = S;
2229 Op->EndLoc = S;
2230 return Op;
2231 }
2232
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002233 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002234 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002235 Op->CC.Val = CC;
2236 Op->StartLoc = S;
2237 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002238 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002239 }
2240
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002241 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002242 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002243 Op->Cop.Val = CopVal;
2244 Op->StartLoc = S;
2245 Op->EndLoc = S;
2246 return Op;
2247 }
2248
2249 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002250 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002251 Op->Cop.Val = CopVal;
2252 Op->StartLoc = S;
2253 Op->EndLoc = S;
2254 return Op;
2255 }
2256
Jim Grosbach48399582011-10-12 17:34:41 +00002257 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2258 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2259 Op->Cop.Val = Val;
2260 Op->StartLoc = S;
2261 Op->EndLoc = E;
2262 return Op;
2263 }
2264
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002265 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002266 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002267 Op->Reg.RegNum = RegNum;
2268 Op->StartLoc = S;
2269 Op->EndLoc = S;
2270 return Op;
2271 }
2272
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002273 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002274 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002275 Op->Tok.Data = Str.data();
2276 Op->Tok.Length = Str.size();
2277 Op->StartLoc = S;
2278 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002279 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002280 }
2281
Bill Wendling2063b842010-11-18 23:43:05 +00002282 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002283 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002284 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002285 Op->StartLoc = S;
2286 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002287 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002288 }
2289
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002290 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2291 unsigned SrcReg,
2292 unsigned ShiftReg,
2293 unsigned ShiftImm,
2294 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002295 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002296 Op->RegShiftedReg.ShiftTy = ShTy;
2297 Op->RegShiftedReg.SrcReg = SrcReg;
2298 Op->RegShiftedReg.ShiftReg = ShiftReg;
2299 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002300 Op->StartLoc = S;
2301 Op->EndLoc = E;
2302 return Op;
2303 }
2304
Owen Andersonb595ed02011-07-21 18:54:16 +00002305 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2306 unsigned SrcReg,
2307 unsigned ShiftImm,
2308 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002309 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002310 Op->RegShiftedImm.ShiftTy = ShTy;
2311 Op->RegShiftedImm.SrcReg = SrcReg;
2312 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002313 Op->StartLoc = S;
2314 Op->EndLoc = E;
2315 return Op;
2316 }
2317
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002318 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002319 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002320 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002321 Op->ShifterImm.isASR = isASR;
2322 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002323 Op->StartLoc = S;
2324 Op->EndLoc = E;
2325 return Op;
2326 }
2327
Jim Grosbach833b9d32011-07-27 20:15:40 +00002328 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002329 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002330 Op->RotImm.Imm = Imm;
2331 Op->StartLoc = S;
2332 Op->EndLoc = E;
2333 return Op;
2334 }
2335
Jim Grosbach864b6092011-07-28 21:34:26 +00002336 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2337 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002338 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002339 Op->Bitfield.LSB = LSB;
2340 Op->Bitfield.Width = Width;
2341 Op->StartLoc = S;
2342 Op->EndLoc = E;
2343 return Op;
2344 }
2345
Bill Wendling2cae3272010-11-09 22:44:22 +00002346 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002347 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002348 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002349 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002350 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002351
Chad Rosierfa705ee2013-07-01 20:49:23 +00002352 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002353 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002354 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002355 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002356 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002357
Chad Rosierfa705ee2013-07-01 20:49:23 +00002358 // Sort based on the register encoding values.
2359 array_pod_sort(Regs.begin(), Regs.end());
2360
Bill Wendling9898ac92010-11-17 04:32:08 +00002361 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002362 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002363 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002364 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002365 Op->StartLoc = StartLoc;
2366 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002367 return Op;
2368 }
2369
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002370 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002371 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002372 ARMOperand *Op = new ARMOperand(k_VectorList);
2373 Op->VectorList.RegNum = RegNum;
2374 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002375 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002376 Op->StartLoc = S;
2377 Op->EndLoc = E;
2378 return Op;
2379 }
2380
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002381 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002382 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002383 SMLoc S, SMLoc E) {
2384 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2385 Op->VectorList.RegNum = RegNum;
2386 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002387 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002388 Op->StartLoc = S;
2389 Op->EndLoc = E;
2390 return Op;
2391 }
2392
Jim Grosbach04945c42011-12-02 00:35:16 +00002393 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002394 unsigned Index,
2395 bool isDoubleSpaced,
2396 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002397 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2398 Op->VectorList.RegNum = RegNum;
2399 Op->VectorList.Count = Count;
2400 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002401 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002402 Op->StartLoc = S;
2403 Op->EndLoc = E;
2404 return Op;
2405 }
2406
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002407 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2408 MCContext &Ctx) {
2409 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2410 Op->VectorIndex.Val = Idx;
2411 Op->StartLoc = S;
2412 Op->EndLoc = E;
2413 return Op;
2414 }
2415
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002416 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002417 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002418 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002419 Op->StartLoc = S;
2420 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002421 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002422 }
2423
Jim Grosbachd3595712011-08-03 23:50:40 +00002424 static ARMOperand *CreateMem(unsigned BaseRegNum,
2425 const MCConstantExpr *OffsetImm,
2426 unsigned OffsetRegNum,
2427 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002428 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002429 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002430 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002431 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002432 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002433 Op->Memory.BaseRegNum = BaseRegNum;
2434 Op->Memory.OffsetImm = OffsetImm;
2435 Op->Memory.OffsetRegNum = OffsetRegNum;
2436 Op->Memory.ShiftType = ShiftType;
2437 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002438 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002439 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002440 Op->StartLoc = S;
2441 Op->EndLoc = E;
2442 return Op;
2443 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002444
Jim Grosbachc320c852011-08-05 21:28:30 +00002445 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2446 ARM_AM::ShiftOpc ShiftTy,
2447 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002448 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002449 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002450 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002451 Op->PostIdxReg.isAdd = isAdd;
2452 Op->PostIdxReg.ShiftTy = ShiftTy;
2453 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002454 Op->StartLoc = S;
2455 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002456 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002457 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002458
2459 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002460 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002461 Op->MBOpt.Val = Opt;
2462 Op->StartLoc = S;
2463 Op->EndLoc = S;
2464 return Op;
2465 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002466
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002467 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2468 SMLoc S) {
2469 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2470 Op->ISBOpt.Val = Opt;
2471 Op->StartLoc = S;
2472 Op->EndLoc = S;
2473 return Op;
2474 }
2475
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002476 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002477 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002478 Op->IFlags.Val = IFlags;
2479 Op->StartLoc = S;
2480 Op->EndLoc = S;
2481 return Op;
2482 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002483
2484 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002485 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002486 Op->MMask.Val = MMask;
2487 Op->StartLoc = S;
2488 Op->EndLoc = S;
2489 return Op;
2490 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002491};
2492
2493} // end anonymous namespace.
2494
Jim Grosbach602aa902011-07-13 15:34:57 +00002495void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002496 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002497 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002498 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002499 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002500 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002501 OS << "<ccout " << getReg() << ">";
2502 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002503 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002504 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002505 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2506 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2507 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002508 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2509 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2510 break;
2511 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002512 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002513 OS << "<coprocessor number: " << getCoproc() << ">";
2514 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002515 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002516 OS << "<coprocessor register: " << getCoproc() << ">";
2517 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002518 case k_CoprocOption:
2519 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2520 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002521 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002522 OS << "<mask: " << getMSRMask() << ">";
2523 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002524 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002525 getImm()->print(OS);
2526 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002527 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002528 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002529 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002530 case k_InstSyncBarrierOpt:
2531 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2532 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002533 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002534 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002535 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002536 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002537 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002538 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002539 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2540 << PostIdxReg.RegNum;
2541 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2542 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2543 << PostIdxReg.ShiftImm;
2544 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002545 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002546 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002547 OS << "<ARM_PROC::";
2548 unsigned IFlags = getProcIFlags();
2549 for (int i=2; i >= 0; --i)
2550 if (IFlags & (1 << i))
2551 OS << ARM_PROC::IFlagsToString(1 << i);
2552 OS << ">";
2553 break;
2554 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002555 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002556 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002557 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002558 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002559 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2560 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002561 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002562 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002563 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002564 << RegShiftedReg.SrcReg << " "
2565 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2566 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002567 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002568 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002569 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002570 << RegShiftedImm.SrcReg << " "
2571 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2572 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002573 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002574 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002575 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2576 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002577 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002578 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2579 << ", width: " << Bitfield.Width << ">";
2580 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002581 case k_RegisterList:
2582 case k_DPRRegisterList:
2583 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002584 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002585
Bill Wendlingbed94652010-11-09 23:28:44 +00002586 const SmallVectorImpl<unsigned> &RegList = getRegList();
2587 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002588 I = RegList.begin(), E = RegList.end(); I != E; ) {
2589 OS << *I;
2590 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002591 }
2592
2593 OS << ">";
2594 break;
2595 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002596 case k_VectorList:
2597 OS << "<vector_list " << VectorList.Count << " * "
2598 << VectorList.RegNum << ">";
2599 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002600 case k_VectorListAllLanes:
2601 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2602 << VectorList.RegNum << ">";
2603 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002604 case k_VectorListIndexed:
2605 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2606 << VectorList.Count << " * " << VectorList.RegNum << ">";
2607 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002608 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002609 OS << "'" << getToken() << "'";
2610 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002611 case k_VectorIndex:
2612 OS << "<vectorindex " << getVectorIndex() << ">";
2613 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002614 }
2615}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002616
2617/// @name Auto-generated Match Functions
2618/// {
2619
2620static unsigned MatchRegisterName(StringRef Name);
2621
2622/// }
2623
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002624bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2625 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002626 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002627 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002628 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002629
2630 return (RegNo == (unsigned)-1);
2631}
2632
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002633/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002634/// and if it is a register name the token is eaten and the register number is
2635/// returned. Otherwise return -1.
2636///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002637int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002638 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002639 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002640
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002641 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002642 unsigned RegNum = MatchRegisterName(lowerCase);
2643 if (!RegNum) {
2644 RegNum = StringSwitch<unsigned>(lowerCase)
2645 .Case("r13", ARM::SP)
2646 .Case("r14", ARM::LR)
2647 .Case("r15", ARM::PC)
2648 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002649 // Additional register name aliases for 'gas' compatibility.
2650 .Case("a1", ARM::R0)
2651 .Case("a2", ARM::R1)
2652 .Case("a3", ARM::R2)
2653 .Case("a4", ARM::R3)
2654 .Case("v1", ARM::R4)
2655 .Case("v2", ARM::R5)
2656 .Case("v3", ARM::R6)
2657 .Case("v4", ARM::R7)
2658 .Case("v5", ARM::R8)
2659 .Case("v6", ARM::R9)
2660 .Case("v7", ARM::R10)
2661 .Case("v8", ARM::R11)
2662 .Case("sb", ARM::R9)
2663 .Case("sl", ARM::R10)
2664 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002665 .Default(0);
2666 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002667 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002668 // Check for aliases registered via .req. Canonicalize to lower case.
2669 // That's more consistent since register names are case insensitive, and
2670 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2671 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002672 // If no match, return failure.
2673 if (Entry == RegisterReqs.end())
2674 return -1;
2675 Parser.Lex(); // Eat identifier token.
2676 return Entry->getValue();
2677 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002678
Chris Lattner44e5981c2010-10-30 04:09:10 +00002679 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002680
Chris Lattner44e5981c2010-10-30 04:09:10 +00002681 return RegNum;
2682}
Jim Grosbach99710a82010-11-01 16:44:21 +00002683
Jim Grosbachbb24c592011-07-13 18:49:30 +00002684// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2685// If a recoverable error occurs, return 1. If an irrecoverable error
2686// occurs, return -1. An irrecoverable error is one where tokens have been
2687// consumed in the process of trying to parse the shifter (i.e., when it is
2688// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002689int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002690 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2691 SMLoc S = Parser.getTok().getLoc();
2692 const AsmToken &Tok = Parser.getTok();
2693 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2694
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002695 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002696 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002697 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002698 .Case("lsl", ARM_AM::lsl)
2699 .Case("lsr", ARM_AM::lsr)
2700 .Case("asr", ARM_AM::asr)
2701 .Case("ror", ARM_AM::ror)
2702 .Case("rrx", ARM_AM::rrx)
2703 .Default(ARM_AM::no_shift);
2704
2705 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002706 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002707
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002708 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002709
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002710 // The source register for the shift has already been added to the
2711 // operand list, so we need to pop it off and combine it into the shifted
2712 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002713 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002714 if (!PrevOp->isReg())
2715 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2716 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002717
2718 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002719 int64_t Imm = 0;
2720 int ShiftReg = 0;
2721 if (ShiftTy == ARM_AM::rrx) {
2722 // RRX Doesn't have an explicit shift amount. The encoder expects
2723 // the shift register to be the same as the source register. Seems odd,
2724 // but OK.
2725 ShiftReg = SrcReg;
2726 } else {
2727 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002728 if (Parser.getTok().is(AsmToken::Hash) ||
2729 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002730 Parser.Lex(); // Eat hash.
2731 SMLoc ImmLoc = Parser.getTok().getLoc();
2732 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002733 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002734 Error(ImmLoc, "invalid immediate shift value");
2735 return -1;
2736 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002737 // The expression must be evaluatable as an immediate.
2738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002739 if (!CE) {
2740 Error(ImmLoc, "invalid immediate shift value");
2741 return -1;
2742 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002743 // Range check the immediate.
2744 // lsl, ror: 0 <= imm <= 31
2745 // lsr, asr: 0 <= imm <= 32
2746 Imm = CE->getValue();
2747 if (Imm < 0 ||
2748 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2749 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002750 Error(ImmLoc, "immediate shift value out of range");
2751 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002752 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002753 // shift by zero is a nop. Always send it through as lsl.
2754 // ('as' compatibility)
2755 if (Imm == 0)
2756 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002757 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002758 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002759 EndLoc = Parser.getTok().getEndLoc();
2760 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002761 if (ShiftReg == -1) {
2762 Error (L, "expected immediate or register in shift operand");
2763 return -1;
2764 }
2765 } else {
2766 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002767 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002768 return -1;
2769 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002770 }
2771
Owen Andersonb595ed02011-07-21 18:54:16 +00002772 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2773 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002774 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002775 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002776 else
2777 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002778 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002779
Jim Grosbachbb24c592011-07-13 18:49:30 +00002780 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002781}
2782
2783
Bill Wendling2063b842010-11-18 23:43:05 +00002784/// Try to parse a register name. The token must be an Identifier when called.
2785/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2786/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002787///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002788/// TODO this is likely to change to allow different register types and or to
2789/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002790bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002791tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002792 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002793 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002794 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002795 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002796
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002797 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2798 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002799
Chris Lattner44e5981c2010-10-30 04:09:10 +00002800 const AsmToken &ExclaimTok = Parser.getTok();
2801 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002802 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2803 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002804 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002805 return false;
2806 }
2807
2808 // Also check for an index operand. This is only legal for vector registers,
2809 // but that'll get caught OK in operand matching, so we don't need to
2810 // explicitly filter everything else out here.
2811 if (Parser.getTok().is(AsmToken::LBrac)) {
2812 SMLoc SIdx = Parser.getTok().getLoc();
2813 Parser.Lex(); // Eat left bracket token.
2814
2815 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002816 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002817 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002818 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002819 if (!MCE)
2820 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002821
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002822 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002823 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002824
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002825 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002826 Parser.Lex(); // Eat right bracket token.
2827
2828 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2829 SIdx, E,
2830 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002831 }
2832
Bill Wendling2063b842010-11-18 23:43:05 +00002833 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002834}
2835
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002836/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2837/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2838/// "c5", ...
2839static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002840 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2841 // but efficient.
2842 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002843 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002844 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002845 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002846 return -1;
2847 switch (Name[1]) {
2848 default: return -1;
2849 case '0': return 0;
2850 case '1': return 1;
2851 case '2': return 2;
2852 case '3': return 3;
2853 case '4': return 4;
2854 case '5': return 5;
2855 case '6': return 6;
2856 case '7': return 7;
2857 case '8': return 8;
2858 case '9': return 9;
2859 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002860 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002861 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002862 return -1;
2863 switch (Name[2]) {
2864 default: return -1;
2865 case '0': return 10;
2866 case '1': return 11;
2867 case '2': return 12;
2868 case '3': return 13;
2869 case '4': return 14;
2870 case '5': return 15;
2871 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002872 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002873}
2874
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002875/// parseITCondCode - Try to parse a condition code for an IT instruction.
2876ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2877parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2878 SMLoc S = Parser.getTok().getLoc();
2879 const AsmToken &Tok = Parser.getTok();
2880 if (!Tok.is(AsmToken::Identifier))
2881 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002882 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002883 .Case("eq", ARMCC::EQ)
2884 .Case("ne", ARMCC::NE)
2885 .Case("hs", ARMCC::HS)
2886 .Case("cs", ARMCC::HS)
2887 .Case("lo", ARMCC::LO)
2888 .Case("cc", ARMCC::LO)
2889 .Case("mi", ARMCC::MI)
2890 .Case("pl", ARMCC::PL)
2891 .Case("vs", ARMCC::VS)
2892 .Case("vc", ARMCC::VC)
2893 .Case("hi", ARMCC::HI)
2894 .Case("ls", ARMCC::LS)
2895 .Case("ge", ARMCC::GE)
2896 .Case("lt", ARMCC::LT)
2897 .Case("gt", ARMCC::GT)
2898 .Case("le", ARMCC::LE)
2899 .Case("al", ARMCC::AL)
2900 .Default(~0U);
2901 if (CC == ~0U)
2902 return MatchOperand_NoMatch;
2903 Parser.Lex(); // Eat the token.
2904
2905 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2906
2907 return MatchOperand_Success;
2908}
2909
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002910/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002911/// token must be an Identifier when called, and if it is a coprocessor
2912/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002913ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002914parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002915 SMLoc S = Parser.getTok().getLoc();
2916 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002917 if (Tok.isNot(AsmToken::Identifier))
2918 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002919
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002920 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002921 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002922 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002923
2924 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002925 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002926 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002927}
2928
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002929/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002930/// token must be an Identifier when called, and if it is a coprocessor
2931/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002932ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002933parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002934 SMLoc S = Parser.getTok().getLoc();
2935 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002936 if (Tok.isNot(AsmToken::Identifier))
2937 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002938
2939 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2940 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002941 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002942
2943 Parser.Lex(); // Eat identifier token.
2944 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002945 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002946}
2947
Jim Grosbach48399582011-10-12 17:34:41 +00002948/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2949/// coproc_option : '{' imm0_255 '}'
2950ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2951parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2952 SMLoc S = Parser.getTok().getLoc();
2953
2954 // If this isn't a '{', this isn't a coprocessor immediate operand.
2955 if (Parser.getTok().isNot(AsmToken::LCurly))
2956 return MatchOperand_NoMatch;
2957 Parser.Lex(); // Eat the '{'
2958
2959 const MCExpr *Expr;
2960 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002961 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002962 Error(Loc, "illegal expression");
2963 return MatchOperand_ParseFail;
2964 }
2965 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2966 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2967 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2968 return MatchOperand_ParseFail;
2969 }
2970 int Val = CE->getValue();
2971
2972 // Check for and consume the closing '}'
2973 if (Parser.getTok().isNot(AsmToken::RCurly))
2974 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002975 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002976 Parser.Lex(); // Eat the '}'
2977
2978 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2979 return MatchOperand_Success;
2980}
2981
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002982// For register list parsing, we need to map from raw GPR register numbering
2983// to the enumeration values. The enumeration values aren't sorted by
2984// register number due to our using "sp", "lr" and "pc" as canonical names.
2985static unsigned getNextRegister(unsigned Reg) {
2986 // If this is a GPR, we need to do it manually, otherwise we can rely
2987 // on the sort ordering of the enumeration since the other reg-classes
2988 // are sane.
2989 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2990 return Reg + 1;
2991 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002992 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002993 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2994 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2995 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2996 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2997 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2998 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2999 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3000 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3001 }
3002}
3003
Jim Grosbach85a23432011-11-11 21:27:40 +00003004// Return the low-subreg of a given Q register.
3005static unsigned getDRegFromQReg(unsigned QReg) {
3006 switch (QReg) {
3007 default: llvm_unreachable("expected a Q register!");
3008 case ARM::Q0: return ARM::D0;
3009 case ARM::Q1: return ARM::D2;
3010 case ARM::Q2: return ARM::D4;
3011 case ARM::Q3: return ARM::D6;
3012 case ARM::Q4: return ARM::D8;
3013 case ARM::Q5: return ARM::D10;
3014 case ARM::Q6: return ARM::D12;
3015 case ARM::Q7: return ARM::D14;
3016 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003017 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003018 case ARM::Q10: return ARM::D20;
3019 case ARM::Q11: return ARM::D22;
3020 case ARM::Q12: return ARM::D24;
3021 case ARM::Q13: return ARM::D26;
3022 case ARM::Q14: return ARM::D28;
3023 case ARM::Q15: return ARM::D30;
3024 }
3025}
3026
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003027/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003028bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003029parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003030 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003031 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003032 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003033 Parser.Lex(); // Eat '{' token.
3034 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003035
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003036 // Check the first register in the list to see what register class
3037 // this is a list of.
3038 int Reg = tryParseRegister();
3039 if (Reg == -1)
3040 return Error(RegLoc, "register expected");
3041
Jim Grosbach85a23432011-11-11 21:27:40 +00003042 // The reglist instructions have at most 16 registers, so reserve
3043 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003044 int EReg = 0;
3045 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003046
3047 // Allow Q regs and just interpret them as the two D sub-registers.
3048 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3049 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003050 EReg = MRI->getEncodingValue(Reg);
3051 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003052 ++Reg;
3053 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003054 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003055 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3056 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3057 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3058 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3059 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3060 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3061 else
3062 return Error(RegLoc, "invalid register in register list");
3063
Jim Grosbach85a23432011-11-11 21:27:40 +00003064 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003065 EReg = MRI->getEncodingValue(Reg);
3066 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003067
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003068 // This starts immediately after the first register token in the list,
3069 // so we can see either a comma or a minus (range separator) as a legal
3070 // next token.
3071 while (Parser.getTok().is(AsmToken::Comma) ||
3072 Parser.getTok().is(AsmToken::Minus)) {
3073 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003074 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003075 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003076 int EndReg = tryParseRegister();
3077 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003078 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003079 // Allow Q regs and just interpret them as the two D sub-registers.
3080 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3081 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003082 // If the register is the same as the start reg, there's nothing
3083 // more to do.
3084 if (Reg == EndReg)
3085 continue;
3086 // The register must be in the same register class as the first.
3087 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003088 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003089 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003090 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003091 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003092
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003093 // Add all the registers in the range to the register list.
3094 while (Reg != EndReg) {
3095 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003096 EReg = MRI->getEncodingValue(Reg);
3097 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003098 }
3099 continue;
3100 }
3101 Parser.Lex(); // Eat the comma.
3102 RegLoc = Parser.getTok().getLoc();
3103 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003104 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003105 Reg = tryParseRegister();
3106 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003107 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003108 // Allow Q regs and just interpret them as the two D sub-registers.
3109 bool isQReg = false;
3110 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3111 Reg = getDRegFromQReg(Reg);
3112 isQReg = true;
3113 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003114 // The register must be in the same register class as the first.
3115 if (!RC->contains(Reg))
3116 return Error(RegLoc, "invalid register in register list");
3117 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003118 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003119 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3120 Warning(RegLoc, "register list not in ascending order");
3121 else
3122 return Error(RegLoc, "register list not in ascending order");
3123 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003124 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003125 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3126 ") in register list");
3127 continue;
3128 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003129 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003130 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3131 Reg != OldReg + 1)
3132 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003133 EReg = MRI->getEncodingValue(Reg);
3134 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3135 if (isQReg) {
3136 EReg = MRI->getEncodingValue(++Reg);
3137 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3138 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003139 }
3140
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003141 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003142 return Error(Parser.getTok().getLoc(), "'}' expected");
3143 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003144 Parser.Lex(); // Eat '}' token.
3145
Jim Grosbach18bf3632011-12-13 21:48:29 +00003146 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003147 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003148
3149 // The ARM system instruction variants for LDM/STM have a '^' token here.
3150 if (Parser.getTok().is(AsmToken::Caret)) {
3151 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3152 Parser.Lex(); // Eat '^' token.
3153 }
3154
Bill Wendling2063b842010-11-18 23:43:05 +00003155 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003156}
3157
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003158// Helper function to parse the lane index for vector lists.
3159ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003160parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003161 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003162 if (Parser.getTok().is(AsmToken::LBrac)) {
3163 Parser.Lex(); // Eat the '['.
3164 if (Parser.getTok().is(AsmToken::RBrac)) {
3165 // "Dn[]" is the 'all lanes' syntax.
3166 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003167 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003168 Parser.Lex(); // Eat the ']'.
3169 return MatchOperand_Success;
3170 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003171
3172 // There's an optional '#' token here. Normally there wouldn't be, but
3173 // inline assemble puts one in, and it's friendly to accept that.
3174 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003175 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003176
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003177 const MCExpr *LaneIndex;
3178 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003179 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003180 Error(Loc, "illegal expression");
3181 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003182 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003183 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3184 if (!CE) {
3185 Error(Loc, "lane index must be empty or an integer");
3186 return MatchOperand_ParseFail;
3187 }
3188 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3189 Error(Parser.getTok().getLoc(), "']' expected");
3190 return MatchOperand_ParseFail;
3191 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003192 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003193 Parser.Lex(); // Eat the ']'.
3194 int64_t Val = CE->getValue();
3195
3196 // FIXME: Make this range check context sensitive for .8, .16, .32.
3197 if (Val < 0 || Val > 7) {
3198 Error(Parser.getTok().getLoc(), "lane index out of range");
3199 return MatchOperand_ParseFail;
3200 }
3201 Index = Val;
3202 LaneKind = IndexedLane;
3203 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003204 }
3205 LaneKind = NoLanes;
3206 return MatchOperand_Success;
3207}
3208
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003209// parse a vector register list
3210ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3211parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003212 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003213 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003214 SMLoc S = Parser.getTok().getLoc();
3215 // As an extension (to match gas), support a plain D register or Q register
3216 // (without encosing curly braces) as a single or double entry list,
3217 // respectively.
3218 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003219 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003220 int Reg = tryParseRegister();
3221 if (Reg == -1)
3222 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003223 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003224 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003225 if (Res != MatchOperand_Success)
3226 return Res;
3227 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003228 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003229 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003230 break;
3231 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003232 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3233 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003234 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003235 case IndexedLane:
3236 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003237 LaneIndex,
3238 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003239 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003240 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003241 return MatchOperand_Success;
3242 }
3243 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3244 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003245 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003246 if (Res != MatchOperand_Success)
3247 return Res;
3248 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003249 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003250 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003251 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003252 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003253 break;
3254 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003255 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3256 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003257 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3258 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003259 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003260 case IndexedLane:
3261 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003262 LaneIndex,
3263 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003264 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003265 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003266 return MatchOperand_Success;
3267 }
3268 Error(S, "vector register expected");
3269 return MatchOperand_ParseFail;
3270 }
3271
3272 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003273 return MatchOperand_NoMatch;
3274
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003275 Parser.Lex(); // Eat '{' token.
3276 SMLoc RegLoc = Parser.getTok().getLoc();
3277
3278 int Reg = tryParseRegister();
3279 if (Reg == -1) {
3280 Error(RegLoc, "register expected");
3281 return MatchOperand_ParseFail;
3282 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003283 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003284 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003285 unsigned FirstReg = Reg;
3286 // The list is of D registers, but we also allow Q regs and just interpret
3287 // them as the two D sub-registers.
3288 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3289 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003290 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3291 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003292 ++Reg;
3293 ++Count;
3294 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003295
3296 SMLoc E;
3297 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003298 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003299
Jim Grosbache891fe82011-11-15 23:19:15 +00003300 while (Parser.getTok().is(AsmToken::Comma) ||
3301 Parser.getTok().is(AsmToken::Minus)) {
3302 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003303 if (!Spacing)
3304 Spacing = 1; // Register range implies a single spaced list.
3305 else if (Spacing == 2) {
3306 Error(Parser.getTok().getLoc(),
3307 "sequential registers in double spaced list");
3308 return MatchOperand_ParseFail;
3309 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003310 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003311 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003312 int EndReg = tryParseRegister();
3313 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003314 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003315 return MatchOperand_ParseFail;
3316 }
3317 // Allow Q regs and just interpret them as the two D sub-registers.
3318 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3319 EndReg = getDRegFromQReg(EndReg) + 1;
3320 // If the register is the same as the start reg, there's nothing
3321 // more to do.
3322 if (Reg == EndReg)
3323 continue;
3324 // The register must be in the same register class as the first.
3325 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003326 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003327 return MatchOperand_ParseFail;
3328 }
3329 // Ranges must go from low to high.
3330 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003331 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003332 return MatchOperand_ParseFail;
3333 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003334 // Parse the lane specifier if present.
3335 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003336 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003337 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3338 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003339 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003340 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003341 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003342 return MatchOperand_ParseFail;
3343 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003344
3345 // Add all the registers in the range to the register list.
3346 Count += EndReg - Reg;
3347 Reg = EndReg;
3348 continue;
3349 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003350 Parser.Lex(); // Eat the comma.
3351 RegLoc = Parser.getTok().getLoc();
3352 int OldReg = Reg;
3353 Reg = tryParseRegister();
3354 if (Reg == -1) {
3355 Error(RegLoc, "register expected");
3356 return MatchOperand_ParseFail;
3357 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003358 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003359 // It's OK to use the enumeration values directly here rather, as the
3360 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003361 //
3362 // The list is of D registers, but we also allow Q regs and just interpret
3363 // them as the two D sub-registers.
3364 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003365 if (!Spacing)
3366 Spacing = 1; // Register range implies a single spaced list.
3367 else if (Spacing == 2) {
3368 Error(RegLoc,
3369 "invalid register in double-spaced list (must be 'D' register')");
3370 return MatchOperand_ParseFail;
3371 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003372 Reg = getDRegFromQReg(Reg);
3373 if (Reg != OldReg + 1) {
3374 Error(RegLoc, "non-contiguous register range");
3375 return MatchOperand_ParseFail;
3376 }
3377 ++Reg;
3378 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003379 // Parse the lane specifier if present.
3380 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003381 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003382 SMLoc LaneLoc = Parser.getTok().getLoc();
3383 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3384 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003385 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003386 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003387 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003388 return MatchOperand_ParseFail;
3389 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003390 continue;
3391 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003392 // Normal D register.
3393 // Figure out the register spacing (single or double) of the list if
3394 // we don't know it already.
3395 if (!Spacing)
3396 Spacing = 1 + (Reg == OldReg + 2);
3397
3398 // Just check that it's contiguous and keep going.
3399 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003400 Error(RegLoc, "non-contiguous register range");
3401 return MatchOperand_ParseFail;
3402 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003403 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003404 // Parse the lane specifier if present.
3405 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003406 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003407 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003408 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003409 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003410 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003411 Error(EndLoc, "mismatched lane index in register list");
3412 return MatchOperand_ParseFail;
3413 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003414 }
3415
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003416 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003417 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003418 return MatchOperand_ParseFail;
3419 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003420 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003421 Parser.Lex(); // Eat '}' token.
3422
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003423 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003424 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003425 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003426 // composite register classes.
3427 if (Count == 2) {
3428 const MCRegisterClass *RC = (Spacing == 1) ?
3429 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3430 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3431 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3432 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003433
Jim Grosbach2f50e922011-12-15 21:44:33 +00003434 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3435 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003436 break;
3437 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003438 // Two-register operands have been converted to the
3439 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003440 if (Count == 2) {
3441 const MCRegisterClass *RC = (Spacing == 1) ?
3442 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3443 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003444 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3445 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003446 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003447 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003448 S, E));
3449 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003450 case IndexedLane:
3451 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003452 LaneIndex,
3453 (Spacing == 2),
3454 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003455 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003456 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003457 return MatchOperand_Success;
3458}
3459
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003460/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003461ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003462parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003463 SMLoc S = Parser.getTok().getLoc();
3464 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003465 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003466
Jiangning Liu288e1af2012-08-02 08:21:27 +00003467 if (Tok.is(AsmToken::Identifier)) {
3468 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003469
Jiangning Liu288e1af2012-08-02 08:21:27 +00003470 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3471 .Case("sy", ARM_MB::SY)
3472 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003473 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003474 .Case("sh", ARM_MB::ISH)
3475 .Case("ish", ARM_MB::ISH)
3476 .Case("shst", ARM_MB::ISHST)
3477 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003478 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003479 .Case("nsh", ARM_MB::NSH)
3480 .Case("un", ARM_MB::NSH)
3481 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003482 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003483 .Case("unst", ARM_MB::NSHST)
3484 .Case("osh", ARM_MB::OSH)
3485 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003486 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003487 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003488
Joey Gouly926d3f52013-09-05 15:35:24 +00003489 // ishld, oshld, nshld and ld are only available from ARMv8.
3490 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3491 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3492 Opt = ~0U;
3493
Jiangning Liu288e1af2012-08-02 08:21:27 +00003494 if (Opt == ~0U)
3495 return MatchOperand_NoMatch;
3496
3497 Parser.Lex(); // Eat identifier token.
3498 } else if (Tok.is(AsmToken::Hash) ||
3499 Tok.is(AsmToken::Dollar) ||
3500 Tok.is(AsmToken::Integer)) {
3501 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003502 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003503 SMLoc Loc = Parser.getTok().getLoc();
3504
3505 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003506 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003507 Error(Loc, "illegal expression");
3508 return MatchOperand_ParseFail;
3509 }
3510
3511 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3512 if (!CE) {
3513 Error(Loc, "constant expression expected");
3514 return MatchOperand_ParseFail;
3515 }
3516
3517 int Val = CE->getValue();
3518 if (Val & ~0xf) {
3519 Error(Loc, "immediate value out of range");
3520 return MatchOperand_ParseFail;
3521 }
3522
3523 Opt = ARM_MB::RESERVED_0 + Val;
3524 } else
3525 return MatchOperand_ParseFail;
3526
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003527 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003528 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003529}
3530
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003531/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3532ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3533parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3534 SMLoc S = Parser.getTok().getLoc();
3535 const AsmToken &Tok = Parser.getTok();
3536 unsigned Opt;
3537
3538 if (Tok.is(AsmToken::Identifier)) {
3539 StringRef OptStr = Tok.getString();
3540
3541 if (OptStr.lower() == "sy")
3542 Opt = ARM_ISB::SY;
3543 else
3544 return MatchOperand_NoMatch;
3545
3546 Parser.Lex(); // Eat identifier token.
3547 } else if (Tok.is(AsmToken::Hash) ||
3548 Tok.is(AsmToken::Dollar) ||
3549 Tok.is(AsmToken::Integer)) {
3550 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003551 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003552 SMLoc Loc = Parser.getTok().getLoc();
3553
3554 const MCExpr *ISBarrierID;
3555 if (getParser().parseExpression(ISBarrierID)) {
3556 Error(Loc, "illegal expression");
3557 return MatchOperand_ParseFail;
3558 }
3559
3560 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3561 if (!CE) {
3562 Error(Loc, "constant expression expected");
3563 return MatchOperand_ParseFail;
3564 }
3565
3566 int Val = CE->getValue();
3567 if (Val & ~0xf) {
3568 Error(Loc, "immediate value out of range");
3569 return MatchOperand_ParseFail;
3570 }
3571
3572 Opt = ARM_ISB::RESERVED_0 + Val;
3573 } else
3574 return MatchOperand_ParseFail;
3575
3576 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3577 (ARM_ISB::InstSyncBOpt)Opt, S));
3578 return MatchOperand_Success;
3579}
3580
3581
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003582/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003583ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003584parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003585 SMLoc S = Parser.getTok().getLoc();
3586 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003587 if (!Tok.is(AsmToken::Identifier))
3588 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003589 StringRef IFlagsStr = Tok.getString();
3590
Owen Anderson10c5b122011-10-05 17:16:40 +00003591 // An iflags string of "none" is interpreted to mean that none of the AIF
3592 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003593 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003594 if (IFlagsStr != "none") {
3595 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3596 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3597 .Case("a", ARM_PROC::A)
3598 .Case("i", ARM_PROC::I)
3599 .Case("f", ARM_PROC::F)
3600 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003601
Owen Anderson10c5b122011-10-05 17:16:40 +00003602 // If some specific iflag is already set, it means that some letter is
3603 // present more than once, this is not acceptable.
3604 if (Flag == ~0U || (IFlags & Flag))
3605 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003606
Owen Anderson10c5b122011-10-05 17:16:40 +00003607 IFlags |= Flag;
3608 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003609 }
3610
3611 Parser.Lex(); // Eat identifier token.
3612 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3613 return MatchOperand_Success;
3614}
3615
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003616/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003617ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003618parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003619 SMLoc S = Parser.getTok().getLoc();
3620 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003621 if (!Tok.is(AsmToken::Identifier))
3622 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003623 StringRef Mask = Tok.getString();
3624
James Molloy21efa7d2011-09-28 14:21:38 +00003625 if (isMClass()) {
3626 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003627 std::string Name = Mask.lower();
3628 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003629 // Note: in the documentation:
3630 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3631 // for MSR APSR_nzcvq.
3632 // but we do make it an alias here. This is so to get the "mask encoding"
3633 // bits correct on MSR APSR writes.
3634 //
3635 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3636 // should really only be allowed when writing a special register. Note
3637 // they get dropped in the MRS instruction reading a special register as
3638 // the SYSm field is only 8 bits.
3639 //
3640 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3641 // includes the DSP extension but that is not checked.
3642 .Case("apsr", 0x800)
3643 .Case("apsr_nzcvq", 0x800)
3644 .Case("apsr_g", 0x400)
3645 .Case("apsr_nzcvqg", 0xc00)
3646 .Case("iapsr", 0x801)
3647 .Case("iapsr_nzcvq", 0x801)
3648 .Case("iapsr_g", 0x401)
3649 .Case("iapsr_nzcvqg", 0xc01)
3650 .Case("eapsr", 0x802)
3651 .Case("eapsr_nzcvq", 0x802)
3652 .Case("eapsr_g", 0x402)
3653 .Case("eapsr_nzcvqg", 0xc02)
3654 .Case("xpsr", 0x803)
3655 .Case("xpsr_nzcvq", 0x803)
3656 .Case("xpsr_g", 0x403)
3657 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003658 .Case("ipsr", 0x805)
3659 .Case("epsr", 0x806)
3660 .Case("iepsr", 0x807)
3661 .Case("msp", 0x808)
3662 .Case("psp", 0x809)
3663 .Case("primask", 0x810)
3664 .Case("basepri", 0x811)
3665 .Case("basepri_max", 0x812)
3666 .Case("faultmask", 0x813)
3667 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003668 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003669
James Molloy21efa7d2011-09-28 14:21:38 +00003670 if (FlagsVal == ~0U)
3671 return MatchOperand_NoMatch;
3672
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003673 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003674 // basepri, basepri_max and faultmask only valid for V7m.
3675 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003676
James Molloy21efa7d2011-09-28 14:21:38 +00003677 Parser.Lex(); // Eat identifier token.
3678 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3679 return MatchOperand_Success;
3680 }
3681
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003682 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3683 size_t Start = 0, Next = Mask.find('_');
3684 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003685 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003686 if (Next != StringRef::npos)
3687 Flags = Mask.slice(Next+1, Mask.size());
3688
3689 // FlagsVal contains the complete mask:
3690 // 3-0: Mask
3691 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3692 unsigned FlagsVal = 0;
3693
3694 if (SpecReg == "apsr") {
3695 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003696 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003697 .Case("g", 0x4) // same as CPSR_s
3698 .Case("nzcvqg", 0xc) // same as CPSR_fs
3699 .Default(~0U);
3700
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003701 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003702 if (!Flags.empty())
3703 return MatchOperand_NoMatch;
3704 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003705 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003706 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003707 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003708 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3709 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003710 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003711 for (int i = 0, e = Flags.size(); i != e; ++i) {
3712 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3713 .Case("c", 1)
3714 .Case("x", 2)
3715 .Case("s", 4)
3716 .Case("f", 8)
3717 .Default(~0U);
3718
3719 // If some specific flag is already set, it means that some letter is
3720 // present more than once, this is not acceptable.
3721 if (FlagsVal == ~0U || (FlagsVal & Flag))
3722 return MatchOperand_NoMatch;
3723 FlagsVal |= Flag;
3724 }
3725 } else // No match for special register.
3726 return MatchOperand_NoMatch;
3727
Owen Anderson03a173e2011-10-21 18:43:28 +00003728 // Special register without flags is NOT equivalent to "fc" flags.
3729 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3730 // two lines would enable gas compatibility at the expense of breaking
3731 // round-tripping.
3732 //
3733 // if (!FlagsVal)
3734 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003735
3736 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3737 if (SpecReg == "spsr")
3738 FlagsVal |= 16;
3739
3740 Parser.Lex(); // Eat identifier token.
3741 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3742 return MatchOperand_Success;
3743}
3744
Jim Grosbach27c1e252011-07-21 17:23:04 +00003745ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3746parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3747 int Low, int High) {
3748 const AsmToken &Tok = Parser.getTok();
3749 if (Tok.isNot(AsmToken::Identifier)) {
3750 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3751 return MatchOperand_ParseFail;
3752 }
3753 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003754 std::string LowerOp = Op.lower();
3755 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003756 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3757 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3758 return MatchOperand_ParseFail;
3759 }
3760 Parser.Lex(); // Eat shift type token.
3761
3762 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003763 if (Parser.getTok().isNot(AsmToken::Hash) &&
3764 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003765 Error(Parser.getTok().getLoc(), "'#' expected");
3766 return MatchOperand_ParseFail;
3767 }
3768 Parser.Lex(); // Eat hash token.
3769
3770 const MCExpr *ShiftAmount;
3771 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003772 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003773 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003774 Error(Loc, "illegal expression");
3775 return MatchOperand_ParseFail;
3776 }
3777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3778 if (!CE) {
3779 Error(Loc, "constant expression expected");
3780 return MatchOperand_ParseFail;
3781 }
3782 int Val = CE->getValue();
3783 if (Val < Low || Val > High) {
3784 Error(Loc, "immediate value out of range");
3785 return MatchOperand_ParseFail;
3786 }
3787
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003788 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003789
3790 return MatchOperand_Success;
3791}
3792
Jim Grosbach0a547702011-07-22 17:44:50 +00003793ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3794parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3795 const AsmToken &Tok = Parser.getTok();
3796 SMLoc S = Tok.getLoc();
3797 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003798 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003799 return MatchOperand_ParseFail;
3800 }
Tim Northover4d141442013-05-31 15:58:45 +00003801 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003802 .Case("be", 1)
3803 .Case("le", 0)
3804 .Default(-1);
3805 Parser.Lex(); // Eat the token.
3806
3807 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003808 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003809 return MatchOperand_ParseFail;
3810 }
3811 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3812 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003813 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003814 return MatchOperand_Success;
3815}
3816
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003817/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3818/// instructions. Legal values are:
3819/// lsl #n 'n' in [0,31]
3820/// asr #n 'n' in [1,32]
3821/// n == 32 encoded as n == 0.
3822ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3823parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3824 const AsmToken &Tok = Parser.getTok();
3825 SMLoc S = Tok.getLoc();
3826 if (Tok.isNot(AsmToken::Identifier)) {
3827 Error(S, "shift operator 'asr' or 'lsl' expected");
3828 return MatchOperand_ParseFail;
3829 }
3830 StringRef ShiftName = Tok.getString();
3831 bool isASR;
3832 if (ShiftName == "lsl" || ShiftName == "LSL")
3833 isASR = false;
3834 else if (ShiftName == "asr" || ShiftName == "ASR")
3835 isASR = true;
3836 else {
3837 Error(S, "shift operator 'asr' or 'lsl' expected");
3838 return MatchOperand_ParseFail;
3839 }
3840 Parser.Lex(); // Eat the operator.
3841
3842 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003843 if (Parser.getTok().isNot(AsmToken::Hash) &&
3844 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003845 Error(Parser.getTok().getLoc(), "'#' expected");
3846 return MatchOperand_ParseFail;
3847 }
3848 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003849 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003850
3851 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003852 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003853 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003854 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003855 return MatchOperand_ParseFail;
3856 }
3857 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3858 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003859 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003860 return MatchOperand_ParseFail;
3861 }
3862
3863 int64_t Val = CE->getValue();
3864 if (isASR) {
3865 // Shift amount must be in [1,32]
3866 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003867 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003868 return MatchOperand_ParseFail;
3869 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003870 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3871 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003872 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003873 return MatchOperand_ParseFail;
3874 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003875 if (Val == 32) Val = 0;
3876 } else {
3877 // Shift amount must be in [1,32]
3878 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003879 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003880 return MatchOperand_ParseFail;
3881 }
3882 }
3883
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003884 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003885
3886 return MatchOperand_Success;
3887}
3888
Jim Grosbach833b9d32011-07-27 20:15:40 +00003889/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3890/// of instructions. Legal values are:
3891/// ror #n 'n' in {0, 8, 16, 24}
3892ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3893parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3894 const AsmToken &Tok = Parser.getTok();
3895 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003896 if (Tok.isNot(AsmToken::Identifier))
3897 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003898 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003899 if (ShiftName != "ror" && ShiftName != "ROR")
3900 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003901 Parser.Lex(); // Eat the operator.
3902
3903 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003904 if (Parser.getTok().isNot(AsmToken::Hash) &&
3905 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003906 Error(Parser.getTok().getLoc(), "'#' expected");
3907 return MatchOperand_ParseFail;
3908 }
3909 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003910 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003911
3912 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003913 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003914 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003915 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003916 return MatchOperand_ParseFail;
3917 }
3918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3919 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003920 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003921 return MatchOperand_ParseFail;
3922 }
3923
3924 int64_t Val = CE->getValue();
3925 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3926 // normally, zero is represented in asm by omitting the rotate operand
3927 // entirely.
3928 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003929 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003930 return MatchOperand_ParseFail;
3931 }
3932
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003933 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003934
3935 return MatchOperand_Success;
3936}
3937
Jim Grosbach864b6092011-07-28 21:34:26 +00003938ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3939parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3940 SMLoc S = Parser.getTok().getLoc();
3941 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003942 if (Parser.getTok().isNot(AsmToken::Hash) &&
3943 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003944 Error(Parser.getTok().getLoc(), "'#' expected");
3945 return MatchOperand_ParseFail;
3946 }
3947 Parser.Lex(); // Eat hash token.
3948
3949 const MCExpr *LSBExpr;
3950 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003951 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003952 Error(E, "malformed immediate expression");
3953 return MatchOperand_ParseFail;
3954 }
3955 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3956 if (!CE) {
3957 Error(E, "'lsb' operand must be an immediate");
3958 return MatchOperand_ParseFail;
3959 }
3960
3961 int64_t LSB = CE->getValue();
3962 // The LSB must be in the range [0,31]
3963 if (LSB < 0 || LSB > 31) {
3964 Error(E, "'lsb' operand must be in the range [0,31]");
3965 return MatchOperand_ParseFail;
3966 }
3967 E = Parser.getTok().getLoc();
3968
3969 // Expect another immediate operand.
3970 if (Parser.getTok().isNot(AsmToken::Comma)) {
3971 Error(Parser.getTok().getLoc(), "too few operands");
3972 return MatchOperand_ParseFail;
3973 }
3974 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003975 if (Parser.getTok().isNot(AsmToken::Hash) &&
3976 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003977 Error(Parser.getTok().getLoc(), "'#' expected");
3978 return MatchOperand_ParseFail;
3979 }
3980 Parser.Lex(); // Eat hash token.
3981
3982 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003983 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003984 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003985 Error(E, "malformed immediate expression");
3986 return MatchOperand_ParseFail;
3987 }
3988 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3989 if (!CE) {
3990 Error(E, "'width' operand must be an immediate");
3991 return MatchOperand_ParseFail;
3992 }
3993
3994 int64_t Width = CE->getValue();
3995 // The LSB must be in the range [1,32-lsb]
3996 if (Width < 1 || Width > 32 - LSB) {
3997 Error(E, "'width' operand must be in the range [1,32-lsb]");
3998 return MatchOperand_ParseFail;
3999 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004000
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004001 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004002
4003 return MatchOperand_Success;
4004}
4005
Jim Grosbachd3595712011-08-03 23:50:40 +00004006ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4007parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4008 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004009 // postidx_reg := '+' register {, shift}
4010 // | '-' register {, shift}
4011 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004012
4013 // This method must return MatchOperand_NoMatch without consuming any tokens
4014 // in the case where there is no match, as other alternatives take other
4015 // parse methods.
4016 AsmToken Tok = Parser.getTok();
4017 SMLoc S = Tok.getLoc();
4018 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004019 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004020 if (Tok.is(AsmToken::Plus)) {
4021 Parser.Lex(); // Eat the '+' token.
4022 haveEaten = true;
4023 } else if (Tok.is(AsmToken::Minus)) {
4024 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004025 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004026 haveEaten = true;
4027 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004028
4029 SMLoc E = Parser.getTok().getEndLoc();
4030 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004031 if (Reg == -1) {
4032 if (!haveEaten)
4033 return MatchOperand_NoMatch;
4034 Error(Parser.getTok().getLoc(), "register expected");
4035 return MatchOperand_ParseFail;
4036 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004037
Jim Grosbachc320c852011-08-05 21:28:30 +00004038 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4039 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004040 if (Parser.getTok().is(AsmToken::Comma)) {
4041 Parser.Lex(); // Eat the ','.
4042 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4043 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004044
4045 // FIXME: Only approximates end...may include intervening whitespace.
4046 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004047 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004048
4049 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4050 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004051
4052 return MatchOperand_Success;
4053}
4054
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004055ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4056parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4057 // Check for a post-index addressing register operand. Specifically:
4058 // am3offset := '+' register
4059 // | '-' register
4060 // | register
4061 // | # imm
4062 // | # + imm
4063 // | # - imm
4064
4065 // This method must return MatchOperand_NoMatch without consuming any tokens
4066 // in the case where there is no match, as other alternatives take other
4067 // parse methods.
4068 AsmToken Tok = Parser.getTok();
4069 SMLoc S = Tok.getLoc();
4070
4071 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004072 if (Parser.getTok().is(AsmToken::Hash) ||
4073 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004074 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004075 // Explicitly look for a '-', as we need to encode negative zero
4076 // differently.
4077 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4078 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004079 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004080 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004081 return MatchOperand_ParseFail;
4082 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4083 if (!CE) {
4084 Error(S, "constant expression expected");
4085 return MatchOperand_ParseFail;
4086 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004087 // Negative zero is encoded as the flag value INT32_MIN.
4088 int32_t Val = CE->getValue();
4089 if (isNegative && Val == 0)
4090 Val = INT32_MIN;
4091
4092 Operands.push_back(
4093 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4094
4095 return MatchOperand_Success;
4096 }
4097
4098
4099 bool haveEaten = false;
4100 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004101 if (Tok.is(AsmToken::Plus)) {
4102 Parser.Lex(); // Eat the '+' token.
4103 haveEaten = true;
4104 } else if (Tok.is(AsmToken::Minus)) {
4105 Parser.Lex(); // Eat the '-' token.
4106 isAdd = false;
4107 haveEaten = true;
4108 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004109
4110 Tok = Parser.getTok();
4111 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004112 if (Reg == -1) {
4113 if (!haveEaten)
4114 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004115 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004116 return MatchOperand_ParseFail;
4117 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004118
4119 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004120 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004121
4122 return MatchOperand_Success;
4123}
4124
Tim Northovereb5e4d52013-07-22 09:06:12 +00004125/// Convert parsed operands to MCInst. Needed here because this instruction
4126/// only has two register operands, but multiplication is commutative so
4127/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004128void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004129cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004130 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004131 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4132 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004133 // If we have a three-operand form, make sure to set Rn to be the operand
4134 // that isn't the same as Rd.
4135 unsigned RegOp = 4;
4136 if (Operands.size() == 6 &&
4137 ((ARMOperand*)Operands[4])->getReg() ==
4138 ((ARMOperand*)Operands[3])->getReg())
4139 RegOp = 5;
4140 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4141 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004142 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004143}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004144
Mihai Popaad18d3c2013-08-09 10:38:32 +00004145void ARMAsmParser::
4146cvtThumbBranches(MCInst &Inst,
4147 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4148 int CondOp = -1, ImmOp = -1;
4149 switch(Inst.getOpcode()) {
4150 case ARM::tB:
4151 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4152
4153 case ARM::t2B:
4154 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4155
4156 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4157 }
4158 // first decide whether or not the branch should be conditional
4159 // by looking at it's location relative to an IT block
4160 if(inITBlock()) {
4161 // inside an IT block we cannot have any conditional branches. any
4162 // such instructions needs to be converted to unconditional form
4163 switch(Inst.getOpcode()) {
4164 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4165 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4166 }
4167 } else {
4168 // outside IT blocks we can only have unconditional branches with AL
4169 // condition code or conditional branches with non-AL condition code
4170 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4171 switch(Inst.getOpcode()) {
4172 case ARM::tB:
4173 case ARM::tBcc:
4174 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4175 break;
4176 case ARM::t2B:
4177 case ARM::t2Bcc:
4178 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4179 break;
4180 }
4181 }
4182
4183 // now decide on encoding size based on branch target range
4184 switch(Inst.getOpcode()) {
4185 // classify tB as either t2B or t1B based on range of immediate operand
4186 case ARM::tB: {
4187 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4188 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4189 Inst.setOpcode(ARM::t2B);
4190 break;
4191 }
4192 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4193 case ARM::tBcc: {
4194 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4195 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4196 Inst.setOpcode(ARM::t2Bcc);
4197 break;
4198 }
4199 }
4200 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4201 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4202}
4203
Bill Wendlinge18980a2010-11-06 22:36:58 +00004204/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004205/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004206bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004207parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004208 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004209 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004210 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004211 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004212 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004213
Sean Callanan936b0d32010-01-19 21:44:56 +00004214 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004215 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004216 if (BaseRegNum == -1)
4217 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004218
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004219 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004220 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004221 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4222 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004223 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004224
Jim Grosbachd3595712011-08-03 23:50:40 +00004225 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004226 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004227 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004228
Jim Grosbachd3595712011-08-03 23:50:40 +00004229 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004230 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004231
Jim Grosbach40700e02011-09-19 18:42:21 +00004232 // If there's a pre-indexing writeback marker, '!', just add it as a token
4233 // operand. It's rather odd, but syntactically valid.
4234 if (Parser.getTok().is(AsmToken::Exclaim)) {
4235 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4236 Parser.Lex(); // Eat the '!'.
4237 }
4238
Jim Grosbachd3595712011-08-03 23:50:40 +00004239 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004240 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004241
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004242 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4243 "Lost colon or comma in memory operand?!");
4244 if (Tok.is(AsmToken::Comma)) {
4245 Parser.Lex(); // Eat the comma.
4246 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004247
Jim Grosbacha95ec992011-10-11 17:29:55 +00004248 // If we have a ':', it's an alignment specifier.
4249 if (Parser.getTok().is(AsmToken::Colon)) {
4250 Parser.Lex(); // Eat the ':'.
4251 E = Parser.getTok().getLoc();
4252
4253 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004254 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004255 return true;
4256
4257 // The expression has to be a constant. Memory references with relocations
4258 // don't come through here, as they use the <label> forms of the relevant
4259 // instructions.
4260 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4261 if (!CE)
4262 return Error (E, "constant expression expected");
4263
4264 unsigned Align = 0;
4265 switch (CE->getValue()) {
4266 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004267 return Error(E,
4268 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4269 case 16: Align = 2; break;
4270 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004271 case 64: Align = 8; break;
4272 case 128: Align = 16; break;
4273 case 256: Align = 32; break;
4274 }
4275
4276 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004277 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004278 return Error(Parser.getTok().getLoc(), "']' expected");
4279 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004280 Parser.Lex(); // Eat right bracket token.
4281
4282 // Don't worry about range checking the value here. That's handled by
4283 // the is*() predicates.
4284 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4285 ARM_AM::no_shift, 0, Align,
4286 false, S, E));
4287
4288 // If there's a pre-indexing writeback marker, '!', just add it as a token
4289 // operand.
4290 if (Parser.getTok().is(AsmToken::Exclaim)) {
4291 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4292 Parser.Lex(); // Eat the '!'.
4293 }
4294
4295 return false;
4296 }
4297
4298 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004299 // offset. Be friendly and also accept a plain integer (without a leading
4300 // hash) for gas compatibility.
4301 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004302 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004303 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004304 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004305 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004306 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004307
Owen Anderson967674d2011-08-29 19:36:44 +00004308 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004309 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004310 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004311 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004312
4313 // The expression has to be a constant. Memory references with relocations
4314 // don't come through here, as they use the <label> forms of the relevant
4315 // instructions.
4316 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4317 if (!CE)
4318 return Error (E, "constant expression expected");
4319
Owen Anderson967674d2011-08-29 19:36:44 +00004320 // If the constant was #-0, represent it as INT32_MIN.
4321 int32_t Val = CE->getValue();
4322 if (isNegative && Val == 0)
4323 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4324
Jim Grosbachd3595712011-08-03 23:50:40 +00004325 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004326 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004327 return Error(Parser.getTok().getLoc(), "']' expected");
4328 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004329 Parser.Lex(); // Eat right bracket token.
4330
4331 // Don't worry about range checking the value here. That's handled by
4332 // the is*() predicates.
4333 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004334 ARM_AM::no_shift, 0, 0,
4335 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004336
4337 // If there's a pre-indexing writeback marker, '!', just add it as a token
4338 // operand.
4339 if (Parser.getTok().is(AsmToken::Exclaim)) {
4340 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4341 Parser.Lex(); // Eat the '!'.
4342 }
4343
4344 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004345 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004346
4347 // The register offset is optionally preceded by a '+' or '-'
4348 bool isNegative = false;
4349 if (Parser.getTok().is(AsmToken::Minus)) {
4350 isNegative = true;
4351 Parser.Lex(); // Eat the '-'.
4352 } else if (Parser.getTok().is(AsmToken::Plus)) {
4353 // Nothing to do.
4354 Parser.Lex(); // Eat the '+'.
4355 }
4356
4357 E = Parser.getTok().getLoc();
4358 int OffsetRegNum = tryParseRegister();
4359 if (OffsetRegNum == -1)
4360 return Error(E, "register expected");
4361
4362 // If there's a shift operator, handle it.
4363 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004364 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004365 if (Parser.getTok().is(AsmToken::Comma)) {
4366 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004367 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004368 return true;
4369 }
4370
4371 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004372 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004373 return Error(Parser.getTok().getLoc(), "']' expected");
4374 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004375 Parser.Lex(); // Eat right bracket token.
4376
4377 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004378 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004379 S, E));
4380
Jim Grosbachc320c852011-08-05 21:28:30 +00004381 // If there's a pre-indexing writeback marker, '!', just add it as a token
4382 // operand.
4383 if (Parser.getTok().is(AsmToken::Exclaim)) {
4384 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4385 Parser.Lex(); // Eat the '!'.
4386 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004387
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004388 return false;
4389}
4390
Jim Grosbachd3595712011-08-03 23:50:40 +00004391/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004392/// ( lsl | lsr | asr | ror ) , # shift_amount
4393/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004394/// return true if it parses a shift otherwise it returns false.
4395bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4396 unsigned &Amount) {
4397 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004398 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004399 if (Tok.isNot(AsmToken::Identifier))
4400 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004401 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004402 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4403 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004404 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004405 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004406 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004407 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004408 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004409 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004410 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004411 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004412 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004413 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004414 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004415 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004416
Jim Grosbachd3595712011-08-03 23:50:40 +00004417 // rrx stands alone.
4418 Amount = 0;
4419 if (St != ARM_AM::rrx) {
4420 Loc = Parser.getTok().getLoc();
4421 // A '#' and a shift amount.
4422 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004423 if (HashTok.isNot(AsmToken::Hash) &&
4424 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004425 return Error(HashTok.getLoc(), "'#' expected");
4426 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004427
Jim Grosbachd3595712011-08-03 23:50:40 +00004428 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004429 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004430 return true;
4431 // Range check the immediate.
4432 // lsl, ror: 0 <= imm <= 31
4433 // lsr, asr: 0 <= imm <= 32
4434 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4435 if (!CE)
4436 return Error(Loc, "shift amount must be an immediate");
4437 int64_t Imm = CE->getValue();
4438 if (Imm < 0 ||
4439 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4440 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4441 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004442 // If <ShiftTy> #0, turn it into a no_shift.
4443 if (Imm == 0)
4444 St = ARM_AM::lsl;
4445 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4446 if (Imm == 32)
4447 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004448 Amount = Imm;
4449 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004450
4451 return false;
4452}
4453
Jim Grosbache7fbce72011-10-03 23:38:36 +00004454/// parseFPImm - A floating point immediate expression operand.
4455ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4456parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004457 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004458 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004459 // integer only.
4460 //
4461 // This routine still creates a generic Immediate operand, containing
4462 // a bitcast of the 64-bit floating point value. The various operands
4463 // that accept floats can check whether the value is valid for them
4464 // via the standard is*() predicates.
4465
Jim Grosbache7fbce72011-10-03 23:38:36 +00004466 SMLoc S = Parser.getTok().getLoc();
4467
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004468 if (Parser.getTok().isNot(AsmToken::Hash) &&
4469 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004470 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004471
4472 // Disambiguate the VMOV forms that can accept an FP immediate.
4473 // vmov.f32 <sreg>, #imm
4474 // vmov.f64 <dreg>, #imm
4475 // vmov.f32 <dreg>, #imm @ vector f32x2
4476 // vmov.f32 <qreg>, #imm @ vector f32x4
4477 //
4478 // There are also the NEON VMOV instructions which expect an
4479 // integer constant. Make sure we don't try to parse an FPImm
4480 // for these:
4481 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4482 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4483 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4484 TyOp->getToken() != ".f64"))
4485 return MatchOperand_NoMatch;
4486
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004487 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004488
4489 // Handle negation, as that still comes through as a separate token.
4490 bool isNegative = false;
4491 if (Parser.getTok().is(AsmToken::Minus)) {
4492 isNegative = true;
4493 Parser.Lex();
4494 }
4495 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004496 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004497 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004498 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004499 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4500 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004501 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004502 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004503 Operands.push_back(ARMOperand::CreateImm(
4504 MCConstantExpr::Create(IntVal, getContext()),
4505 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004506 return MatchOperand_Success;
4507 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004508 // Also handle plain integers. Instructions which allow floating point
4509 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004510 if (Tok.is(AsmToken::Integer)) {
4511 int64_t Val = Tok.getIntVal();
4512 Parser.Lex(); // Eat the token.
4513 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004514 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004515 return MatchOperand_ParseFail;
4516 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004517 double RealVal = ARM_AM::getFPImmFloat(Val);
4518 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4519 Operands.push_back(ARMOperand::CreateImm(
4520 MCConstantExpr::Create(Val, getContext()), S,
4521 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004522 return MatchOperand_Success;
4523 }
4524
Jim Grosbach235c8d22012-01-19 02:47:30 +00004525 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004526 return MatchOperand_ParseFail;
4527}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004528
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004529/// Parse a arm instruction operand. For now this parses the operand regardless
4530/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004531bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004532 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004533 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004534
4535 // Check if the current operand has a custom associated parser, if so, try to
4536 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004537 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4538 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004539 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004540 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4541 // there was a match, but an error occurred, in which case, just return that
4542 // the operand parsing failed.
4543 if (ResTy == MatchOperand_ParseFail)
4544 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004545
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004546 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004547 default:
4548 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004549 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004550 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004551 // If we've seen a branch mnemonic, the next operand must be a label. This
4552 // is true even if the label is a register name. So "br r1" means branch to
4553 // label "r1".
4554 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4555 if (!ExpectLabel) {
4556 if (!tryParseRegisterWithWriteBack(Operands))
4557 return false;
4558 int Res = tryParseShiftRegister(Operands);
4559 if (Res == 0) // success
4560 return false;
4561 else if (Res == -1) // irrecoverable error
4562 return true;
4563 // If this is VMRS, check for the apsr_nzcv operand.
4564 if (Mnemonic == "vmrs" &&
4565 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4566 S = Parser.getTok().getLoc();
4567 Parser.Lex();
4568 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4569 return false;
4570 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004571 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004572
4573 // Fall though for the Identifier case that is not a register or a
4574 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004575 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004576 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004577 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004578 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004579 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004580 // This was not a register so parse other operands that start with an
4581 // identifier (like labels) as expressions and create them as immediates.
4582 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004583 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004584 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004585 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004586 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004587 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4588 return false;
4589 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004590 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004591 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004592 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004593 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004594 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004595 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004596 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004597 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004598 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004599
4600 if (Parser.getTok().isNot(AsmToken::Colon)) {
4601 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4602 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004603 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004604 return true;
4605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4606 if (CE) {
4607 int32_t Val = CE->getValue();
4608 if (isNegative && Val == 0)
4609 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4610 }
4611 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4612 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004613
4614 // There can be a trailing '!' on operands that we want as a separate
4615 // '!' Token operand. Handle that here. For example, the compatibilty
4616 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4617 if (Parser.getTok().is(AsmToken::Exclaim)) {
4618 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4619 Parser.getTok().getLoc()));
4620 Parser.Lex(); // Eat exclaim token
4621 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004622 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004623 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004624 // w/ a ':' after the '#', it's just like a plain ':'.
4625 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004626 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004627 case AsmToken::Colon: {
4628 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004629 // FIXME: Check it's an expression prefix,
4630 // e.g. (FOO - :lower16:BAR) isn't legal.
4631 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004632 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004633 return true;
4634
Evan Cheng965b3c72011-01-13 07:58:56 +00004635 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004636 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004637 return true;
4638
Evan Cheng965b3c72011-01-13 07:58:56 +00004639 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004640 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004641 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004642 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004643 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004644 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004645 }
4646}
4647
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004648// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004649// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004650bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004651 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004652
4653 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004654 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004655 Parser.Lex(); // Eat ':'
4656
4657 if (getLexer().isNot(AsmToken::Identifier)) {
4658 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4659 return true;
4660 }
4661
4662 StringRef IDVal = Parser.getTok().getIdentifier();
4663 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004664 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004665 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004666 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004667 } else {
4668 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4669 return true;
4670 }
4671 Parser.Lex();
4672
4673 if (getLexer().isNot(AsmToken::Colon)) {
4674 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4675 return true;
4676 }
4677 Parser.Lex(); // Eat the last ':'
4678 return false;
4679}
4680
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004681/// \brief Given a mnemonic, split out possible predication code and carry
4682/// setting letters to form a canonical mnemonic and flags.
4683//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004684// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004685// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004686StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004687 unsigned &PredicationCode,
4688 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004689 unsigned &ProcessorIMod,
4690 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004691 PredicationCode = ARMCC::AL;
4692 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004693 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004694
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004695 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004696 //
4697 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004698 if ((Mnemonic == "movs" && isThumb()) ||
4699 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4700 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4701 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4702 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004703 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004704 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4705 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004706 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004707 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004708 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4709 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4710 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004711 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004712
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004713 // First, split out any predication code. Ignore mnemonics we know aren't
4714 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004715 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004716 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004717 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004718 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004719 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4720 .Case("eq", ARMCC::EQ)
4721 .Case("ne", ARMCC::NE)
4722 .Case("hs", ARMCC::HS)
4723 .Case("cs", ARMCC::HS)
4724 .Case("lo", ARMCC::LO)
4725 .Case("cc", ARMCC::LO)
4726 .Case("mi", ARMCC::MI)
4727 .Case("pl", ARMCC::PL)
4728 .Case("vs", ARMCC::VS)
4729 .Case("vc", ARMCC::VC)
4730 .Case("hi", ARMCC::HI)
4731 .Case("ls", ARMCC::LS)
4732 .Case("ge", ARMCC::GE)
4733 .Case("lt", ARMCC::LT)
4734 .Case("gt", ARMCC::GT)
4735 .Case("le", ARMCC::LE)
4736 .Case("al", ARMCC::AL)
4737 .Default(~0U);
4738 if (CC != ~0U) {
4739 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4740 PredicationCode = CC;
4741 }
Bill Wendling193961b2010-10-29 23:50:21 +00004742 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004743
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004744 // Next, determine if we have a carry setting bit. We explicitly ignore all
4745 // the instructions we know end in 's'.
4746 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004747 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004748 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4749 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4750 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004751 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004752 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004753 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004754 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004755 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004756 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004757 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4758 CarrySetting = true;
4759 }
4760
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004761 // The "cps" instruction can have a interrupt mode operand which is glued into
4762 // the mnemonic. Check if this is the case, split it and parse the imod op
4763 if (Mnemonic.startswith("cps")) {
4764 // Split out any imod code.
4765 unsigned IMod =
4766 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4767 .Case("ie", ARM_PROC::IE)
4768 .Case("id", ARM_PROC::ID)
4769 .Default(~0U);
4770 if (IMod != ~0U) {
4771 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4772 ProcessorIMod = IMod;
4773 }
4774 }
4775
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004776 // The "it" instruction has the condition mask on the end of the mnemonic.
4777 if (Mnemonic.startswith("it")) {
4778 ITMask = Mnemonic.slice(2, Mnemonic.size());
4779 Mnemonic = Mnemonic.slice(0, 2);
4780 }
4781
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004782 return Mnemonic;
4783}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004784
4785/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4786/// inclusion of carry set or predication code operands.
4787//
4788// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004789void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00004790getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4791 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004792 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4793 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004794 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004795 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004796 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004797 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004798 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004799 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004800 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004801 Mnemonic == "mla" || Mnemonic == "smlal" ||
4802 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004803 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004804 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004805 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004806
Tim Northover2c45a382013-06-26 16:52:40 +00004807 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4808 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Joey Gouly2f8890e2013-09-18 09:45:55 +00004809 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004810 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4811 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004812 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4813 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00004814 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4815 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4816 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00004817 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004818 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004819 } else if (!isThumb()) {
4820 // Some instructions are only predicable in Thumb mode
4821 CanAcceptPredicationCode
4822 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4823 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4824 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4825 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4826 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4827 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4828 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4829 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00004830 if (hasV6MOps())
4831 CanAcceptPredicationCode = Mnemonic != "movs";
4832 else
4833 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004834 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004835 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004836}
4837
Jim Grosbach7283da92011-08-16 21:12:37 +00004838bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4839 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004840 // FIXME: This is all horribly hacky. We really need a better way to deal
4841 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004842
4843 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4844 // another does not. Specifically, the MOVW instruction does not. So we
4845 // special case it here and remove the defaulted (non-setting) cc_out
4846 // operand if that's the instruction we're trying to match.
4847 //
4848 // We do this as post-processing of the explicit operands rather than just
4849 // conditionally adding the cc_out in the first place because we need
4850 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004851 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004852 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4853 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4854 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4855 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004856
4857 // Register-register 'add' for thumb does not have a cc_out operand
4858 // when there are only two register operands.
4859 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4860 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4861 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4862 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4863 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004864 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004865 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4866 // have to check the immediate range here since Thumb2 has a variant
4867 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004868 if (((isThumb() && Mnemonic == "add") ||
4869 (isThumbTwo() && Mnemonic == "sub")) &&
4870 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004871 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4872 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4873 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004874 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004875 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004876 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004877 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004878 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4879 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004880 // selecting via the generic "add" mnemonic, so to know that we
4881 // should remove the cc_out operand, we have to explicitly check that
4882 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004883 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4884 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004885 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4886 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4887 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4888 // Nest conditions rather than one big 'if' statement for readability.
4889 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004890 // If both registers are low, we're in an IT block, and the immediate is
4891 // in range, we should use encoding T1 instead, which has a cc_out.
4892 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004893 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004894 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4895 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4896 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004897 // Check against T3. If the second register is the PC, this is an
4898 // alternate form of ADR, which uses encoding T4, so check for that too.
4899 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4900 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4901 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004902
4903 // Otherwise, we use encoding T4, which does not have a cc_out
4904 // operand.
4905 return true;
4906 }
4907
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004908 // The thumb2 multiply instruction doesn't have a CCOut register, so
4909 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4910 // use the 16-bit encoding or not.
4911 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4912 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4913 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4914 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4915 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4916 // If the registers aren't low regs, the destination reg isn't the
4917 // same as one of the source regs, or the cc_out operand is zero
4918 // outside of an IT block, we have to use the 32-bit encoding, so
4919 // remove the cc_out operand.
4920 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4921 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004922 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004923 !inITBlock() ||
4924 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4925 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4926 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4927 static_cast<ARMOperand*>(Operands[4])->getReg())))
4928 return true;
4929
Jim Grosbachefa7e952011-11-15 19:55:16 +00004930 // Also check the 'mul' syntax variant that doesn't specify an explicit
4931 // destination register.
4932 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4933 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4934 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4935 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4936 // If the registers aren't low regs or the cc_out operand is zero
4937 // outside of an IT block, we have to use the 32-bit encoding, so
4938 // remove the cc_out operand.
4939 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4940 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4941 !inITBlock()))
4942 return true;
4943
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004944
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004945
Jim Grosbach4b701af2011-08-24 21:42:27 +00004946 // Register-register 'add/sub' for thumb does not have a cc_out operand
4947 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4948 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4949 // right, this will result in better diagnostics (which operand is off)
4950 // anyway.
4951 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4952 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004953 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4954 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004955 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4956 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4957 (Operands.size() == 6 &&
4958 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004959 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004960
Jim Grosbach7283da92011-08-16 21:12:37 +00004961 return false;
4962}
4963
Joey Goulye8602552013-07-19 16:34:16 +00004964bool ARMAsmParser::shouldOmitPredicateOperand(
4965 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4966 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4967 unsigned RegIdx = 3;
4968 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4969 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4970 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4971 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4972 RegIdx = 4;
4973
4974 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4975 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4976 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4977 ARMMCRegisterClasses[ARM::QPRRegClassID]
4978 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4979 return true;
4980 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004981 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004982}
4983
Jim Grosbach12952fe2011-11-11 23:08:10 +00004984static bool isDataTypeToken(StringRef Tok) {
4985 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4986 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4987 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4988 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4989 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4990 Tok == ".f" || Tok == ".d";
4991}
4992
4993// FIXME: This bit should probably be handled via an explicit match class
4994// in the .td files that matches the suffix instead of having it be
4995// a literal string token the way it is now.
4996static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4997 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4998}
Chad Rosier9f7a2212013-04-18 22:35:36 +00004999static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5000 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005001/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005002bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5003 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005004 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00005005 // Apply mnemonic aliases before doing anything else, as the destination
5006 // mnemnonic may include suffices and we want to handle them normally.
5007 // The generic tblgen'erated code does this later, at the start of
5008 // MatchInstructionImpl(), but that's too late for aliases that include
5009 // any sort of suffix.
5010 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005011 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5012 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005013
Jim Grosbachab5830e2011-12-14 02:16:11 +00005014 // First check for the ARM-specific .req directive.
5015 if (Parser.getTok().is(AsmToken::Identifier) &&
5016 Parser.getTok().getIdentifier() == ".req") {
5017 parseDirectiveReq(Name, NameLoc);
5018 // We always return 'error' for this, as we're done with this
5019 // statement and don't need to match the 'instruction."
5020 return true;
5021 }
5022
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005023 // Create the leading tokens for the mnemonic, split by '.' characters.
5024 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005025 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005026
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005027 // Split out the predication code and carry setting flag from the mnemonic.
5028 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005029 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005030 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005031 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005032 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005033 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005034
Jim Grosbach1c171b12011-08-25 17:23:55 +00005035 // In Thumb1, only the branch (B) instruction can be predicated.
5036 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005037 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005038 return Error(NameLoc, "conditional execution not supported in Thumb1");
5039 }
5040
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005041 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5042
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005043 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5044 // is the mask as it will be for the IT encoding if the conditional
5045 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5046 // where the conditional bit0 is zero, the instruction post-processing
5047 // will adjust the mask accordingly.
5048 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005049 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5050 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005051 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005052 return Error(Loc, "too many conditions on IT instruction");
5053 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005054 unsigned Mask = 8;
5055 for (unsigned i = ITMask.size(); i != 0; --i) {
5056 char pos = ITMask[i - 1];
5057 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005058 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005059 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005060 }
5061 Mask >>= 1;
5062 if (ITMask[i - 1] == 't')
5063 Mask |= 8;
5064 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005065 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005066 }
5067
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005068 // FIXME: This is all a pretty gross hack. We should automatically handle
5069 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005070
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005071 // Next, add the CCOut and ConditionCode operands, if needed.
5072 //
5073 // For mnemonics which can ever incorporate a carry setting bit or predication
5074 // code, our matching model involves us always generating CCOut and
5075 // ConditionCode operands to match the mnemonic "as written" and then we let
5076 // the matcher deal with finding the right instruction or generating an
5077 // appropriate error.
5078 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005079 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005080
Jim Grosbach03a8a162011-07-14 22:04:21 +00005081 // If we had a carry-set on an instruction that can't do that, issue an
5082 // error.
5083 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005084 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005085 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005086 "' can not set flags, but 's' suffix specified");
5087 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005088 // If we had a predication code on an instruction that can't do that, issue an
5089 // error.
5090 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005091 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005092 return Error(NameLoc, "instruction '" + Mnemonic +
5093 "' is not predicable, but condition code specified");
5094 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005095
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005096 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005097 if (CanAcceptCarrySet) {
5098 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005099 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005100 Loc));
5101 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005102
5103 // Add the predication code operand, if necessary.
5104 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005105 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5106 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005107 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005108 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005109 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005110
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005111 // Add the processor imod operand, if necessary.
5112 if (ProcessorIMod) {
5113 Operands.push_back(ARMOperand::CreateImm(
5114 MCConstantExpr::Create(ProcessorIMod, getContext()),
5115 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005116 }
5117
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005118 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005119 while (Next != StringRef::npos) {
5120 Start = Next;
5121 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005122 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005123
Jim Grosbach12952fe2011-11-11 23:08:10 +00005124 // Some NEON instructions have an optional datatype suffix that is
5125 // completely ignored. Check for that.
5126 if (isDataTypeToken(ExtraToken) &&
5127 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5128 continue;
5129
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005130 // For for ARM mode generate an error if the .n qualifier is used.
5131 if (ExtraToken == ".n" && !isThumb()) {
5132 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5133 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5134 "arm mode");
5135 }
5136
5137 // The .n qualifier is always discarded as that is what the tables
5138 // and matcher expect. In ARM mode the .w qualifier has no effect,
5139 // so discard it to avoid errors that can be caused by the matcher.
5140 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005141 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5142 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5143 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005144 }
5145
5146 // Read the remaining operands.
5147 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005148 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005149 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005150 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005151 return true;
5152 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005153
5154 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005155 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005156
5157 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005158 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005159 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005160 return true;
5161 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005162 }
5163 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005164
Chris Lattnera2a9d162010-09-11 16:18:25 +00005165 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005166 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005167 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005168 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005169 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005170
Chris Lattner91689c12010-09-08 05:10:46 +00005171 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005172
Jim Grosbach7283da92011-08-16 21:12:37 +00005173 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5174 // do and don't have a cc_out optional-def operand. With some spot-checks
5175 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005176 // parse and adjust accordingly before actually matching. We shouldn't ever
5177 // try to remove a cc_out operand that was explicitly set on the the
5178 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5179 // table driven matcher doesn't fit well with the ARM instruction set.
5180 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005181 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5182 Operands.erase(Operands.begin() + 1);
5183 delete Op;
5184 }
5185
Joey Goulye8602552013-07-19 16:34:16 +00005186 // Some instructions have the same mnemonic, but don't always
5187 // have a predicate. Distinguish them here and delete the
5188 // predicate if needed.
5189 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5190 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5191 Operands.erase(Operands.begin() + 1);
5192 delete Op;
5193 }
5194
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005195 // ARM mode 'blx' need special handling, as the register operand version
5196 // is predicable, but the label operand version is not. So, we can't rely
5197 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005198 // a k_CondCode operand in the list. If we're trying to match the label
5199 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005200 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5201 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5202 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5203 Operands.erase(Operands.begin() + 1);
5204 delete Op;
5205 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005206
Weiming Zhao8f56f882012-11-16 21:55:34 +00005207 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5208 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5209 // a single GPRPair reg operand is used in the .td file to replace the two
5210 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5211 // expressed as a GPRPair, so we have to manually merge them.
5212 // FIXME: We would really like to be able to tablegen'erate this.
5213 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005214 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5215 Mnemonic == "stlexd")) {
5216 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005217 unsigned Idx = isLoad ? 2 : 3;
5218 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5219 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5220
5221 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5222 // Adjust only if Op1 and Op2 are GPRs.
5223 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5224 MRC.contains(Op2->getReg())) {
5225 unsigned Reg1 = Op1->getReg();
5226 unsigned Reg2 = Op2->getReg();
5227 unsigned Rt = MRI->getEncodingValue(Reg1);
5228 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5229
5230 // Rt2 must be Rt + 1 and Rt must be even.
5231 if (Rt + 1 != Rt2 || (Rt & 1)) {
5232 Error(Op2->getStartLoc(), isLoad ?
5233 "destination operands must be sequential" :
5234 "source operands must be sequential");
5235 return true;
5236 }
5237 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5238 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5239 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5240 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5241 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5242 delete Op1;
5243 delete Op2;
5244 }
5245 }
5246
Kevin Enderby78f95722013-07-31 21:05:30 +00005247 // FIXME: As said above, this is all a pretty gross hack. This instruction
5248 // does not fit with other "subs" and tblgen.
5249 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5250 // so the Mnemonic is the original name "subs" and delete the predicate
5251 // operand so it will match the table entry.
5252 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5253 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5254 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5255 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5256 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5257 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5258 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5259 Operands.erase(Operands.begin());
5260 delete Op0;
5261 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5262
5263 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5264 Operands.erase(Operands.begin() + 1);
5265 delete Op1;
5266 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005267 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005268}
5269
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005270// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005271
5272// return 'true' if register list contains non-low GPR registers,
5273// 'false' otherwise. If Reg is in the register list or is HiReg, set
5274// 'containsReg' to true.
5275static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5276 unsigned HiReg, bool &containsReg) {
5277 containsReg = false;
5278 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5279 unsigned OpReg = Inst.getOperand(i).getReg();
5280 if (OpReg == Reg)
5281 containsReg = true;
5282 // Anything other than a low register isn't legal here.
5283 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5284 return true;
5285 }
5286 return false;
5287}
5288
Jim Grosbacha31f2232011-09-07 18:05:34 +00005289// Check if the specified regisgter is in the register list of the inst,
5290// starting at the indicated operand number.
5291static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5292 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5293 unsigned OpReg = Inst.getOperand(i).getReg();
5294 if (OpReg == Reg)
5295 return true;
5296 }
5297 return false;
5298}
5299
Richard Barton8d519fe2013-09-05 14:14:19 +00005300// Return true if instruction has the interesting property of being
5301// allowed in IT blocks, but not being predicable.
5302static bool instIsBreakpoint(const MCInst &Inst) {
5303 return Inst.getOpcode() == ARM::tBKPT ||
5304 Inst.getOpcode() == ARM::BKPT ||
5305 Inst.getOpcode() == ARM::tHLT ||
5306 Inst.getOpcode() == ARM::HLT;
5307
5308}
5309
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005310// FIXME: We would really like to be able to tablegen'erate this.
5311bool ARMAsmParser::
5312validateInstruction(MCInst &Inst,
5313 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005314 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005315 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005316
Jim Grosbached16ec42011-08-29 22:24:09 +00005317 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005318 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005319 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005320 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005321 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005322 if (ITState.FirstCond)
5323 ITState.FirstCond = false;
5324 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005325 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005326 // The instruction must be predicable.
5327 if (!MCID.isPredicable())
5328 return Error(Loc, "instructions in IT block must be predicable");
5329 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005330 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005331 ARMCC::getOppositeCondition(ITState.Cond);
5332 if (Cond != ITCond) {
5333 // Find the condition code Operand to get its SMLoc information.
5334 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005335 for (unsigned I = 1; I < Operands.size(); ++I)
5336 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5337 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005338 return Error(CondLoc, "incorrect condition in IT block; got '" +
5339 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5340 "', but expected '" +
5341 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5342 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005343 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005344 } else if (isThumbTwo() && MCID.isPredicable() &&
5345 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005346 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5347 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005348 return Error(Loc, "predicated instructions must be in IT block");
5349
Tilmann Scheller255722b2013-09-30 16:11:48 +00005350 const unsigned Opcode = Inst.getOpcode();
5351 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005352 case ARM::LDRD:
5353 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005354 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005355 const unsigned RtReg = Inst.getOperand(0).getReg();
5356
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005357 // Rt can't be R14.
5358 if (RtReg == ARM::LR)
5359 return Error(Operands[3]->getStartLoc(),
5360 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005361
5362 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005363 // Rt must be even-numbered.
5364 if ((Rt & 1) == 1)
5365 return Error(Operands[3]->getStartLoc(),
5366 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005367
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005368 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005369 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005370 if (Rt2 != Rt + 1)
5371 return Error(Operands[3]->getStartLoc(),
5372 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005373
5374 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5375 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5376 // For addressing modes with writeback, the base register needs to be
5377 // different from the destination registers.
5378 if (Rn == Rt || Rn == Rt2)
5379 return Error(Operands[3]->getStartLoc(),
5380 "base register needs to be different from destination "
5381 "registers");
5382 }
5383
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005384 return false;
5385 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005386 case ARM::t2LDRDi8:
5387 case ARM::t2LDRD_PRE:
5388 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005389 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005390 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5391 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5392 if (Rt2 == Rt)
5393 return Error(Operands[3]->getStartLoc(),
5394 "destination operands can't be identical");
5395 return false;
5396 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005397 case ARM::STRD: {
5398 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005399 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5400 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005401 if (Rt2 != Rt + 1)
5402 return Error(Operands[3]->getStartLoc(),
5403 "source operands must be sequential");
5404 return false;
5405 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005406 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005407 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005408 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005409 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5410 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005411 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005412 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005413 "source operands must be sequential");
5414 return false;
5415 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005416 case ARM::SBFX:
5417 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005418 // Width must be in range [1, 32-lsb].
5419 unsigned LSB = Inst.getOperand(2).getImm();
5420 unsigned Widthm1 = Inst.getOperand(3).getImm();
5421 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005422 return Error(Operands[5]->getStartLoc(),
5423 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005424 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005425 }
Tim Northover08a86602013-10-22 19:00:39 +00005426 // Notionally handles ARM::tLDMIA_UPD too.
Jim Grosbach90103cc2011-08-18 21:50:53 +00005427 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005428 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005429 // most cases that are normally illegal for a Thumb1 LDM instruction.
5430 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005431 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005432 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005433 // in the register list.
5434 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005435 bool HasWritebackToken =
Jim Grosbach139acd22011-08-22 23:01:07 +00005436 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5437 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005438 bool ListContainsBase;
5439 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5440 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005441 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005442 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005443 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005444 return Error(Operands[2]->getStartLoc(),
5445 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005446 // If we should not have writeback, there must not be a '!'. This is
5447 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005448 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005449 return Error(Operands[3]->getStartLoc(),
5450 "writeback operator '!' not allowed when base register "
5451 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005452
5453 break;
5454 }
Tim Northover08a86602013-10-22 19:00:39 +00005455 case ARM::LDMIA_UPD:
5456 case ARM::LDMDB_UPD:
5457 case ARM::LDMIB_UPD:
5458 case ARM::LDMDA_UPD:
5459 // ARM variants loading and updating the same register are only officially
5460 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5461 if (!hasV7Ops())
5462 break;
5463 // Fallthrough
5464 case ARM::t2LDMIA_UPD:
5465 case ARM::t2LDMDB_UPD:
5466 case ARM::t2STMIA_UPD:
5467 case ARM::t2STMDB_UPD: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005468 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5469 return Error(Operands[4]->getStartLoc(),
5470 "writeback operator '!' not allowed when base register "
5471 "in register list");
5472 break;
5473 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005474 case ARM::tMUL: {
5475 // The second source operand must be the same register as the destination
5476 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005477 //
5478 // In this case, we must directly check the parsed operands because the
5479 // cvtThumbMultiply() function is written in such a way that it guarantees
5480 // this first statement is always true for the new Inst. Essentially, the
5481 // destination is unconditionally copied into the second source operand
5482 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005483 if (Operands.size() == 6 &&
5484 (((ARMOperand*)Operands[3])->getReg() !=
5485 ((ARMOperand*)Operands[5])->getReg()) &&
5486 (((ARMOperand*)Operands[3])->getReg() !=
5487 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005488 return Error(Operands[3]->getStartLoc(),
5489 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005490 }
5491 break;
5492 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005493 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5494 // so only issue a diagnostic for thumb1. The instructions will be
5495 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005496 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005497 bool ListContainsBase;
5498 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005499 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005500 return Error(Operands[2]->getStartLoc(),
5501 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005502 break;
5503 }
5504 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005505 bool ListContainsBase;
5506 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005507 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005508 return Error(Operands[2]->getStartLoc(),
5509 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005510 break;
5511 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005512 case ARM::tSTMIA_UPD: {
Tim Northover08a86602013-10-22 19:00:39 +00005513 bool ListContainsBase, InvalidLowList;
5514 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5515 0, ListContainsBase);
5516 if (InvalidLowList && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005517 return Error(Operands[4]->getStartLoc(),
5518 "registers must be in range r0-r7");
Tim Northover08a86602013-10-22 19:00:39 +00005519
5520 // This would be converted to a 32-bit stm, but that's not valid if the
5521 // writeback register is in the list.
5522 if (InvalidLowList && ListContainsBase)
5523 return Error(Operands[4]->getStartLoc(),
5524 "writeback operator '!' not allowed when base register "
5525 "in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00005526 break;
5527 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005528 case ARM::tADDrSP: {
5529 // If the non-SP source operand and the destination operand are not the
5530 // same, we need thumb2 (for the wide encoding), or we have an error.
5531 if (!isThumbTwo() &&
5532 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5533 return Error(Operands[4]->getStartLoc(),
5534 "source register must be the same as destination");
5535 }
5536 break;
5537 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005538 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005539 case ARM::tB:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005540 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5541 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005542 break;
5543 case ARM::t2B: {
5544 int op = (Operands[2]->isImm()) ? 2 : 3;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005545 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5546 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005547 break;
5548 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005549 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005550 case ARM::tBcc:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005551 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5552 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005553 break;
5554 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005555 int Op = (Operands[2]->isImm()) ? 2 : 3;
5556 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5557 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005558 break;
5559 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005560 }
5561
5562 return false;
5563}
5564
Jim Grosbach1a747242012-01-23 23:45:44 +00005565static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005566 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005567 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005568 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005569 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5570 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5571 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5572 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5573 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5574 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5575 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5576 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5577 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005578
5579 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005580 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5581 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5582 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5583 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5584 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005585
Jim Grosbach1e946a42012-01-24 00:43:12 +00005586 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5587 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5588 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5589 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5590 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005591
Jim Grosbach1e946a42012-01-24 00:43:12 +00005592 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5593 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5594 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5595 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5596 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005597
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005598 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005599 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5600 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5601 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5602 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5603 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5604 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5605 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5606 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5607 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5608 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5609 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5610 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5611 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5612 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5613 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005614
Jim Grosbach1a747242012-01-23 23:45:44 +00005615 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005616 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5617 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5618 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5619 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5620 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5621 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5622 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5623 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5624 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5625 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5626 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5627 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5628 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5629 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5630 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5631 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5632 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5633 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005634
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005635 // VST4LN
5636 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5637 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5638 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5639 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5640 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5641 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5642 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5643 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5644 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5645 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5646 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5647 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5648 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5649 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5650 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5651
Jim Grosbachda70eac2012-01-24 00:58:13 +00005652 // VST4
5653 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5654 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5655 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5656 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5657 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5658 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5659 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5660 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5661 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5662 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5663 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5664 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5665 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5666 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5667 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5668 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5669 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5670 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005671 }
5672}
5673
Jim Grosbach1a747242012-01-23 23:45:44 +00005674static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005675 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005676 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005677 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005678 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5679 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5680 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5681 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5682 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5683 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5684 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5685 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5686 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005687
5688 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005689 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5690 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5691 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5692 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5693 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5694 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5695 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5696 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5697 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5698 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5699 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5700 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5701 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5702 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5703 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005704
Jim Grosbachb78403c2012-01-24 23:47:04 +00005705 // VLD3DUP
5706 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5707 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5708 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5709 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5710 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5711 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5712 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5713 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5714 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5715 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5716 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5717 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5718 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5719 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5720 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5721 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5722 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5723 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5724
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005725 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005726 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5727 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5728 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5729 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5730 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5731 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5732 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5733 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5734 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5735 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5736 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5737 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5738 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5739 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5740 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005741
5742 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005743 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5744 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5745 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5746 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5747 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5748 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5749 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5750 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5751 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5752 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5753 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5754 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5755 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5756 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5757 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5758 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5759 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5760 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005761
Jim Grosbach14952a02012-01-24 18:37:25 +00005762 // VLD4LN
5763 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5764 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5765 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5766 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5767 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5768 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5769 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5770 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5771 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5772 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5773 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5774 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5775 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5776 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5777 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5778
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005779 // VLD4DUP
5780 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5781 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5782 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5783 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5784 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5785 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5786 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5787 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5788 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5789 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5790 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5791 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5792 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5793 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5794 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5795 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5796 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5797 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5798
Jim Grosbached561fc2012-01-24 00:43:17 +00005799 // VLD4
5800 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5801 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5802 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5803 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5804 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5805 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5806 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5807 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5808 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5809 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5810 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5811 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5812 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5813 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5814 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5815 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5816 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5817 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005818 }
5819}
5820
Jim Grosbachafad0532011-11-10 23:42:14 +00005821bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005822processInstruction(MCInst &Inst,
5823 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5824 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005825 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5826 case ARM::ADDri: {
5827 if (Inst.getOperand(1).getReg() != ARM::PC ||
5828 Inst.getOperand(5).getReg() != 0)
5829 return false;
5830 MCInst TmpInst;
5831 TmpInst.setOpcode(ARM::ADR);
5832 TmpInst.addOperand(Inst.getOperand(0));
5833 TmpInst.addOperand(Inst.getOperand(2));
5834 TmpInst.addOperand(Inst.getOperand(3));
5835 TmpInst.addOperand(Inst.getOperand(4));
5836 Inst = TmpInst;
5837 return true;
5838 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005839 // Aliases for alternate PC+imm syntax of LDR instructions.
5840 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005841 // Select the narrow version if the immediate will fit.
5842 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005843 Inst.getOperand(1).getImm() <= 0xff &&
5844 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5845 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005846 Inst.setOpcode(ARM::tLDRpci);
5847 else
5848 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005849 return true;
5850 case ARM::t2LDRBpcrel:
5851 Inst.setOpcode(ARM::t2LDRBpci);
5852 return true;
5853 case ARM::t2LDRHpcrel:
5854 Inst.setOpcode(ARM::t2LDRHpci);
5855 return true;
5856 case ARM::t2LDRSBpcrel:
5857 Inst.setOpcode(ARM::t2LDRSBpci);
5858 return true;
5859 case ARM::t2LDRSHpcrel:
5860 Inst.setOpcode(ARM::t2LDRSHpci);
5861 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005862 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005863 case ARM::VST1LNdWB_register_Asm_8:
5864 case ARM::VST1LNdWB_register_Asm_16:
5865 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005866 MCInst TmpInst;
5867 // Shuffle the operands around so the lane index operand is in the
5868 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005869 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005870 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005871 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5872 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5873 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5874 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5875 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5876 TmpInst.addOperand(Inst.getOperand(1)); // lane
5877 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5878 TmpInst.addOperand(Inst.getOperand(6));
5879 Inst = TmpInst;
5880 return true;
5881 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005882
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005883 case ARM::VST2LNdWB_register_Asm_8:
5884 case ARM::VST2LNdWB_register_Asm_16:
5885 case ARM::VST2LNdWB_register_Asm_32:
5886 case ARM::VST2LNqWB_register_Asm_16:
5887 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005888 MCInst TmpInst;
5889 // Shuffle the operands around so the lane index operand is in the
5890 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005891 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005892 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005893 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5894 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5895 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5896 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5897 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005898 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5899 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005900 TmpInst.addOperand(Inst.getOperand(1)); // lane
5901 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5902 TmpInst.addOperand(Inst.getOperand(6));
5903 Inst = TmpInst;
5904 return true;
5905 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005906
5907 case ARM::VST3LNdWB_register_Asm_8:
5908 case ARM::VST3LNdWB_register_Asm_16:
5909 case ARM::VST3LNdWB_register_Asm_32:
5910 case ARM::VST3LNqWB_register_Asm_16:
5911 case ARM::VST3LNqWB_register_Asm_32: {
5912 MCInst TmpInst;
5913 // Shuffle the operands around so the lane index operand is in the
5914 // right place.
5915 unsigned Spacing;
5916 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5917 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5918 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5919 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5920 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5921 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5922 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5923 Spacing));
5924 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5925 Spacing * 2));
5926 TmpInst.addOperand(Inst.getOperand(1)); // lane
5927 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5928 TmpInst.addOperand(Inst.getOperand(6));
5929 Inst = TmpInst;
5930 return true;
5931 }
5932
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005933 case ARM::VST4LNdWB_register_Asm_8:
5934 case ARM::VST4LNdWB_register_Asm_16:
5935 case ARM::VST4LNdWB_register_Asm_32:
5936 case ARM::VST4LNqWB_register_Asm_16:
5937 case ARM::VST4LNqWB_register_Asm_32: {
5938 MCInst TmpInst;
5939 // Shuffle the operands around so the lane index operand is in the
5940 // right place.
5941 unsigned Spacing;
5942 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5943 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5944 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5945 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5946 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5947 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5948 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5949 Spacing));
5950 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5951 Spacing * 2));
5952 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5953 Spacing * 3));
5954 TmpInst.addOperand(Inst.getOperand(1)); // lane
5955 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5956 TmpInst.addOperand(Inst.getOperand(6));
5957 Inst = TmpInst;
5958 return true;
5959 }
5960
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005961 case ARM::VST1LNdWB_fixed_Asm_8:
5962 case ARM::VST1LNdWB_fixed_Asm_16:
5963 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005964 MCInst TmpInst;
5965 // Shuffle the operands around so the lane index operand is in the
5966 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005967 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005968 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005969 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5970 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5971 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5972 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5973 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5974 TmpInst.addOperand(Inst.getOperand(1)); // lane
5975 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5976 TmpInst.addOperand(Inst.getOperand(5));
5977 Inst = TmpInst;
5978 return true;
5979 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005980
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005981 case ARM::VST2LNdWB_fixed_Asm_8:
5982 case ARM::VST2LNdWB_fixed_Asm_16:
5983 case ARM::VST2LNdWB_fixed_Asm_32:
5984 case ARM::VST2LNqWB_fixed_Asm_16:
5985 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005986 MCInst TmpInst;
5987 // Shuffle the operands around so the lane index operand is in the
5988 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005989 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005990 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005991 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5992 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5993 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5994 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5995 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005996 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5997 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005998 TmpInst.addOperand(Inst.getOperand(1)); // lane
5999 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6000 TmpInst.addOperand(Inst.getOperand(5));
6001 Inst = TmpInst;
6002 return true;
6003 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006004
6005 case ARM::VST3LNdWB_fixed_Asm_8:
6006 case ARM::VST3LNdWB_fixed_Asm_16:
6007 case ARM::VST3LNdWB_fixed_Asm_32:
6008 case ARM::VST3LNqWB_fixed_Asm_16:
6009 case ARM::VST3LNqWB_fixed_Asm_32: {
6010 MCInst TmpInst;
6011 // Shuffle the operands around so the lane index operand is in the
6012 // right place.
6013 unsigned Spacing;
6014 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6015 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6016 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6017 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6018 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6019 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6020 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6021 Spacing));
6022 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6023 Spacing * 2));
6024 TmpInst.addOperand(Inst.getOperand(1)); // lane
6025 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6026 TmpInst.addOperand(Inst.getOperand(5));
6027 Inst = TmpInst;
6028 return true;
6029 }
6030
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006031 case ARM::VST4LNdWB_fixed_Asm_8:
6032 case ARM::VST4LNdWB_fixed_Asm_16:
6033 case ARM::VST4LNdWB_fixed_Asm_32:
6034 case ARM::VST4LNqWB_fixed_Asm_16:
6035 case ARM::VST4LNqWB_fixed_Asm_32: {
6036 MCInst TmpInst;
6037 // Shuffle the operands around so the lane index operand is in the
6038 // right place.
6039 unsigned Spacing;
6040 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6041 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6042 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6043 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6044 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6045 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6046 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6047 Spacing));
6048 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6049 Spacing * 2));
6050 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6051 Spacing * 3));
6052 TmpInst.addOperand(Inst.getOperand(1)); // lane
6053 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6054 TmpInst.addOperand(Inst.getOperand(5));
6055 Inst = TmpInst;
6056 return true;
6057 }
6058
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006059 case ARM::VST1LNdAsm_8:
6060 case ARM::VST1LNdAsm_16:
6061 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006062 MCInst TmpInst;
6063 // Shuffle the operands around so the lane index operand is in the
6064 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006065 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006066 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006067 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6068 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6069 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6070 TmpInst.addOperand(Inst.getOperand(1)); // lane
6071 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6072 TmpInst.addOperand(Inst.getOperand(5));
6073 Inst = TmpInst;
6074 return true;
6075 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006076
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006077 case ARM::VST2LNdAsm_8:
6078 case ARM::VST2LNdAsm_16:
6079 case ARM::VST2LNdAsm_32:
6080 case ARM::VST2LNqAsm_16:
6081 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006082 MCInst TmpInst;
6083 // Shuffle the operands around so the lane index operand is in the
6084 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006085 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006086 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006087 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6088 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6089 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006090 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6091 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006092 TmpInst.addOperand(Inst.getOperand(1)); // lane
6093 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6094 TmpInst.addOperand(Inst.getOperand(5));
6095 Inst = TmpInst;
6096 return true;
6097 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006098
6099 case ARM::VST3LNdAsm_8:
6100 case ARM::VST3LNdAsm_16:
6101 case ARM::VST3LNdAsm_32:
6102 case ARM::VST3LNqAsm_16:
6103 case ARM::VST3LNqAsm_32: {
6104 MCInst TmpInst;
6105 // Shuffle the operands around so the lane index operand is in the
6106 // right place.
6107 unsigned Spacing;
6108 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6109 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6110 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6111 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6112 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6113 Spacing));
6114 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6115 Spacing * 2));
6116 TmpInst.addOperand(Inst.getOperand(1)); // lane
6117 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6118 TmpInst.addOperand(Inst.getOperand(5));
6119 Inst = TmpInst;
6120 return true;
6121 }
6122
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006123 case ARM::VST4LNdAsm_8:
6124 case ARM::VST4LNdAsm_16:
6125 case ARM::VST4LNdAsm_32:
6126 case ARM::VST4LNqAsm_16:
6127 case ARM::VST4LNqAsm_32: {
6128 MCInst TmpInst;
6129 // Shuffle the operands around so the lane index operand is in the
6130 // right place.
6131 unsigned Spacing;
6132 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6133 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6134 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6135 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6136 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6137 Spacing));
6138 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6139 Spacing * 2));
6140 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6141 Spacing * 3));
6142 TmpInst.addOperand(Inst.getOperand(1)); // lane
6143 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6144 TmpInst.addOperand(Inst.getOperand(5));
6145 Inst = TmpInst;
6146 return true;
6147 }
6148
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006149 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006150 case ARM::VLD1LNdWB_register_Asm_8:
6151 case ARM::VLD1LNdWB_register_Asm_16:
6152 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006153 MCInst TmpInst;
6154 // Shuffle the operands around so the lane index operand is in the
6155 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006156 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006157 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006158 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6159 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6160 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6161 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6162 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6163 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6164 TmpInst.addOperand(Inst.getOperand(1)); // lane
6165 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6166 TmpInst.addOperand(Inst.getOperand(6));
6167 Inst = TmpInst;
6168 return true;
6169 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006170
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006171 case ARM::VLD2LNdWB_register_Asm_8:
6172 case ARM::VLD2LNdWB_register_Asm_16:
6173 case ARM::VLD2LNdWB_register_Asm_32:
6174 case ARM::VLD2LNqWB_register_Asm_16:
6175 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006176 MCInst TmpInst;
6177 // Shuffle the operands around so the lane index operand is in the
6178 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006179 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006180 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006181 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006182 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6183 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006184 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6185 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6186 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6187 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6188 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006189 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6190 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006191 TmpInst.addOperand(Inst.getOperand(1)); // lane
6192 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6193 TmpInst.addOperand(Inst.getOperand(6));
6194 Inst = TmpInst;
6195 return true;
6196 }
6197
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006198 case ARM::VLD3LNdWB_register_Asm_8:
6199 case ARM::VLD3LNdWB_register_Asm_16:
6200 case ARM::VLD3LNdWB_register_Asm_32:
6201 case ARM::VLD3LNqWB_register_Asm_16:
6202 case ARM::VLD3LNqWB_register_Asm_32: {
6203 MCInst TmpInst;
6204 // Shuffle the operands around so the lane index operand is in the
6205 // right place.
6206 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006207 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006208 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6209 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6210 Spacing));
6211 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006212 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006213 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6214 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6215 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6216 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6217 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6218 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6219 Spacing));
6220 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006221 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006222 TmpInst.addOperand(Inst.getOperand(1)); // lane
6223 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6224 TmpInst.addOperand(Inst.getOperand(6));
6225 Inst = TmpInst;
6226 return true;
6227 }
6228
Jim Grosbach14952a02012-01-24 18:37:25 +00006229 case ARM::VLD4LNdWB_register_Asm_8:
6230 case ARM::VLD4LNdWB_register_Asm_16:
6231 case ARM::VLD4LNdWB_register_Asm_32:
6232 case ARM::VLD4LNqWB_register_Asm_16:
6233 case ARM::VLD4LNqWB_register_Asm_32: {
6234 MCInst TmpInst;
6235 // Shuffle the operands around so the lane index operand is in the
6236 // right place.
6237 unsigned Spacing;
6238 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6239 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6240 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6241 Spacing));
6242 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6243 Spacing * 2));
6244 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6245 Spacing * 3));
6246 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6247 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6248 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6249 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6250 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6251 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6252 Spacing));
6253 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6254 Spacing * 2));
6255 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6256 Spacing * 3));
6257 TmpInst.addOperand(Inst.getOperand(1)); // lane
6258 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6259 TmpInst.addOperand(Inst.getOperand(6));
6260 Inst = TmpInst;
6261 return true;
6262 }
6263
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006264 case ARM::VLD1LNdWB_fixed_Asm_8:
6265 case ARM::VLD1LNdWB_fixed_Asm_16:
6266 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006267 MCInst TmpInst;
6268 // Shuffle the operands around so the lane index operand is in the
6269 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006270 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006271 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006272 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6273 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6274 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6275 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6276 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6277 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6278 TmpInst.addOperand(Inst.getOperand(1)); // lane
6279 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6280 TmpInst.addOperand(Inst.getOperand(5));
6281 Inst = TmpInst;
6282 return true;
6283 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006284
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006285 case ARM::VLD2LNdWB_fixed_Asm_8:
6286 case ARM::VLD2LNdWB_fixed_Asm_16:
6287 case ARM::VLD2LNdWB_fixed_Asm_32:
6288 case ARM::VLD2LNqWB_fixed_Asm_16:
6289 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006290 MCInst TmpInst;
6291 // Shuffle the operands around so the lane index operand is in the
6292 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006293 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006294 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006295 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6297 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006298 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6299 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6300 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6301 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6302 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006303 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6304 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006305 TmpInst.addOperand(Inst.getOperand(1)); // lane
6306 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6307 TmpInst.addOperand(Inst.getOperand(5));
6308 Inst = TmpInst;
6309 return true;
6310 }
6311
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006312 case ARM::VLD3LNdWB_fixed_Asm_8:
6313 case ARM::VLD3LNdWB_fixed_Asm_16:
6314 case ARM::VLD3LNdWB_fixed_Asm_32:
6315 case ARM::VLD3LNqWB_fixed_Asm_16:
6316 case ARM::VLD3LNqWB_fixed_Asm_32: {
6317 MCInst TmpInst;
6318 // Shuffle the operands around so the lane index operand is in the
6319 // right place.
6320 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006321 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006322 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6323 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6324 Spacing));
6325 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006326 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006327 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6328 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6329 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6330 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6331 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6332 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6333 Spacing));
6334 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006335 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006336 TmpInst.addOperand(Inst.getOperand(1)); // lane
6337 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6338 TmpInst.addOperand(Inst.getOperand(5));
6339 Inst = TmpInst;
6340 return true;
6341 }
6342
Jim Grosbach14952a02012-01-24 18:37:25 +00006343 case ARM::VLD4LNdWB_fixed_Asm_8:
6344 case ARM::VLD4LNdWB_fixed_Asm_16:
6345 case ARM::VLD4LNdWB_fixed_Asm_32:
6346 case ARM::VLD4LNqWB_fixed_Asm_16:
6347 case ARM::VLD4LNqWB_fixed_Asm_32: {
6348 MCInst TmpInst;
6349 // Shuffle the operands around so the lane index operand is in the
6350 // right place.
6351 unsigned Spacing;
6352 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6353 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6354 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6355 Spacing));
6356 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6357 Spacing * 2));
6358 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6359 Spacing * 3));
6360 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6361 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6362 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6363 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6364 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6365 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6366 Spacing));
6367 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6368 Spacing * 2));
6369 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6370 Spacing * 3));
6371 TmpInst.addOperand(Inst.getOperand(1)); // lane
6372 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6373 TmpInst.addOperand(Inst.getOperand(5));
6374 Inst = TmpInst;
6375 return true;
6376 }
6377
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006378 case ARM::VLD1LNdAsm_8:
6379 case ARM::VLD1LNdAsm_16:
6380 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006381 MCInst TmpInst;
6382 // Shuffle the operands around so the lane index operand is in the
6383 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006384 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006385 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006386 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6387 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6388 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6389 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
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 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006396
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006397 case ARM::VLD2LNdAsm_8:
6398 case ARM::VLD2LNdAsm_16:
6399 case ARM::VLD2LNdAsm_32:
6400 case ARM::VLD2LNqAsm_16:
6401 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006402 MCInst TmpInst;
6403 // Shuffle the operands around so the lane index operand is in the
6404 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006405 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006406 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006407 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006408 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6409 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006410 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6411 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6412 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006413 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6414 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006415 TmpInst.addOperand(Inst.getOperand(1)); // lane
6416 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6417 TmpInst.addOperand(Inst.getOperand(5));
6418 Inst = TmpInst;
6419 return true;
6420 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006421
6422 case ARM::VLD3LNdAsm_8:
6423 case ARM::VLD3LNdAsm_16:
6424 case ARM::VLD3LNdAsm_32:
6425 case ARM::VLD3LNqAsm_16:
6426 case ARM::VLD3LNqAsm_32: {
6427 MCInst TmpInst;
6428 // Shuffle the operands around so the lane index operand is in the
6429 // right place.
6430 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006431 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006432 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6433 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6434 Spacing));
6435 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006436 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006437 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6438 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6439 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6440 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6441 Spacing));
6442 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006443 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006444 TmpInst.addOperand(Inst.getOperand(1)); // lane
6445 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6446 TmpInst.addOperand(Inst.getOperand(5));
6447 Inst = TmpInst;
6448 return true;
6449 }
6450
Jim Grosbach14952a02012-01-24 18:37:25 +00006451 case ARM::VLD4LNdAsm_8:
6452 case ARM::VLD4LNdAsm_16:
6453 case ARM::VLD4LNdAsm_32:
6454 case ARM::VLD4LNqAsm_16:
6455 case ARM::VLD4LNqAsm_32: {
6456 MCInst TmpInst;
6457 // Shuffle the operands around so the lane index operand is in the
6458 // right place.
6459 unsigned Spacing;
6460 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6461 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6462 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6463 Spacing));
6464 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6465 Spacing * 2));
6466 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6467 Spacing * 3));
6468 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6469 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6470 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6472 Spacing));
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6474 Spacing * 2));
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6476 Spacing * 3));
6477 TmpInst.addOperand(Inst.getOperand(1)); // lane
6478 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6479 TmpInst.addOperand(Inst.getOperand(5));
6480 Inst = TmpInst;
6481 return true;
6482 }
6483
Jim Grosbachb78403c2012-01-24 23:47:04 +00006484 // VLD3DUP single 3-element structure to all lanes instructions.
6485 case ARM::VLD3DUPdAsm_8:
6486 case ARM::VLD3DUPdAsm_16:
6487 case ARM::VLD3DUPdAsm_32:
6488 case ARM::VLD3DUPqAsm_8:
6489 case ARM::VLD3DUPqAsm_16:
6490 case ARM::VLD3DUPqAsm_32: {
6491 MCInst TmpInst;
6492 unsigned Spacing;
6493 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6494 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6496 Spacing));
6497 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6498 Spacing * 2));
6499 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6500 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6501 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6502 TmpInst.addOperand(Inst.getOperand(4));
6503 Inst = TmpInst;
6504 return true;
6505 }
6506
6507 case ARM::VLD3DUPdWB_fixed_Asm_8:
6508 case ARM::VLD3DUPdWB_fixed_Asm_16:
6509 case ARM::VLD3DUPdWB_fixed_Asm_32:
6510 case ARM::VLD3DUPqWB_fixed_Asm_8:
6511 case ARM::VLD3DUPqWB_fixed_Asm_16:
6512 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6513 MCInst TmpInst;
6514 unsigned Spacing;
6515 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6516 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6517 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6518 Spacing));
6519 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6520 Spacing * 2));
6521 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6522 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6523 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6524 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6525 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6526 TmpInst.addOperand(Inst.getOperand(4));
6527 Inst = TmpInst;
6528 return true;
6529 }
6530
6531 case ARM::VLD3DUPdWB_register_Asm_8:
6532 case ARM::VLD3DUPdWB_register_Asm_16:
6533 case ARM::VLD3DUPdWB_register_Asm_32:
6534 case ARM::VLD3DUPqWB_register_Asm_8:
6535 case ARM::VLD3DUPqWB_register_Asm_16:
6536 case ARM::VLD3DUPqWB_register_Asm_32: {
6537 MCInst TmpInst;
6538 unsigned Spacing;
6539 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6540 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6541 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6542 Spacing));
6543 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6544 Spacing * 2));
6545 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6546 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6547 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6548 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6549 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6550 TmpInst.addOperand(Inst.getOperand(5));
6551 Inst = TmpInst;
6552 return true;
6553 }
6554
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006555 // VLD3 multiple 3-element structure instructions.
6556 case ARM::VLD3dAsm_8:
6557 case ARM::VLD3dAsm_16:
6558 case ARM::VLD3dAsm_32:
6559 case ARM::VLD3qAsm_8:
6560 case ARM::VLD3qAsm_16:
6561 case ARM::VLD3qAsm_32: {
6562 MCInst TmpInst;
6563 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006564 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006565 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6566 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6567 Spacing));
6568 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6569 Spacing * 2));
6570 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6571 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6572 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6573 TmpInst.addOperand(Inst.getOperand(4));
6574 Inst = TmpInst;
6575 return true;
6576 }
6577
6578 case ARM::VLD3dWB_fixed_Asm_8:
6579 case ARM::VLD3dWB_fixed_Asm_16:
6580 case ARM::VLD3dWB_fixed_Asm_32:
6581 case ARM::VLD3qWB_fixed_Asm_8:
6582 case ARM::VLD3qWB_fixed_Asm_16:
6583 case ARM::VLD3qWB_fixed_Asm_32: {
6584 MCInst TmpInst;
6585 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006586 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006587 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6588 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6589 Spacing));
6590 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6591 Spacing * 2));
6592 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6593 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6594 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6595 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6596 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6597 TmpInst.addOperand(Inst.getOperand(4));
6598 Inst = TmpInst;
6599 return true;
6600 }
6601
6602 case ARM::VLD3dWB_register_Asm_8:
6603 case ARM::VLD3dWB_register_Asm_16:
6604 case ARM::VLD3dWB_register_Asm_32:
6605 case ARM::VLD3qWB_register_Asm_8:
6606 case ARM::VLD3qWB_register_Asm_16:
6607 case ARM::VLD3qWB_register_Asm_32: {
6608 MCInst TmpInst;
6609 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006610 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006611 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6612 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6613 Spacing));
6614 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6615 Spacing * 2));
6616 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6617 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6618 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6619 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6620 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6621 TmpInst.addOperand(Inst.getOperand(5));
6622 Inst = TmpInst;
6623 return true;
6624 }
6625
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006626 // VLD4DUP single 3-element structure to all lanes instructions.
6627 case ARM::VLD4DUPdAsm_8:
6628 case ARM::VLD4DUPdAsm_16:
6629 case ARM::VLD4DUPdAsm_32:
6630 case ARM::VLD4DUPqAsm_8:
6631 case ARM::VLD4DUPqAsm_16:
6632 case ARM::VLD4DUPqAsm_32: {
6633 MCInst TmpInst;
6634 unsigned Spacing;
6635 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6636 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6637 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6638 Spacing));
6639 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6640 Spacing * 2));
6641 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6642 Spacing * 3));
6643 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6644 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6645 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6646 TmpInst.addOperand(Inst.getOperand(4));
6647 Inst = TmpInst;
6648 return true;
6649 }
6650
6651 case ARM::VLD4DUPdWB_fixed_Asm_8:
6652 case ARM::VLD4DUPdWB_fixed_Asm_16:
6653 case ARM::VLD4DUPdWB_fixed_Asm_32:
6654 case ARM::VLD4DUPqWB_fixed_Asm_8:
6655 case ARM::VLD4DUPqWB_fixed_Asm_16:
6656 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6657 MCInst TmpInst;
6658 unsigned Spacing;
6659 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6660 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6661 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6662 Spacing));
6663 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6664 Spacing * 2));
6665 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6666 Spacing * 3));
6667 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6668 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6669 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6670 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6671 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6672 TmpInst.addOperand(Inst.getOperand(4));
6673 Inst = TmpInst;
6674 return true;
6675 }
6676
6677 case ARM::VLD4DUPdWB_register_Asm_8:
6678 case ARM::VLD4DUPdWB_register_Asm_16:
6679 case ARM::VLD4DUPdWB_register_Asm_32:
6680 case ARM::VLD4DUPqWB_register_Asm_8:
6681 case ARM::VLD4DUPqWB_register_Asm_16:
6682 case ARM::VLD4DUPqWB_register_Asm_32: {
6683 MCInst TmpInst;
6684 unsigned Spacing;
6685 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6686 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6687 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6688 Spacing));
6689 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6690 Spacing * 2));
6691 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6692 Spacing * 3));
6693 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6694 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6695 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6696 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6697 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6698 TmpInst.addOperand(Inst.getOperand(5));
6699 Inst = TmpInst;
6700 return true;
6701 }
6702
6703 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006704 case ARM::VLD4dAsm_8:
6705 case ARM::VLD4dAsm_16:
6706 case ARM::VLD4dAsm_32:
6707 case ARM::VLD4qAsm_8:
6708 case ARM::VLD4qAsm_16:
6709 case ARM::VLD4qAsm_32: {
6710 MCInst TmpInst;
6711 unsigned Spacing;
6712 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6713 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6714 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6715 Spacing));
6716 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6717 Spacing * 2));
6718 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6719 Spacing * 3));
6720 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6721 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6722 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6723 TmpInst.addOperand(Inst.getOperand(4));
6724 Inst = TmpInst;
6725 return true;
6726 }
6727
6728 case ARM::VLD4dWB_fixed_Asm_8:
6729 case ARM::VLD4dWB_fixed_Asm_16:
6730 case ARM::VLD4dWB_fixed_Asm_32:
6731 case ARM::VLD4qWB_fixed_Asm_8:
6732 case ARM::VLD4qWB_fixed_Asm_16:
6733 case ARM::VLD4qWB_fixed_Asm_32: {
6734 MCInst TmpInst;
6735 unsigned Spacing;
6736 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6737 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6738 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6739 Spacing));
6740 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6741 Spacing * 2));
6742 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6743 Spacing * 3));
6744 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6745 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6746 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6747 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6748 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6749 TmpInst.addOperand(Inst.getOperand(4));
6750 Inst = TmpInst;
6751 return true;
6752 }
6753
6754 case ARM::VLD4dWB_register_Asm_8:
6755 case ARM::VLD4dWB_register_Asm_16:
6756 case ARM::VLD4dWB_register_Asm_32:
6757 case ARM::VLD4qWB_register_Asm_8:
6758 case ARM::VLD4qWB_register_Asm_16:
6759 case ARM::VLD4qWB_register_Asm_32: {
6760 MCInst TmpInst;
6761 unsigned Spacing;
6762 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6763 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6764 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6765 Spacing));
6766 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6767 Spacing * 2));
6768 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6769 Spacing * 3));
6770 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6771 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6772 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6773 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6774 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6775 TmpInst.addOperand(Inst.getOperand(5));
6776 Inst = TmpInst;
6777 return true;
6778 }
6779
Jim Grosbach1a747242012-01-23 23:45:44 +00006780 // VST3 multiple 3-element structure instructions.
6781 case ARM::VST3dAsm_8:
6782 case ARM::VST3dAsm_16:
6783 case ARM::VST3dAsm_32:
6784 case ARM::VST3qAsm_8:
6785 case ARM::VST3qAsm_16:
6786 case ARM::VST3qAsm_32: {
6787 MCInst TmpInst;
6788 unsigned Spacing;
6789 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6790 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6791 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6792 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6793 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6794 Spacing));
6795 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6796 Spacing * 2));
6797 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6798 TmpInst.addOperand(Inst.getOperand(4));
6799 Inst = TmpInst;
6800 return true;
6801 }
6802
6803 case ARM::VST3dWB_fixed_Asm_8:
6804 case ARM::VST3dWB_fixed_Asm_16:
6805 case ARM::VST3dWB_fixed_Asm_32:
6806 case ARM::VST3qWB_fixed_Asm_8:
6807 case ARM::VST3qWB_fixed_Asm_16:
6808 case ARM::VST3qWB_fixed_Asm_32: {
6809 MCInst TmpInst;
6810 unsigned Spacing;
6811 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6812 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6813 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6814 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6815 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6816 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6817 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6818 Spacing));
6819 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6820 Spacing * 2));
6821 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6822 TmpInst.addOperand(Inst.getOperand(4));
6823 Inst = TmpInst;
6824 return true;
6825 }
6826
6827 case ARM::VST3dWB_register_Asm_8:
6828 case ARM::VST3dWB_register_Asm_16:
6829 case ARM::VST3dWB_register_Asm_32:
6830 case ARM::VST3qWB_register_Asm_8:
6831 case ARM::VST3qWB_register_Asm_16:
6832 case ARM::VST3qWB_register_Asm_32: {
6833 MCInst TmpInst;
6834 unsigned Spacing;
6835 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6836 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6837 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6838 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6839 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6840 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6841 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6842 Spacing));
6843 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6844 Spacing * 2));
6845 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6846 TmpInst.addOperand(Inst.getOperand(5));
6847 Inst = TmpInst;
6848 return true;
6849 }
6850
Jim Grosbachda70eac2012-01-24 00:58:13 +00006851 // VST4 multiple 3-element structure instructions.
6852 case ARM::VST4dAsm_8:
6853 case ARM::VST4dAsm_16:
6854 case ARM::VST4dAsm_32:
6855 case ARM::VST4qAsm_8:
6856 case ARM::VST4qAsm_16:
6857 case ARM::VST4qAsm_32: {
6858 MCInst TmpInst;
6859 unsigned Spacing;
6860 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6861 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6862 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6863 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6864 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6865 Spacing));
6866 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6867 Spacing * 2));
6868 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6869 Spacing * 3));
6870 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6871 TmpInst.addOperand(Inst.getOperand(4));
6872 Inst = TmpInst;
6873 return true;
6874 }
6875
6876 case ARM::VST4dWB_fixed_Asm_8:
6877 case ARM::VST4dWB_fixed_Asm_16:
6878 case ARM::VST4dWB_fixed_Asm_32:
6879 case ARM::VST4qWB_fixed_Asm_8:
6880 case ARM::VST4qWB_fixed_Asm_16:
6881 case ARM::VST4qWB_fixed_Asm_32: {
6882 MCInst TmpInst;
6883 unsigned Spacing;
6884 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6885 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6886 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6887 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6888 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6889 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6890 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6891 Spacing));
6892 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6893 Spacing * 2));
6894 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6895 Spacing * 3));
6896 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6897 TmpInst.addOperand(Inst.getOperand(4));
6898 Inst = TmpInst;
6899 return true;
6900 }
6901
6902 case ARM::VST4dWB_register_Asm_8:
6903 case ARM::VST4dWB_register_Asm_16:
6904 case ARM::VST4dWB_register_Asm_32:
6905 case ARM::VST4qWB_register_Asm_8:
6906 case ARM::VST4qWB_register_Asm_16:
6907 case ARM::VST4qWB_register_Asm_32: {
6908 MCInst TmpInst;
6909 unsigned Spacing;
6910 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
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(0)); // Vd
6916 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6917 Spacing));
6918 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6919 Spacing * 2));
6920 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6921 Spacing * 3));
6922 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6923 TmpInst.addOperand(Inst.getOperand(5));
6924 Inst = TmpInst;
6925 return true;
6926 }
6927
Jim Grosbachad66de12012-04-11 00:15:16 +00006928 // Handle encoding choice for the shift-immediate instructions.
6929 case ARM::t2LSLri:
6930 case ARM::t2LSRri:
6931 case ARM::t2ASRri: {
6932 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6933 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6934 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6935 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6936 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6937 unsigned NewOpc;
6938 switch (Inst.getOpcode()) {
6939 default: llvm_unreachable("unexpected opcode");
6940 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6941 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6942 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6943 }
6944 // The Thumb1 operands aren't in the same order. Awesome, eh?
6945 MCInst TmpInst;
6946 TmpInst.setOpcode(NewOpc);
6947 TmpInst.addOperand(Inst.getOperand(0));
6948 TmpInst.addOperand(Inst.getOperand(5));
6949 TmpInst.addOperand(Inst.getOperand(1));
6950 TmpInst.addOperand(Inst.getOperand(2));
6951 TmpInst.addOperand(Inst.getOperand(3));
6952 TmpInst.addOperand(Inst.getOperand(4));
6953 Inst = TmpInst;
6954 return true;
6955 }
6956 return false;
6957 }
6958
Jim Grosbach485e5622011-12-13 22:45:11 +00006959 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006960 case ARM::t2MOVsr:
6961 case ARM::t2MOVSsr: {
6962 // Which instruction to expand to depends on the CCOut operand and
6963 // whether we're in an IT block if the register operands are low
6964 // registers.
6965 bool isNarrow = false;
6966 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6967 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6968 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6969 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6970 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6971 isNarrow = true;
6972 MCInst TmpInst;
6973 unsigned newOpc;
6974 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6975 default: llvm_unreachable("unexpected opcode!");
6976 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6977 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6978 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6979 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6980 }
6981 TmpInst.setOpcode(newOpc);
6982 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6983 if (isNarrow)
6984 TmpInst.addOperand(MCOperand::CreateReg(
6985 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6986 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6987 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6988 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6989 TmpInst.addOperand(Inst.getOperand(5));
6990 if (!isNarrow)
6991 TmpInst.addOperand(MCOperand::CreateReg(
6992 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6993 Inst = TmpInst;
6994 return true;
6995 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006996 case ARM::t2MOVsi:
6997 case ARM::t2MOVSsi: {
6998 // Which instruction to expand to depends on the CCOut operand and
6999 // whether we're in an IT block if the register operands are low
7000 // registers.
7001 bool isNarrow = false;
7002 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7003 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7004 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7005 isNarrow = true;
7006 MCInst TmpInst;
7007 unsigned newOpc;
7008 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7009 default: llvm_unreachable("unexpected opcode!");
7010 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7011 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7012 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7013 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007014 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007015 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007016 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7017 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007018 TmpInst.setOpcode(newOpc);
7019 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7020 if (isNarrow)
7021 TmpInst.addOperand(MCOperand::CreateReg(
7022 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7023 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007024 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007025 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007026 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7027 TmpInst.addOperand(Inst.getOperand(4));
7028 if (!isNarrow)
7029 TmpInst.addOperand(MCOperand::CreateReg(
7030 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7031 Inst = TmpInst;
7032 return true;
7033 }
7034 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007035 case ARM::ASRr:
7036 case ARM::LSRr:
7037 case ARM::LSLr:
7038 case ARM::RORr: {
7039 ARM_AM::ShiftOpc ShiftTy;
7040 switch(Inst.getOpcode()) {
7041 default: llvm_unreachable("unexpected opcode!");
7042 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7043 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7044 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7045 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7046 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007047 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7048 MCInst TmpInst;
7049 TmpInst.setOpcode(ARM::MOVsr);
7050 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7051 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7052 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7053 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7054 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7055 TmpInst.addOperand(Inst.getOperand(4));
7056 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7057 Inst = TmpInst;
7058 return true;
7059 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007060 case ARM::ASRi:
7061 case ARM::LSRi:
7062 case ARM::LSLi:
7063 case ARM::RORi: {
7064 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007065 switch(Inst.getOpcode()) {
7066 default: llvm_unreachable("unexpected opcode!");
7067 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7068 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7069 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7070 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7071 }
7072 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007073 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007074 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007075 // A shift by 32 should be encoded as 0 when permitted
7076 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7077 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007078 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007079 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007080 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007081 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7082 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007083 if (Opc == ARM::MOVsi)
7084 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007085 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7086 TmpInst.addOperand(Inst.getOperand(4));
7087 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7088 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007089 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007090 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007091 case ARM::RRXi: {
7092 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7093 MCInst TmpInst;
7094 TmpInst.setOpcode(ARM::MOVsi);
7095 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7096 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7097 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7098 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7099 TmpInst.addOperand(Inst.getOperand(3));
7100 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7101 Inst = TmpInst;
7102 return true;
7103 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007104 case ARM::t2LDMIA_UPD: {
7105 // If this is a load of a single register, then we should use
7106 // a post-indexed LDR instruction instead, per the ARM ARM.
7107 if (Inst.getNumOperands() != 5)
7108 return false;
7109 MCInst TmpInst;
7110 TmpInst.setOpcode(ARM::t2LDR_POST);
7111 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7112 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7113 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7114 TmpInst.addOperand(MCOperand::CreateImm(4));
7115 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7116 TmpInst.addOperand(Inst.getOperand(3));
7117 Inst = TmpInst;
7118 return true;
7119 }
7120 case ARM::t2STMDB_UPD: {
7121 // If this is a store of a single register, then we should use
7122 // a pre-indexed STR instruction instead, per the ARM ARM.
7123 if (Inst.getNumOperands() != 5)
7124 return false;
7125 MCInst TmpInst;
7126 TmpInst.setOpcode(ARM::t2STR_PRE);
7127 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7128 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7129 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7130 TmpInst.addOperand(MCOperand::CreateImm(-4));
7131 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7132 TmpInst.addOperand(Inst.getOperand(3));
7133 Inst = TmpInst;
7134 return true;
7135 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007136 case ARM::LDMIA_UPD:
7137 // If this is a load of a single register via a 'pop', then we should use
7138 // a post-indexed LDR instruction instead, per the ARM ARM.
7139 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7140 Inst.getNumOperands() == 5) {
7141 MCInst TmpInst;
7142 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7143 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7144 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7145 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7146 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7147 TmpInst.addOperand(MCOperand::CreateImm(4));
7148 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7149 TmpInst.addOperand(Inst.getOperand(3));
7150 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007151 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007152 }
7153 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007154 case ARM::STMDB_UPD:
7155 // If this is a store of a single register via a 'push', then we should use
7156 // a pre-indexed STR instruction instead, per the ARM ARM.
7157 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7158 Inst.getNumOperands() == 5) {
7159 MCInst TmpInst;
7160 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7161 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7162 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7163 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7164 TmpInst.addOperand(MCOperand::CreateImm(-4));
7165 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7166 TmpInst.addOperand(Inst.getOperand(3));
7167 Inst = TmpInst;
7168 }
7169 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007170 case ARM::t2ADDri12:
7171 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7172 // mnemonic was used (not "addw"), encoding T3 is preferred.
7173 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7174 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7175 break;
7176 Inst.setOpcode(ARM::t2ADDri);
7177 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7178 break;
7179 case ARM::t2SUBri12:
7180 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7181 // mnemonic was used (not "subw"), encoding T3 is preferred.
7182 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7183 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7184 break;
7185 Inst.setOpcode(ARM::t2SUBri);
7186 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7187 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007188 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007189 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007190 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7191 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7192 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007193 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007194 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007195 return true;
7196 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007197 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007198 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007199 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007200 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7201 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7202 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007203 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007204 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007205 return true;
7206 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007207 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007208 case ARM::t2ADDri:
7209 case ARM::t2SUBri: {
7210 // If the destination and first source operand are the same, and
7211 // the flags are compatible with the current IT status, use encoding T2
7212 // instead of T3. For compatibility with the system 'as'. Make sure the
7213 // wide encoding wasn't explicit.
7214 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007215 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007216 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7217 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7218 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7219 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7220 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7221 break;
7222 MCInst TmpInst;
7223 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7224 ARM::tADDi8 : ARM::tSUBi8);
7225 TmpInst.addOperand(Inst.getOperand(0));
7226 TmpInst.addOperand(Inst.getOperand(5));
7227 TmpInst.addOperand(Inst.getOperand(0));
7228 TmpInst.addOperand(Inst.getOperand(2));
7229 TmpInst.addOperand(Inst.getOperand(3));
7230 TmpInst.addOperand(Inst.getOperand(4));
7231 Inst = TmpInst;
7232 return true;
7233 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007234 case ARM::t2ADDrr: {
7235 // If the destination and first source operand are the same, and
7236 // there's no setting of the flags, use encoding T2 instead of T3.
7237 // Note that this is only for ADD, not SUB. This mirrors the system
7238 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7239 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7240 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007241 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7242 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007243 break;
7244 MCInst TmpInst;
7245 TmpInst.setOpcode(ARM::tADDhirr);
7246 TmpInst.addOperand(Inst.getOperand(0));
7247 TmpInst.addOperand(Inst.getOperand(0));
7248 TmpInst.addOperand(Inst.getOperand(2));
7249 TmpInst.addOperand(Inst.getOperand(3));
7250 TmpInst.addOperand(Inst.getOperand(4));
7251 Inst = TmpInst;
7252 return true;
7253 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007254 case ARM::tADDrSP: {
7255 // If the non-SP source operand and the destination operand are not the
7256 // same, we need to use the 32-bit encoding if it's available.
7257 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7258 Inst.setOpcode(ARM::t2ADDrr);
7259 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7260 return true;
7261 }
7262 break;
7263 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007264 case ARM::tB:
7265 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007266 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007267 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007268 return true;
7269 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007270 break;
7271 case ARM::t2B:
7272 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007273 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007274 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007275 return true;
7276 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007277 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007278 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007279 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007280 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007281 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007282 return true;
7283 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007284 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007285 case ARM::tBcc:
7286 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007287 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007288 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007289 return true;
7290 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007291 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007292 case ARM::tLDMIA: {
7293 // If the register list contains any high registers, or if the writeback
7294 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7295 // instead if we're in Thumb2. Otherwise, this should have generated
7296 // an error in validateInstruction().
7297 unsigned Rn = Inst.getOperand(0).getReg();
7298 bool hasWritebackToken =
7299 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7300 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7301 bool listContainsBase;
7302 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7303 (!listContainsBase && !hasWritebackToken) ||
7304 (listContainsBase && hasWritebackToken)) {
7305 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7306 assert (isThumbTwo());
7307 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7308 // If we're switching to the updating version, we need to insert
7309 // the writeback tied operand.
7310 if (hasWritebackToken)
7311 Inst.insert(Inst.begin(),
7312 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007313 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007314 }
7315 break;
7316 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007317 case ARM::tSTMIA_UPD: {
7318 // If the register list contains any high registers, we need to use
7319 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7320 // should have generated an error in validateInstruction().
7321 unsigned Rn = Inst.getOperand(0).getReg();
7322 bool listContainsBase;
7323 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7324 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7325 assert (isThumbTwo());
7326 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007327 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007328 }
7329 break;
7330 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007331 case ARM::tPOP: {
7332 bool listContainsBase;
7333 // If the register list contains any high registers, we need to use
7334 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7335 // should have generated an error in validateInstruction().
7336 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007337 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007338 assert (isThumbTwo());
7339 Inst.setOpcode(ARM::t2LDMIA_UPD);
7340 // Add the base register and writeback operands.
7341 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7342 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007343 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007344 }
7345 case ARM::tPUSH: {
7346 bool listContainsBase;
7347 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007348 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007349 assert (isThumbTwo());
7350 Inst.setOpcode(ARM::t2STMDB_UPD);
7351 // Add the base register and writeback operands.
7352 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7353 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007354 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007355 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007356 case ARM::t2MOVi: {
7357 // If we can use the 16-bit encoding and the user didn't explicitly
7358 // request the 32-bit variant, transform it here.
7359 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007360 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007361 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7362 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7363 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007364 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7365 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7366 // The operands aren't in the same order for tMOVi8...
7367 MCInst TmpInst;
7368 TmpInst.setOpcode(ARM::tMOVi8);
7369 TmpInst.addOperand(Inst.getOperand(0));
7370 TmpInst.addOperand(Inst.getOperand(4));
7371 TmpInst.addOperand(Inst.getOperand(1));
7372 TmpInst.addOperand(Inst.getOperand(2));
7373 TmpInst.addOperand(Inst.getOperand(3));
7374 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007375 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007376 }
7377 break;
7378 }
7379 case ARM::t2MOVr: {
7380 // If we can use the 16-bit encoding and the user didn't explicitly
7381 // request the 32-bit variant, transform it here.
7382 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7383 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7384 Inst.getOperand(2).getImm() == ARMCC::AL &&
7385 Inst.getOperand(4).getReg() == ARM::CPSR &&
7386 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7387 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7388 // The operands aren't the same for tMOV[S]r... (no cc_out)
7389 MCInst TmpInst;
7390 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7391 TmpInst.addOperand(Inst.getOperand(0));
7392 TmpInst.addOperand(Inst.getOperand(1));
7393 TmpInst.addOperand(Inst.getOperand(2));
7394 TmpInst.addOperand(Inst.getOperand(3));
7395 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007396 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007397 }
7398 break;
7399 }
Jim Grosbach82213192011-09-19 20:29:33 +00007400 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007401 case ARM::t2SXTB:
7402 case ARM::t2UXTH:
7403 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007404 // If we can use the 16-bit encoding and the user didn't explicitly
7405 // request the 32-bit variant, transform it here.
7406 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7407 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7408 Inst.getOperand(2).getImm() == 0 &&
7409 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7410 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007411 unsigned NewOpc;
7412 switch (Inst.getOpcode()) {
7413 default: llvm_unreachable("Illegal opcode!");
7414 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7415 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7416 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7417 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7418 }
Jim Grosbach82213192011-09-19 20:29:33 +00007419 // The operands aren't the same for thumb1 (no rotate operand).
7420 MCInst TmpInst;
7421 TmpInst.setOpcode(NewOpc);
7422 TmpInst.addOperand(Inst.getOperand(0));
7423 TmpInst.addOperand(Inst.getOperand(1));
7424 TmpInst.addOperand(Inst.getOperand(3));
7425 TmpInst.addOperand(Inst.getOperand(4));
7426 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007427 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007428 }
7429 break;
7430 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007431 case ARM::MOVsi: {
7432 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007433 // rrx shifts and asr/lsr of #32 is encoded as 0
7434 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7435 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007436 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7437 // Shifting by zero is accepted as a vanilla 'MOVr'
7438 MCInst TmpInst;
7439 TmpInst.setOpcode(ARM::MOVr);
7440 TmpInst.addOperand(Inst.getOperand(0));
7441 TmpInst.addOperand(Inst.getOperand(1));
7442 TmpInst.addOperand(Inst.getOperand(3));
7443 TmpInst.addOperand(Inst.getOperand(4));
7444 TmpInst.addOperand(Inst.getOperand(5));
7445 Inst = TmpInst;
7446 return true;
7447 }
7448 return false;
7449 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007450 case ARM::ANDrsi:
7451 case ARM::ORRrsi:
7452 case ARM::EORrsi:
7453 case ARM::BICrsi:
7454 case ARM::SUBrsi:
7455 case ARM::ADDrsi: {
7456 unsigned newOpc;
7457 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7458 if (SOpc == ARM_AM::rrx) return false;
7459 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007460 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007461 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7462 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7463 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7464 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7465 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7466 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7467 }
7468 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007469 // The exception is for right shifts, where 0 == 32
7470 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7471 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007472 MCInst TmpInst;
7473 TmpInst.setOpcode(newOpc);
7474 TmpInst.addOperand(Inst.getOperand(0));
7475 TmpInst.addOperand(Inst.getOperand(1));
7476 TmpInst.addOperand(Inst.getOperand(2));
7477 TmpInst.addOperand(Inst.getOperand(4));
7478 TmpInst.addOperand(Inst.getOperand(5));
7479 TmpInst.addOperand(Inst.getOperand(6));
7480 Inst = TmpInst;
7481 return true;
7482 }
7483 return false;
7484 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007485 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007486 case ARM::t2IT: {
7487 // The mask bits for all but the first condition are represented as
7488 // the low bit of the condition code value implies 't'. We currently
7489 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007490 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007491 MCOperand &MO = Inst.getOperand(1);
7492 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007493 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007494 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007495 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007496 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007497 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007498 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007499 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007500
7501 // Set up the IT block state according to the IT instruction we just
7502 // matched.
7503 assert(!inITBlock() && "nested IT blocks?!");
7504 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7505 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7506 ITState.CurPosition = 0;
7507 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007508 break;
7509 }
Richard Bartona39625e2012-07-09 16:12:24 +00007510 case ARM::t2LSLrr:
7511 case ARM::t2LSRrr:
7512 case ARM::t2ASRrr:
7513 case ARM::t2SBCrr:
7514 case ARM::t2RORrr:
7515 case ARM::t2BICrr:
7516 {
Richard Bartond5660372012-07-09 16:14:28 +00007517 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007518 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7519 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7520 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007521 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7522 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007523 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7524 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7525 unsigned NewOpc;
7526 switch (Inst.getOpcode()) {
7527 default: llvm_unreachable("unexpected opcode");
7528 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7529 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7530 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7531 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7532 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7533 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7534 }
7535 MCInst TmpInst;
7536 TmpInst.setOpcode(NewOpc);
7537 TmpInst.addOperand(Inst.getOperand(0));
7538 TmpInst.addOperand(Inst.getOperand(5));
7539 TmpInst.addOperand(Inst.getOperand(1));
7540 TmpInst.addOperand(Inst.getOperand(2));
7541 TmpInst.addOperand(Inst.getOperand(3));
7542 TmpInst.addOperand(Inst.getOperand(4));
7543 Inst = TmpInst;
7544 return true;
7545 }
7546 return false;
7547 }
7548 case ARM::t2ANDrr:
7549 case ARM::t2EORrr:
7550 case ARM::t2ADCrr:
7551 case ARM::t2ORRrr:
7552 {
Richard Bartond5660372012-07-09 16:14:28 +00007553 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007554 // These instructions are special in that they are commutable, so shorter encodings
7555 // are available more often.
7556 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7557 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7558 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7559 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007560 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7561 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007562 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7563 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7564 unsigned NewOpc;
7565 switch (Inst.getOpcode()) {
7566 default: llvm_unreachable("unexpected opcode");
7567 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7568 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7569 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7570 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7571 }
7572 MCInst TmpInst;
7573 TmpInst.setOpcode(NewOpc);
7574 TmpInst.addOperand(Inst.getOperand(0));
7575 TmpInst.addOperand(Inst.getOperand(5));
7576 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7577 TmpInst.addOperand(Inst.getOperand(1));
7578 TmpInst.addOperand(Inst.getOperand(2));
7579 } else {
7580 TmpInst.addOperand(Inst.getOperand(2));
7581 TmpInst.addOperand(Inst.getOperand(1));
7582 }
7583 TmpInst.addOperand(Inst.getOperand(3));
7584 TmpInst.addOperand(Inst.getOperand(4));
7585 Inst = TmpInst;
7586 return true;
7587 }
7588 return false;
7589 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007590 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007591 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007592}
7593
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007594unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7595 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7596 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007597 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007598 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007599 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7600 assert(MCID.hasOptionalDef() &&
7601 "optionally flag setting instruction missing optional def operand");
7602 assert(MCID.NumOperands == Inst.getNumOperands() &&
7603 "operand count mismatch!");
7604 // Find the optional-def operand (cc_out).
7605 unsigned OpNo;
7606 for (OpNo = 0;
7607 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7608 ++OpNo)
7609 ;
7610 // If we're parsing Thumb1, reject it completely.
7611 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7612 return Match_MnemonicFail;
7613 // If we're parsing Thumb2, which form is legal depends on whether we're
7614 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007615 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7616 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007617 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007618 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7619 inITBlock())
7620 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007621 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007622 // Some high-register supporting Thumb1 encodings only allow both registers
7623 // to be from r0-r7 when in Thumb2.
7624 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7625 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7626 isARMLowRegister(Inst.getOperand(2).getReg()))
7627 return Match_RequiresThumb2;
7628 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007629 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007630 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7631 isARMLowRegister(Inst.getOperand(1).getReg()))
7632 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007633 return Match_Success;
7634}
7635
Jim Grosbach5117ef72012-04-24 22:40:08 +00007636static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007637bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007638MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007639 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007640 MCStreamer &Out, unsigned &ErrorInfo,
7641 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007642 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007643 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007644
Chad Rosier2f480a82012-10-12 22:53:36 +00007645 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007646 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007647 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007648 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007649 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007650 // Context sensitive operand constraints aren't handled by the matcher,
7651 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007652 if (validateInstruction(Inst, Operands)) {
7653 // Still progress the IT block, otherwise one wrong condition causes
7654 // nasty cascading errors.
7655 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007656 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007657 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007658
Amara Emerson52cfb6a2013-10-03 09:31:51 +00007659 { // processInstruction() updates inITBlock state, we need to save it away
7660 bool wasInITBlock = inITBlock();
7661
7662 // Some instructions need post-processing to, for example, tweak which
7663 // encoding is selected. Loop on it while changes happen so the
7664 // individual transformations can chain off each other. E.g.,
7665 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7666 while (processInstruction(Inst, Operands))
7667 ;
7668
7669 // Only after the instruction is fully processed, we can validate it
7670 if (wasInITBlock && hasV8Ops() && isThumb() &&
7671 !isV8EligibleForIT(&Inst, 2)) {
7672 Warning(IDLoc, "deprecated instruction in IT block");
7673 }
7674 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007675
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007676 // Only move forward at the very end so that everything in validate
7677 // and process gets a consistent answer about whether we're in an IT
7678 // block.
7679 forwardITPosition();
7680
Jim Grosbach82f76d12012-01-25 19:52:01 +00007681 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7682 // doesn't actually encode.
7683 if (Inst.getOpcode() == ARM::ITasm)
7684 return false;
7685
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007686 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007687 Out.EmitInstruction(Inst);
7688 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007689 case Match_MissingFeature: {
7690 assert(ErrorInfo && "Unknown missing feature!");
7691 // Special case the error message for the very common case where only
7692 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7693 std::string Msg = "instruction requires:";
7694 unsigned Mask = 1;
7695 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7696 if (ErrorInfo & Mask) {
7697 Msg += " ";
7698 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7699 }
7700 Mask <<= 1;
7701 }
7702 return Error(IDLoc, Msg);
7703 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007704 case Match_InvalidOperand: {
7705 SMLoc ErrorLoc = IDLoc;
7706 if (ErrorInfo != ~0U) {
7707 if (ErrorInfo >= Operands.size())
7708 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007709
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007710 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7711 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7712 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007713
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007714 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007715 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007716 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007717 return Error(IDLoc, "invalid instruction",
7718 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007719 case Match_RequiresNotITBlock:
7720 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007721 case Match_RequiresITBlock:
7722 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007723 case Match_RequiresV6:
7724 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7725 case Match_RequiresThumb2:
7726 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007727 case Match_ImmRange0_15: {
7728 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7729 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7730 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7731 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00007732 case Match_ImmRange0_239: {
7733 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7734 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7735 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7736 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007737 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007738
Eric Christopher91d7b902010-10-29 09:26:59 +00007739 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007740}
7741
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007742/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007743bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7744 StringRef IDVal = DirectiveID.getIdentifier();
7745 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007746 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007747 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007748 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007749 else if (IDVal == ".arm")
7750 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007751 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007752 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007753 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007754 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007755 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007756 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007757 else if (IDVal == ".unreq")
7758 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007759 else if (IDVal == ".arch")
7760 return parseDirectiveArch(DirectiveID.getLoc());
7761 else if (IDVal == ".eabi_attribute")
7762 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007763 else if (IDVal == ".fnstart")
7764 return parseDirectiveFnStart(DirectiveID.getLoc());
7765 else if (IDVal == ".fnend")
7766 return parseDirectiveFnEnd(DirectiveID.getLoc());
7767 else if (IDVal == ".cantunwind")
7768 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7769 else if (IDVal == ".personality")
7770 return parseDirectivePersonality(DirectiveID.getLoc());
7771 else if (IDVal == ".handlerdata")
7772 return parseDirectiveHandlerData(DirectiveID.getLoc());
7773 else if (IDVal == ".setfp")
7774 return parseDirectiveSetFP(DirectiveID.getLoc());
7775 else if (IDVal == ".pad")
7776 return parseDirectivePad(DirectiveID.getLoc());
7777 else if (IDVal == ".save")
7778 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7779 else if (IDVal == ".vsave")
7780 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007781 return true;
7782}
7783
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007784/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007785/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007786bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007787 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7788 for (;;) {
7789 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007790 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007791 return true;
7792
Eric Christopherbf7bc492013-01-09 03:52:05 +00007793 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007794
7795 if (getLexer().is(AsmToken::EndOfStatement))
7796 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007797
Kevin Enderbyccab3172009-09-15 00:27:25 +00007798 // FIXME: Improve diagnostic.
7799 if (getLexer().isNot(AsmToken::Comma))
7800 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007801 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007802 }
7803 }
7804
Sean Callanana83fd7d2010-01-19 20:27:46 +00007805 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007806 return false;
7807}
7808
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007809/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007810/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007811bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007812 if (getLexer().isNot(AsmToken::EndOfStatement))
7813 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007814 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007815
Tim Northovera2292d02013-06-10 23:20:58 +00007816 if (!hasThumb())
7817 return Error(L, "target does not support Thumb mode");
7818
Jim Grosbach7f882392011-12-07 18:04:19 +00007819 if (!isThumb())
7820 SwitchMode();
7821 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7822 return false;
7823}
7824
7825/// parseDirectiveARM
7826/// ::= .arm
7827bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7828 if (getLexer().isNot(AsmToken::EndOfStatement))
7829 return Error(L, "unexpected token in directive");
7830 Parser.Lex();
7831
Tim Northovera2292d02013-06-10 23:20:58 +00007832 if (!hasARM())
7833 return Error(L, "target does not support ARM mode");
7834
Jim Grosbach7f882392011-12-07 18:04:19 +00007835 if (isThumb())
7836 SwitchMode();
7837 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007838 return false;
7839}
7840
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007841/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007842/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007843bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007844 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7845 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007846 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007847 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007848
Jim Grosbach1152cc02011-12-21 22:30:16 +00007849 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007850 // ELF doesn't
7851 if (isMachO) {
7852 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007853 if (Tok.isNot(AsmToken::EndOfStatement)) {
7854 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7855 return Error(L, "unexpected token in .thumb_func directive");
7856 Name = Tok.getIdentifier();
7857 Parser.Lex(); // Consume the identifier token.
7858 needFuncName = false;
7859 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007860 }
7861
Jim Grosbach1152cc02011-12-21 22:30:16 +00007862 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007863 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007864
7865 // Eat the end of statement and any blank lines that follow.
7866 while (getLexer().is(AsmToken::EndOfStatement))
7867 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007868
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007869 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007870 // We really should be checking the next symbol definition even if there's
7871 // stuff in between.
7872 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007873 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007874 }
7875
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007876 // Mark symbol as a thumb symbol.
7877 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7878 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007879 return false;
7880}
7881
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007882/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007883/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007884bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007885 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007886 if (Tok.isNot(AsmToken::Identifier))
7887 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007888 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007889 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007890 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007891 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007892 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007893 else
7894 return Error(L, "unrecognized syntax mode in .syntax directive");
7895
7896 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007897 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007898 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007899
7900 // TODO tell the MC streamer the mode
7901 // getParser().getStreamer().Emit???();
7902 return false;
7903}
7904
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007905/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007906/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007907bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007908 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007909 if (Tok.isNot(AsmToken::Integer))
7910 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007911 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007912 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007913 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007914 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007915 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007916 else
7917 return Error(L, "invalid operand to .code directive");
7918
7919 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007920 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007921 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007922
Evan Cheng284b4672011-07-08 22:36:29 +00007923 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007924 if (!hasThumb())
7925 return Error(L, "target does not support Thumb mode");
7926
Jim Grosbachf471ac32011-09-06 18:46:23 +00007927 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007928 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007929 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007930 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007931 if (!hasARM())
7932 return Error(L, "target does not support ARM mode");
7933
Jim Grosbachf471ac32011-09-06 18:46:23 +00007934 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007935 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007936 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007937 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007938
Kevin Enderby146dcf22009-10-15 20:48:48 +00007939 return false;
7940}
7941
Jim Grosbachab5830e2011-12-14 02:16:11 +00007942/// parseDirectiveReq
7943/// ::= name .req registername
7944bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7945 Parser.Lex(); // Eat the '.req' token.
7946 unsigned Reg;
7947 SMLoc SRegLoc, ERegLoc;
7948 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007949 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007950 return Error(SRegLoc, "register name expected");
7951 }
7952
7953 // Shouldn't be anything else.
7954 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007955 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007956 return Error(Parser.getTok().getLoc(),
7957 "unexpected input in .req directive.");
7958 }
7959
7960 Parser.Lex(); // Consume the EndOfStatement
7961
7962 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7963 return Error(SRegLoc, "redefinition of '" + Name +
7964 "' does not match original.");
7965
7966 return false;
7967}
7968
7969/// parseDirectiveUneq
7970/// ::= .unreq registername
7971bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7972 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007973 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007974 return Error(L, "unexpected input in .unreq directive.");
7975 }
7976 RegisterReqs.erase(Parser.getTok().getIdentifier());
7977 Parser.Lex(); // Eat the identifier.
7978 return false;
7979}
7980
Jason W Kim135d2442011-12-20 17:38:12 +00007981/// parseDirectiveArch
7982/// ::= .arch token
7983bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7984 return true;
7985}
7986
7987/// parseDirectiveEabiAttr
7988/// ::= .eabi_attribute int, int
7989bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7990 return true;
7991}
7992
Logan Chien4ea23b52013-05-10 16:17:24 +00007993/// parseDirectiveFnStart
7994/// ::= .fnstart
7995bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7996 if (FnStartLoc.isValid()) {
7997 Error(L, ".fnstart starts before the end of previous one");
7998 Error(FnStartLoc, "previous .fnstart starts here");
7999 return true;
8000 }
8001
8002 FnStartLoc = L;
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008003 getTargetStreamer().emitFnStart();
Logan Chien4ea23b52013-05-10 16:17:24 +00008004 return false;
8005}
8006
8007/// parseDirectiveFnEnd
8008/// ::= .fnend
8009bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8010 // Check the ordering of unwind directives
8011 if (!FnStartLoc.isValid())
8012 return Error(L, ".fnstart must precede .fnend directive");
8013
8014 // Reset the unwind directives parser state
8015 resetUnwindDirectiveParserState();
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008016 getTargetStreamer().emitFnEnd();
Logan Chien4ea23b52013-05-10 16:17:24 +00008017 return false;
8018}
8019
8020/// parseDirectiveCantUnwind
8021/// ::= .cantunwind
8022bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8023 // Check the ordering of unwind directives
8024 CantUnwindLoc = L;
8025 if (!FnStartLoc.isValid())
8026 return Error(L, ".fnstart must precede .cantunwind directive");
8027 if (HandlerDataLoc.isValid()) {
8028 Error(L, ".cantunwind can't be used with .handlerdata directive");
8029 Error(HandlerDataLoc, ".handlerdata was specified here");
8030 return true;
8031 }
8032 if (PersonalityLoc.isValid()) {
8033 Error(L, ".cantunwind can't be used with .personality directive");
8034 Error(PersonalityLoc, ".personality was specified here");
8035 return true;
8036 }
8037
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008038 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00008039 return false;
8040}
8041
8042/// parseDirectivePersonality
8043/// ::= .personality name
8044bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8045 // Check the ordering of unwind directives
8046 PersonalityLoc = L;
8047 if (!FnStartLoc.isValid())
8048 return Error(L, ".fnstart must precede .personality directive");
8049 if (CantUnwindLoc.isValid()) {
8050 Error(L, ".personality can't be used with .cantunwind directive");
8051 Error(CantUnwindLoc, ".cantunwind was specified here");
8052 return true;
8053 }
8054 if (HandlerDataLoc.isValid()) {
8055 Error(L, ".personality must precede .handlerdata directive");
8056 Error(HandlerDataLoc, ".handlerdata was specified here");
8057 return true;
8058 }
8059
8060 // Parse the name of the personality routine
8061 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8062 Parser.eatToEndOfStatement();
8063 return Error(L, "unexpected input in .personality directive.");
8064 }
8065 StringRef Name(Parser.getTok().getIdentifier());
8066 Parser.Lex();
8067
8068 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008069 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00008070 return false;
8071}
8072
8073/// parseDirectiveHandlerData
8074/// ::= .handlerdata
8075bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8076 // Check the ordering of unwind directives
8077 HandlerDataLoc = L;
8078 if (!FnStartLoc.isValid())
8079 return Error(L, ".fnstart must precede .personality directive");
8080 if (CantUnwindLoc.isValid()) {
8081 Error(L, ".handlerdata can't be used with .cantunwind directive");
8082 Error(CantUnwindLoc, ".cantunwind was specified here");
8083 return true;
8084 }
8085
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008086 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00008087 return false;
8088}
8089
8090/// parseDirectiveSetFP
8091/// ::= .setfp fpreg, spreg [, offset]
8092bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8093 // Check the ordering of unwind directives
8094 if (!FnStartLoc.isValid())
8095 return Error(L, ".fnstart must precede .setfp directive");
8096 if (HandlerDataLoc.isValid())
8097 return Error(L, ".setfp must precede .handlerdata directive");
8098
8099 // Parse fpreg
8100 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8101 int NewFPReg = tryParseRegister();
8102 if (NewFPReg == -1)
8103 return Error(NewFPRegLoc, "frame pointer register expected");
8104
8105 // Consume comma
8106 if (!Parser.getTok().is(AsmToken::Comma))
8107 return Error(Parser.getTok().getLoc(), "comma expected");
8108 Parser.Lex(); // skip comma
8109
8110 // Parse spreg
8111 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8112 int NewSPReg = tryParseRegister();
8113 if (NewSPReg == -1)
8114 return Error(NewSPRegLoc, "stack pointer register expected");
8115
8116 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8117 return Error(NewSPRegLoc,
8118 "register should be either $sp or the latest fp register");
8119
8120 // Update the frame pointer register
8121 FPReg = NewFPReg;
8122
8123 // Parse offset
8124 int64_t Offset = 0;
8125 if (Parser.getTok().is(AsmToken::Comma)) {
8126 Parser.Lex(); // skip comma
8127
8128 if (Parser.getTok().isNot(AsmToken::Hash) &&
8129 Parser.getTok().isNot(AsmToken::Dollar)) {
8130 return Error(Parser.getTok().getLoc(), "'#' expected");
8131 }
8132 Parser.Lex(); // skip hash token.
8133
8134 const MCExpr *OffsetExpr;
8135 SMLoc ExLoc = Parser.getTok().getLoc();
8136 SMLoc EndLoc;
8137 if (getParser().parseExpression(OffsetExpr, EndLoc))
8138 return Error(ExLoc, "malformed setfp offset");
8139 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8140 if (!CE)
8141 return Error(ExLoc, "setfp offset must be an immediate");
8142
8143 Offset = CE->getValue();
8144 }
8145
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008146 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8147 static_cast<unsigned>(NewSPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00008148 return false;
8149}
8150
8151/// parseDirective
8152/// ::= .pad offset
8153bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8154 // Check the ordering of unwind directives
8155 if (!FnStartLoc.isValid())
8156 return Error(L, ".fnstart must precede .pad directive");
8157 if (HandlerDataLoc.isValid())
8158 return Error(L, ".pad must precede .handlerdata directive");
8159
8160 // Parse the offset
8161 if (Parser.getTok().isNot(AsmToken::Hash) &&
8162 Parser.getTok().isNot(AsmToken::Dollar)) {
8163 return Error(Parser.getTok().getLoc(), "'#' expected");
8164 }
8165 Parser.Lex(); // skip hash token.
8166
8167 const MCExpr *OffsetExpr;
8168 SMLoc ExLoc = Parser.getTok().getLoc();
8169 SMLoc EndLoc;
8170 if (getParser().parseExpression(OffsetExpr, EndLoc))
8171 return Error(ExLoc, "malformed pad offset");
8172 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8173 if (!CE)
8174 return Error(ExLoc, "pad offset must be an immediate");
8175
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008176 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00008177 return false;
8178}
8179
8180/// parseDirectiveRegSave
8181/// ::= .save { registers }
8182/// ::= .vsave { registers }
8183bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8184 // Check the ordering of unwind directives
8185 if (!FnStartLoc.isValid())
8186 return Error(L, ".fnstart must precede .save or .vsave directives");
8187 if (HandlerDataLoc.isValid())
8188 return Error(L, ".save or .vsave must precede .handlerdata directive");
8189
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008190 // RAII object to make sure parsed operands are deleted.
8191 struct CleanupObject {
8192 SmallVector<MCParsedAsmOperand *, 1> Operands;
8193 ~CleanupObject() {
8194 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8195 delete Operands[I];
8196 }
8197 } CO;
8198
Logan Chien4ea23b52013-05-10 16:17:24 +00008199 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008200 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008201 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008202 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008203 if (!IsVector && !Op->isRegList())
8204 return Error(L, ".save expects GPR registers");
8205 if (IsVector && !Op->isDPRRegList())
8206 return Error(L, ".vsave expects DPR registers");
8207
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008208 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00008209 return false;
8210}
8211
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008212/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008213extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008214 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8215 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008216}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008217
Chris Lattner3e4582a2010-09-06 19:11:01 +00008218#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008219#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008220#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008221#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008222
8223// Define this matcher function after the auto-generated include so we
8224// have the match class enum definitions.
8225unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8226 unsigned Kind) {
8227 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8228 // If the kind is a token for a literal immediate, check if our asm
8229 // operand matches. This is for InstAliases which have a fixed-value
8230 // immediate in the syntax.
8231 if (Kind == MCK__35_0 && Op->isImm()) {
8232 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8233 if (!CE)
8234 return Match_InvalidOperand;
8235 if (CE->getValue() == 0)
8236 return Match_Success;
8237 }
8238 return Match_InvalidOperand;
8239}