blob: 084ac9b0a16aefa11116a6984724319e2fbb2668 [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 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000706 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000707 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000708 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
709 if (!CE) return false;
710 int64_t Value = CE->getValue();
711 return Value >= 0 && Value < 256;
712 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000713 bool isImm0_4095() const {
714 if (!isImm()) return false;
715 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
716 if (!CE) return false;
717 int64_t Value = CE->getValue();
718 return Value >= 0 && Value < 4096;
719 }
720 bool isImm0_4095Neg() 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 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000727 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000728 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000729 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
730 if (!CE) return false;
731 int64_t Value = CE->getValue();
732 return Value >= 0 && Value < 2;
733 }
734 bool isImm0_3() 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 < 4;
740 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000741 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000742 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000743 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
744 if (!CE) return false;
745 int64_t Value = CE->getValue();
746 return Value >= 0 && Value < 8;
747 }
748 bool isImm0_15() 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 < 16;
754 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000755 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000756 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000757 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
758 if (!CE) return false;
759 int64_t Value = CE->getValue();
760 return Value >= 0 && Value < 32;
761 }
Jim Grosbach00326402011-12-08 01:30:04 +0000762 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000763 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000764 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
765 if (!CE) return false;
766 int64_t Value = CE->getValue();
767 return Value >= 0 && Value < 64;
768 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000769 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000770 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000771 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
772 if (!CE) return false;
773 int64_t Value = CE->getValue();
774 return Value == 8;
775 }
776 bool isImm16() 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 == 16;
782 }
783 bool isImm32() 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 == 32;
789 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000790 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000791 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
793 if (!CE) return false;
794 int64_t Value = CE->getValue();
795 return Value > 0 && Value <= 8;
796 }
797 bool isShrImm16() 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 <= 16;
803 }
804 bool isShrImm32() 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 <= 32;
810 }
811 bool isShrImm64() 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 <= 64;
817 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000818 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000819 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
821 if (!CE) return false;
822 int64_t Value = CE->getValue();
823 return Value > 0 && Value < 8;
824 }
825 bool isImm1_15() 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 < 16;
831 }
832 bool isImm1_31() 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 < 32;
838 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000839 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000840 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
842 if (!CE) return false;
843 int64_t Value = CE->getValue();
844 return Value > 0 && Value < 17;
845 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000846 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000847 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
849 if (!CE) return false;
850 int64_t Value = CE->getValue();
851 return Value > 0 && Value < 33;
852 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000853 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000854 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +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 Grosbach975b6412011-07-13 20:10:10 +0000860 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000861 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
863 if (!CE) return false;
864 int64_t Value = CE->getValue();
865 return Value >= 0 && Value < 65536;
866 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000867 bool isImm256_65535Expr() const {
868 if (!isImm()) return false;
869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
870 // If it's not a constant expression, it'll generate a fixup and be
871 // handled later.
872 if (!CE) return true;
873 int64_t Value = CE->getValue();
874 return Value >= 256 && Value < 65536;
875 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000876 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000877 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000878 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
879 // If it's not a constant expression, it'll generate a fixup and be
880 // handled later.
881 if (!CE) return true;
882 int64_t Value = CE->getValue();
883 return Value >= 0 && Value < 65536;
884 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000885 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000886 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000887 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
888 if (!CE) return false;
889 int64_t Value = CE->getValue();
890 return Value >= 0 && Value <= 0xffffff;
891 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000892 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000893 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51: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 < 33;
898 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000899 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000900 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000901 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
902 if (!CE) return false;
903 int64_t Value = CE->getValue();
904 return Value >= 0 && Value < 32;
905 }
906 bool isPKHASRImm() 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 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000913 bool isAdrLabel() const {
914 // If we have an immediate that's not a constant, treat it as a label
915 // reference needing a fixup. If it is a constant, but it can't fit
916 // into shift immediate encoding, we reject it.
917 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
918 else return (isARMSOImm() || isARMSOImmNeg());
919 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000920 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000921 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000922 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
923 if (!CE) return false;
924 int64_t Value = CE->getValue();
925 return ARM_AM::getSOImmVal(Value) != -1;
926 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000927 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000928 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +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 Grosbach30506252011-12-08 00:31:07 +0000934 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000935 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000936 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
937 if (!CE) return false;
938 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000939 // Only use this when not representable as a plain so_imm.
940 return ARM_AM::getSOImmVal(Value) == -1 &&
941 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000942 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000943 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000944 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000945 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
946 if (!CE) return false;
947 int64_t Value = CE->getValue();
948 return ARM_AM::getT2SOImmVal(Value) != -1;
949 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000950 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000951 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000952 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
953 if (!CE) return false;
954 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +0000955 return ARM_AM::getT2SOImmVal(Value) == -1 &&
956 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +0000957 }
Jim Grosbach30506252011-12-08 00:31:07 +0000958 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000959 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000960 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
961 if (!CE) return false;
962 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000963 // Only use this when not representable as a plain so_imm.
964 return ARM_AM::getT2SOImmVal(Value) == -1 &&
965 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000966 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000967 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000968 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000969 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
970 if (!CE) return false;
971 int64_t Value = CE->getValue();
972 return Value == 1 || Value == 0;
973 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000974 bool isReg() const { return Kind == k_Register; }
975 bool isRegList() const { return Kind == k_RegisterList; }
976 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
977 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
978 bool isToken() const { return Kind == k_Token; }
979 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000980 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000981 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000982 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
983 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
984 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
985 bool isRotImm() const { return Kind == k_RotateImmediate; }
986 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
987 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000988 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000989 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000990 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000991 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000992 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000993 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000994 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000995 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
996 (alignOK || Memory.Alignment == 0);
997 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000998 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000999 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001000 return false;
1001 // Base register must be PC.
1002 if (Memory.BaseRegNum != ARM::PC)
1003 return false;
1004 // Immediate offset in range [-4095, 4095].
1005 if (!Memory.OffsetImm) return true;
1006 int64_t Val = Memory.OffsetImm->getValue();
1007 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1008 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001009 bool isAlignedMemory() const {
1010 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001011 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001012 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001013 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001014 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001015 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001016 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001017 if (!Memory.OffsetImm) return true;
1018 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001019 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001020 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001021 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001022 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001023 // Immediate offset in range [-4095, 4095].
1024 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1025 if (!CE) return false;
1026 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001027 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001028 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001029 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001030 // If we have an immediate that's not a constant, treat it as a label
1031 // reference needing a fixup. If it is a constant, it's something else
1032 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001033 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001034 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001035 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001036 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001037 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001038 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001039 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001040 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001041 if (!Memory.OffsetImm) return true;
1042 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001043 // The #-0 offset is encoded as INT32_MIN, and we have to check
1044 // for this too.
1045 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001046 }
1047 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001048 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001049 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001050 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001051 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1052 // Immediate offset in range [-255, 255].
1053 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1054 if (!CE) return false;
1055 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001056 // Special case, #-0 is INT32_MIN.
1057 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001058 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001059 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001060 // If we have an immediate that's not a constant, treat it as a label
1061 // reference needing a fixup. If it is a constant, it's something else
1062 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001063 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001064 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001065 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001066 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001067 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001068 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001069 if (!Memory.OffsetImm) return true;
1070 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001071 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001072 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001073 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001074 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001075 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001076 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001077 return false;
1078 return true;
1079 }
1080 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001081 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001082 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1083 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001084 return false;
1085 return true;
1086 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001087 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001088 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001089 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001090 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001091 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001092 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001093 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001094 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001095 return false;
1096 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001097 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001098 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001099 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001100 return false;
1101 return true;
1102 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001103 bool isMemThumbRR() const {
1104 // Thumb reg+reg addressing is simple. Just two registers, a base and
1105 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001106 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001107 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001108 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001109 return isARMLowRegister(Memory.BaseRegNum) &&
1110 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001111 }
1112 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001113 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001114 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001115 return false;
1116 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001117 if (!Memory.OffsetImm) return true;
1118 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001119 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1120 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001121 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001122 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001123 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001124 return false;
1125 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001126 if (!Memory.OffsetImm) return true;
1127 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001128 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1129 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001130 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001131 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001132 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001133 return false;
1134 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001135 if (!Memory.OffsetImm) return true;
1136 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001137 return Val >= 0 && Val <= 31;
1138 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001139 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001140 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001141 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001142 return false;
1143 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001144 if (!Memory.OffsetImm) return true;
1145 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001146 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001147 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001148 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001149 // If we have an immediate that's not a constant, treat it as a label
1150 // reference needing a fixup. If it is a constant, it's something else
1151 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001152 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001153 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001154 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001155 return false;
1156 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001157 if (!Memory.OffsetImm) return true;
1158 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001159 // Special case, #-0 is INT32_MIN.
1160 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001161 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001162 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001163 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001164 return false;
1165 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001166 if (!Memory.OffsetImm) return true;
1167 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001168 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1169 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001170 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001171 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001172 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001173 // Base reg of PC isn't allowed for these encodings.
1174 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001175 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001176 if (!Memory.OffsetImm) return true;
1177 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001178 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001179 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001180 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001181 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001182 return false;
1183 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001184 if (!Memory.OffsetImm) return true;
1185 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001186 return Val >= 0 && Val < 256;
1187 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001188 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001189 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001190 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001191 // Base reg of PC isn't allowed for these encodings.
1192 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001193 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001194 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001195 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001196 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001197 }
1198 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001199 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001200 return false;
1201 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001202 if (!Memory.OffsetImm) return true;
1203 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001204 return (Val >= 0 && Val < 4096);
1205 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001206 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001207 // If we have an immediate that's not a constant, treat it as a label
1208 // reference needing a fixup. If it is a constant, it's something else
1209 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001210 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001211 return true;
1212
Chad Rosier41099832012-09-11 23:02:35 +00001213 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001214 return false;
1215 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001216 if (!Memory.OffsetImm) return true;
1217 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001218 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001219 }
1220 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001221 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001222 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1223 if (!CE) return false;
1224 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001225 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001226 }
Jim Grosbach93981412011-10-11 21:55:36 +00001227 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001228 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001229 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1230 if (!CE) return false;
1231 int64_t Val = CE->getValue();
1232 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1233 (Val == INT32_MIN);
1234 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001235
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001236 bool isMSRMask() const { return Kind == k_MSRMask; }
1237 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001238
Jim Grosbach741cd732011-10-17 22:26:03 +00001239 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001240 bool isSingleSpacedVectorList() const {
1241 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1242 }
1243 bool isDoubleSpacedVectorList() const {
1244 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1245 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001246 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001247 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001248 return VectorList.Count == 1;
1249 }
1250
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001251 bool isVecListDPair() const {
1252 if (!isSingleSpacedVectorList()) return false;
1253 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1254 .contains(VectorList.RegNum));
1255 }
1256
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001257 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001258 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001259 return VectorList.Count == 3;
1260 }
1261
Jim Grosbach846bcff2011-10-21 20:35:01 +00001262 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001263 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001264 return VectorList.Count == 4;
1265 }
1266
Jim Grosbache5307f92012-03-05 21:43:40 +00001267 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001268 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001269 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1270 .contains(VectorList.RegNum));
1271 }
1272
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001273 bool isVecListThreeQ() const {
1274 if (!isDoubleSpacedVectorList()) return false;
1275 return VectorList.Count == 3;
1276 }
1277
Jim Grosbach1e946a42012-01-24 00:43:12 +00001278 bool isVecListFourQ() const {
1279 if (!isDoubleSpacedVectorList()) return false;
1280 return VectorList.Count == 4;
1281 }
1282
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001283 bool isSingleSpacedVectorAllLanes() const {
1284 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1285 }
1286 bool isDoubleSpacedVectorAllLanes() const {
1287 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1288 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001289 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001290 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001291 return VectorList.Count == 1;
1292 }
1293
Jim Grosbach13a292c2012-03-06 22:01:44 +00001294 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001295 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001296 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1297 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001298 }
1299
Jim Grosbached428bc2012-03-06 23:10:38 +00001300 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001301 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001302 return VectorList.Count == 2;
1303 }
1304
Jim Grosbachb78403c2012-01-24 23:47:04 +00001305 bool isVecListThreeDAllLanes() const {
1306 if (!isSingleSpacedVectorAllLanes()) return false;
1307 return VectorList.Count == 3;
1308 }
1309
1310 bool isVecListThreeQAllLanes() const {
1311 if (!isDoubleSpacedVectorAllLanes()) return false;
1312 return VectorList.Count == 3;
1313 }
1314
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001315 bool isVecListFourDAllLanes() const {
1316 if (!isSingleSpacedVectorAllLanes()) return false;
1317 return VectorList.Count == 4;
1318 }
1319
1320 bool isVecListFourQAllLanes() const {
1321 if (!isDoubleSpacedVectorAllLanes()) return false;
1322 return VectorList.Count == 4;
1323 }
1324
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001325 bool isSingleSpacedVectorIndexed() const {
1326 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1327 }
1328 bool isDoubleSpacedVectorIndexed() const {
1329 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1330 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001331 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001332 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001333 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1334 }
1335
Jim Grosbachda511042011-12-14 23:35:06 +00001336 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001337 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001338 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1339 }
1340
1341 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001342 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001343 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1344 }
1345
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001346 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001347 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001348 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1349 }
1350
Jim Grosbachda511042011-12-14 23:35:06 +00001351 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001352 if (!isSingleSpacedVectorIndexed()) return false;
1353 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1354 }
1355
1356 bool isVecListTwoQWordIndexed() const {
1357 if (!isDoubleSpacedVectorIndexed()) return false;
1358 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1359 }
1360
1361 bool isVecListTwoQHWordIndexed() const {
1362 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001363 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1364 }
1365
1366 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001367 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001368 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1369 }
1370
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001371 bool isVecListThreeDByteIndexed() const {
1372 if (!isSingleSpacedVectorIndexed()) return false;
1373 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1374 }
1375
1376 bool isVecListThreeDHWordIndexed() const {
1377 if (!isSingleSpacedVectorIndexed()) return false;
1378 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1379 }
1380
1381 bool isVecListThreeQWordIndexed() const {
1382 if (!isDoubleSpacedVectorIndexed()) return false;
1383 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1384 }
1385
1386 bool isVecListThreeQHWordIndexed() const {
1387 if (!isDoubleSpacedVectorIndexed()) return false;
1388 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1389 }
1390
1391 bool isVecListThreeDWordIndexed() const {
1392 if (!isSingleSpacedVectorIndexed()) return false;
1393 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1394 }
1395
Jim Grosbach14952a02012-01-24 18:37:25 +00001396 bool isVecListFourDByteIndexed() const {
1397 if (!isSingleSpacedVectorIndexed()) return false;
1398 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1399 }
1400
1401 bool isVecListFourDHWordIndexed() const {
1402 if (!isSingleSpacedVectorIndexed()) return false;
1403 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1404 }
1405
1406 bool isVecListFourQWordIndexed() const {
1407 if (!isDoubleSpacedVectorIndexed()) return false;
1408 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1409 }
1410
1411 bool isVecListFourQHWordIndexed() const {
1412 if (!isDoubleSpacedVectorIndexed()) return false;
1413 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1414 }
1415
1416 bool isVecListFourDWordIndexed() const {
1417 if (!isSingleSpacedVectorIndexed()) return false;
1418 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1419 }
1420
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001421 bool isVectorIndex8() const {
1422 if (Kind != k_VectorIndex) return false;
1423 return VectorIndex.Val < 8;
1424 }
1425 bool isVectorIndex16() const {
1426 if (Kind != k_VectorIndex) return false;
1427 return VectorIndex.Val < 4;
1428 }
1429 bool isVectorIndex32() const {
1430 if (Kind != k_VectorIndex) return false;
1431 return VectorIndex.Val < 2;
1432 }
1433
Jim Grosbach741cd732011-10-17 22:26:03 +00001434 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001435 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001436 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1437 // Must be a constant.
1438 if (!CE) return false;
1439 int64_t Value = CE->getValue();
1440 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1441 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001442 return Value >= 0 && Value < 256;
1443 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001444
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001445 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001446 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001447 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1448 // Must be a constant.
1449 if (!CE) return false;
1450 int64_t Value = CE->getValue();
1451 // i16 value in the range [0,255] or [0x0100, 0xff00]
1452 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1453 }
1454
Jim Grosbach8211c052011-10-18 00:22:00 +00001455 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001456 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001457 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1458 // Must be a constant.
1459 if (!CE) return false;
1460 int64_t Value = CE->getValue();
1461 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1462 return (Value >= 0 && Value < 256) ||
1463 (Value >= 0x0100 && Value <= 0xff00) ||
1464 (Value >= 0x010000 && Value <= 0xff0000) ||
1465 (Value >= 0x01000000 && Value <= 0xff000000);
1466 }
1467
1468 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001469 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001470 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1471 // Must be a constant.
1472 if (!CE) return false;
1473 int64_t Value = CE->getValue();
1474 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1475 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1476 return (Value >= 0 && Value < 256) ||
1477 (Value >= 0x0100 && Value <= 0xff00) ||
1478 (Value >= 0x010000 && Value <= 0xff0000) ||
1479 (Value >= 0x01000000 && Value <= 0xff000000) ||
1480 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1481 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1482 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001483 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001484 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001485 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1486 // Must be a constant.
1487 if (!CE) return false;
1488 int64_t Value = ~CE->getValue();
1489 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1490 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1491 return (Value >= 0 && Value < 256) ||
1492 (Value >= 0x0100 && Value <= 0xff00) ||
1493 (Value >= 0x010000 && Value <= 0xff0000) ||
1494 (Value >= 0x01000000 && Value <= 0xff000000) ||
1495 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1496 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1497 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001498
Jim Grosbache4454e02011-10-18 16:18:11 +00001499 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001500 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001501 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1502 // Must be a constant.
1503 if (!CE) return false;
1504 uint64_t Value = CE->getValue();
1505 // i64 value with each byte being either 0 or 0xff.
1506 for (unsigned i = 0; i < 8; ++i)
1507 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1508 return true;
1509 }
1510
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001511 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001512 // Add as immediates when possible. Null MCExpr = 0.
1513 if (Expr == 0)
1514 Inst.addOperand(MCOperand::CreateImm(0));
1515 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001516 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1517 else
1518 Inst.addOperand(MCOperand::CreateExpr(Expr));
1519 }
1520
Daniel Dunbard8042b72010-08-11 06:36:53 +00001521 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001522 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001523 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001524 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1525 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001526 }
1527
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001528 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1529 assert(N == 1 && "Invalid number of operands!");
1530 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1531 }
1532
Jim Grosbach48399582011-10-12 17:34:41 +00001533 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1534 assert(N == 1 && "Invalid number of operands!");
1535 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1536 }
1537
1538 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1539 assert(N == 1 && "Invalid number of operands!");
1540 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1541 }
1542
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001543 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1544 assert(N == 1 && "Invalid number of operands!");
1545 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1546 }
1547
1548 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1549 assert(N == 1 && "Invalid number of operands!");
1550 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1551 }
1552
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001553 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 Inst.addOperand(MCOperand::CreateReg(getReg()));
1556 }
1557
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001558 void addRegOperands(MCInst &Inst, unsigned N) const {
1559 assert(N == 1 && "Invalid number of operands!");
1560 Inst.addOperand(MCOperand::CreateReg(getReg()));
1561 }
1562
Jim Grosbachac798e12011-07-25 20:49:51 +00001563 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001564 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001565 assert(isRegShiftedReg() &&
1566 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001567 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1568 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001569 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001570 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001571 }
1572
Jim Grosbachac798e12011-07-25 20:49:51 +00001573 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001574 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001575 assert(isRegShiftedImm() &&
1576 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001577 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001578 // Shift of #32 is encoded as 0 where permitted
1579 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001580 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001581 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001582 }
1583
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001584 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001585 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001586 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1587 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001588 }
1589
Bill Wendling8d2aa032010-11-08 23:49:57 +00001590 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001591 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001592 const SmallVectorImpl<unsigned> &RegList = getRegList();
1593 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001594 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1595 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001596 }
1597
Bill Wendling9898ac92010-11-17 04:32:08 +00001598 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1599 addRegListOperands(Inst, N);
1600 }
1601
1602 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1603 addRegListOperands(Inst, N);
1604 }
1605
Jim Grosbach833b9d32011-07-27 20:15:40 +00001606 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1607 assert(N == 1 && "Invalid number of operands!");
1608 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1609 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1610 }
1611
Jim Grosbach864b6092011-07-28 21:34:26 +00001612 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1613 assert(N == 1 && "Invalid number of operands!");
1614 // Munge the lsb/width into a bitfield mask.
1615 unsigned lsb = Bitfield.LSB;
1616 unsigned width = Bitfield.Width;
1617 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1618 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1619 (32 - (lsb + width)));
1620 Inst.addOperand(MCOperand::CreateImm(Mask));
1621 }
1622
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001623 void addImmOperands(MCInst &Inst, unsigned N) const {
1624 assert(N == 1 && "Invalid number of operands!");
1625 addExpr(Inst, getImm());
1626 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001627
Jim Grosbachea231912011-12-22 22:19:05 +00001628 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1629 assert(N == 1 && "Invalid number of operands!");
1630 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1631 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1632 }
1633
1634 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1635 assert(N == 1 && "Invalid number of operands!");
1636 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1637 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1638 }
1639
Jim Grosbache7fbce72011-10-03 23:38:36 +00001640 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1641 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001642 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1643 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1644 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001645 }
1646
Jim Grosbach7db8d692011-09-08 22:07:06 +00001647 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1648 assert(N == 1 && "Invalid number of operands!");
1649 // FIXME: We really want to scale the value here, but the LDRD/STRD
1650 // instruction don't encode operands that way yet.
1651 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1652 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1653 }
1654
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001655 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1656 assert(N == 1 && "Invalid number of operands!");
1657 // The immediate is scaled by four in the encoding and is stored
1658 // in the MCInst as such. Lop off the low two bits here.
1659 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1660 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1661 }
1662
Jim Grosbach930f2f62012-04-05 20:57:13 +00001663 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1664 assert(N == 1 && "Invalid number of operands!");
1665 // The immediate is scaled by four in the encoding and is stored
1666 // in the MCInst as such. Lop off the low two bits here.
1667 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1668 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1669 }
1670
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001671 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1672 assert(N == 1 && "Invalid number of operands!");
1673 // The immediate is scaled by four in the encoding and is stored
1674 // in the MCInst as such. Lop off the low two bits here.
1675 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1676 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1677 }
1678
Jim Grosbach475c6db2011-07-25 23:09:14 +00001679 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1680 assert(N == 1 && "Invalid number of operands!");
1681 // The constant encodes as the immediate-1, and we store in the instruction
1682 // the bits as encoded, so subtract off one here.
1683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1684 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1685 }
1686
Jim Grosbach801e0a32011-07-22 23:16:18 +00001687 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1688 assert(N == 1 && "Invalid number of operands!");
1689 // The constant encodes as the immediate-1, and we store in the instruction
1690 // the bits as encoded, so subtract off one here.
1691 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1692 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1693 }
1694
Jim Grosbach46dd4132011-08-17 21:51:27 +00001695 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1696 assert(N == 1 && "Invalid number of operands!");
1697 // The constant encodes as the immediate, except for 32, which encodes as
1698 // zero.
1699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1700 unsigned Imm = CE->getValue();
1701 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1702 }
1703
Jim Grosbach27c1e252011-07-21 17:23:04 +00001704 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1705 assert(N == 1 && "Invalid number of operands!");
1706 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1707 // the instruction as well.
1708 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1709 int Val = CE->getValue();
1710 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1711 }
1712
Jim Grosbachb009a872011-10-28 22:36:30 +00001713 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1714 assert(N == 1 && "Invalid number of operands!");
1715 // The operand is actually a t2_so_imm, but we have its bitwise
1716 // negation in the assembly source, so twiddle it here.
1717 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1718 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1719 }
1720
Jim Grosbach30506252011-12-08 00:31:07 +00001721 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1722 assert(N == 1 && "Invalid number of operands!");
1723 // The operand is actually a t2_so_imm, but we have its
1724 // negation in the assembly source, so twiddle it here.
1725 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1726 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1727 }
1728
Jim Grosbach930f2f62012-04-05 20:57:13 +00001729 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1730 assert(N == 1 && "Invalid number of operands!");
1731 // The operand is actually an imm0_4095, but we have its
1732 // negation in the assembly source, so twiddle it here.
1733 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1734 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1735 }
1736
Mihai Popad36cbaa2013-07-03 09:21:44 +00001737 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1738 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1739 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1740 return;
1741 }
1742
1743 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1744 assert(SR && "Unknown value type!");
1745 Inst.addOperand(MCOperand::CreateExpr(SR));
1746 }
1747
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001748 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1749 assert(N == 1 && "Invalid number of operands!");
1750 if (isImm()) {
1751 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1752 if (CE) {
1753 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1754 return;
1755 }
1756
1757 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1758 assert(SR && "Unknown value type!");
1759 Inst.addOperand(MCOperand::CreateExpr(SR));
1760 return;
1761 }
1762
1763 assert(isMem() && "Unknown value type!");
1764 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1765 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1766 }
1767
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001768 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1769 assert(N == 1 && "Invalid number of operands!");
1770 // The operand is actually a so_imm, but we have its bitwise
1771 // negation in the assembly source, so twiddle it here.
1772 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1773 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1774 }
1775
Jim Grosbach30506252011-12-08 00:31:07 +00001776 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1777 assert(N == 1 && "Invalid number of operands!");
1778 // The operand is actually a so_imm, but we have its
1779 // negation in the assembly source, so twiddle it here.
1780 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1781 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1782 }
1783
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001784 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1785 assert(N == 1 && "Invalid number of operands!");
1786 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1787 }
1788
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001789 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1790 assert(N == 1 && "Invalid number of operands!");
1791 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1792 }
1793
Jim Grosbachd3595712011-08-03 23:50:40 +00001794 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1795 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001796 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001797 }
1798
Jim Grosbach94298a92012-01-18 22:46:46 +00001799 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1800 assert(N == 1 && "Invalid number of operands!");
1801 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001802 Inst.addOperand(MCOperand::CreateImm(Imm));
1803 }
1804
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001805 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1806 assert(N == 1 && "Invalid number of operands!");
1807 assert(isImm() && "Not an immediate!");
1808
1809 // If we have an immediate that's not a constant, treat it as a label
1810 // reference needing a fixup.
1811 if (!isa<MCConstantExpr>(getImm())) {
1812 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1813 return;
1814 }
1815
1816 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1817 int Val = CE->getValue();
1818 Inst.addOperand(MCOperand::CreateImm(Val));
1819 }
1820
Jim Grosbacha95ec992011-10-11 17:29:55 +00001821 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1822 assert(N == 2 && "Invalid number of operands!");
1823 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1824 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1825 }
1826
Jim Grosbachd3595712011-08-03 23:50:40 +00001827 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1828 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001829 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1830 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001831 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1832 // Special case for #-0
1833 if (Val == INT32_MIN) Val = 0;
1834 if (Val < 0) Val = -Val;
1835 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1836 } else {
1837 // For register offset, we encode the shift type and negation flag
1838 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001839 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1840 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001841 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001842 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1843 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001844 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001845 }
1846
Jim Grosbachcd17c122011-08-04 23:01:30 +00001847 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1848 assert(N == 2 && "Invalid number of operands!");
1849 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1850 assert(CE && "non-constant AM2OffsetImm operand!");
1851 int32_t Val = CE->getValue();
1852 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1853 // Special case for #-0
1854 if (Val == INT32_MIN) Val = 0;
1855 if (Val < 0) Val = -Val;
1856 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1857 Inst.addOperand(MCOperand::CreateReg(0));
1858 Inst.addOperand(MCOperand::CreateImm(Val));
1859 }
1860
Jim Grosbach5b96b802011-08-10 20:29:19 +00001861 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1862 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001863 // If we have an immediate that's not a constant, treat it as a label
1864 // reference needing a fixup. If it is a constant, it's something else
1865 // and we reject it.
1866 if (isImm()) {
1867 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1868 Inst.addOperand(MCOperand::CreateReg(0));
1869 Inst.addOperand(MCOperand::CreateImm(0));
1870 return;
1871 }
1872
Jim Grosbach871dff72011-10-11 15:59:20 +00001873 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1874 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001875 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1876 // Special case for #-0
1877 if (Val == INT32_MIN) Val = 0;
1878 if (Val < 0) Val = -Val;
1879 Val = ARM_AM::getAM3Opc(AddSub, Val);
1880 } else {
1881 // For register offset, we encode the shift type and negation flag
1882 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001883 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001884 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001885 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1886 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001887 Inst.addOperand(MCOperand::CreateImm(Val));
1888 }
1889
1890 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1891 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001892 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001893 int32_t Val =
1894 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1895 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1896 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001897 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001898 }
1899
1900 // Constant offset.
1901 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1902 int32_t Val = CE->getValue();
1903 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1904 // Special case for #-0
1905 if (Val == INT32_MIN) Val = 0;
1906 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001907 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001908 Inst.addOperand(MCOperand::CreateReg(0));
1909 Inst.addOperand(MCOperand::CreateImm(Val));
1910 }
1911
Jim Grosbachd3595712011-08-03 23:50:40 +00001912 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1913 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001914 // If we have an immediate that's not a constant, treat it as a label
1915 // reference needing a fixup. If it is a constant, it's something else
1916 // and we reject it.
1917 if (isImm()) {
1918 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1919 Inst.addOperand(MCOperand::CreateImm(0));
1920 return;
1921 }
1922
Jim Grosbachd3595712011-08-03 23:50:40 +00001923 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001924 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001925 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1926 // Special case for #-0
1927 if (Val == INT32_MIN) Val = 0;
1928 if (Val < 0) Val = -Val;
1929 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001930 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001931 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001932 }
1933
Jim Grosbach7db8d692011-09-08 22:07:06 +00001934 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1935 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001936 // If we have an immediate that's not a constant, treat it as a label
1937 // reference needing a fixup. If it is a constant, it's something else
1938 // and we reject it.
1939 if (isImm()) {
1940 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1941 Inst.addOperand(MCOperand::CreateImm(0));
1942 return;
1943 }
1944
Jim Grosbach871dff72011-10-11 15:59:20 +00001945 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1946 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001947 Inst.addOperand(MCOperand::CreateImm(Val));
1948 }
1949
Jim Grosbacha05627e2011-09-09 18:37:27 +00001950 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1951 assert(N == 2 && "Invalid number of operands!");
1952 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001953 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1954 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001955 Inst.addOperand(MCOperand::CreateImm(Val));
1956 }
1957
Jim Grosbachd3595712011-08-03 23:50:40 +00001958 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1959 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001960 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1961 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001962 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001963 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001964
Jim Grosbach2392c532011-09-07 23:39:14 +00001965 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1966 addMemImm8OffsetOperands(Inst, N);
1967 }
1968
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001969 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001970 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001971 }
1972
1973 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1974 assert(N == 2 && "Invalid number of operands!");
1975 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001976 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001977 addExpr(Inst, getImm());
1978 Inst.addOperand(MCOperand::CreateImm(0));
1979 return;
1980 }
1981
1982 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001983 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1984 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001985 Inst.addOperand(MCOperand::CreateImm(Val));
1986 }
1987
Jim Grosbachd3595712011-08-03 23:50:40 +00001988 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1989 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001990 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001991 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001992 addExpr(Inst, getImm());
1993 Inst.addOperand(MCOperand::CreateImm(0));
1994 return;
1995 }
1996
1997 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001998 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1999 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002000 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002001 }
Bill Wendling811c9362010-11-30 07:44:32 +00002002
Jim Grosbach05541f42011-09-19 22:21:13 +00002003 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2004 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002005 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2006 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002007 }
2008
2009 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2010 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002011 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2012 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002013 }
2014
Jim Grosbachd3595712011-08-03 23:50:40 +00002015 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2016 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002017 unsigned Val =
2018 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2019 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002020 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2021 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002022 Inst.addOperand(MCOperand::CreateImm(Val));
2023 }
2024
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002025 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2026 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002027 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2028 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2029 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002030 }
2031
Jim Grosbachd3595712011-08-03 23:50:40 +00002032 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2033 assert(N == 2 && "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));
Jim Grosbachd3595712011-08-03 23:50:40 +00002036 }
2037
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002038 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2039 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002040 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2041 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002042 Inst.addOperand(MCOperand::CreateImm(Val));
2043 }
2044
Jim Grosbach26d35872011-08-19 18:55:51 +00002045 void addMemThumbRIs2Operands(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() / 2) : 0;
2048 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002049 Inst.addOperand(MCOperand::CreateImm(Val));
2050 }
2051
Jim Grosbacha32c7532011-08-19 18:49:59 +00002052 void addMemThumbRIs1Operands(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()) : 0;
2055 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002056 Inst.addOperand(MCOperand::CreateImm(Val));
2057 }
2058
Jim Grosbach23983d62011-08-19 18:13:48 +00002059 void addMemThumbSPIOperands(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() / 4) : 0;
2062 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002063 Inst.addOperand(MCOperand::CreateImm(Val));
2064 }
2065
Jim Grosbachd3595712011-08-03 23:50:40 +00002066 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2067 assert(N == 1 && "Invalid number of operands!");
2068 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2069 assert(CE && "non-constant post-idx-imm8 operand!");
2070 int Imm = CE->getValue();
2071 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002072 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002073 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2074 Inst.addOperand(MCOperand::CreateImm(Imm));
2075 }
2076
Jim Grosbach93981412011-10-11 21:55:36 +00002077 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2078 assert(N == 1 && "Invalid number of operands!");
2079 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2080 assert(CE && "non-constant post-idx-imm8s4 operand!");
2081 int Imm = CE->getValue();
2082 bool isAdd = Imm >= 0;
2083 if (Imm == INT32_MIN) Imm = 0;
2084 // Immediate is scaled by 4.
2085 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2086 Inst.addOperand(MCOperand::CreateImm(Imm));
2087 }
2088
Jim Grosbachd3595712011-08-03 23:50:40 +00002089 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2090 assert(N == 2 && "Invalid number of operands!");
2091 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002092 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2093 }
2094
2095 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2096 assert(N == 2 && "Invalid number of operands!");
2097 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2098 // The sign, shift type, and shift amount are encoded in a single operand
2099 // using the AM2 encoding helpers.
2100 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2101 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2102 PostIdxReg.ShiftTy);
2103 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002104 }
2105
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002106 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2107 assert(N == 1 && "Invalid number of operands!");
2108 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2109 }
2110
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002111 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2112 assert(N == 1 && "Invalid number of operands!");
2113 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2114 }
2115
Jim Grosbach182b6a02011-11-29 23:51:09 +00002116 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002117 assert(N == 1 && "Invalid number of operands!");
2118 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2119 }
2120
Jim Grosbach04945c42011-12-02 00:35:16 +00002121 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2122 assert(N == 2 && "Invalid number of operands!");
2123 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2124 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2125 }
2126
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002127 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2128 assert(N == 1 && "Invalid number of operands!");
2129 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2130 }
2131
2132 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2133 assert(N == 1 && "Invalid number of operands!");
2134 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2135 }
2136
2137 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2138 assert(N == 1 && "Invalid number of operands!");
2139 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2140 }
2141
Jim Grosbach741cd732011-10-17 22:26:03 +00002142 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2143 assert(N == 1 && "Invalid number of operands!");
2144 // The immediate encodes the type of constant as well as the value.
2145 // Mask in that this is an i8 splat.
2146 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2147 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2148 }
2149
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002150 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2151 assert(N == 1 && "Invalid number of operands!");
2152 // The immediate encodes the type of constant as well as the value.
2153 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2154 unsigned Value = CE->getValue();
2155 if (Value >= 256)
2156 Value = (Value >> 8) | 0xa00;
2157 else
2158 Value |= 0x800;
2159 Inst.addOperand(MCOperand::CreateImm(Value));
2160 }
2161
Jim Grosbach8211c052011-10-18 00:22:00 +00002162 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2163 assert(N == 1 && "Invalid number of operands!");
2164 // The immediate encodes the type of constant as well as the value.
2165 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2166 unsigned Value = CE->getValue();
2167 if (Value >= 256 && Value <= 0xff00)
2168 Value = (Value >> 8) | 0x200;
2169 else if (Value > 0xffff && Value <= 0xff0000)
2170 Value = (Value >> 16) | 0x400;
2171 else if (Value > 0xffffff)
2172 Value = (Value >> 24) | 0x600;
2173 Inst.addOperand(MCOperand::CreateImm(Value));
2174 }
2175
2176 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2177 assert(N == 1 && "Invalid number of operands!");
2178 // The immediate encodes the type of constant as well as the value.
2179 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2180 unsigned Value = CE->getValue();
2181 if (Value >= 256 && Value <= 0xffff)
2182 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2183 else if (Value > 0xffff && Value <= 0xffffff)
2184 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2185 else if (Value > 0xffffff)
2186 Value = (Value >> 24) | 0x600;
2187 Inst.addOperand(MCOperand::CreateImm(Value));
2188 }
2189
Jim Grosbach045b6c72011-12-19 23:51:07 +00002190 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2191 assert(N == 1 && "Invalid number of operands!");
2192 // The immediate encodes the type of constant as well as the value.
2193 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2194 unsigned Value = ~CE->getValue();
2195 if (Value >= 256 && Value <= 0xffff)
2196 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2197 else if (Value > 0xffff && Value <= 0xffffff)
2198 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2199 else if (Value > 0xffffff)
2200 Value = (Value >> 24) | 0x600;
2201 Inst.addOperand(MCOperand::CreateImm(Value));
2202 }
2203
Jim Grosbache4454e02011-10-18 16:18:11 +00002204 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2205 assert(N == 1 && "Invalid number of operands!");
2206 // The immediate encodes the type of constant as well as the value.
2207 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2208 uint64_t Value = CE->getValue();
2209 unsigned Imm = 0;
2210 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2211 Imm |= (Value & 1) << i;
2212 }
2213 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2214 }
2215
Jim Grosbach602aa902011-07-13 15:34:57 +00002216 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002217
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002218 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002219 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002220 Op->ITMask.Mask = Mask;
2221 Op->StartLoc = S;
2222 Op->EndLoc = S;
2223 return Op;
2224 }
2225
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002226 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002227 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002228 Op->CC.Val = CC;
2229 Op->StartLoc = S;
2230 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002231 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002232 }
2233
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002234 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002235 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002236 Op->Cop.Val = CopVal;
2237 Op->StartLoc = S;
2238 Op->EndLoc = S;
2239 return Op;
2240 }
2241
2242 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002243 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002244 Op->Cop.Val = CopVal;
2245 Op->StartLoc = S;
2246 Op->EndLoc = S;
2247 return Op;
2248 }
2249
Jim Grosbach48399582011-10-12 17:34:41 +00002250 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2251 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2252 Op->Cop.Val = Val;
2253 Op->StartLoc = S;
2254 Op->EndLoc = E;
2255 return Op;
2256 }
2257
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002258 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002259 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002260 Op->Reg.RegNum = RegNum;
2261 Op->StartLoc = S;
2262 Op->EndLoc = S;
2263 return Op;
2264 }
2265
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002266 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002267 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002268 Op->Tok.Data = Str.data();
2269 Op->Tok.Length = Str.size();
2270 Op->StartLoc = S;
2271 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002272 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002273 }
2274
Bill Wendling2063b842010-11-18 23:43:05 +00002275 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002276 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002277 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002278 Op->StartLoc = S;
2279 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002280 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002281 }
2282
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002283 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2284 unsigned SrcReg,
2285 unsigned ShiftReg,
2286 unsigned ShiftImm,
2287 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002288 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002289 Op->RegShiftedReg.ShiftTy = ShTy;
2290 Op->RegShiftedReg.SrcReg = SrcReg;
2291 Op->RegShiftedReg.ShiftReg = ShiftReg;
2292 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002293 Op->StartLoc = S;
2294 Op->EndLoc = E;
2295 return Op;
2296 }
2297
Owen Andersonb595ed02011-07-21 18:54:16 +00002298 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2299 unsigned SrcReg,
2300 unsigned ShiftImm,
2301 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002302 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002303 Op->RegShiftedImm.ShiftTy = ShTy;
2304 Op->RegShiftedImm.SrcReg = SrcReg;
2305 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002306 Op->StartLoc = S;
2307 Op->EndLoc = E;
2308 return Op;
2309 }
2310
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002311 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002312 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002313 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002314 Op->ShifterImm.isASR = isASR;
2315 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002316 Op->StartLoc = S;
2317 Op->EndLoc = E;
2318 return Op;
2319 }
2320
Jim Grosbach833b9d32011-07-27 20:15:40 +00002321 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002322 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002323 Op->RotImm.Imm = Imm;
2324 Op->StartLoc = S;
2325 Op->EndLoc = E;
2326 return Op;
2327 }
2328
Jim Grosbach864b6092011-07-28 21:34:26 +00002329 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2330 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002331 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002332 Op->Bitfield.LSB = LSB;
2333 Op->Bitfield.Width = Width;
2334 Op->StartLoc = S;
2335 Op->EndLoc = E;
2336 return Op;
2337 }
2338
Bill Wendling2cae3272010-11-09 22:44:22 +00002339 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002340 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002341 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002342 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002343 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002344
Chad Rosierfa705ee2013-07-01 20:49:23 +00002345 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002346 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002347 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002348 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002349 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002350
Chad Rosierfa705ee2013-07-01 20:49:23 +00002351 // Sort based on the register encoding values.
2352 array_pod_sort(Regs.begin(), Regs.end());
2353
Bill Wendling9898ac92010-11-17 04:32:08 +00002354 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002355 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002356 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002357 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002358 Op->StartLoc = StartLoc;
2359 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002360 return Op;
2361 }
2362
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002363 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002364 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002365 ARMOperand *Op = new ARMOperand(k_VectorList);
2366 Op->VectorList.RegNum = RegNum;
2367 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002368 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002369 Op->StartLoc = S;
2370 Op->EndLoc = E;
2371 return Op;
2372 }
2373
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002374 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002375 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002376 SMLoc S, SMLoc E) {
2377 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2378 Op->VectorList.RegNum = RegNum;
2379 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002380 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002381 Op->StartLoc = S;
2382 Op->EndLoc = E;
2383 return Op;
2384 }
2385
Jim Grosbach04945c42011-12-02 00:35:16 +00002386 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002387 unsigned Index,
2388 bool isDoubleSpaced,
2389 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002390 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2391 Op->VectorList.RegNum = RegNum;
2392 Op->VectorList.Count = Count;
2393 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002394 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002395 Op->StartLoc = S;
2396 Op->EndLoc = E;
2397 return Op;
2398 }
2399
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002400 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2401 MCContext &Ctx) {
2402 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2403 Op->VectorIndex.Val = Idx;
2404 Op->StartLoc = S;
2405 Op->EndLoc = E;
2406 return Op;
2407 }
2408
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002409 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002410 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002411 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002412 Op->StartLoc = S;
2413 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002414 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002415 }
2416
Jim Grosbachd3595712011-08-03 23:50:40 +00002417 static ARMOperand *CreateMem(unsigned BaseRegNum,
2418 const MCConstantExpr *OffsetImm,
2419 unsigned OffsetRegNum,
2420 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002421 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002422 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002423 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002424 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002425 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002426 Op->Memory.BaseRegNum = BaseRegNum;
2427 Op->Memory.OffsetImm = OffsetImm;
2428 Op->Memory.OffsetRegNum = OffsetRegNum;
2429 Op->Memory.ShiftType = ShiftType;
2430 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002431 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002432 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002433 Op->StartLoc = S;
2434 Op->EndLoc = E;
2435 return Op;
2436 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002437
Jim Grosbachc320c852011-08-05 21:28:30 +00002438 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2439 ARM_AM::ShiftOpc ShiftTy,
2440 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002441 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002442 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002443 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002444 Op->PostIdxReg.isAdd = isAdd;
2445 Op->PostIdxReg.ShiftTy = ShiftTy;
2446 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002447 Op->StartLoc = S;
2448 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002449 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002450 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002451
2452 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002453 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002454 Op->MBOpt.Val = Opt;
2455 Op->StartLoc = S;
2456 Op->EndLoc = S;
2457 return Op;
2458 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002459
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002460 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2461 SMLoc S) {
2462 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2463 Op->ISBOpt.Val = Opt;
2464 Op->StartLoc = S;
2465 Op->EndLoc = S;
2466 return Op;
2467 }
2468
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002469 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002470 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002471 Op->IFlags.Val = IFlags;
2472 Op->StartLoc = S;
2473 Op->EndLoc = S;
2474 return Op;
2475 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002476
2477 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002478 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002479 Op->MMask.Val = MMask;
2480 Op->StartLoc = S;
2481 Op->EndLoc = S;
2482 return Op;
2483 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002484};
2485
2486} // end anonymous namespace.
2487
Jim Grosbach602aa902011-07-13 15:34:57 +00002488void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002489 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002490 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002491 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002492 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002493 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002494 OS << "<ccout " << getReg() << ">";
2495 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002496 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002497 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002498 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2499 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2500 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002501 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2502 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2503 break;
2504 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002505 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002506 OS << "<coprocessor number: " << getCoproc() << ">";
2507 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002508 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002509 OS << "<coprocessor register: " << getCoproc() << ">";
2510 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002511 case k_CoprocOption:
2512 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2513 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002514 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002515 OS << "<mask: " << getMSRMask() << ">";
2516 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002517 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002518 getImm()->print(OS);
2519 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002520 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002521 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002522 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002523 case k_InstSyncBarrierOpt:
2524 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2525 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002526 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002527 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002528 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002529 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002530 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002531 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002532 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2533 << PostIdxReg.RegNum;
2534 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2535 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2536 << PostIdxReg.ShiftImm;
2537 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002538 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002539 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002540 OS << "<ARM_PROC::";
2541 unsigned IFlags = getProcIFlags();
2542 for (int i=2; i >= 0; --i)
2543 if (IFlags & (1 << i))
2544 OS << ARM_PROC::IFlagsToString(1 << i);
2545 OS << ">";
2546 break;
2547 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002548 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002549 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002550 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002551 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002552 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2553 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002554 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002555 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002556 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002557 << RegShiftedReg.SrcReg << " "
2558 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2559 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002560 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002561 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002562 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002563 << RegShiftedImm.SrcReg << " "
2564 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2565 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002566 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002567 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002568 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2569 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002570 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002571 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2572 << ", width: " << Bitfield.Width << ">";
2573 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002574 case k_RegisterList:
2575 case k_DPRRegisterList:
2576 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002577 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002578
Bill Wendlingbed94652010-11-09 23:28:44 +00002579 const SmallVectorImpl<unsigned> &RegList = getRegList();
2580 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002581 I = RegList.begin(), E = RegList.end(); I != E; ) {
2582 OS << *I;
2583 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002584 }
2585
2586 OS << ">";
2587 break;
2588 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002589 case k_VectorList:
2590 OS << "<vector_list " << VectorList.Count << " * "
2591 << VectorList.RegNum << ">";
2592 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002593 case k_VectorListAllLanes:
2594 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2595 << VectorList.RegNum << ">";
2596 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002597 case k_VectorListIndexed:
2598 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2599 << VectorList.Count << " * " << VectorList.RegNum << ">";
2600 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002601 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002602 OS << "'" << getToken() << "'";
2603 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002604 case k_VectorIndex:
2605 OS << "<vectorindex " << getVectorIndex() << ">";
2606 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002607 }
2608}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002609
2610/// @name Auto-generated Match Functions
2611/// {
2612
2613static unsigned MatchRegisterName(StringRef Name);
2614
2615/// }
2616
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002617bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2618 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002619 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002620 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002621 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002622
2623 return (RegNo == (unsigned)-1);
2624}
2625
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002626/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002627/// and if it is a register name the token is eaten and the register number is
2628/// returned. Otherwise return -1.
2629///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002630int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002631 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002632 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002633
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002634 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002635 unsigned RegNum = MatchRegisterName(lowerCase);
2636 if (!RegNum) {
2637 RegNum = StringSwitch<unsigned>(lowerCase)
2638 .Case("r13", ARM::SP)
2639 .Case("r14", ARM::LR)
2640 .Case("r15", ARM::PC)
2641 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002642 // Additional register name aliases for 'gas' compatibility.
2643 .Case("a1", ARM::R0)
2644 .Case("a2", ARM::R1)
2645 .Case("a3", ARM::R2)
2646 .Case("a4", ARM::R3)
2647 .Case("v1", ARM::R4)
2648 .Case("v2", ARM::R5)
2649 .Case("v3", ARM::R6)
2650 .Case("v4", ARM::R7)
2651 .Case("v5", ARM::R8)
2652 .Case("v6", ARM::R9)
2653 .Case("v7", ARM::R10)
2654 .Case("v8", ARM::R11)
2655 .Case("sb", ARM::R9)
2656 .Case("sl", ARM::R10)
2657 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002658 .Default(0);
2659 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002660 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002661 // Check for aliases registered via .req. Canonicalize to lower case.
2662 // That's more consistent since register names are case insensitive, and
2663 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2664 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002665 // If no match, return failure.
2666 if (Entry == RegisterReqs.end())
2667 return -1;
2668 Parser.Lex(); // Eat identifier token.
2669 return Entry->getValue();
2670 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002671
Chris Lattner44e5981c2010-10-30 04:09:10 +00002672 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002673
Chris Lattner44e5981c2010-10-30 04:09:10 +00002674 return RegNum;
2675}
Jim Grosbach99710a82010-11-01 16:44:21 +00002676
Jim Grosbachbb24c592011-07-13 18:49:30 +00002677// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2678// If a recoverable error occurs, return 1. If an irrecoverable error
2679// occurs, return -1. An irrecoverable error is one where tokens have been
2680// consumed in the process of trying to parse the shifter (i.e., when it is
2681// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002682int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002683 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2684 SMLoc S = Parser.getTok().getLoc();
2685 const AsmToken &Tok = Parser.getTok();
2686 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2687
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002688 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002689 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002690 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002691 .Case("lsl", ARM_AM::lsl)
2692 .Case("lsr", ARM_AM::lsr)
2693 .Case("asr", ARM_AM::asr)
2694 .Case("ror", ARM_AM::ror)
2695 .Case("rrx", ARM_AM::rrx)
2696 .Default(ARM_AM::no_shift);
2697
2698 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002699 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002700
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002701 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002702
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002703 // The source register for the shift has already been added to the
2704 // operand list, so we need to pop it off and combine it into the shifted
2705 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002706 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002707 if (!PrevOp->isReg())
2708 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2709 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002710
2711 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002712 int64_t Imm = 0;
2713 int ShiftReg = 0;
2714 if (ShiftTy == ARM_AM::rrx) {
2715 // RRX Doesn't have an explicit shift amount. The encoder expects
2716 // the shift register to be the same as the source register. Seems odd,
2717 // but OK.
2718 ShiftReg = SrcReg;
2719 } else {
2720 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002721 if (Parser.getTok().is(AsmToken::Hash) ||
2722 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002723 Parser.Lex(); // Eat hash.
2724 SMLoc ImmLoc = Parser.getTok().getLoc();
2725 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002726 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002727 Error(ImmLoc, "invalid immediate shift value");
2728 return -1;
2729 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002730 // The expression must be evaluatable as an immediate.
2731 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002732 if (!CE) {
2733 Error(ImmLoc, "invalid immediate shift value");
2734 return -1;
2735 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002736 // Range check the immediate.
2737 // lsl, ror: 0 <= imm <= 31
2738 // lsr, asr: 0 <= imm <= 32
2739 Imm = CE->getValue();
2740 if (Imm < 0 ||
2741 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2742 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002743 Error(ImmLoc, "immediate shift value out of range");
2744 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002745 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002746 // shift by zero is a nop. Always send it through as lsl.
2747 // ('as' compatibility)
2748 if (Imm == 0)
2749 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002750 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002751 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002752 EndLoc = Parser.getTok().getEndLoc();
2753 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002754 if (ShiftReg == -1) {
2755 Error (L, "expected immediate or register in shift operand");
2756 return -1;
2757 }
2758 } else {
2759 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002760 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002761 return -1;
2762 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002763 }
2764
Owen Andersonb595ed02011-07-21 18:54:16 +00002765 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2766 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002767 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002768 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002769 else
2770 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002771 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002772
Jim Grosbachbb24c592011-07-13 18:49:30 +00002773 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002774}
2775
2776
Bill Wendling2063b842010-11-18 23:43:05 +00002777/// Try to parse a register name. The token must be an Identifier when called.
2778/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2779/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002780///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002781/// TODO this is likely to change to allow different register types and or to
2782/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002783bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002784tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002785 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002786 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002787 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002788 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002789
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002790 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2791 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002792
Chris Lattner44e5981c2010-10-30 04:09:10 +00002793 const AsmToken &ExclaimTok = Parser.getTok();
2794 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002795 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2796 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002797 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002798 return false;
2799 }
2800
2801 // Also check for an index operand. This is only legal for vector registers,
2802 // but that'll get caught OK in operand matching, so we don't need to
2803 // explicitly filter everything else out here.
2804 if (Parser.getTok().is(AsmToken::LBrac)) {
2805 SMLoc SIdx = Parser.getTok().getLoc();
2806 Parser.Lex(); // Eat left bracket token.
2807
2808 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002809 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002810 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002811 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002812 if (!MCE)
2813 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002814
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002815 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002816 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002817
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002818 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002819 Parser.Lex(); // Eat right bracket token.
2820
2821 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2822 SIdx, E,
2823 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002824 }
2825
Bill Wendling2063b842010-11-18 23:43:05 +00002826 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002827}
2828
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002829/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2830/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2831/// "c5", ...
2832static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002833 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2834 // but efficient.
2835 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002836 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002837 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002838 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002839 return -1;
2840 switch (Name[1]) {
2841 default: return -1;
2842 case '0': return 0;
2843 case '1': return 1;
2844 case '2': return 2;
2845 case '3': return 3;
2846 case '4': return 4;
2847 case '5': return 5;
2848 case '6': return 6;
2849 case '7': return 7;
2850 case '8': return 8;
2851 case '9': return 9;
2852 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002853 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002854 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002855 return -1;
2856 switch (Name[2]) {
2857 default: return -1;
2858 case '0': return 10;
2859 case '1': return 11;
2860 case '2': return 12;
2861 case '3': return 13;
2862 case '4': return 14;
2863 case '5': return 15;
2864 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002865 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002866}
2867
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002868/// parseITCondCode - Try to parse a condition code for an IT instruction.
2869ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2870parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2871 SMLoc S = Parser.getTok().getLoc();
2872 const AsmToken &Tok = Parser.getTok();
2873 if (!Tok.is(AsmToken::Identifier))
2874 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002875 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002876 .Case("eq", ARMCC::EQ)
2877 .Case("ne", ARMCC::NE)
2878 .Case("hs", ARMCC::HS)
2879 .Case("cs", ARMCC::HS)
2880 .Case("lo", ARMCC::LO)
2881 .Case("cc", ARMCC::LO)
2882 .Case("mi", ARMCC::MI)
2883 .Case("pl", ARMCC::PL)
2884 .Case("vs", ARMCC::VS)
2885 .Case("vc", ARMCC::VC)
2886 .Case("hi", ARMCC::HI)
2887 .Case("ls", ARMCC::LS)
2888 .Case("ge", ARMCC::GE)
2889 .Case("lt", ARMCC::LT)
2890 .Case("gt", ARMCC::GT)
2891 .Case("le", ARMCC::LE)
2892 .Case("al", ARMCC::AL)
2893 .Default(~0U);
2894 if (CC == ~0U)
2895 return MatchOperand_NoMatch;
2896 Parser.Lex(); // Eat the token.
2897
2898 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2899
2900 return MatchOperand_Success;
2901}
2902
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002903/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002904/// token must be an Identifier when called, and if it is a coprocessor
2905/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002906ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002907parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002908 SMLoc S = Parser.getTok().getLoc();
2909 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002910 if (Tok.isNot(AsmToken::Identifier))
2911 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002912
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002913 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002914 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002915 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002916
2917 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002918 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002919 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002920}
2921
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002922/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002923/// token must be an Identifier when called, and if it is a coprocessor
2924/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002925ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002926parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002927 SMLoc S = Parser.getTok().getLoc();
2928 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002929 if (Tok.isNot(AsmToken::Identifier))
2930 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002931
2932 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2933 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002934 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002935
2936 Parser.Lex(); // Eat identifier token.
2937 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002938 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002939}
2940
Jim Grosbach48399582011-10-12 17:34:41 +00002941/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2942/// coproc_option : '{' imm0_255 '}'
2943ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2944parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2945 SMLoc S = Parser.getTok().getLoc();
2946
2947 // If this isn't a '{', this isn't a coprocessor immediate operand.
2948 if (Parser.getTok().isNot(AsmToken::LCurly))
2949 return MatchOperand_NoMatch;
2950 Parser.Lex(); // Eat the '{'
2951
2952 const MCExpr *Expr;
2953 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002954 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002955 Error(Loc, "illegal expression");
2956 return MatchOperand_ParseFail;
2957 }
2958 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2959 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2960 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2961 return MatchOperand_ParseFail;
2962 }
2963 int Val = CE->getValue();
2964
2965 // Check for and consume the closing '}'
2966 if (Parser.getTok().isNot(AsmToken::RCurly))
2967 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002968 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002969 Parser.Lex(); // Eat the '}'
2970
2971 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2972 return MatchOperand_Success;
2973}
2974
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002975// For register list parsing, we need to map from raw GPR register numbering
2976// to the enumeration values. The enumeration values aren't sorted by
2977// register number due to our using "sp", "lr" and "pc" as canonical names.
2978static unsigned getNextRegister(unsigned Reg) {
2979 // If this is a GPR, we need to do it manually, otherwise we can rely
2980 // on the sort ordering of the enumeration since the other reg-classes
2981 // are sane.
2982 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2983 return Reg + 1;
2984 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002985 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002986 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2987 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2988 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2989 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2990 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2991 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2992 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2993 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2994 }
2995}
2996
Jim Grosbach85a23432011-11-11 21:27:40 +00002997// Return the low-subreg of a given Q register.
2998static unsigned getDRegFromQReg(unsigned QReg) {
2999 switch (QReg) {
3000 default: llvm_unreachable("expected a Q register!");
3001 case ARM::Q0: return ARM::D0;
3002 case ARM::Q1: return ARM::D2;
3003 case ARM::Q2: return ARM::D4;
3004 case ARM::Q3: return ARM::D6;
3005 case ARM::Q4: return ARM::D8;
3006 case ARM::Q5: return ARM::D10;
3007 case ARM::Q6: return ARM::D12;
3008 case ARM::Q7: return ARM::D14;
3009 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003010 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003011 case ARM::Q10: return ARM::D20;
3012 case ARM::Q11: return ARM::D22;
3013 case ARM::Q12: return ARM::D24;
3014 case ARM::Q13: return ARM::D26;
3015 case ARM::Q14: return ARM::D28;
3016 case ARM::Q15: return ARM::D30;
3017 }
3018}
3019
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003020/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003021bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003022parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003023 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003024 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003025 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003026 Parser.Lex(); // Eat '{' token.
3027 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003028
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003029 // Check the first register in the list to see what register class
3030 // this is a list of.
3031 int Reg = tryParseRegister();
3032 if (Reg == -1)
3033 return Error(RegLoc, "register expected");
3034
Jim Grosbach85a23432011-11-11 21:27:40 +00003035 // The reglist instructions have at most 16 registers, so reserve
3036 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003037 int EReg = 0;
3038 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003039
3040 // Allow Q regs and just interpret them as the two D sub-registers.
3041 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3042 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003043 EReg = MRI->getEncodingValue(Reg);
3044 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003045 ++Reg;
3046 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003047 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003048 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3049 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3050 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3051 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3052 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3053 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3054 else
3055 return Error(RegLoc, "invalid register in register list");
3056
Jim Grosbach85a23432011-11-11 21:27:40 +00003057 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003058 EReg = MRI->getEncodingValue(Reg);
3059 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003060
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003061 // This starts immediately after the first register token in the list,
3062 // so we can see either a comma or a minus (range separator) as a legal
3063 // next token.
3064 while (Parser.getTok().is(AsmToken::Comma) ||
3065 Parser.getTok().is(AsmToken::Minus)) {
3066 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003067 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003068 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003069 int EndReg = tryParseRegister();
3070 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003071 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003072 // Allow Q regs and just interpret them as the two D sub-registers.
3073 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3074 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003075 // If the register is the same as the start reg, there's nothing
3076 // more to do.
3077 if (Reg == EndReg)
3078 continue;
3079 // The register must be in the same register class as the first.
3080 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003081 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003082 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003083 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003084 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003085
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003086 // Add all the registers in the range to the register list.
3087 while (Reg != EndReg) {
3088 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003089 EReg = MRI->getEncodingValue(Reg);
3090 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003091 }
3092 continue;
3093 }
3094 Parser.Lex(); // Eat the comma.
3095 RegLoc = Parser.getTok().getLoc();
3096 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003097 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003098 Reg = tryParseRegister();
3099 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003100 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003101 // Allow Q regs and just interpret them as the two D sub-registers.
3102 bool isQReg = false;
3103 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3104 Reg = getDRegFromQReg(Reg);
3105 isQReg = true;
3106 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003107 // The register must be in the same register class as the first.
3108 if (!RC->contains(Reg))
3109 return Error(RegLoc, "invalid register in register list");
3110 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003111 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003112 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3113 Warning(RegLoc, "register list not in ascending order");
3114 else
3115 return Error(RegLoc, "register list not in ascending order");
3116 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003117 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003118 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3119 ") in register list");
3120 continue;
3121 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003122 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003123 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3124 Reg != OldReg + 1)
3125 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003126 EReg = MRI->getEncodingValue(Reg);
3127 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3128 if (isQReg) {
3129 EReg = MRI->getEncodingValue(++Reg);
3130 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3131 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003132 }
3133
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003134 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003135 return Error(Parser.getTok().getLoc(), "'}' expected");
3136 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003137 Parser.Lex(); // Eat '}' token.
3138
Jim Grosbach18bf3632011-12-13 21:48:29 +00003139 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003140 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003141
3142 // The ARM system instruction variants for LDM/STM have a '^' token here.
3143 if (Parser.getTok().is(AsmToken::Caret)) {
3144 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3145 Parser.Lex(); // Eat '^' token.
3146 }
3147
Bill Wendling2063b842010-11-18 23:43:05 +00003148 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003149}
3150
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003151// Helper function to parse the lane index for vector lists.
3152ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003153parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003154 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003155 if (Parser.getTok().is(AsmToken::LBrac)) {
3156 Parser.Lex(); // Eat the '['.
3157 if (Parser.getTok().is(AsmToken::RBrac)) {
3158 // "Dn[]" is the 'all lanes' syntax.
3159 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003160 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003161 Parser.Lex(); // Eat the ']'.
3162 return MatchOperand_Success;
3163 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003164
3165 // There's an optional '#' token here. Normally there wouldn't be, but
3166 // inline assemble puts one in, and it's friendly to accept that.
3167 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003168 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003169
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003170 const MCExpr *LaneIndex;
3171 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003172 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003173 Error(Loc, "illegal expression");
3174 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003175 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003176 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3177 if (!CE) {
3178 Error(Loc, "lane index must be empty or an integer");
3179 return MatchOperand_ParseFail;
3180 }
3181 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3182 Error(Parser.getTok().getLoc(), "']' expected");
3183 return MatchOperand_ParseFail;
3184 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003185 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003186 Parser.Lex(); // Eat the ']'.
3187 int64_t Val = CE->getValue();
3188
3189 // FIXME: Make this range check context sensitive for .8, .16, .32.
3190 if (Val < 0 || Val > 7) {
3191 Error(Parser.getTok().getLoc(), "lane index out of range");
3192 return MatchOperand_ParseFail;
3193 }
3194 Index = Val;
3195 LaneKind = IndexedLane;
3196 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003197 }
3198 LaneKind = NoLanes;
3199 return MatchOperand_Success;
3200}
3201
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003202// parse a vector register list
3203ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3204parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003205 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003206 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003207 SMLoc S = Parser.getTok().getLoc();
3208 // As an extension (to match gas), support a plain D register or Q register
3209 // (without encosing curly braces) as a single or double entry list,
3210 // respectively.
3211 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003212 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003213 int Reg = tryParseRegister();
3214 if (Reg == -1)
3215 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003216 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003217 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003218 if (Res != MatchOperand_Success)
3219 return Res;
3220 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003221 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003222 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003223 break;
3224 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003225 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3226 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003227 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003228 case IndexedLane:
3229 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003230 LaneIndex,
3231 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003232 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003233 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003234 return MatchOperand_Success;
3235 }
3236 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3237 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003238 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003239 if (Res != MatchOperand_Success)
3240 return Res;
3241 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003242 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003243 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003244 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003245 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003246 break;
3247 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003248 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3249 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003250 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3251 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003252 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003253 case IndexedLane:
3254 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003255 LaneIndex,
3256 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003257 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003258 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003259 return MatchOperand_Success;
3260 }
3261 Error(S, "vector register expected");
3262 return MatchOperand_ParseFail;
3263 }
3264
3265 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003266 return MatchOperand_NoMatch;
3267
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003268 Parser.Lex(); // Eat '{' token.
3269 SMLoc RegLoc = Parser.getTok().getLoc();
3270
3271 int Reg = tryParseRegister();
3272 if (Reg == -1) {
3273 Error(RegLoc, "register expected");
3274 return MatchOperand_ParseFail;
3275 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003276 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003277 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003278 unsigned FirstReg = Reg;
3279 // The list is of D registers, but we also allow Q regs and just interpret
3280 // them as the two D sub-registers.
3281 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3282 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003283 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3284 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003285 ++Reg;
3286 ++Count;
3287 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003288
3289 SMLoc E;
3290 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003291 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003292
Jim Grosbache891fe82011-11-15 23:19:15 +00003293 while (Parser.getTok().is(AsmToken::Comma) ||
3294 Parser.getTok().is(AsmToken::Minus)) {
3295 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003296 if (!Spacing)
3297 Spacing = 1; // Register range implies a single spaced list.
3298 else if (Spacing == 2) {
3299 Error(Parser.getTok().getLoc(),
3300 "sequential registers in double spaced list");
3301 return MatchOperand_ParseFail;
3302 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003303 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003304 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003305 int EndReg = tryParseRegister();
3306 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003307 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003308 return MatchOperand_ParseFail;
3309 }
3310 // Allow Q regs and just interpret them as the two D sub-registers.
3311 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3312 EndReg = getDRegFromQReg(EndReg) + 1;
3313 // If the register is the same as the start reg, there's nothing
3314 // more to do.
3315 if (Reg == EndReg)
3316 continue;
3317 // The register must be in the same register class as the first.
3318 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003319 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003320 return MatchOperand_ParseFail;
3321 }
3322 // Ranges must go from low to high.
3323 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003324 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003325 return MatchOperand_ParseFail;
3326 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003327 // Parse the lane specifier if present.
3328 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003329 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003330 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3331 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003332 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003333 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003334 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003335 return MatchOperand_ParseFail;
3336 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003337
3338 // Add all the registers in the range to the register list.
3339 Count += EndReg - Reg;
3340 Reg = EndReg;
3341 continue;
3342 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003343 Parser.Lex(); // Eat the comma.
3344 RegLoc = Parser.getTok().getLoc();
3345 int OldReg = Reg;
3346 Reg = tryParseRegister();
3347 if (Reg == -1) {
3348 Error(RegLoc, "register expected");
3349 return MatchOperand_ParseFail;
3350 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003351 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003352 // It's OK to use the enumeration values directly here rather, as the
3353 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003354 //
3355 // The list is of D registers, but we also allow Q regs and just interpret
3356 // them as the two D sub-registers.
3357 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003358 if (!Spacing)
3359 Spacing = 1; // Register range implies a single spaced list.
3360 else if (Spacing == 2) {
3361 Error(RegLoc,
3362 "invalid register in double-spaced list (must be 'D' register')");
3363 return MatchOperand_ParseFail;
3364 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003365 Reg = getDRegFromQReg(Reg);
3366 if (Reg != OldReg + 1) {
3367 Error(RegLoc, "non-contiguous register range");
3368 return MatchOperand_ParseFail;
3369 }
3370 ++Reg;
3371 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003372 // Parse the lane specifier if present.
3373 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003374 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003375 SMLoc LaneLoc = Parser.getTok().getLoc();
3376 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3377 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003378 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003379 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003380 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003381 return MatchOperand_ParseFail;
3382 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003383 continue;
3384 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003385 // Normal D register.
3386 // Figure out the register spacing (single or double) of the list if
3387 // we don't know it already.
3388 if (!Spacing)
3389 Spacing = 1 + (Reg == OldReg + 2);
3390
3391 // Just check that it's contiguous and keep going.
3392 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003393 Error(RegLoc, "non-contiguous register range");
3394 return MatchOperand_ParseFail;
3395 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003396 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003397 // Parse the lane specifier if present.
3398 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003399 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003400 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003401 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003402 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003403 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003404 Error(EndLoc, "mismatched lane index in register list");
3405 return MatchOperand_ParseFail;
3406 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003407 }
3408
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003409 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003410 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003411 return MatchOperand_ParseFail;
3412 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003413 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003414 Parser.Lex(); // Eat '}' token.
3415
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003416 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003417 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003418 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003419 // composite register classes.
3420 if (Count == 2) {
3421 const MCRegisterClass *RC = (Spacing == 1) ?
3422 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3423 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3424 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3425 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003426
Jim Grosbach2f50e922011-12-15 21:44:33 +00003427 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3428 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003429 break;
3430 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003431 // Two-register operands have been converted to the
3432 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003433 if (Count == 2) {
3434 const MCRegisterClass *RC = (Spacing == 1) ?
3435 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3436 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003437 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3438 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003439 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003440 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003441 S, E));
3442 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003443 case IndexedLane:
3444 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003445 LaneIndex,
3446 (Spacing == 2),
3447 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003448 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003449 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003450 return MatchOperand_Success;
3451}
3452
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003453/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003454ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003455parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003456 SMLoc S = Parser.getTok().getLoc();
3457 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003458 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003459
Jiangning Liu288e1af2012-08-02 08:21:27 +00003460 if (Tok.is(AsmToken::Identifier)) {
3461 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003462
Jiangning Liu288e1af2012-08-02 08:21:27 +00003463 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3464 .Case("sy", ARM_MB::SY)
3465 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003466 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003467 .Case("sh", ARM_MB::ISH)
3468 .Case("ish", ARM_MB::ISH)
3469 .Case("shst", ARM_MB::ISHST)
3470 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003471 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003472 .Case("nsh", ARM_MB::NSH)
3473 .Case("un", ARM_MB::NSH)
3474 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003475 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003476 .Case("unst", ARM_MB::NSHST)
3477 .Case("osh", ARM_MB::OSH)
3478 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003479 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003480 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003481
Joey Gouly926d3f52013-09-05 15:35:24 +00003482 // ishld, oshld, nshld and ld are only available from ARMv8.
3483 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3484 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3485 Opt = ~0U;
3486
Jiangning Liu288e1af2012-08-02 08:21:27 +00003487 if (Opt == ~0U)
3488 return MatchOperand_NoMatch;
3489
3490 Parser.Lex(); // Eat identifier token.
3491 } else if (Tok.is(AsmToken::Hash) ||
3492 Tok.is(AsmToken::Dollar) ||
3493 Tok.is(AsmToken::Integer)) {
3494 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003495 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003496 SMLoc Loc = Parser.getTok().getLoc();
3497
3498 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003499 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003500 Error(Loc, "illegal expression");
3501 return MatchOperand_ParseFail;
3502 }
3503
3504 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3505 if (!CE) {
3506 Error(Loc, "constant expression expected");
3507 return MatchOperand_ParseFail;
3508 }
3509
3510 int Val = CE->getValue();
3511 if (Val & ~0xf) {
3512 Error(Loc, "immediate value out of range");
3513 return MatchOperand_ParseFail;
3514 }
3515
3516 Opt = ARM_MB::RESERVED_0 + Val;
3517 } else
3518 return MatchOperand_ParseFail;
3519
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003520 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003521 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003522}
3523
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003524/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3525ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3526parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3527 SMLoc S = Parser.getTok().getLoc();
3528 const AsmToken &Tok = Parser.getTok();
3529 unsigned Opt;
3530
3531 if (Tok.is(AsmToken::Identifier)) {
3532 StringRef OptStr = Tok.getString();
3533
3534 if (OptStr.lower() == "sy")
3535 Opt = ARM_ISB::SY;
3536 else
3537 return MatchOperand_NoMatch;
3538
3539 Parser.Lex(); // Eat identifier token.
3540 } else if (Tok.is(AsmToken::Hash) ||
3541 Tok.is(AsmToken::Dollar) ||
3542 Tok.is(AsmToken::Integer)) {
3543 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003544 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003545 SMLoc Loc = Parser.getTok().getLoc();
3546
3547 const MCExpr *ISBarrierID;
3548 if (getParser().parseExpression(ISBarrierID)) {
3549 Error(Loc, "illegal expression");
3550 return MatchOperand_ParseFail;
3551 }
3552
3553 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3554 if (!CE) {
3555 Error(Loc, "constant expression expected");
3556 return MatchOperand_ParseFail;
3557 }
3558
3559 int Val = CE->getValue();
3560 if (Val & ~0xf) {
3561 Error(Loc, "immediate value out of range");
3562 return MatchOperand_ParseFail;
3563 }
3564
3565 Opt = ARM_ISB::RESERVED_0 + Val;
3566 } else
3567 return MatchOperand_ParseFail;
3568
3569 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3570 (ARM_ISB::InstSyncBOpt)Opt, S));
3571 return MatchOperand_Success;
3572}
3573
3574
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003575/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003576ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003577parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003578 SMLoc S = Parser.getTok().getLoc();
3579 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003580 if (!Tok.is(AsmToken::Identifier))
3581 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003582 StringRef IFlagsStr = Tok.getString();
3583
Owen Anderson10c5b122011-10-05 17:16:40 +00003584 // An iflags string of "none" is interpreted to mean that none of the AIF
3585 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003586 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003587 if (IFlagsStr != "none") {
3588 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3589 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3590 .Case("a", ARM_PROC::A)
3591 .Case("i", ARM_PROC::I)
3592 .Case("f", ARM_PROC::F)
3593 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003594
Owen Anderson10c5b122011-10-05 17:16:40 +00003595 // If some specific iflag is already set, it means that some letter is
3596 // present more than once, this is not acceptable.
3597 if (Flag == ~0U || (IFlags & Flag))
3598 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003599
Owen Anderson10c5b122011-10-05 17:16:40 +00003600 IFlags |= Flag;
3601 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003602 }
3603
3604 Parser.Lex(); // Eat identifier token.
3605 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3606 return MatchOperand_Success;
3607}
3608
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003609/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003610ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003611parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003612 SMLoc S = Parser.getTok().getLoc();
3613 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003614 if (!Tok.is(AsmToken::Identifier))
3615 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003616 StringRef Mask = Tok.getString();
3617
James Molloy21efa7d2011-09-28 14:21:38 +00003618 if (isMClass()) {
3619 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003620 std::string Name = Mask.lower();
3621 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003622 // Note: in the documentation:
3623 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3624 // for MSR APSR_nzcvq.
3625 // but we do make it an alias here. This is so to get the "mask encoding"
3626 // bits correct on MSR APSR writes.
3627 //
3628 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3629 // should really only be allowed when writing a special register. Note
3630 // they get dropped in the MRS instruction reading a special register as
3631 // the SYSm field is only 8 bits.
3632 //
3633 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3634 // includes the DSP extension but that is not checked.
3635 .Case("apsr", 0x800)
3636 .Case("apsr_nzcvq", 0x800)
3637 .Case("apsr_g", 0x400)
3638 .Case("apsr_nzcvqg", 0xc00)
3639 .Case("iapsr", 0x801)
3640 .Case("iapsr_nzcvq", 0x801)
3641 .Case("iapsr_g", 0x401)
3642 .Case("iapsr_nzcvqg", 0xc01)
3643 .Case("eapsr", 0x802)
3644 .Case("eapsr_nzcvq", 0x802)
3645 .Case("eapsr_g", 0x402)
3646 .Case("eapsr_nzcvqg", 0xc02)
3647 .Case("xpsr", 0x803)
3648 .Case("xpsr_nzcvq", 0x803)
3649 .Case("xpsr_g", 0x403)
3650 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003651 .Case("ipsr", 0x805)
3652 .Case("epsr", 0x806)
3653 .Case("iepsr", 0x807)
3654 .Case("msp", 0x808)
3655 .Case("psp", 0x809)
3656 .Case("primask", 0x810)
3657 .Case("basepri", 0x811)
3658 .Case("basepri_max", 0x812)
3659 .Case("faultmask", 0x813)
3660 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003661 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003662
James Molloy21efa7d2011-09-28 14:21:38 +00003663 if (FlagsVal == ~0U)
3664 return MatchOperand_NoMatch;
3665
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003666 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003667 // basepri, basepri_max and faultmask only valid for V7m.
3668 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003669
James Molloy21efa7d2011-09-28 14:21:38 +00003670 Parser.Lex(); // Eat identifier token.
3671 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3672 return MatchOperand_Success;
3673 }
3674
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003675 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3676 size_t Start = 0, Next = Mask.find('_');
3677 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003678 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003679 if (Next != StringRef::npos)
3680 Flags = Mask.slice(Next+1, Mask.size());
3681
3682 // FlagsVal contains the complete mask:
3683 // 3-0: Mask
3684 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3685 unsigned FlagsVal = 0;
3686
3687 if (SpecReg == "apsr") {
3688 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003689 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003690 .Case("g", 0x4) // same as CPSR_s
3691 .Case("nzcvqg", 0xc) // same as CPSR_fs
3692 .Default(~0U);
3693
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003694 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003695 if (!Flags.empty())
3696 return MatchOperand_NoMatch;
3697 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003698 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003699 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003700 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003701 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3702 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003703 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003704 for (int i = 0, e = Flags.size(); i != e; ++i) {
3705 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3706 .Case("c", 1)
3707 .Case("x", 2)
3708 .Case("s", 4)
3709 .Case("f", 8)
3710 .Default(~0U);
3711
3712 // If some specific flag is already set, it means that some letter is
3713 // present more than once, this is not acceptable.
3714 if (FlagsVal == ~0U || (FlagsVal & Flag))
3715 return MatchOperand_NoMatch;
3716 FlagsVal |= Flag;
3717 }
3718 } else // No match for special register.
3719 return MatchOperand_NoMatch;
3720
Owen Anderson03a173e2011-10-21 18:43:28 +00003721 // Special register without flags is NOT equivalent to "fc" flags.
3722 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3723 // two lines would enable gas compatibility at the expense of breaking
3724 // round-tripping.
3725 //
3726 // if (!FlagsVal)
3727 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003728
3729 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3730 if (SpecReg == "spsr")
3731 FlagsVal |= 16;
3732
3733 Parser.Lex(); // Eat identifier token.
3734 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3735 return MatchOperand_Success;
3736}
3737
Jim Grosbach27c1e252011-07-21 17:23:04 +00003738ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3739parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3740 int Low, int High) {
3741 const AsmToken &Tok = Parser.getTok();
3742 if (Tok.isNot(AsmToken::Identifier)) {
3743 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3744 return MatchOperand_ParseFail;
3745 }
3746 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003747 std::string LowerOp = Op.lower();
3748 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003749 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3750 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3751 return MatchOperand_ParseFail;
3752 }
3753 Parser.Lex(); // Eat shift type token.
3754
3755 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003756 if (Parser.getTok().isNot(AsmToken::Hash) &&
3757 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003758 Error(Parser.getTok().getLoc(), "'#' expected");
3759 return MatchOperand_ParseFail;
3760 }
3761 Parser.Lex(); // Eat hash token.
3762
3763 const MCExpr *ShiftAmount;
3764 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003765 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003766 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003767 Error(Loc, "illegal expression");
3768 return MatchOperand_ParseFail;
3769 }
3770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3771 if (!CE) {
3772 Error(Loc, "constant expression expected");
3773 return MatchOperand_ParseFail;
3774 }
3775 int Val = CE->getValue();
3776 if (Val < Low || Val > High) {
3777 Error(Loc, "immediate value out of range");
3778 return MatchOperand_ParseFail;
3779 }
3780
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003781 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003782
3783 return MatchOperand_Success;
3784}
3785
Jim Grosbach0a547702011-07-22 17:44:50 +00003786ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3787parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3788 const AsmToken &Tok = Parser.getTok();
3789 SMLoc S = Tok.getLoc();
3790 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003791 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003792 return MatchOperand_ParseFail;
3793 }
Tim Northover4d141442013-05-31 15:58:45 +00003794 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003795 .Case("be", 1)
3796 .Case("le", 0)
3797 .Default(-1);
3798 Parser.Lex(); // Eat the token.
3799
3800 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003801 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003802 return MatchOperand_ParseFail;
3803 }
3804 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3805 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003806 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003807 return MatchOperand_Success;
3808}
3809
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003810/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3811/// instructions. Legal values are:
3812/// lsl #n 'n' in [0,31]
3813/// asr #n 'n' in [1,32]
3814/// n == 32 encoded as n == 0.
3815ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3816parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3817 const AsmToken &Tok = Parser.getTok();
3818 SMLoc S = Tok.getLoc();
3819 if (Tok.isNot(AsmToken::Identifier)) {
3820 Error(S, "shift operator 'asr' or 'lsl' expected");
3821 return MatchOperand_ParseFail;
3822 }
3823 StringRef ShiftName = Tok.getString();
3824 bool isASR;
3825 if (ShiftName == "lsl" || ShiftName == "LSL")
3826 isASR = false;
3827 else if (ShiftName == "asr" || ShiftName == "ASR")
3828 isASR = true;
3829 else {
3830 Error(S, "shift operator 'asr' or 'lsl' expected");
3831 return MatchOperand_ParseFail;
3832 }
3833 Parser.Lex(); // Eat the operator.
3834
3835 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003836 if (Parser.getTok().isNot(AsmToken::Hash) &&
3837 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003838 Error(Parser.getTok().getLoc(), "'#' expected");
3839 return MatchOperand_ParseFail;
3840 }
3841 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003842 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003843
3844 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003845 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003846 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003847 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003848 return MatchOperand_ParseFail;
3849 }
3850 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3851 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003852 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003853 return MatchOperand_ParseFail;
3854 }
3855
3856 int64_t Val = CE->getValue();
3857 if (isASR) {
3858 // Shift amount must be in [1,32]
3859 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003860 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003861 return MatchOperand_ParseFail;
3862 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003863 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3864 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003865 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003866 return MatchOperand_ParseFail;
3867 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003868 if (Val == 32) Val = 0;
3869 } else {
3870 // Shift amount must be in [1,32]
3871 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003872 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003873 return MatchOperand_ParseFail;
3874 }
3875 }
3876
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003877 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003878
3879 return MatchOperand_Success;
3880}
3881
Jim Grosbach833b9d32011-07-27 20:15:40 +00003882/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3883/// of instructions. Legal values are:
3884/// ror #n 'n' in {0, 8, 16, 24}
3885ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3886parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3887 const AsmToken &Tok = Parser.getTok();
3888 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003889 if (Tok.isNot(AsmToken::Identifier))
3890 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003891 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003892 if (ShiftName != "ror" && ShiftName != "ROR")
3893 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003894 Parser.Lex(); // Eat the operator.
3895
3896 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003897 if (Parser.getTok().isNot(AsmToken::Hash) &&
3898 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003899 Error(Parser.getTok().getLoc(), "'#' expected");
3900 return MatchOperand_ParseFail;
3901 }
3902 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003903 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003904
3905 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003906 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003907 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003908 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003909 return MatchOperand_ParseFail;
3910 }
3911 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3912 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003913 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003914 return MatchOperand_ParseFail;
3915 }
3916
3917 int64_t Val = CE->getValue();
3918 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3919 // normally, zero is represented in asm by omitting the rotate operand
3920 // entirely.
3921 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003922 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003923 return MatchOperand_ParseFail;
3924 }
3925
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003926 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003927
3928 return MatchOperand_Success;
3929}
3930
Jim Grosbach864b6092011-07-28 21:34:26 +00003931ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3932parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3933 SMLoc S = Parser.getTok().getLoc();
3934 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003935 if (Parser.getTok().isNot(AsmToken::Hash) &&
3936 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003937 Error(Parser.getTok().getLoc(), "'#' expected");
3938 return MatchOperand_ParseFail;
3939 }
3940 Parser.Lex(); // Eat hash token.
3941
3942 const MCExpr *LSBExpr;
3943 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003944 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003945 Error(E, "malformed immediate expression");
3946 return MatchOperand_ParseFail;
3947 }
3948 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3949 if (!CE) {
3950 Error(E, "'lsb' operand must be an immediate");
3951 return MatchOperand_ParseFail;
3952 }
3953
3954 int64_t LSB = CE->getValue();
3955 // The LSB must be in the range [0,31]
3956 if (LSB < 0 || LSB > 31) {
3957 Error(E, "'lsb' operand must be in the range [0,31]");
3958 return MatchOperand_ParseFail;
3959 }
3960 E = Parser.getTok().getLoc();
3961
3962 // Expect another immediate operand.
3963 if (Parser.getTok().isNot(AsmToken::Comma)) {
3964 Error(Parser.getTok().getLoc(), "too few operands");
3965 return MatchOperand_ParseFail;
3966 }
3967 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003968 if (Parser.getTok().isNot(AsmToken::Hash) &&
3969 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003970 Error(Parser.getTok().getLoc(), "'#' expected");
3971 return MatchOperand_ParseFail;
3972 }
3973 Parser.Lex(); // Eat hash token.
3974
3975 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003976 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003977 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003978 Error(E, "malformed immediate expression");
3979 return MatchOperand_ParseFail;
3980 }
3981 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3982 if (!CE) {
3983 Error(E, "'width' operand must be an immediate");
3984 return MatchOperand_ParseFail;
3985 }
3986
3987 int64_t Width = CE->getValue();
3988 // The LSB must be in the range [1,32-lsb]
3989 if (Width < 1 || Width > 32 - LSB) {
3990 Error(E, "'width' operand must be in the range [1,32-lsb]");
3991 return MatchOperand_ParseFail;
3992 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003993
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003994 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003995
3996 return MatchOperand_Success;
3997}
3998
Jim Grosbachd3595712011-08-03 23:50:40 +00003999ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4000parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4001 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004002 // postidx_reg := '+' register {, shift}
4003 // | '-' register {, shift}
4004 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004005
4006 // This method must return MatchOperand_NoMatch without consuming any tokens
4007 // in the case where there is no match, as other alternatives take other
4008 // parse methods.
4009 AsmToken Tok = Parser.getTok();
4010 SMLoc S = Tok.getLoc();
4011 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004012 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004013 if (Tok.is(AsmToken::Plus)) {
4014 Parser.Lex(); // Eat the '+' token.
4015 haveEaten = true;
4016 } else if (Tok.is(AsmToken::Minus)) {
4017 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004018 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004019 haveEaten = true;
4020 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004021
4022 SMLoc E = Parser.getTok().getEndLoc();
4023 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004024 if (Reg == -1) {
4025 if (!haveEaten)
4026 return MatchOperand_NoMatch;
4027 Error(Parser.getTok().getLoc(), "register expected");
4028 return MatchOperand_ParseFail;
4029 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004030
Jim Grosbachc320c852011-08-05 21:28:30 +00004031 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4032 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004033 if (Parser.getTok().is(AsmToken::Comma)) {
4034 Parser.Lex(); // Eat the ','.
4035 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4036 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004037
4038 // FIXME: Only approximates end...may include intervening whitespace.
4039 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004040 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004041
4042 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4043 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004044
4045 return MatchOperand_Success;
4046}
4047
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004048ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4049parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4050 // Check for a post-index addressing register operand. Specifically:
4051 // am3offset := '+' register
4052 // | '-' register
4053 // | register
4054 // | # imm
4055 // | # + imm
4056 // | # - imm
4057
4058 // This method must return MatchOperand_NoMatch without consuming any tokens
4059 // in the case where there is no match, as other alternatives take other
4060 // parse methods.
4061 AsmToken Tok = Parser.getTok();
4062 SMLoc S = Tok.getLoc();
4063
4064 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004065 if (Parser.getTok().is(AsmToken::Hash) ||
4066 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004067 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004068 // Explicitly look for a '-', as we need to encode negative zero
4069 // differently.
4070 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4071 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004072 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004073 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004074 return MatchOperand_ParseFail;
4075 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4076 if (!CE) {
4077 Error(S, "constant expression expected");
4078 return MatchOperand_ParseFail;
4079 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004080 // Negative zero is encoded as the flag value INT32_MIN.
4081 int32_t Val = CE->getValue();
4082 if (isNegative && Val == 0)
4083 Val = INT32_MIN;
4084
4085 Operands.push_back(
4086 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4087
4088 return MatchOperand_Success;
4089 }
4090
4091
4092 bool haveEaten = false;
4093 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004094 if (Tok.is(AsmToken::Plus)) {
4095 Parser.Lex(); // Eat the '+' token.
4096 haveEaten = true;
4097 } else if (Tok.is(AsmToken::Minus)) {
4098 Parser.Lex(); // Eat the '-' token.
4099 isAdd = false;
4100 haveEaten = true;
4101 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004102
4103 Tok = Parser.getTok();
4104 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004105 if (Reg == -1) {
4106 if (!haveEaten)
4107 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004108 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004109 return MatchOperand_ParseFail;
4110 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004111
4112 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004113 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004114
4115 return MatchOperand_Success;
4116}
4117
Tim Northovereb5e4d52013-07-22 09:06:12 +00004118/// Convert parsed operands to MCInst. Needed here because this instruction
4119/// only has two register operands, but multiplication is commutative so
4120/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004121void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004122cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004123 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004124 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4125 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004126 // If we have a three-operand form, make sure to set Rn to be the operand
4127 // that isn't the same as Rd.
4128 unsigned RegOp = 4;
4129 if (Operands.size() == 6 &&
4130 ((ARMOperand*)Operands[4])->getReg() ==
4131 ((ARMOperand*)Operands[3])->getReg())
4132 RegOp = 5;
4133 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4134 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004135 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004136}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004137
Mihai Popaad18d3c2013-08-09 10:38:32 +00004138void ARMAsmParser::
4139cvtThumbBranches(MCInst &Inst,
4140 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4141 int CondOp = -1, ImmOp = -1;
4142 switch(Inst.getOpcode()) {
4143 case ARM::tB:
4144 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4145
4146 case ARM::t2B:
4147 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4148
4149 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4150 }
4151 // first decide whether or not the branch should be conditional
4152 // by looking at it's location relative to an IT block
4153 if(inITBlock()) {
4154 // inside an IT block we cannot have any conditional branches. any
4155 // such instructions needs to be converted to unconditional form
4156 switch(Inst.getOpcode()) {
4157 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4158 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4159 }
4160 } else {
4161 // outside IT blocks we can only have unconditional branches with AL
4162 // condition code or conditional branches with non-AL condition code
4163 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4164 switch(Inst.getOpcode()) {
4165 case ARM::tB:
4166 case ARM::tBcc:
4167 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4168 break;
4169 case ARM::t2B:
4170 case ARM::t2Bcc:
4171 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4172 break;
4173 }
4174 }
4175
4176 // now decide on encoding size based on branch target range
4177 switch(Inst.getOpcode()) {
4178 // classify tB as either t2B or t1B based on range of immediate operand
4179 case ARM::tB: {
4180 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4181 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4182 Inst.setOpcode(ARM::t2B);
4183 break;
4184 }
4185 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4186 case ARM::tBcc: {
4187 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4188 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4189 Inst.setOpcode(ARM::t2Bcc);
4190 break;
4191 }
4192 }
4193 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4194 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4195}
4196
Bill Wendlinge18980a2010-11-06 22:36:58 +00004197/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004198/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004199bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004200parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004201 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004202 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004203 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004204 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004205 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004206
Sean Callanan936b0d32010-01-19 21:44:56 +00004207 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004208 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004209 if (BaseRegNum == -1)
4210 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004211
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004212 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004213 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004214 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4215 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004216 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004217
Jim Grosbachd3595712011-08-03 23:50:40 +00004218 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004219 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004220 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004221
Jim Grosbachd3595712011-08-03 23:50:40 +00004222 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004223 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004224
Jim Grosbach40700e02011-09-19 18:42:21 +00004225 // If there's a pre-indexing writeback marker, '!', just add it as a token
4226 // operand. It's rather odd, but syntactically valid.
4227 if (Parser.getTok().is(AsmToken::Exclaim)) {
4228 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4229 Parser.Lex(); // Eat the '!'.
4230 }
4231
Jim Grosbachd3595712011-08-03 23:50:40 +00004232 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004233 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004234
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004235 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4236 "Lost colon or comma in memory operand?!");
4237 if (Tok.is(AsmToken::Comma)) {
4238 Parser.Lex(); // Eat the comma.
4239 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004240
Jim Grosbacha95ec992011-10-11 17:29:55 +00004241 // If we have a ':', it's an alignment specifier.
4242 if (Parser.getTok().is(AsmToken::Colon)) {
4243 Parser.Lex(); // Eat the ':'.
4244 E = Parser.getTok().getLoc();
4245
4246 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004247 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004248 return true;
4249
4250 // The expression has to be a constant. Memory references with relocations
4251 // don't come through here, as they use the <label> forms of the relevant
4252 // instructions.
4253 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4254 if (!CE)
4255 return Error (E, "constant expression expected");
4256
4257 unsigned Align = 0;
4258 switch (CE->getValue()) {
4259 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004260 return Error(E,
4261 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4262 case 16: Align = 2; break;
4263 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004264 case 64: Align = 8; break;
4265 case 128: Align = 16; break;
4266 case 256: Align = 32; break;
4267 }
4268
4269 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004270 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004271 return Error(Parser.getTok().getLoc(), "']' expected");
4272 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004273 Parser.Lex(); // Eat right bracket token.
4274
4275 // Don't worry about range checking the value here. That's handled by
4276 // the is*() predicates.
4277 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4278 ARM_AM::no_shift, 0, Align,
4279 false, S, E));
4280
4281 // If there's a pre-indexing writeback marker, '!', just add it as a token
4282 // operand.
4283 if (Parser.getTok().is(AsmToken::Exclaim)) {
4284 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4285 Parser.Lex(); // Eat the '!'.
4286 }
4287
4288 return false;
4289 }
4290
4291 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004292 // offset. Be friendly and also accept a plain integer (without a leading
4293 // hash) for gas compatibility.
4294 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004295 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004296 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004297 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004298 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004299 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004300
Owen Anderson967674d2011-08-29 19:36:44 +00004301 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004302 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004303 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004304 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004305
4306 // The expression has to be a constant. Memory references with relocations
4307 // don't come through here, as they use the <label> forms of the relevant
4308 // instructions.
4309 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4310 if (!CE)
4311 return Error (E, "constant expression expected");
4312
Owen Anderson967674d2011-08-29 19:36:44 +00004313 // If the constant was #-0, represent it as INT32_MIN.
4314 int32_t Val = CE->getValue();
4315 if (isNegative && Val == 0)
4316 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4317
Jim Grosbachd3595712011-08-03 23:50:40 +00004318 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004319 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004320 return Error(Parser.getTok().getLoc(), "']' expected");
4321 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004322 Parser.Lex(); // Eat right bracket token.
4323
4324 // Don't worry about range checking the value here. That's handled by
4325 // the is*() predicates.
4326 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004327 ARM_AM::no_shift, 0, 0,
4328 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004329
4330 // If there's a pre-indexing writeback marker, '!', just add it as a token
4331 // operand.
4332 if (Parser.getTok().is(AsmToken::Exclaim)) {
4333 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4334 Parser.Lex(); // Eat the '!'.
4335 }
4336
4337 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004338 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004339
4340 // The register offset is optionally preceded by a '+' or '-'
4341 bool isNegative = false;
4342 if (Parser.getTok().is(AsmToken::Minus)) {
4343 isNegative = true;
4344 Parser.Lex(); // Eat the '-'.
4345 } else if (Parser.getTok().is(AsmToken::Plus)) {
4346 // Nothing to do.
4347 Parser.Lex(); // Eat the '+'.
4348 }
4349
4350 E = Parser.getTok().getLoc();
4351 int OffsetRegNum = tryParseRegister();
4352 if (OffsetRegNum == -1)
4353 return Error(E, "register expected");
4354
4355 // If there's a shift operator, handle it.
4356 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004357 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004358 if (Parser.getTok().is(AsmToken::Comma)) {
4359 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004360 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004361 return true;
4362 }
4363
4364 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004365 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004366 return Error(Parser.getTok().getLoc(), "']' expected");
4367 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004368 Parser.Lex(); // Eat right bracket token.
4369
4370 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004371 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004372 S, E));
4373
Jim Grosbachc320c852011-08-05 21:28:30 +00004374 // If there's a pre-indexing writeback marker, '!', just add it as a token
4375 // operand.
4376 if (Parser.getTok().is(AsmToken::Exclaim)) {
4377 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4378 Parser.Lex(); // Eat the '!'.
4379 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004380
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004381 return false;
4382}
4383
Jim Grosbachd3595712011-08-03 23:50:40 +00004384/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004385/// ( lsl | lsr | asr | ror ) , # shift_amount
4386/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004387/// return true if it parses a shift otherwise it returns false.
4388bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4389 unsigned &Amount) {
4390 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004391 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004392 if (Tok.isNot(AsmToken::Identifier))
4393 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004394 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004395 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4396 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004397 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004398 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004399 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004400 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004401 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004402 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004403 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004404 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004405 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004406 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004407 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004408 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004409
Jim Grosbachd3595712011-08-03 23:50:40 +00004410 // rrx stands alone.
4411 Amount = 0;
4412 if (St != ARM_AM::rrx) {
4413 Loc = Parser.getTok().getLoc();
4414 // A '#' and a shift amount.
4415 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004416 if (HashTok.isNot(AsmToken::Hash) &&
4417 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004418 return Error(HashTok.getLoc(), "'#' expected");
4419 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004420
Jim Grosbachd3595712011-08-03 23:50:40 +00004421 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004422 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004423 return true;
4424 // Range check the immediate.
4425 // lsl, ror: 0 <= imm <= 31
4426 // lsr, asr: 0 <= imm <= 32
4427 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4428 if (!CE)
4429 return Error(Loc, "shift amount must be an immediate");
4430 int64_t Imm = CE->getValue();
4431 if (Imm < 0 ||
4432 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4433 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4434 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004435 // If <ShiftTy> #0, turn it into a no_shift.
4436 if (Imm == 0)
4437 St = ARM_AM::lsl;
4438 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4439 if (Imm == 32)
4440 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004441 Amount = Imm;
4442 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004443
4444 return false;
4445}
4446
Jim Grosbache7fbce72011-10-03 23:38:36 +00004447/// parseFPImm - A floating point immediate expression operand.
4448ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4449parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004450 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004451 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004452 // integer only.
4453 //
4454 // This routine still creates a generic Immediate operand, containing
4455 // a bitcast of the 64-bit floating point value. The various operands
4456 // that accept floats can check whether the value is valid for them
4457 // via the standard is*() predicates.
4458
Jim Grosbache7fbce72011-10-03 23:38:36 +00004459 SMLoc S = Parser.getTok().getLoc();
4460
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004461 if (Parser.getTok().isNot(AsmToken::Hash) &&
4462 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004463 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004464
4465 // Disambiguate the VMOV forms that can accept an FP immediate.
4466 // vmov.f32 <sreg>, #imm
4467 // vmov.f64 <dreg>, #imm
4468 // vmov.f32 <dreg>, #imm @ vector f32x2
4469 // vmov.f32 <qreg>, #imm @ vector f32x4
4470 //
4471 // There are also the NEON VMOV instructions which expect an
4472 // integer constant. Make sure we don't try to parse an FPImm
4473 // for these:
4474 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4475 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4476 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4477 TyOp->getToken() != ".f64"))
4478 return MatchOperand_NoMatch;
4479
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004480 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004481
4482 // Handle negation, as that still comes through as a separate token.
4483 bool isNegative = false;
4484 if (Parser.getTok().is(AsmToken::Minus)) {
4485 isNegative = true;
4486 Parser.Lex();
4487 }
4488 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004489 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004490 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004491 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004492 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4493 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004494 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004495 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004496 Operands.push_back(ARMOperand::CreateImm(
4497 MCConstantExpr::Create(IntVal, getContext()),
4498 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004499 return MatchOperand_Success;
4500 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004501 // Also handle plain integers. Instructions which allow floating point
4502 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004503 if (Tok.is(AsmToken::Integer)) {
4504 int64_t Val = Tok.getIntVal();
4505 Parser.Lex(); // Eat the token.
4506 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004507 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004508 return MatchOperand_ParseFail;
4509 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004510 double RealVal = ARM_AM::getFPImmFloat(Val);
4511 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4512 Operands.push_back(ARMOperand::CreateImm(
4513 MCConstantExpr::Create(Val, getContext()), S,
4514 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004515 return MatchOperand_Success;
4516 }
4517
Jim Grosbach235c8d22012-01-19 02:47:30 +00004518 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004519 return MatchOperand_ParseFail;
4520}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004521
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004522/// Parse a arm instruction operand. For now this parses the operand regardless
4523/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004524bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004525 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004526 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004527
4528 // Check if the current operand has a custom associated parser, if so, try to
4529 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004530 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4531 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004532 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004533 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4534 // there was a match, but an error occurred, in which case, just return that
4535 // the operand parsing failed.
4536 if (ResTy == MatchOperand_ParseFail)
4537 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004538
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004539 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004540 default:
4541 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004542 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004543 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004544 // If we've seen a branch mnemonic, the next operand must be a label. This
4545 // is true even if the label is a register name. So "br r1" means branch to
4546 // label "r1".
4547 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4548 if (!ExpectLabel) {
4549 if (!tryParseRegisterWithWriteBack(Operands))
4550 return false;
4551 int Res = tryParseShiftRegister(Operands);
4552 if (Res == 0) // success
4553 return false;
4554 else if (Res == -1) // irrecoverable error
4555 return true;
4556 // If this is VMRS, check for the apsr_nzcv operand.
4557 if (Mnemonic == "vmrs" &&
4558 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4559 S = Parser.getTok().getLoc();
4560 Parser.Lex();
4561 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4562 return false;
4563 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004564 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004565
4566 // Fall though for the Identifier case that is not a register or a
4567 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004568 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004569 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004570 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004571 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004572 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004573 // This was not a register so parse other operands that start with an
4574 // identifier (like labels) as expressions and create them as immediates.
4575 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004576 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004577 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004578 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004579 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004580 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4581 return false;
4582 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004583 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004584 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004585 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004586 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004587 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004588 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004589 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004590 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004591 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004592
4593 if (Parser.getTok().isNot(AsmToken::Colon)) {
4594 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4595 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004596 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004597 return true;
4598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4599 if (CE) {
4600 int32_t Val = CE->getValue();
4601 if (isNegative && Val == 0)
4602 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4603 }
4604 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4605 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004606
4607 // There can be a trailing '!' on operands that we want as a separate
4608 // '!' Token operand. Handle that here. For example, the compatibilty
4609 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4610 if (Parser.getTok().is(AsmToken::Exclaim)) {
4611 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4612 Parser.getTok().getLoc()));
4613 Parser.Lex(); // Eat exclaim token
4614 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004615 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004616 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004617 // w/ a ':' after the '#', it's just like a plain ':'.
4618 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004619 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004620 case AsmToken::Colon: {
4621 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004622 // FIXME: Check it's an expression prefix,
4623 // e.g. (FOO - :lower16:BAR) isn't legal.
4624 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004625 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004626 return true;
4627
Evan Cheng965b3c72011-01-13 07:58:56 +00004628 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004629 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004630 return true;
4631
Evan Cheng965b3c72011-01-13 07:58:56 +00004632 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004633 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004634 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004635 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004636 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004637 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004638 }
4639}
4640
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004641// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004642// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004643bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004644 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004645
4646 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004647 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004648 Parser.Lex(); // Eat ':'
4649
4650 if (getLexer().isNot(AsmToken::Identifier)) {
4651 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4652 return true;
4653 }
4654
4655 StringRef IDVal = Parser.getTok().getIdentifier();
4656 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004657 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004658 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004659 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004660 } else {
4661 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4662 return true;
4663 }
4664 Parser.Lex();
4665
4666 if (getLexer().isNot(AsmToken::Colon)) {
4667 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4668 return true;
4669 }
4670 Parser.Lex(); // Eat the last ':'
4671 return false;
4672}
4673
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004674/// \brief Given a mnemonic, split out possible predication code and carry
4675/// setting letters to form a canonical mnemonic and flags.
4676//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004677// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004678// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004679StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004680 unsigned &PredicationCode,
4681 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004682 unsigned &ProcessorIMod,
4683 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004684 PredicationCode = ARMCC::AL;
4685 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004686 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004687
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004688 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004689 //
4690 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004691 if ((Mnemonic == "movs" && isThumb()) ||
4692 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4693 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4694 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4695 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004696 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004697 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4698 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004699 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004700 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004701 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4702 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4703 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004704 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004705
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004706 // First, split out any predication code. Ignore mnemonics we know aren't
4707 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004708 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004709 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004710 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004711 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004712 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4713 .Case("eq", ARMCC::EQ)
4714 .Case("ne", ARMCC::NE)
4715 .Case("hs", ARMCC::HS)
4716 .Case("cs", ARMCC::HS)
4717 .Case("lo", ARMCC::LO)
4718 .Case("cc", ARMCC::LO)
4719 .Case("mi", ARMCC::MI)
4720 .Case("pl", ARMCC::PL)
4721 .Case("vs", ARMCC::VS)
4722 .Case("vc", ARMCC::VC)
4723 .Case("hi", ARMCC::HI)
4724 .Case("ls", ARMCC::LS)
4725 .Case("ge", ARMCC::GE)
4726 .Case("lt", ARMCC::LT)
4727 .Case("gt", ARMCC::GT)
4728 .Case("le", ARMCC::LE)
4729 .Case("al", ARMCC::AL)
4730 .Default(~0U);
4731 if (CC != ~0U) {
4732 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4733 PredicationCode = CC;
4734 }
Bill Wendling193961b2010-10-29 23:50:21 +00004735 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004736
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004737 // Next, determine if we have a carry setting bit. We explicitly ignore all
4738 // the instructions we know end in 's'.
4739 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004740 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004741 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4742 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4743 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004744 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004745 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004746 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004747 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004748 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004749 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004750 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4751 CarrySetting = true;
4752 }
4753
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004754 // The "cps" instruction can have a interrupt mode operand which is glued into
4755 // the mnemonic. Check if this is the case, split it and parse the imod op
4756 if (Mnemonic.startswith("cps")) {
4757 // Split out any imod code.
4758 unsigned IMod =
4759 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4760 .Case("ie", ARM_PROC::IE)
4761 .Case("id", ARM_PROC::ID)
4762 .Default(~0U);
4763 if (IMod != ~0U) {
4764 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4765 ProcessorIMod = IMod;
4766 }
4767 }
4768
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004769 // The "it" instruction has the condition mask on the end of the mnemonic.
4770 if (Mnemonic.startswith("it")) {
4771 ITMask = Mnemonic.slice(2, Mnemonic.size());
4772 Mnemonic = Mnemonic.slice(0, 2);
4773 }
4774
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004775 return Mnemonic;
4776}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004777
4778/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4779/// inclusion of carry set or predication code operands.
4780//
4781// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004782void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00004783getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4784 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004785 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4786 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004787 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004788 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004789 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004790 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004791 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004792 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004793 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004794 Mnemonic == "mla" || Mnemonic == "smlal" ||
4795 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004796 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004797 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004798 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004799
Tim Northover2c45a382013-06-26 16:52:40 +00004800 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4801 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Joey Gouly2f8890e2013-09-18 09:45:55 +00004802 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004803 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4804 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004805 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4806 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00004807 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4808 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4809 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00004810 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004811 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004812 } else if (!isThumb()) {
4813 // Some instructions are only predicable in Thumb mode
4814 CanAcceptPredicationCode
4815 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4816 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4817 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4818 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4819 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4820 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4821 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4822 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00004823 if (hasV6MOps())
4824 CanAcceptPredicationCode = Mnemonic != "movs";
4825 else
4826 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004827 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004828 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004829}
4830
Jim Grosbach7283da92011-08-16 21:12:37 +00004831bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4832 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004833 // FIXME: This is all horribly hacky. We really need a better way to deal
4834 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004835
4836 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4837 // another does not. Specifically, the MOVW instruction does not. So we
4838 // special case it here and remove the defaulted (non-setting) cc_out
4839 // operand if that's the instruction we're trying to match.
4840 //
4841 // We do this as post-processing of the explicit operands rather than just
4842 // conditionally adding the cc_out in the first place because we need
4843 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004844 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004845 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4846 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4847 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4848 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004849
4850 // Register-register 'add' for thumb does not have a cc_out operand
4851 // when there are only two register operands.
4852 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4853 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4854 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4855 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4856 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004857 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004858 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4859 // have to check the immediate range here since Thumb2 has a variant
4860 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004861 if (((isThumb() && Mnemonic == "add") ||
4862 (isThumbTwo() && Mnemonic == "sub")) &&
4863 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004864 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4865 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4866 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004867 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004868 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004869 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004870 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004871 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4872 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004873 // selecting via the generic "add" mnemonic, so to know that we
4874 // should remove the cc_out operand, we have to explicitly check that
4875 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004876 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4877 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004878 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4879 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4880 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4881 // Nest conditions rather than one big 'if' statement for readability.
4882 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004883 // If both registers are low, we're in an IT block, and the immediate is
4884 // in range, we should use encoding T1 instead, which has a cc_out.
4885 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004886 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004887 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4888 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4889 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004890 // Check against T3. If the second register is the PC, this is an
4891 // alternate form of ADR, which uses encoding T4, so check for that too.
4892 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4893 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4894 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004895
4896 // Otherwise, we use encoding T4, which does not have a cc_out
4897 // operand.
4898 return true;
4899 }
4900
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004901 // The thumb2 multiply instruction doesn't have a CCOut register, so
4902 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4903 // use the 16-bit encoding or not.
4904 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4905 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4906 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4907 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4908 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4909 // If the registers aren't low regs, the destination reg isn't the
4910 // same as one of the source regs, or the cc_out operand is zero
4911 // outside of an IT block, we have to use the 32-bit encoding, so
4912 // remove the cc_out operand.
4913 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4914 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004915 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004916 !inITBlock() ||
4917 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4918 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4919 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4920 static_cast<ARMOperand*>(Operands[4])->getReg())))
4921 return true;
4922
Jim Grosbachefa7e952011-11-15 19:55:16 +00004923 // Also check the 'mul' syntax variant that doesn't specify an explicit
4924 // destination register.
4925 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4926 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4927 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4928 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4929 // If the registers aren't low regs or the cc_out operand is zero
4930 // outside of an IT block, we have to use the 32-bit encoding, so
4931 // remove the cc_out operand.
4932 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4933 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4934 !inITBlock()))
4935 return true;
4936
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004937
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004938
Jim Grosbach4b701af2011-08-24 21:42:27 +00004939 // Register-register 'add/sub' for thumb does not have a cc_out operand
4940 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4941 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4942 // right, this will result in better diagnostics (which operand is off)
4943 // anyway.
4944 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4945 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004946 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4947 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004948 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4949 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4950 (Operands.size() == 6 &&
4951 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004952 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004953
Jim Grosbach7283da92011-08-16 21:12:37 +00004954 return false;
4955}
4956
Joey Goulye8602552013-07-19 16:34:16 +00004957bool ARMAsmParser::shouldOmitPredicateOperand(
4958 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4959 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4960 unsigned RegIdx = 3;
4961 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4962 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4963 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4964 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4965 RegIdx = 4;
4966
4967 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4968 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4969 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4970 ARMMCRegisterClasses[ARM::QPRRegClassID]
4971 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4972 return true;
4973 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004974 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004975}
4976
Jim Grosbach12952fe2011-11-11 23:08:10 +00004977static bool isDataTypeToken(StringRef Tok) {
4978 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4979 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4980 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4981 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4982 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4983 Tok == ".f" || Tok == ".d";
4984}
4985
4986// FIXME: This bit should probably be handled via an explicit match class
4987// in the .td files that matches the suffix instead of having it be
4988// a literal string token the way it is now.
4989static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4990 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4991}
Chad Rosier9f7a2212013-04-18 22:35:36 +00004992static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4993 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004994/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004995bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4996 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004997 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004998 // Apply mnemonic aliases before doing anything else, as the destination
4999 // mnemnonic may include suffices and we want to handle them normally.
5000 // The generic tblgen'erated code does this later, at the start of
5001 // MatchInstructionImpl(), but that's too late for aliases that include
5002 // any sort of suffix.
5003 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005004 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5005 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005006
Jim Grosbachab5830e2011-12-14 02:16:11 +00005007 // First check for the ARM-specific .req directive.
5008 if (Parser.getTok().is(AsmToken::Identifier) &&
5009 Parser.getTok().getIdentifier() == ".req") {
5010 parseDirectiveReq(Name, NameLoc);
5011 // We always return 'error' for this, as we're done with this
5012 // statement and don't need to match the 'instruction."
5013 return true;
5014 }
5015
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005016 // Create the leading tokens for the mnemonic, split by '.' characters.
5017 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005018 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005019
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005020 // Split out the predication code and carry setting flag from the mnemonic.
5021 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005022 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005023 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005024 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005025 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005026 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005027
Jim Grosbach1c171b12011-08-25 17:23:55 +00005028 // In Thumb1, only the branch (B) instruction can be predicated.
5029 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005030 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005031 return Error(NameLoc, "conditional execution not supported in Thumb1");
5032 }
5033
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005034 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5035
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005036 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5037 // is the mask as it will be for the IT encoding if the conditional
5038 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5039 // where the conditional bit0 is zero, the instruction post-processing
5040 // will adjust the mask accordingly.
5041 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005042 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5043 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005044 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005045 return Error(Loc, "too many conditions on IT instruction");
5046 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005047 unsigned Mask = 8;
5048 for (unsigned i = ITMask.size(); i != 0; --i) {
5049 char pos = ITMask[i - 1];
5050 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005051 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005052 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005053 }
5054 Mask >>= 1;
5055 if (ITMask[i - 1] == 't')
5056 Mask |= 8;
5057 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005058 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005059 }
5060
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005061 // FIXME: This is all a pretty gross hack. We should automatically handle
5062 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005063
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005064 // Next, add the CCOut and ConditionCode operands, if needed.
5065 //
5066 // For mnemonics which can ever incorporate a carry setting bit or predication
5067 // code, our matching model involves us always generating CCOut and
5068 // ConditionCode operands to match the mnemonic "as written" and then we let
5069 // the matcher deal with finding the right instruction or generating an
5070 // appropriate error.
5071 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005072 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005073
Jim Grosbach03a8a162011-07-14 22:04:21 +00005074 // If we had a carry-set on an instruction that can't do that, issue an
5075 // error.
5076 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005077 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005078 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005079 "' can not set flags, but 's' suffix specified");
5080 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005081 // If we had a predication code on an instruction that can't do that, issue an
5082 // error.
5083 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005084 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005085 return Error(NameLoc, "instruction '" + Mnemonic +
5086 "' is not predicable, but condition code specified");
5087 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005088
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005089 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005090 if (CanAcceptCarrySet) {
5091 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005092 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005093 Loc));
5094 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005095
5096 // Add the predication code operand, if necessary.
5097 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005098 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5099 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005100 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005101 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005102 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005103
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005104 // Add the processor imod operand, if necessary.
5105 if (ProcessorIMod) {
5106 Operands.push_back(ARMOperand::CreateImm(
5107 MCConstantExpr::Create(ProcessorIMod, getContext()),
5108 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005109 }
5110
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005111 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005112 while (Next != StringRef::npos) {
5113 Start = Next;
5114 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005115 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005116
Jim Grosbach12952fe2011-11-11 23:08:10 +00005117 // Some NEON instructions have an optional datatype suffix that is
5118 // completely ignored. Check for that.
5119 if (isDataTypeToken(ExtraToken) &&
5120 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5121 continue;
5122
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005123 // For for ARM mode generate an error if the .n qualifier is used.
5124 if (ExtraToken == ".n" && !isThumb()) {
5125 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5126 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5127 "arm mode");
5128 }
5129
5130 // The .n qualifier is always discarded as that is what the tables
5131 // and matcher expect. In ARM mode the .w qualifier has no effect,
5132 // so discard it to avoid errors that can be caused by the matcher.
5133 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005134 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5135 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5136 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005137 }
5138
5139 // Read the remaining operands.
5140 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005141 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005142 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005143 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005144 return true;
5145 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005146
5147 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005148 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005149
5150 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005151 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005152 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005153 return true;
5154 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005155 }
5156 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005157
Chris Lattnera2a9d162010-09-11 16:18:25 +00005158 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005159 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005160 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005161 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005162 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005163
Chris Lattner91689c12010-09-08 05:10:46 +00005164 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005165
Jim Grosbach7283da92011-08-16 21:12:37 +00005166 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5167 // do and don't have a cc_out optional-def operand. With some spot-checks
5168 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005169 // parse and adjust accordingly before actually matching. We shouldn't ever
5170 // try to remove a cc_out operand that was explicitly set on the the
5171 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5172 // table driven matcher doesn't fit well with the ARM instruction set.
5173 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005174 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5175 Operands.erase(Operands.begin() + 1);
5176 delete Op;
5177 }
5178
Joey Goulye8602552013-07-19 16:34:16 +00005179 // Some instructions have the same mnemonic, but don't always
5180 // have a predicate. Distinguish them here and delete the
5181 // predicate if needed.
5182 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5183 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5184 Operands.erase(Operands.begin() + 1);
5185 delete Op;
5186 }
5187
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005188 // ARM mode 'blx' need special handling, as the register operand version
5189 // is predicable, but the label operand version is not. So, we can't rely
5190 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005191 // a k_CondCode operand in the list. If we're trying to match the label
5192 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005193 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5194 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5195 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5196 Operands.erase(Operands.begin() + 1);
5197 delete Op;
5198 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005199
Weiming Zhao8f56f882012-11-16 21:55:34 +00005200 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5201 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5202 // a single GPRPair reg operand is used in the .td file to replace the two
5203 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5204 // expressed as a GPRPair, so we have to manually merge them.
5205 // FIXME: We would really like to be able to tablegen'erate this.
5206 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005207 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5208 Mnemonic == "stlexd")) {
5209 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005210 unsigned Idx = isLoad ? 2 : 3;
5211 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5212 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5213
5214 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5215 // Adjust only if Op1 and Op2 are GPRs.
5216 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5217 MRC.contains(Op2->getReg())) {
5218 unsigned Reg1 = Op1->getReg();
5219 unsigned Reg2 = Op2->getReg();
5220 unsigned Rt = MRI->getEncodingValue(Reg1);
5221 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5222
5223 // Rt2 must be Rt + 1 and Rt must be even.
5224 if (Rt + 1 != Rt2 || (Rt & 1)) {
5225 Error(Op2->getStartLoc(), isLoad ?
5226 "destination operands must be sequential" :
5227 "source operands must be sequential");
5228 return true;
5229 }
5230 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5231 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5232 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5233 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5234 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5235 delete Op1;
5236 delete Op2;
5237 }
5238 }
5239
Kevin Enderby78f95722013-07-31 21:05:30 +00005240 // FIXME: As said above, this is all a pretty gross hack. This instruction
5241 // does not fit with other "subs" and tblgen.
5242 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5243 // so the Mnemonic is the original name "subs" and delete the predicate
5244 // operand so it will match the table entry.
5245 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5246 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5247 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5248 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5249 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5250 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5251 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5252 Operands.erase(Operands.begin());
5253 delete Op0;
5254 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5255
5256 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5257 Operands.erase(Operands.begin() + 1);
5258 delete Op1;
5259 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005260 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005261}
5262
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005263// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005264
5265// return 'true' if register list contains non-low GPR registers,
5266// 'false' otherwise. If Reg is in the register list or is HiReg, set
5267// 'containsReg' to true.
5268static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5269 unsigned HiReg, bool &containsReg) {
5270 containsReg = false;
5271 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5272 unsigned OpReg = Inst.getOperand(i).getReg();
5273 if (OpReg == Reg)
5274 containsReg = true;
5275 // Anything other than a low register isn't legal here.
5276 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5277 return true;
5278 }
5279 return false;
5280}
5281
Jim Grosbacha31f2232011-09-07 18:05:34 +00005282// Check if the specified regisgter is in the register list of the inst,
5283// starting at the indicated operand number.
5284static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5285 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5286 unsigned OpReg = Inst.getOperand(i).getReg();
5287 if (OpReg == Reg)
5288 return true;
5289 }
5290 return false;
5291}
5292
Richard Barton8d519fe2013-09-05 14:14:19 +00005293// Return true if instruction has the interesting property of being
5294// allowed in IT blocks, but not being predicable.
5295static bool instIsBreakpoint(const MCInst &Inst) {
5296 return Inst.getOpcode() == ARM::tBKPT ||
5297 Inst.getOpcode() == ARM::BKPT ||
5298 Inst.getOpcode() == ARM::tHLT ||
5299 Inst.getOpcode() == ARM::HLT;
5300
5301}
5302
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005303// FIXME: We would really like to be able to tablegen'erate this.
5304bool ARMAsmParser::
5305validateInstruction(MCInst &Inst,
5306 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005307 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005308 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005309
Jim Grosbached16ec42011-08-29 22:24:09 +00005310 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005311 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005312 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005313 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005314 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005315 if (ITState.FirstCond)
5316 ITState.FirstCond = false;
5317 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005318 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005319 // The instruction must be predicable.
5320 if (!MCID.isPredicable())
5321 return Error(Loc, "instructions in IT block must be predicable");
5322 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005323 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005324 ARMCC::getOppositeCondition(ITState.Cond);
5325 if (Cond != ITCond) {
5326 // Find the condition code Operand to get its SMLoc information.
5327 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005328 for (unsigned I = 1; I < Operands.size(); ++I)
5329 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5330 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005331 return Error(CondLoc, "incorrect condition in IT block; got '" +
5332 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5333 "', but expected '" +
5334 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5335 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005336 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005337 } else if (isThumbTwo() && MCID.isPredicable() &&
5338 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005339 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5340 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005341 return Error(Loc, "predicated instructions must be in IT block");
5342
Tilmann Scheller255722b2013-09-30 16:11:48 +00005343 const unsigned Opcode = Inst.getOpcode();
5344 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005345 case ARM::LDRD:
5346 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005347 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005348 const unsigned RtReg = Inst.getOperand(0).getReg();
5349
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005350 // Rt can't be R14.
5351 if (RtReg == ARM::LR)
5352 return Error(Operands[3]->getStartLoc(),
5353 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005354
5355 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005356 // Rt must be even-numbered.
5357 if ((Rt & 1) == 1)
5358 return Error(Operands[3]->getStartLoc(),
5359 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005360
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005361 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005362 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005363 if (Rt2 != Rt + 1)
5364 return Error(Operands[3]->getStartLoc(),
5365 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005366
5367 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5368 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5369 // For addressing modes with writeback, the base register needs to be
5370 // different from the destination registers.
5371 if (Rn == Rt || Rn == Rt2)
5372 return Error(Operands[3]->getStartLoc(),
5373 "base register needs to be different from destination "
5374 "registers");
5375 }
5376
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005377 return false;
5378 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005379 case ARM::t2LDRDi8:
5380 case ARM::t2LDRD_PRE:
5381 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005382 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005383 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5384 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5385 if (Rt2 == Rt)
5386 return Error(Operands[3]->getStartLoc(),
5387 "destination operands can't be identical");
5388 return false;
5389 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005390 case ARM::STRD: {
5391 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005392 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5393 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005394 if (Rt2 != Rt + 1)
5395 return Error(Operands[3]->getStartLoc(),
5396 "source operands must be sequential");
5397 return false;
5398 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005399 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005400 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005401 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005402 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5403 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005404 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005405 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005406 "source operands must be sequential");
5407 return false;
5408 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005409 case ARM::SBFX:
5410 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005411 // Width must be in range [1, 32-lsb].
5412 unsigned LSB = Inst.getOperand(2).getImm();
5413 unsigned Widthm1 = Inst.getOperand(3).getImm();
5414 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005415 return Error(Operands[5]->getStartLoc(),
5416 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005417 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005418 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005419 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005420 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005421 // most cases that are normally illegal for a Thumb1 LDM instruction.
5422 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005423 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005424 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005425 // in the register list.
5426 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005427 bool HasWritebackToken =
Jim Grosbach139acd22011-08-22 23:01:07 +00005428 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5429 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005430 bool ListContainsBase;
5431 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5432 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005433 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005434 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005435 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005436 return Error(Operands[2]->getStartLoc(),
5437 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005438 // If we should not have writeback, there must not be a '!'. This is
5439 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005440 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005441 return Error(Operands[3]->getStartLoc(),
5442 "writeback operator '!' not allowed when base register "
5443 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005444
5445 break;
5446 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005447 case ARM::t2LDMIA_UPD: {
5448 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5449 return Error(Operands[4]->getStartLoc(),
5450 "writeback operator '!' not allowed when base register "
5451 "in register list");
5452 break;
5453 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005454 case ARM::tMUL: {
5455 // The second source operand must be the same register as the destination
5456 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005457 //
5458 // In this case, we must directly check the parsed operands because the
5459 // cvtThumbMultiply() function is written in such a way that it guarantees
5460 // this first statement is always true for the new Inst. Essentially, the
5461 // destination is unconditionally copied into the second source operand
5462 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005463 if (Operands.size() == 6 &&
5464 (((ARMOperand*)Operands[3])->getReg() !=
5465 ((ARMOperand*)Operands[5])->getReg()) &&
5466 (((ARMOperand*)Operands[3])->getReg() !=
5467 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005468 return Error(Operands[3]->getStartLoc(),
5469 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005470 }
5471 break;
5472 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005473 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5474 // so only issue a diagnostic for thumb1. The instructions will be
5475 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005476 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005477 bool ListContainsBase;
5478 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005479 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005480 return Error(Operands[2]->getStartLoc(),
5481 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005482 break;
5483 }
5484 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005485 bool ListContainsBase;
5486 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005487 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005488 return Error(Operands[2]->getStartLoc(),
5489 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005490 break;
5491 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005492 case ARM::tSTMIA_UPD: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005493 bool ListContainsBase;
5494 if (checkLowRegisterList(Inst, 4, 0, 0, ListContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005495 return Error(Operands[4]->getStartLoc(),
5496 "registers must be in range r0-r7");
5497 break;
5498 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005499 case ARM::tADDrSP: {
5500 // If the non-SP source operand and the destination operand are not the
5501 // same, we need thumb2 (for the wide encoding), or we have an error.
5502 if (!isThumbTwo() &&
5503 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5504 return Error(Operands[4]->getStartLoc(),
5505 "source register must be the same as destination");
5506 }
5507 break;
5508 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005509 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005510 case ARM::tB:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005511 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5512 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005513 break;
5514 case ARM::t2B: {
5515 int op = (Operands[2]->isImm()) ? 2 : 3;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005516 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5517 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005518 break;
5519 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005520 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005521 case ARM::tBcc:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005522 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5523 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005524 break;
5525 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005526 int Op = (Operands[2]->isImm()) ? 2 : 3;
5527 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5528 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005529 break;
5530 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005531 }
5532
5533 return false;
5534}
5535
Jim Grosbach1a747242012-01-23 23:45:44 +00005536static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005537 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005538 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005539 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005540 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5541 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5542 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5543 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5544 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5545 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5546 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5547 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5548 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005549
5550 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005551 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5552 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5553 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5554 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5555 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005556
Jim Grosbach1e946a42012-01-24 00:43:12 +00005557 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5558 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5559 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5560 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5561 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005562
Jim Grosbach1e946a42012-01-24 00:43:12 +00005563 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5564 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5565 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5566 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5567 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005568
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005569 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005570 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5571 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5572 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5573 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5574 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5575 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5576 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5577 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5578 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5579 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5580 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5581 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5582 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5583 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5584 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005585
Jim Grosbach1a747242012-01-23 23:45:44 +00005586 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005587 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5588 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5589 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5590 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5591 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5592 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5593 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5594 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5595 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5596 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5597 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5598 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5599 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5600 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5601 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5602 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5603 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5604 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005605
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005606 // VST4LN
5607 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5608 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5609 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5610 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5611 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5612 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5613 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5614 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5615 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5616 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5617 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5618 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5619 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5620 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5621 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5622
Jim Grosbachda70eac2012-01-24 00:58:13 +00005623 // VST4
5624 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5625 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5626 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5627 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5628 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5629 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5630 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5631 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5632 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5633 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5634 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5635 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5636 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5637 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5638 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5639 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5640 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5641 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005642 }
5643}
5644
Jim Grosbach1a747242012-01-23 23:45:44 +00005645static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005646 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005647 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005648 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005649 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5650 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5651 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5652 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5653 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5654 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5655 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5656 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5657 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005658
5659 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005660 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5661 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5662 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5663 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5664 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5665 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5666 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5667 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5668 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5669 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5670 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5671 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5672 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5673 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5674 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005675
Jim Grosbachb78403c2012-01-24 23:47:04 +00005676 // VLD3DUP
5677 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5678 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5679 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5680 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5681 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5682 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5683 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5684 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5685 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5686 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5687 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5688 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5689 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5690 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5691 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5692 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5693 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5694 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5695
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005696 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005697 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5698 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5699 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5700 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5701 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5702 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5703 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5704 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5705 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5706 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5707 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5708 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5709 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5710 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5711 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005712
5713 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005714 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5715 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5716 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5717 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5718 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5719 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5720 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5721 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5722 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5723 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5724 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5725 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5726 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5727 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5728 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5729 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5730 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5731 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005732
Jim Grosbach14952a02012-01-24 18:37:25 +00005733 // VLD4LN
5734 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5735 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5736 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5737 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5738 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5739 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5740 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5741 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5742 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5743 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5744 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5745 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5746 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5747 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5748 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5749
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005750 // VLD4DUP
5751 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5752 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5753 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5754 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5755 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5756 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5757 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5758 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5759 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5760 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5761 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5762 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5763 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5764 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5765 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5766 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5767 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5768 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5769
Jim Grosbached561fc2012-01-24 00:43:17 +00005770 // VLD4
5771 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5772 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5773 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5774 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5775 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5776 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5777 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5778 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5779 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5780 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5781 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5782 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5783 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5784 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5785 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5786 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5787 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5788 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005789 }
5790}
5791
Jim Grosbachafad0532011-11-10 23:42:14 +00005792bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005793processInstruction(MCInst &Inst,
5794 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5795 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005796 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5797 case ARM::ADDri: {
5798 if (Inst.getOperand(1).getReg() != ARM::PC ||
5799 Inst.getOperand(5).getReg() != 0)
5800 return false;
5801 MCInst TmpInst;
5802 TmpInst.setOpcode(ARM::ADR);
5803 TmpInst.addOperand(Inst.getOperand(0));
5804 TmpInst.addOperand(Inst.getOperand(2));
5805 TmpInst.addOperand(Inst.getOperand(3));
5806 TmpInst.addOperand(Inst.getOperand(4));
5807 Inst = TmpInst;
5808 return true;
5809 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005810 // Aliases for alternate PC+imm syntax of LDR instructions.
5811 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005812 // Select the narrow version if the immediate will fit.
5813 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005814 Inst.getOperand(1).getImm() <= 0xff &&
5815 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5816 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005817 Inst.setOpcode(ARM::tLDRpci);
5818 else
5819 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005820 return true;
5821 case ARM::t2LDRBpcrel:
5822 Inst.setOpcode(ARM::t2LDRBpci);
5823 return true;
5824 case ARM::t2LDRHpcrel:
5825 Inst.setOpcode(ARM::t2LDRHpci);
5826 return true;
5827 case ARM::t2LDRSBpcrel:
5828 Inst.setOpcode(ARM::t2LDRSBpci);
5829 return true;
5830 case ARM::t2LDRSHpcrel:
5831 Inst.setOpcode(ARM::t2LDRSHpci);
5832 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005833 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005834 case ARM::VST1LNdWB_register_Asm_8:
5835 case ARM::VST1LNdWB_register_Asm_16:
5836 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005837 MCInst TmpInst;
5838 // Shuffle the operands around so the lane index operand is in the
5839 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005840 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005841 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005842 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5843 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5844 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5845 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5846 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5847 TmpInst.addOperand(Inst.getOperand(1)); // lane
5848 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5849 TmpInst.addOperand(Inst.getOperand(6));
5850 Inst = TmpInst;
5851 return true;
5852 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005853
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005854 case ARM::VST2LNdWB_register_Asm_8:
5855 case ARM::VST2LNdWB_register_Asm_16:
5856 case ARM::VST2LNdWB_register_Asm_32:
5857 case ARM::VST2LNqWB_register_Asm_16:
5858 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005859 MCInst TmpInst;
5860 // Shuffle the operands around so the lane index operand is in the
5861 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005862 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005863 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005864 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5865 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5866 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5867 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5868 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005869 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5870 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005871 TmpInst.addOperand(Inst.getOperand(1)); // lane
5872 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5873 TmpInst.addOperand(Inst.getOperand(6));
5874 Inst = TmpInst;
5875 return true;
5876 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005877
5878 case ARM::VST3LNdWB_register_Asm_8:
5879 case ARM::VST3LNdWB_register_Asm_16:
5880 case ARM::VST3LNdWB_register_Asm_32:
5881 case ARM::VST3LNqWB_register_Asm_16:
5882 case ARM::VST3LNqWB_register_Asm_32: {
5883 MCInst TmpInst;
5884 // Shuffle the operands around so the lane index operand is in the
5885 // right place.
5886 unsigned Spacing;
5887 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5888 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5889 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5890 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5891 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5892 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5893 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5894 Spacing));
5895 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5896 Spacing * 2));
5897 TmpInst.addOperand(Inst.getOperand(1)); // lane
5898 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5899 TmpInst.addOperand(Inst.getOperand(6));
5900 Inst = TmpInst;
5901 return true;
5902 }
5903
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005904 case ARM::VST4LNdWB_register_Asm_8:
5905 case ARM::VST4LNdWB_register_Asm_16:
5906 case ARM::VST4LNdWB_register_Asm_32:
5907 case ARM::VST4LNqWB_register_Asm_16:
5908 case ARM::VST4LNqWB_register_Asm_32: {
5909 MCInst TmpInst;
5910 // Shuffle the operands around so the lane index operand is in the
5911 // right place.
5912 unsigned Spacing;
5913 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5914 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5915 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5916 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5917 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5918 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5919 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5920 Spacing));
5921 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5922 Spacing * 2));
5923 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5924 Spacing * 3));
5925 TmpInst.addOperand(Inst.getOperand(1)); // lane
5926 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5927 TmpInst.addOperand(Inst.getOperand(6));
5928 Inst = TmpInst;
5929 return true;
5930 }
5931
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005932 case ARM::VST1LNdWB_fixed_Asm_8:
5933 case ARM::VST1LNdWB_fixed_Asm_16:
5934 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005935 MCInst TmpInst;
5936 // Shuffle the operands around so the lane index operand is in the
5937 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005938 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005939 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005940 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5941 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5942 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5943 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5944 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5945 TmpInst.addOperand(Inst.getOperand(1)); // lane
5946 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5947 TmpInst.addOperand(Inst.getOperand(5));
5948 Inst = TmpInst;
5949 return true;
5950 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005951
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005952 case ARM::VST2LNdWB_fixed_Asm_8:
5953 case ARM::VST2LNdWB_fixed_Asm_16:
5954 case ARM::VST2LNdWB_fixed_Asm_32:
5955 case ARM::VST2LNqWB_fixed_Asm_16:
5956 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005957 MCInst TmpInst;
5958 // Shuffle the operands around so the lane index operand is in the
5959 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005960 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005961 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005962 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5963 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5964 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5965 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5966 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005967 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5968 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005969 TmpInst.addOperand(Inst.getOperand(1)); // lane
5970 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5971 TmpInst.addOperand(Inst.getOperand(5));
5972 Inst = TmpInst;
5973 return true;
5974 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005975
5976 case ARM::VST3LNdWB_fixed_Asm_8:
5977 case ARM::VST3LNdWB_fixed_Asm_16:
5978 case ARM::VST3LNdWB_fixed_Asm_32:
5979 case ARM::VST3LNqWB_fixed_Asm_16:
5980 case ARM::VST3LNqWB_fixed_Asm_32: {
5981 MCInst TmpInst;
5982 // Shuffle the operands around so the lane index operand is in the
5983 // right place.
5984 unsigned Spacing;
5985 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5986 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5987 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5988 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5989 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5990 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5991 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5992 Spacing));
5993 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5994 Spacing * 2));
5995 TmpInst.addOperand(Inst.getOperand(1)); // lane
5996 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5997 TmpInst.addOperand(Inst.getOperand(5));
5998 Inst = TmpInst;
5999 return true;
6000 }
6001
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006002 case ARM::VST4LNdWB_fixed_Asm_8:
6003 case ARM::VST4LNdWB_fixed_Asm_16:
6004 case ARM::VST4LNdWB_fixed_Asm_32:
6005 case ARM::VST4LNqWB_fixed_Asm_16:
6006 case ARM::VST4LNqWB_fixed_Asm_32: {
6007 MCInst TmpInst;
6008 // Shuffle the operands around so the lane index operand is in the
6009 // right place.
6010 unsigned Spacing;
6011 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6012 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6013 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6014 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6015 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6016 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6017 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6018 Spacing));
6019 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6020 Spacing * 2));
6021 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6022 Spacing * 3));
6023 TmpInst.addOperand(Inst.getOperand(1)); // lane
6024 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6025 TmpInst.addOperand(Inst.getOperand(5));
6026 Inst = TmpInst;
6027 return true;
6028 }
6029
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006030 case ARM::VST1LNdAsm_8:
6031 case ARM::VST1LNdAsm_16:
6032 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006033 MCInst TmpInst;
6034 // Shuffle the operands around so the lane index operand is in the
6035 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006036 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006037 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006038 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6039 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6040 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6041 TmpInst.addOperand(Inst.getOperand(1)); // lane
6042 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6043 TmpInst.addOperand(Inst.getOperand(5));
6044 Inst = TmpInst;
6045 return true;
6046 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006047
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006048 case ARM::VST2LNdAsm_8:
6049 case ARM::VST2LNdAsm_16:
6050 case ARM::VST2LNdAsm_32:
6051 case ARM::VST2LNqAsm_16:
6052 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006053 MCInst TmpInst;
6054 // Shuffle the operands around so the lane index operand is in the
6055 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006056 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006057 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006058 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6059 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6060 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006061 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6062 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006063 TmpInst.addOperand(Inst.getOperand(1)); // lane
6064 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6065 TmpInst.addOperand(Inst.getOperand(5));
6066 Inst = TmpInst;
6067 return true;
6068 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006069
6070 case ARM::VST3LNdAsm_8:
6071 case ARM::VST3LNdAsm_16:
6072 case ARM::VST3LNdAsm_32:
6073 case ARM::VST3LNqAsm_16:
6074 case ARM::VST3LNqAsm_32: {
6075 MCInst TmpInst;
6076 // Shuffle the operands around so the lane index operand is in the
6077 // right place.
6078 unsigned Spacing;
6079 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6080 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6081 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6082 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6083 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6084 Spacing));
6085 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6086 Spacing * 2));
6087 TmpInst.addOperand(Inst.getOperand(1)); // lane
6088 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6089 TmpInst.addOperand(Inst.getOperand(5));
6090 Inst = TmpInst;
6091 return true;
6092 }
6093
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006094 case ARM::VST4LNdAsm_8:
6095 case ARM::VST4LNdAsm_16:
6096 case ARM::VST4LNdAsm_32:
6097 case ARM::VST4LNqAsm_16:
6098 case ARM::VST4LNqAsm_32: {
6099 MCInst TmpInst;
6100 // Shuffle the operands around so the lane index operand is in the
6101 // right place.
6102 unsigned Spacing;
6103 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6104 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6105 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6106 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6107 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6108 Spacing));
6109 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6110 Spacing * 2));
6111 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6112 Spacing * 3));
6113 TmpInst.addOperand(Inst.getOperand(1)); // lane
6114 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6115 TmpInst.addOperand(Inst.getOperand(5));
6116 Inst = TmpInst;
6117 return true;
6118 }
6119
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006120 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006121 case ARM::VLD1LNdWB_register_Asm_8:
6122 case ARM::VLD1LNdWB_register_Asm_16:
6123 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006124 MCInst TmpInst;
6125 // Shuffle the operands around so the lane index operand is in the
6126 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006127 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006128 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006129 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6130 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6131 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6132 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6133 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6134 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6135 TmpInst.addOperand(Inst.getOperand(1)); // lane
6136 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6137 TmpInst.addOperand(Inst.getOperand(6));
6138 Inst = TmpInst;
6139 return true;
6140 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006141
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006142 case ARM::VLD2LNdWB_register_Asm_8:
6143 case ARM::VLD2LNdWB_register_Asm_16:
6144 case ARM::VLD2LNdWB_register_Asm_32:
6145 case ARM::VLD2LNqWB_register_Asm_16:
6146 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006147 MCInst TmpInst;
6148 // Shuffle the operands around so the lane index operand is in the
6149 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006150 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006151 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006152 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006153 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6154 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006155 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6156 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6157 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6158 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6159 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006160 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6161 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006162 TmpInst.addOperand(Inst.getOperand(1)); // lane
6163 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6164 TmpInst.addOperand(Inst.getOperand(6));
6165 Inst = TmpInst;
6166 return true;
6167 }
6168
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006169 case ARM::VLD3LNdWB_register_Asm_8:
6170 case ARM::VLD3LNdWB_register_Asm_16:
6171 case ARM::VLD3LNdWB_register_Asm_32:
6172 case ARM::VLD3LNqWB_register_Asm_16:
6173 case ARM::VLD3LNqWB_register_Asm_32: {
6174 MCInst TmpInst;
6175 // Shuffle the operands around so the lane index operand is in the
6176 // right place.
6177 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006178 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006179 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6180 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6181 Spacing));
6182 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006183 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +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)
6189 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6190 Spacing));
6191 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006192 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006193 TmpInst.addOperand(Inst.getOperand(1)); // lane
6194 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6195 TmpInst.addOperand(Inst.getOperand(6));
6196 Inst = TmpInst;
6197 return true;
6198 }
6199
Jim Grosbach14952a02012-01-24 18:37:25 +00006200 case ARM::VLD4LNdWB_register_Asm_8:
6201 case ARM::VLD4LNdWB_register_Asm_16:
6202 case ARM::VLD4LNdWB_register_Asm_32:
6203 case ARM::VLD4LNqWB_register_Asm_16:
6204 case ARM::VLD4LNqWB_register_Asm_32: {
6205 MCInst TmpInst;
6206 // Shuffle the operands around so the lane index operand is in the
6207 // right place.
6208 unsigned Spacing;
6209 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6210 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6211 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6212 Spacing));
6213 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6214 Spacing * 2));
6215 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6216 Spacing * 3));
6217 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6218 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6219 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6220 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6221 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6222 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6223 Spacing));
6224 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6225 Spacing * 2));
6226 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6227 Spacing * 3));
6228 TmpInst.addOperand(Inst.getOperand(1)); // lane
6229 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6230 TmpInst.addOperand(Inst.getOperand(6));
6231 Inst = TmpInst;
6232 return true;
6233 }
6234
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006235 case ARM::VLD1LNdWB_fixed_Asm_8:
6236 case ARM::VLD1LNdWB_fixed_Asm_16:
6237 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006238 MCInst TmpInst;
6239 // Shuffle the operands around so the lane index operand is in the
6240 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006241 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006242 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006243 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6244 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6245 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6246 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6247 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6248 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6249 TmpInst.addOperand(Inst.getOperand(1)); // lane
6250 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6251 TmpInst.addOperand(Inst.getOperand(5));
6252 Inst = TmpInst;
6253 return true;
6254 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006255
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006256 case ARM::VLD2LNdWB_fixed_Asm_8:
6257 case ARM::VLD2LNdWB_fixed_Asm_16:
6258 case ARM::VLD2LNdWB_fixed_Asm_32:
6259 case ARM::VLD2LNqWB_fixed_Asm_16:
6260 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006261 MCInst TmpInst;
6262 // Shuffle the operands around so the lane index operand is in the
6263 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006264 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006265 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006266 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006267 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6268 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006269 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6270 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6271 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6272 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6273 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006274 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6275 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006276 TmpInst.addOperand(Inst.getOperand(1)); // lane
6277 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6278 TmpInst.addOperand(Inst.getOperand(5));
6279 Inst = TmpInst;
6280 return true;
6281 }
6282
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006283 case ARM::VLD3LNdWB_fixed_Asm_8:
6284 case ARM::VLD3LNdWB_fixed_Asm_16:
6285 case ARM::VLD3LNdWB_fixed_Asm_32:
6286 case ARM::VLD3LNqWB_fixed_Asm_16:
6287 case ARM::VLD3LNqWB_fixed_Asm_32: {
6288 MCInst TmpInst;
6289 // Shuffle the operands around so the lane index operand is in the
6290 // right place.
6291 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006292 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006293 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6294 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6295 Spacing));
6296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006297 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +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)
6303 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6304 Spacing));
6305 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006306 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006307 TmpInst.addOperand(Inst.getOperand(1)); // lane
6308 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6309 TmpInst.addOperand(Inst.getOperand(5));
6310 Inst = TmpInst;
6311 return true;
6312 }
6313
Jim Grosbach14952a02012-01-24 18:37:25 +00006314 case ARM::VLD4LNdWB_fixed_Asm_8:
6315 case ARM::VLD4LNdWB_fixed_Asm_16:
6316 case ARM::VLD4LNdWB_fixed_Asm_32:
6317 case ARM::VLD4LNqWB_fixed_Asm_16:
6318 case ARM::VLD4LNqWB_fixed_Asm_32: {
6319 MCInst TmpInst;
6320 // Shuffle the operands around so the lane index operand is in the
6321 // right place.
6322 unsigned Spacing;
6323 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6324 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6325 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6326 Spacing));
6327 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6328 Spacing * 2));
6329 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6330 Spacing * 3));
6331 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6332 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6333 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6334 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6335 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6336 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6337 Spacing));
6338 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6339 Spacing * 2));
6340 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6341 Spacing * 3));
6342 TmpInst.addOperand(Inst.getOperand(1)); // lane
6343 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6344 TmpInst.addOperand(Inst.getOperand(5));
6345 Inst = TmpInst;
6346 return true;
6347 }
6348
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006349 case ARM::VLD1LNdAsm_8:
6350 case ARM::VLD1LNdAsm_16:
6351 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006352 MCInst TmpInst;
6353 // Shuffle the operands around so the lane index operand is in the
6354 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006355 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006356 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006357 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6358 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6359 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6360 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6361 TmpInst.addOperand(Inst.getOperand(1)); // lane
6362 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6363 TmpInst.addOperand(Inst.getOperand(5));
6364 Inst = TmpInst;
6365 return true;
6366 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006367
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006368 case ARM::VLD2LNdAsm_8:
6369 case ARM::VLD2LNdAsm_16:
6370 case ARM::VLD2LNdAsm_32:
6371 case ARM::VLD2LNqAsm_16:
6372 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006373 MCInst TmpInst;
6374 // Shuffle the operands around so the lane index operand is in the
6375 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006376 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006377 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006378 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006379 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6380 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006381 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6382 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6383 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006384 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6385 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006386 TmpInst.addOperand(Inst.getOperand(1)); // lane
6387 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6388 TmpInst.addOperand(Inst.getOperand(5));
6389 Inst = TmpInst;
6390 return true;
6391 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006392
6393 case ARM::VLD3LNdAsm_8:
6394 case ARM::VLD3LNdAsm_16:
6395 case ARM::VLD3LNdAsm_32:
6396 case ARM::VLD3LNqAsm_16:
6397 case ARM::VLD3LNqAsm_32: {
6398 MCInst TmpInst;
6399 // Shuffle the operands around so the lane index operand is in the
6400 // right place.
6401 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006402 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006403 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6405 Spacing));
6406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006407 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006408 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6409 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6410 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6411 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6412 Spacing));
6413 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006414 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +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 }
6421
Jim Grosbach14952a02012-01-24 18:37:25 +00006422 case ARM::VLD4LNdAsm_8:
6423 case ARM::VLD4LNdAsm_16:
6424 case ARM::VLD4LNdAsm_32:
6425 case ARM::VLD4LNqAsm_16:
6426 case ARM::VLD4LNqAsm_32: {
6427 MCInst TmpInst;
6428 // Shuffle the operands around so the lane index operand is in the
6429 // right place.
6430 unsigned Spacing;
6431 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6432 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() +
6436 Spacing * 2));
6437 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6438 Spacing * 3));
6439 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6440 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6441 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6442 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6443 Spacing));
6444 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6445 Spacing * 2));
6446 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6447 Spacing * 3));
6448 TmpInst.addOperand(Inst.getOperand(1)); // lane
6449 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6450 TmpInst.addOperand(Inst.getOperand(5));
6451 Inst = TmpInst;
6452 return true;
6453 }
6454
Jim Grosbachb78403c2012-01-24 23:47:04 +00006455 // VLD3DUP single 3-element structure to all lanes instructions.
6456 case ARM::VLD3DUPdAsm_8:
6457 case ARM::VLD3DUPdAsm_16:
6458 case ARM::VLD3DUPdAsm_32:
6459 case ARM::VLD3DUPqAsm_8:
6460 case ARM::VLD3DUPqAsm_16:
6461 case ARM::VLD3DUPqAsm_32: {
6462 MCInst TmpInst;
6463 unsigned Spacing;
6464 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6465 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6466 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6467 Spacing));
6468 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6469 Spacing * 2));
6470 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6471 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6472 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6473 TmpInst.addOperand(Inst.getOperand(4));
6474 Inst = TmpInst;
6475 return true;
6476 }
6477
6478 case ARM::VLD3DUPdWB_fixed_Asm_8:
6479 case ARM::VLD3DUPdWB_fixed_Asm_16:
6480 case ARM::VLD3DUPdWB_fixed_Asm_32:
6481 case ARM::VLD3DUPqWB_fixed_Asm_8:
6482 case ARM::VLD3DUPqWB_fixed_Asm_16:
6483 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6484 MCInst TmpInst;
6485 unsigned Spacing;
6486 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6487 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6488 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6489 Spacing));
6490 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6491 Spacing * 2));
6492 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6493 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6494 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6495 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6496 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6497 TmpInst.addOperand(Inst.getOperand(4));
6498 Inst = TmpInst;
6499 return true;
6500 }
6501
6502 case ARM::VLD3DUPdWB_register_Asm_8:
6503 case ARM::VLD3DUPdWB_register_Asm_16:
6504 case ARM::VLD3DUPdWB_register_Asm_32:
6505 case ARM::VLD3DUPqWB_register_Asm_8:
6506 case ARM::VLD3DUPqWB_register_Asm_16:
6507 case ARM::VLD3DUPqWB_register_Asm_32: {
6508 MCInst TmpInst;
6509 unsigned Spacing;
6510 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6511 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6512 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6513 Spacing));
6514 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6515 Spacing * 2));
6516 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6517 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6518 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6519 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6520 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6521 TmpInst.addOperand(Inst.getOperand(5));
6522 Inst = TmpInst;
6523 return true;
6524 }
6525
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006526 // VLD3 multiple 3-element structure instructions.
6527 case ARM::VLD3dAsm_8:
6528 case ARM::VLD3dAsm_16:
6529 case ARM::VLD3dAsm_32:
6530 case ARM::VLD3qAsm_8:
6531 case ARM::VLD3qAsm_16:
6532 case ARM::VLD3qAsm_32: {
6533 MCInst TmpInst;
6534 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006535 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006536 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6537 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6538 Spacing));
6539 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6540 Spacing * 2));
6541 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6542 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6543 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6544 TmpInst.addOperand(Inst.getOperand(4));
6545 Inst = TmpInst;
6546 return true;
6547 }
6548
6549 case ARM::VLD3dWB_fixed_Asm_8:
6550 case ARM::VLD3dWB_fixed_Asm_16:
6551 case ARM::VLD3dWB_fixed_Asm_32:
6552 case ARM::VLD3qWB_fixed_Asm_8:
6553 case ARM::VLD3qWB_fixed_Asm_16:
6554 case ARM::VLD3qWB_fixed_Asm_32: {
6555 MCInst TmpInst;
6556 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006557 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006558 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6559 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6560 Spacing));
6561 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6562 Spacing * 2));
6563 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6564 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6565 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6566 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6567 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6568 TmpInst.addOperand(Inst.getOperand(4));
6569 Inst = TmpInst;
6570 return true;
6571 }
6572
6573 case ARM::VLD3dWB_register_Asm_8:
6574 case ARM::VLD3dWB_register_Asm_16:
6575 case ARM::VLD3dWB_register_Asm_32:
6576 case ARM::VLD3qWB_register_Asm_8:
6577 case ARM::VLD3qWB_register_Asm_16:
6578 case ARM::VLD3qWB_register_Asm_32: {
6579 MCInst TmpInst;
6580 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006581 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006582 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6583 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6584 Spacing));
6585 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6586 Spacing * 2));
6587 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6588 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6589 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6590 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6591 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6592 TmpInst.addOperand(Inst.getOperand(5));
6593 Inst = TmpInst;
6594 return true;
6595 }
6596
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006597 // VLD4DUP single 3-element structure to all lanes instructions.
6598 case ARM::VLD4DUPdAsm_8:
6599 case ARM::VLD4DUPdAsm_16:
6600 case ARM::VLD4DUPdAsm_32:
6601 case ARM::VLD4DUPqAsm_8:
6602 case ARM::VLD4DUPqAsm_16:
6603 case ARM::VLD4DUPqAsm_32: {
6604 MCInst TmpInst;
6605 unsigned Spacing;
6606 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6607 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6608 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6609 Spacing));
6610 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6611 Spacing * 2));
6612 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6613 Spacing * 3));
6614 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6615 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6616 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6617 TmpInst.addOperand(Inst.getOperand(4));
6618 Inst = TmpInst;
6619 return true;
6620 }
6621
6622 case ARM::VLD4DUPdWB_fixed_Asm_8:
6623 case ARM::VLD4DUPdWB_fixed_Asm_16:
6624 case ARM::VLD4DUPdWB_fixed_Asm_32:
6625 case ARM::VLD4DUPqWB_fixed_Asm_8:
6626 case ARM::VLD4DUPqWB_fixed_Asm_16:
6627 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6628 MCInst TmpInst;
6629 unsigned Spacing;
6630 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6631 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6632 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6633 Spacing));
6634 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6635 Spacing * 2));
6636 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6637 Spacing * 3));
6638 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6639 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6640 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6641 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6642 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6643 TmpInst.addOperand(Inst.getOperand(4));
6644 Inst = TmpInst;
6645 return true;
6646 }
6647
6648 case ARM::VLD4DUPdWB_register_Asm_8:
6649 case ARM::VLD4DUPdWB_register_Asm_16:
6650 case ARM::VLD4DUPdWB_register_Asm_32:
6651 case ARM::VLD4DUPqWB_register_Asm_8:
6652 case ARM::VLD4DUPqWB_register_Asm_16:
6653 case ARM::VLD4DUPqWB_register_Asm_32: {
6654 MCInst TmpInst;
6655 unsigned Spacing;
6656 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6657 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6658 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6659 Spacing));
6660 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6661 Spacing * 2));
6662 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6663 Spacing * 3));
6664 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6665 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6666 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6667 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6668 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6669 TmpInst.addOperand(Inst.getOperand(5));
6670 Inst = TmpInst;
6671 return true;
6672 }
6673
6674 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006675 case ARM::VLD4dAsm_8:
6676 case ARM::VLD4dAsm_16:
6677 case ARM::VLD4dAsm_32:
6678 case ARM::VLD4qAsm_8:
6679 case ARM::VLD4qAsm_16:
6680 case ARM::VLD4qAsm_32: {
6681 MCInst TmpInst;
6682 unsigned Spacing;
6683 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6684 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6685 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6686 Spacing));
6687 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6688 Spacing * 2));
6689 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6690 Spacing * 3));
6691 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6692 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6693 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6694 TmpInst.addOperand(Inst.getOperand(4));
6695 Inst = TmpInst;
6696 return true;
6697 }
6698
6699 case ARM::VLD4dWB_fixed_Asm_8:
6700 case ARM::VLD4dWB_fixed_Asm_16:
6701 case ARM::VLD4dWB_fixed_Asm_32:
6702 case ARM::VLD4qWB_fixed_Asm_8:
6703 case ARM::VLD4qWB_fixed_Asm_16:
6704 case ARM::VLD4qWB_fixed_Asm_32: {
6705 MCInst TmpInst;
6706 unsigned Spacing;
6707 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6708 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6709 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6710 Spacing));
6711 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6712 Spacing * 2));
6713 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6714 Spacing * 3));
6715 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6716 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6717 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6718 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6719 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6720 TmpInst.addOperand(Inst.getOperand(4));
6721 Inst = TmpInst;
6722 return true;
6723 }
6724
6725 case ARM::VLD4dWB_register_Asm_8:
6726 case ARM::VLD4dWB_register_Asm_16:
6727 case ARM::VLD4dWB_register_Asm_32:
6728 case ARM::VLD4qWB_register_Asm_8:
6729 case ARM::VLD4qWB_register_Asm_16:
6730 case ARM::VLD4qWB_register_Asm_32: {
6731 MCInst TmpInst;
6732 unsigned Spacing;
6733 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6734 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6735 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6736 Spacing));
6737 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6738 Spacing * 2));
6739 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6740 Spacing * 3));
6741 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6742 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6743 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6744 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6745 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6746 TmpInst.addOperand(Inst.getOperand(5));
6747 Inst = TmpInst;
6748 return true;
6749 }
6750
Jim Grosbach1a747242012-01-23 23:45:44 +00006751 // VST3 multiple 3-element structure instructions.
6752 case ARM::VST3dAsm_8:
6753 case ARM::VST3dAsm_16:
6754 case ARM::VST3dAsm_32:
6755 case ARM::VST3qAsm_8:
6756 case ARM::VST3qAsm_16:
6757 case ARM::VST3qAsm_32: {
6758 MCInst TmpInst;
6759 unsigned Spacing;
6760 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6761 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6762 TmpInst.addOperand(Inst.getOperand(2)); // alignment
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(Inst.getOperand(3)); // CondCode
6769 TmpInst.addOperand(Inst.getOperand(4));
6770 Inst = TmpInst;
6771 return true;
6772 }
6773
6774 case ARM::VST3dWB_fixed_Asm_8:
6775 case ARM::VST3dWB_fixed_Asm_16:
6776 case ARM::VST3dWB_fixed_Asm_32:
6777 case ARM::VST3qWB_fixed_Asm_8:
6778 case ARM::VST3qWB_fixed_Asm_16:
6779 case ARM::VST3qWB_fixed_Asm_32: {
6780 MCInst TmpInst;
6781 unsigned Spacing;
6782 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6783 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6784 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6785 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6786 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6787 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6788 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6789 Spacing));
6790 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6791 Spacing * 2));
6792 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6793 TmpInst.addOperand(Inst.getOperand(4));
6794 Inst = TmpInst;
6795 return true;
6796 }
6797
6798 case ARM::VST3dWB_register_Asm_8:
6799 case ARM::VST3dWB_register_Asm_16:
6800 case ARM::VST3dWB_register_Asm_32:
6801 case ARM::VST3qWB_register_Asm_8:
6802 case ARM::VST3qWB_register_Asm_16:
6803 case ARM::VST3qWB_register_Asm_32: {
6804 MCInst TmpInst;
6805 unsigned Spacing;
6806 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6807 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6808 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6809 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6810 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6811 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6812 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6813 Spacing));
6814 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6815 Spacing * 2));
6816 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6817 TmpInst.addOperand(Inst.getOperand(5));
6818 Inst = TmpInst;
6819 return true;
6820 }
6821
Jim Grosbachda70eac2012-01-24 00:58:13 +00006822 // VST4 multiple 3-element structure instructions.
6823 case ARM::VST4dAsm_8:
6824 case ARM::VST4dAsm_16:
6825 case ARM::VST4dAsm_32:
6826 case ARM::VST4qAsm_8:
6827 case ARM::VST4qAsm_16:
6828 case ARM::VST4qAsm_32: {
6829 MCInst TmpInst;
6830 unsigned Spacing;
6831 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6832 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6833 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6834 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6835 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6836 Spacing));
6837 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6838 Spacing * 2));
6839 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6840 Spacing * 3));
6841 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6842 TmpInst.addOperand(Inst.getOperand(4));
6843 Inst = TmpInst;
6844 return true;
6845 }
6846
6847 case ARM::VST4dWB_fixed_Asm_8:
6848 case ARM::VST4dWB_fixed_Asm_16:
6849 case ARM::VST4dWB_fixed_Asm_32:
6850 case ARM::VST4qWB_fixed_Asm_8:
6851 case ARM::VST4qWB_fixed_Asm_16:
6852 case ARM::VST4qWB_fixed_Asm_32: {
6853 MCInst TmpInst;
6854 unsigned Spacing;
6855 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6856 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6857 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6858 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6859 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6860 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6861 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6862 Spacing));
6863 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6864 Spacing * 2));
6865 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6866 Spacing * 3));
6867 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6868 TmpInst.addOperand(Inst.getOperand(4));
6869 Inst = TmpInst;
6870 return true;
6871 }
6872
6873 case ARM::VST4dWB_register_Asm_8:
6874 case ARM::VST4dWB_register_Asm_16:
6875 case ARM::VST4dWB_register_Asm_32:
6876 case ARM::VST4qWB_register_Asm_8:
6877 case ARM::VST4qWB_register_Asm_16:
6878 case ARM::VST4qWB_register_Asm_32: {
6879 MCInst TmpInst;
6880 unsigned Spacing;
6881 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6882 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6883 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6884 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6885 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6886 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6887 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6888 Spacing));
6889 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6890 Spacing * 2));
6891 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6892 Spacing * 3));
6893 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6894 TmpInst.addOperand(Inst.getOperand(5));
6895 Inst = TmpInst;
6896 return true;
6897 }
6898
Jim Grosbachad66de12012-04-11 00:15:16 +00006899 // Handle encoding choice for the shift-immediate instructions.
6900 case ARM::t2LSLri:
6901 case ARM::t2LSRri:
6902 case ARM::t2ASRri: {
6903 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6904 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6905 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6906 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6907 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6908 unsigned NewOpc;
6909 switch (Inst.getOpcode()) {
6910 default: llvm_unreachable("unexpected opcode");
6911 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6912 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6913 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6914 }
6915 // The Thumb1 operands aren't in the same order. Awesome, eh?
6916 MCInst TmpInst;
6917 TmpInst.setOpcode(NewOpc);
6918 TmpInst.addOperand(Inst.getOperand(0));
6919 TmpInst.addOperand(Inst.getOperand(5));
6920 TmpInst.addOperand(Inst.getOperand(1));
6921 TmpInst.addOperand(Inst.getOperand(2));
6922 TmpInst.addOperand(Inst.getOperand(3));
6923 TmpInst.addOperand(Inst.getOperand(4));
6924 Inst = TmpInst;
6925 return true;
6926 }
6927 return false;
6928 }
6929
Jim Grosbach485e5622011-12-13 22:45:11 +00006930 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006931 case ARM::t2MOVsr:
6932 case ARM::t2MOVSsr: {
6933 // Which instruction to expand to depends on the CCOut operand and
6934 // whether we're in an IT block if the register operands are low
6935 // registers.
6936 bool isNarrow = false;
6937 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6938 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6939 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6940 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6941 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6942 isNarrow = true;
6943 MCInst TmpInst;
6944 unsigned newOpc;
6945 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6946 default: llvm_unreachable("unexpected opcode!");
6947 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6948 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6949 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6950 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6951 }
6952 TmpInst.setOpcode(newOpc);
6953 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6954 if (isNarrow)
6955 TmpInst.addOperand(MCOperand::CreateReg(
6956 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6957 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6958 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6959 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6960 TmpInst.addOperand(Inst.getOperand(5));
6961 if (!isNarrow)
6962 TmpInst.addOperand(MCOperand::CreateReg(
6963 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6964 Inst = TmpInst;
6965 return true;
6966 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006967 case ARM::t2MOVsi:
6968 case ARM::t2MOVSsi: {
6969 // Which instruction to expand to depends on the CCOut operand and
6970 // whether we're in an IT block if the register operands are low
6971 // registers.
6972 bool isNarrow = false;
6973 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6974 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6975 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6976 isNarrow = true;
6977 MCInst TmpInst;
6978 unsigned newOpc;
6979 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6980 default: llvm_unreachable("unexpected opcode!");
6981 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6982 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6983 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6984 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006985 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006986 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006987 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6988 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006989 TmpInst.setOpcode(newOpc);
6990 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6991 if (isNarrow)
6992 TmpInst.addOperand(MCOperand::CreateReg(
6993 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6994 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006995 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006996 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006997 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6998 TmpInst.addOperand(Inst.getOperand(4));
6999 if (!isNarrow)
7000 TmpInst.addOperand(MCOperand::CreateReg(
7001 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7002 Inst = TmpInst;
7003 return true;
7004 }
7005 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007006 case ARM::ASRr:
7007 case ARM::LSRr:
7008 case ARM::LSLr:
7009 case ARM::RORr: {
7010 ARM_AM::ShiftOpc ShiftTy;
7011 switch(Inst.getOpcode()) {
7012 default: llvm_unreachable("unexpected opcode!");
7013 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7014 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7015 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7016 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7017 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007018 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7019 MCInst TmpInst;
7020 TmpInst.setOpcode(ARM::MOVsr);
7021 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7022 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7023 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7024 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7025 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7026 TmpInst.addOperand(Inst.getOperand(4));
7027 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7028 Inst = TmpInst;
7029 return true;
7030 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007031 case ARM::ASRi:
7032 case ARM::LSRi:
7033 case ARM::LSLi:
7034 case ARM::RORi: {
7035 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007036 switch(Inst.getOpcode()) {
7037 default: llvm_unreachable("unexpected opcode!");
7038 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7039 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7040 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7041 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7042 }
7043 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007044 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007045 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007046 // A shift by 32 should be encoded as 0 when permitted
7047 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7048 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007049 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007050 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007051 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007052 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7053 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007054 if (Opc == ARM::MOVsi)
7055 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007056 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7057 TmpInst.addOperand(Inst.getOperand(4));
7058 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7059 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007060 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007061 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007062 case ARM::RRXi: {
7063 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7064 MCInst TmpInst;
7065 TmpInst.setOpcode(ARM::MOVsi);
7066 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7067 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7068 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7069 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7070 TmpInst.addOperand(Inst.getOperand(3));
7071 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7072 Inst = TmpInst;
7073 return true;
7074 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007075 case ARM::t2LDMIA_UPD: {
7076 // If this is a load of a single register, then we should use
7077 // a post-indexed LDR instruction instead, per the ARM ARM.
7078 if (Inst.getNumOperands() != 5)
7079 return false;
7080 MCInst TmpInst;
7081 TmpInst.setOpcode(ARM::t2LDR_POST);
7082 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7083 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7084 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7085 TmpInst.addOperand(MCOperand::CreateImm(4));
7086 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7087 TmpInst.addOperand(Inst.getOperand(3));
7088 Inst = TmpInst;
7089 return true;
7090 }
7091 case ARM::t2STMDB_UPD: {
7092 // If this is a store of a single register, then we should use
7093 // a pre-indexed STR instruction instead, per the ARM ARM.
7094 if (Inst.getNumOperands() != 5)
7095 return false;
7096 MCInst TmpInst;
7097 TmpInst.setOpcode(ARM::t2STR_PRE);
7098 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7099 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7100 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7101 TmpInst.addOperand(MCOperand::CreateImm(-4));
7102 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7103 TmpInst.addOperand(Inst.getOperand(3));
7104 Inst = TmpInst;
7105 return true;
7106 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007107 case ARM::LDMIA_UPD:
7108 // If this is a load of a single register via a 'pop', then we should use
7109 // a post-indexed LDR instruction instead, per the ARM ARM.
7110 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7111 Inst.getNumOperands() == 5) {
7112 MCInst TmpInst;
7113 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7114 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7115 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7116 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7117 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7118 TmpInst.addOperand(MCOperand::CreateImm(4));
7119 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7120 TmpInst.addOperand(Inst.getOperand(3));
7121 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007122 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007123 }
7124 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007125 case ARM::STMDB_UPD:
7126 // If this is a store of a single register via a 'push', then we should use
7127 // a pre-indexed STR instruction instead, per the ARM ARM.
7128 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7129 Inst.getNumOperands() == 5) {
7130 MCInst TmpInst;
7131 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7132 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7133 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7134 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7135 TmpInst.addOperand(MCOperand::CreateImm(-4));
7136 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7137 TmpInst.addOperand(Inst.getOperand(3));
7138 Inst = TmpInst;
7139 }
7140 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007141 case ARM::t2ADDri12:
7142 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7143 // mnemonic was used (not "addw"), encoding T3 is preferred.
7144 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7145 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7146 break;
7147 Inst.setOpcode(ARM::t2ADDri);
7148 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7149 break;
7150 case ARM::t2SUBri12:
7151 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7152 // mnemonic was used (not "subw"), encoding T3 is preferred.
7153 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7154 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7155 break;
7156 Inst.setOpcode(ARM::t2SUBri);
7157 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7158 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007159 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007160 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007161 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7162 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7163 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007164 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007165 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007166 return true;
7167 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007168 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007169 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007170 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007171 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7172 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7173 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007174 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007175 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007176 return true;
7177 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007178 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007179 case ARM::t2ADDri:
7180 case ARM::t2SUBri: {
7181 // If the destination and first source operand are the same, and
7182 // the flags are compatible with the current IT status, use encoding T2
7183 // instead of T3. For compatibility with the system 'as'. Make sure the
7184 // wide encoding wasn't explicit.
7185 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007186 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007187 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7188 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7189 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7190 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7191 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7192 break;
7193 MCInst TmpInst;
7194 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7195 ARM::tADDi8 : ARM::tSUBi8);
7196 TmpInst.addOperand(Inst.getOperand(0));
7197 TmpInst.addOperand(Inst.getOperand(5));
7198 TmpInst.addOperand(Inst.getOperand(0));
7199 TmpInst.addOperand(Inst.getOperand(2));
7200 TmpInst.addOperand(Inst.getOperand(3));
7201 TmpInst.addOperand(Inst.getOperand(4));
7202 Inst = TmpInst;
7203 return true;
7204 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007205 case ARM::t2ADDrr: {
7206 // If the destination and first source operand are the same, and
7207 // there's no setting of the flags, use encoding T2 instead of T3.
7208 // Note that this is only for ADD, not SUB. This mirrors the system
7209 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7210 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7211 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007212 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7213 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007214 break;
7215 MCInst TmpInst;
7216 TmpInst.setOpcode(ARM::tADDhirr);
7217 TmpInst.addOperand(Inst.getOperand(0));
7218 TmpInst.addOperand(Inst.getOperand(0));
7219 TmpInst.addOperand(Inst.getOperand(2));
7220 TmpInst.addOperand(Inst.getOperand(3));
7221 TmpInst.addOperand(Inst.getOperand(4));
7222 Inst = TmpInst;
7223 return true;
7224 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007225 case ARM::tADDrSP: {
7226 // If the non-SP source operand and the destination operand are not the
7227 // same, we need to use the 32-bit encoding if it's available.
7228 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7229 Inst.setOpcode(ARM::t2ADDrr);
7230 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7231 return true;
7232 }
7233 break;
7234 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007235 case ARM::tB:
7236 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007237 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007238 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007239 return true;
7240 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007241 break;
7242 case ARM::t2B:
7243 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007244 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007245 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007246 return true;
7247 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007248 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007249 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007250 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007251 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007252 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007253 return true;
7254 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007255 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007256 case ARM::tBcc:
7257 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007258 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007259 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007260 return true;
7261 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007262 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007263 case ARM::tLDMIA: {
7264 // If the register list contains any high registers, or if the writeback
7265 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7266 // instead if we're in Thumb2. Otherwise, this should have generated
7267 // an error in validateInstruction().
7268 unsigned Rn = Inst.getOperand(0).getReg();
7269 bool hasWritebackToken =
7270 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7271 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7272 bool listContainsBase;
7273 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7274 (!listContainsBase && !hasWritebackToken) ||
7275 (listContainsBase && hasWritebackToken)) {
7276 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7277 assert (isThumbTwo());
7278 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7279 // If we're switching to the updating version, we need to insert
7280 // the writeback tied operand.
7281 if (hasWritebackToken)
7282 Inst.insert(Inst.begin(),
7283 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007284 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007285 }
7286 break;
7287 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007288 case ARM::tSTMIA_UPD: {
7289 // If the register list contains any high registers, we need to use
7290 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7291 // should have generated an error in validateInstruction().
7292 unsigned Rn = Inst.getOperand(0).getReg();
7293 bool listContainsBase;
7294 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7295 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7296 assert (isThumbTwo());
7297 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007298 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007299 }
7300 break;
7301 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007302 case ARM::tPOP: {
7303 bool listContainsBase;
7304 // If the register list contains any high registers, we need to use
7305 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7306 // should have generated an error in validateInstruction().
7307 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007308 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007309 assert (isThumbTwo());
7310 Inst.setOpcode(ARM::t2LDMIA_UPD);
7311 // Add the base register and writeback operands.
7312 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7313 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007314 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007315 }
7316 case ARM::tPUSH: {
7317 bool listContainsBase;
7318 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007319 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007320 assert (isThumbTwo());
7321 Inst.setOpcode(ARM::t2STMDB_UPD);
7322 // Add the base register and writeback operands.
7323 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7324 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007325 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007326 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007327 case ARM::t2MOVi: {
7328 // If we can use the 16-bit encoding and the user didn't explicitly
7329 // request the 32-bit variant, transform it here.
7330 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007331 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007332 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7333 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7334 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007335 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7336 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7337 // The operands aren't in the same order for tMOVi8...
7338 MCInst TmpInst;
7339 TmpInst.setOpcode(ARM::tMOVi8);
7340 TmpInst.addOperand(Inst.getOperand(0));
7341 TmpInst.addOperand(Inst.getOperand(4));
7342 TmpInst.addOperand(Inst.getOperand(1));
7343 TmpInst.addOperand(Inst.getOperand(2));
7344 TmpInst.addOperand(Inst.getOperand(3));
7345 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007346 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007347 }
7348 break;
7349 }
7350 case ARM::t2MOVr: {
7351 // If we can use the 16-bit encoding and the user didn't explicitly
7352 // request the 32-bit variant, transform it here.
7353 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7354 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7355 Inst.getOperand(2).getImm() == ARMCC::AL &&
7356 Inst.getOperand(4).getReg() == ARM::CPSR &&
7357 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7358 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7359 // The operands aren't the same for tMOV[S]r... (no cc_out)
7360 MCInst TmpInst;
7361 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7362 TmpInst.addOperand(Inst.getOperand(0));
7363 TmpInst.addOperand(Inst.getOperand(1));
7364 TmpInst.addOperand(Inst.getOperand(2));
7365 TmpInst.addOperand(Inst.getOperand(3));
7366 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007367 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007368 }
7369 break;
7370 }
Jim Grosbach82213192011-09-19 20:29:33 +00007371 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007372 case ARM::t2SXTB:
7373 case ARM::t2UXTH:
7374 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007375 // If we can use the 16-bit encoding and the user didn't explicitly
7376 // request the 32-bit variant, transform it here.
7377 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7378 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7379 Inst.getOperand(2).getImm() == 0 &&
7380 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7381 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007382 unsigned NewOpc;
7383 switch (Inst.getOpcode()) {
7384 default: llvm_unreachable("Illegal opcode!");
7385 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7386 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7387 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7388 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7389 }
Jim Grosbach82213192011-09-19 20:29:33 +00007390 // The operands aren't the same for thumb1 (no rotate operand).
7391 MCInst TmpInst;
7392 TmpInst.setOpcode(NewOpc);
7393 TmpInst.addOperand(Inst.getOperand(0));
7394 TmpInst.addOperand(Inst.getOperand(1));
7395 TmpInst.addOperand(Inst.getOperand(3));
7396 TmpInst.addOperand(Inst.getOperand(4));
7397 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007398 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007399 }
7400 break;
7401 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007402 case ARM::MOVsi: {
7403 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007404 // rrx shifts and asr/lsr of #32 is encoded as 0
7405 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7406 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007407 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7408 // Shifting by zero is accepted as a vanilla 'MOVr'
7409 MCInst TmpInst;
7410 TmpInst.setOpcode(ARM::MOVr);
7411 TmpInst.addOperand(Inst.getOperand(0));
7412 TmpInst.addOperand(Inst.getOperand(1));
7413 TmpInst.addOperand(Inst.getOperand(3));
7414 TmpInst.addOperand(Inst.getOperand(4));
7415 TmpInst.addOperand(Inst.getOperand(5));
7416 Inst = TmpInst;
7417 return true;
7418 }
7419 return false;
7420 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007421 case ARM::ANDrsi:
7422 case ARM::ORRrsi:
7423 case ARM::EORrsi:
7424 case ARM::BICrsi:
7425 case ARM::SUBrsi:
7426 case ARM::ADDrsi: {
7427 unsigned newOpc;
7428 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7429 if (SOpc == ARM_AM::rrx) return false;
7430 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007431 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007432 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7433 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7434 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7435 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7436 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7437 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7438 }
7439 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007440 // The exception is for right shifts, where 0 == 32
7441 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7442 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007443 MCInst TmpInst;
7444 TmpInst.setOpcode(newOpc);
7445 TmpInst.addOperand(Inst.getOperand(0));
7446 TmpInst.addOperand(Inst.getOperand(1));
7447 TmpInst.addOperand(Inst.getOperand(2));
7448 TmpInst.addOperand(Inst.getOperand(4));
7449 TmpInst.addOperand(Inst.getOperand(5));
7450 TmpInst.addOperand(Inst.getOperand(6));
7451 Inst = TmpInst;
7452 return true;
7453 }
7454 return false;
7455 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007456 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007457 case ARM::t2IT: {
7458 // The mask bits for all but the first condition are represented as
7459 // the low bit of the condition code value implies 't'. We currently
7460 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007461 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007462 MCOperand &MO = Inst.getOperand(1);
7463 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007464 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007465 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007466 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007467 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007468 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007469 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007470 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007471
7472 // Set up the IT block state according to the IT instruction we just
7473 // matched.
7474 assert(!inITBlock() && "nested IT blocks?!");
7475 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7476 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7477 ITState.CurPosition = 0;
7478 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007479 break;
7480 }
Richard Bartona39625e2012-07-09 16:12:24 +00007481 case ARM::t2LSLrr:
7482 case ARM::t2LSRrr:
7483 case ARM::t2ASRrr:
7484 case ARM::t2SBCrr:
7485 case ARM::t2RORrr:
7486 case ARM::t2BICrr:
7487 {
Richard Bartond5660372012-07-09 16:14:28 +00007488 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007489 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7490 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7491 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007492 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7493 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007494 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7495 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7496 unsigned NewOpc;
7497 switch (Inst.getOpcode()) {
7498 default: llvm_unreachable("unexpected opcode");
7499 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7500 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7501 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7502 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7503 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7504 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7505 }
7506 MCInst TmpInst;
7507 TmpInst.setOpcode(NewOpc);
7508 TmpInst.addOperand(Inst.getOperand(0));
7509 TmpInst.addOperand(Inst.getOperand(5));
7510 TmpInst.addOperand(Inst.getOperand(1));
7511 TmpInst.addOperand(Inst.getOperand(2));
7512 TmpInst.addOperand(Inst.getOperand(3));
7513 TmpInst.addOperand(Inst.getOperand(4));
7514 Inst = TmpInst;
7515 return true;
7516 }
7517 return false;
7518 }
7519 case ARM::t2ANDrr:
7520 case ARM::t2EORrr:
7521 case ARM::t2ADCrr:
7522 case ARM::t2ORRrr:
7523 {
Richard Bartond5660372012-07-09 16:14:28 +00007524 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007525 // These instructions are special in that they are commutable, so shorter encodings
7526 // are available more often.
7527 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7528 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7529 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7530 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007531 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7532 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007533 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7534 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7535 unsigned NewOpc;
7536 switch (Inst.getOpcode()) {
7537 default: llvm_unreachable("unexpected opcode");
7538 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7539 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7540 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7541 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7542 }
7543 MCInst TmpInst;
7544 TmpInst.setOpcode(NewOpc);
7545 TmpInst.addOperand(Inst.getOperand(0));
7546 TmpInst.addOperand(Inst.getOperand(5));
7547 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7548 TmpInst.addOperand(Inst.getOperand(1));
7549 TmpInst.addOperand(Inst.getOperand(2));
7550 } else {
7551 TmpInst.addOperand(Inst.getOperand(2));
7552 TmpInst.addOperand(Inst.getOperand(1));
7553 }
7554 TmpInst.addOperand(Inst.getOperand(3));
7555 TmpInst.addOperand(Inst.getOperand(4));
7556 Inst = TmpInst;
7557 return true;
7558 }
7559 return false;
7560 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007561 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007562 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007563}
7564
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007565unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7566 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7567 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007568 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007569 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007570 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7571 assert(MCID.hasOptionalDef() &&
7572 "optionally flag setting instruction missing optional def operand");
7573 assert(MCID.NumOperands == Inst.getNumOperands() &&
7574 "operand count mismatch!");
7575 // Find the optional-def operand (cc_out).
7576 unsigned OpNo;
7577 for (OpNo = 0;
7578 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7579 ++OpNo)
7580 ;
7581 // If we're parsing Thumb1, reject it completely.
7582 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7583 return Match_MnemonicFail;
7584 // If we're parsing Thumb2, which form is legal depends on whether we're
7585 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007586 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7587 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007588 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007589 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7590 inITBlock())
7591 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007592 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007593 // Some high-register supporting Thumb1 encodings only allow both registers
7594 // to be from r0-r7 when in Thumb2.
7595 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7596 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7597 isARMLowRegister(Inst.getOperand(2).getReg()))
7598 return Match_RequiresThumb2;
7599 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007600 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007601 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7602 isARMLowRegister(Inst.getOperand(1).getReg()))
7603 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007604 return Match_Success;
7605}
7606
Jim Grosbach5117ef72012-04-24 22:40:08 +00007607static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007608bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007609MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007610 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007611 MCStreamer &Out, unsigned &ErrorInfo,
7612 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007613 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007614 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007615
Chad Rosier2f480a82012-10-12 22:53:36 +00007616 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007617 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007618 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007619 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007620 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007621 // Context sensitive operand constraints aren't handled by the matcher,
7622 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007623 if (validateInstruction(Inst, Operands)) {
7624 // Still progress the IT block, otherwise one wrong condition causes
7625 // nasty cascading errors.
7626 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007627 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007628 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007629
Amara Emerson52cfb6a2013-10-03 09:31:51 +00007630 { // processInstruction() updates inITBlock state, we need to save it away
7631 bool wasInITBlock = inITBlock();
7632
7633 // Some instructions need post-processing to, for example, tweak which
7634 // encoding is selected. Loop on it while changes happen so the
7635 // individual transformations can chain off each other. E.g.,
7636 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7637 while (processInstruction(Inst, Operands))
7638 ;
7639
7640 // Only after the instruction is fully processed, we can validate it
7641 if (wasInITBlock && hasV8Ops() && isThumb() &&
7642 !isV8EligibleForIT(&Inst, 2)) {
7643 Warning(IDLoc, "deprecated instruction in IT block");
7644 }
7645 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007646
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007647 // Only move forward at the very end so that everything in validate
7648 // and process gets a consistent answer about whether we're in an IT
7649 // block.
7650 forwardITPosition();
7651
Jim Grosbach82f76d12012-01-25 19:52:01 +00007652 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7653 // doesn't actually encode.
7654 if (Inst.getOpcode() == ARM::ITasm)
7655 return false;
7656
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007657 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007658 Out.EmitInstruction(Inst);
7659 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007660 case Match_MissingFeature: {
7661 assert(ErrorInfo && "Unknown missing feature!");
7662 // Special case the error message for the very common case where only
7663 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7664 std::string Msg = "instruction requires:";
7665 unsigned Mask = 1;
7666 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7667 if (ErrorInfo & Mask) {
7668 Msg += " ";
7669 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7670 }
7671 Mask <<= 1;
7672 }
7673 return Error(IDLoc, Msg);
7674 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007675 case Match_InvalidOperand: {
7676 SMLoc ErrorLoc = IDLoc;
7677 if (ErrorInfo != ~0U) {
7678 if (ErrorInfo >= Operands.size())
7679 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007680
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007681 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7682 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7683 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007684
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007685 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007686 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007687 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007688 return Error(IDLoc, "invalid instruction",
7689 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007690 case Match_RequiresNotITBlock:
7691 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007692 case Match_RequiresITBlock:
7693 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007694 case Match_RequiresV6:
7695 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7696 case Match_RequiresThumb2:
7697 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007698 case Match_ImmRange0_15: {
7699 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7700 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7701 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7702 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007703 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007704
Eric Christopher91d7b902010-10-29 09:26:59 +00007705 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007706}
7707
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007708/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007709bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7710 StringRef IDVal = DirectiveID.getIdentifier();
7711 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007712 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007713 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007714 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007715 else if (IDVal == ".arm")
7716 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007717 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007718 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007719 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007720 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007721 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007722 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007723 else if (IDVal == ".unreq")
7724 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007725 else if (IDVal == ".arch")
7726 return parseDirectiveArch(DirectiveID.getLoc());
7727 else if (IDVal == ".eabi_attribute")
7728 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007729 else if (IDVal == ".fnstart")
7730 return parseDirectiveFnStart(DirectiveID.getLoc());
7731 else if (IDVal == ".fnend")
7732 return parseDirectiveFnEnd(DirectiveID.getLoc());
7733 else if (IDVal == ".cantunwind")
7734 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7735 else if (IDVal == ".personality")
7736 return parseDirectivePersonality(DirectiveID.getLoc());
7737 else if (IDVal == ".handlerdata")
7738 return parseDirectiveHandlerData(DirectiveID.getLoc());
7739 else if (IDVal == ".setfp")
7740 return parseDirectiveSetFP(DirectiveID.getLoc());
7741 else if (IDVal == ".pad")
7742 return parseDirectivePad(DirectiveID.getLoc());
7743 else if (IDVal == ".save")
7744 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7745 else if (IDVal == ".vsave")
7746 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007747 return true;
7748}
7749
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007750/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007751/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007752bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007753 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7754 for (;;) {
7755 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007756 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007757 return true;
7758
Eric Christopherbf7bc492013-01-09 03:52:05 +00007759 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007760
7761 if (getLexer().is(AsmToken::EndOfStatement))
7762 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007763
Kevin Enderbyccab3172009-09-15 00:27:25 +00007764 // FIXME: Improve diagnostic.
7765 if (getLexer().isNot(AsmToken::Comma))
7766 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007767 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007768 }
7769 }
7770
Sean Callanana83fd7d2010-01-19 20:27:46 +00007771 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007772 return false;
7773}
7774
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007775/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007776/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007777bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007778 if (getLexer().isNot(AsmToken::EndOfStatement))
7779 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007780 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007781
Tim Northovera2292d02013-06-10 23:20:58 +00007782 if (!hasThumb())
7783 return Error(L, "target does not support Thumb mode");
7784
Jim Grosbach7f882392011-12-07 18:04:19 +00007785 if (!isThumb())
7786 SwitchMode();
7787 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7788 return false;
7789}
7790
7791/// parseDirectiveARM
7792/// ::= .arm
7793bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7794 if (getLexer().isNot(AsmToken::EndOfStatement))
7795 return Error(L, "unexpected token in directive");
7796 Parser.Lex();
7797
Tim Northovera2292d02013-06-10 23:20:58 +00007798 if (!hasARM())
7799 return Error(L, "target does not support ARM mode");
7800
Jim Grosbach7f882392011-12-07 18:04:19 +00007801 if (isThumb())
7802 SwitchMode();
7803 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007804 return false;
7805}
7806
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007807/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007808/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007809bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007810 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7811 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007812 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007813 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007814
Jim Grosbach1152cc02011-12-21 22:30:16 +00007815 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007816 // ELF doesn't
7817 if (isMachO) {
7818 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007819 if (Tok.isNot(AsmToken::EndOfStatement)) {
7820 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7821 return Error(L, "unexpected token in .thumb_func directive");
7822 Name = Tok.getIdentifier();
7823 Parser.Lex(); // Consume the identifier token.
7824 needFuncName = false;
7825 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007826 }
7827
Jim Grosbach1152cc02011-12-21 22:30:16 +00007828 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007829 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007830
7831 // Eat the end of statement and any blank lines that follow.
7832 while (getLexer().is(AsmToken::EndOfStatement))
7833 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007834
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007835 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007836 // We really should be checking the next symbol definition even if there's
7837 // stuff in between.
7838 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007839 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007840 }
7841
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007842 // Mark symbol as a thumb symbol.
7843 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7844 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007845 return false;
7846}
7847
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007848/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007849/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007850bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007851 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007852 if (Tok.isNot(AsmToken::Identifier))
7853 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007854 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007855 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007856 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007857 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007858 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007859 else
7860 return Error(L, "unrecognized syntax mode in .syntax directive");
7861
7862 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007863 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007864 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007865
7866 // TODO tell the MC streamer the mode
7867 // getParser().getStreamer().Emit???();
7868 return false;
7869}
7870
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007871/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007872/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007873bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007874 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007875 if (Tok.isNot(AsmToken::Integer))
7876 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007877 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007878 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007879 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007880 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007881 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007882 else
7883 return Error(L, "invalid operand to .code directive");
7884
7885 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007886 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007887 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007888
Evan Cheng284b4672011-07-08 22:36:29 +00007889 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007890 if (!hasThumb())
7891 return Error(L, "target does not support Thumb mode");
7892
Jim Grosbachf471ac32011-09-06 18:46:23 +00007893 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007894 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007895 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007896 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007897 if (!hasARM())
7898 return Error(L, "target does not support ARM mode");
7899
Jim Grosbachf471ac32011-09-06 18:46:23 +00007900 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007901 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007902 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007903 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007904
Kevin Enderby146dcf22009-10-15 20:48:48 +00007905 return false;
7906}
7907
Jim Grosbachab5830e2011-12-14 02:16:11 +00007908/// parseDirectiveReq
7909/// ::= name .req registername
7910bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7911 Parser.Lex(); // Eat the '.req' token.
7912 unsigned Reg;
7913 SMLoc SRegLoc, ERegLoc;
7914 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007915 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007916 return Error(SRegLoc, "register name expected");
7917 }
7918
7919 // Shouldn't be anything else.
7920 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007921 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007922 return Error(Parser.getTok().getLoc(),
7923 "unexpected input in .req directive.");
7924 }
7925
7926 Parser.Lex(); // Consume the EndOfStatement
7927
7928 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7929 return Error(SRegLoc, "redefinition of '" + Name +
7930 "' does not match original.");
7931
7932 return false;
7933}
7934
7935/// parseDirectiveUneq
7936/// ::= .unreq registername
7937bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7938 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007939 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007940 return Error(L, "unexpected input in .unreq directive.");
7941 }
7942 RegisterReqs.erase(Parser.getTok().getIdentifier());
7943 Parser.Lex(); // Eat the identifier.
7944 return false;
7945}
7946
Jason W Kim135d2442011-12-20 17:38:12 +00007947/// parseDirectiveArch
7948/// ::= .arch token
7949bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7950 return true;
7951}
7952
7953/// parseDirectiveEabiAttr
7954/// ::= .eabi_attribute int, int
7955bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7956 return true;
7957}
7958
Logan Chien4ea23b52013-05-10 16:17:24 +00007959/// parseDirectiveFnStart
7960/// ::= .fnstart
7961bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7962 if (FnStartLoc.isValid()) {
7963 Error(L, ".fnstart starts before the end of previous one");
7964 Error(FnStartLoc, "previous .fnstart starts here");
7965 return true;
7966 }
7967
7968 FnStartLoc = L;
Rafael Espindolaa17151a2013-10-08 13:08:17 +00007969 getTargetStreamer().emitFnStart();
Logan Chien4ea23b52013-05-10 16:17:24 +00007970 return false;
7971}
7972
7973/// parseDirectiveFnEnd
7974/// ::= .fnend
7975bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7976 // Check the ordering of unwind directives
7977 if (!FnStartLoc.isValid())
7978 return Error(L, ".fnstart must precede .fnend directive");
7979
7980 // Reset the unwind directives parser state
7981 resetUnwindDirectiveParserState();
Rafael Espindolaa17151a2013-10-08 13:08:17 +00007982 getTargetStreamer().emitFnEnd();
Logan Chien4ea23b52013-05-10 16:17:24 +00007983 return false;
7984}
7985
7986/// parseDirectiveCantUnwind
7987/// ::= .cantunwind
7988bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7989 // Check the ordering of unwind directives
7990 CantUnwindLoc = L;
7991 if (!FnStartLoc.isValid())
7992 return Error(L, ".fnstart must precede .cantunwind directive");
7993 if (HandlerDataLoc.isValid()) {
7994 Error(L, ".cantunwind can't be used with .handlerdata directive");
7995 Error(HandlerDataLoc, ".handlerdata was specified here");
7996 return true;
7997 }
7998 if (PersonalityLoc.isValid()) {
7999 Error(L, ".cantunwind can't be used with .personality directive");
8000 Error(PersonalityLoc, ".personality was specified here");
8001 return true;
8002 }
8003
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008004 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00008005 return false;
8006}
8007
8008/// parseDirectivePersonality
8009/// ::= .personality name
8010bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8011 // Check the ordering of unwind directives
8012 PersonalityLoc = L;
8013 if (!FnStartLoc.isValid())
8014 return Error(L, ".fnstart must precede .personality directive");
8015 if (CantUnwindLoc.isValid()) {
8016 Error(L, ".personality can't be used with .cantunwind directive");
8017 Error(CantUnwindLoc, ".cantunwind was specified here");
8018 return true;
8019 }
8020 if (HandlerDataLoc.isValid()) {
8021 Error(L, ".personality must precede .handlerdata directive");
8022 Error(HandlerDataLoc, ".handlerdata was specified here");
8023 return true;
8024 }
8025
8026 // Parse the name of the personality routine
8027 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8028 Parser.eatToEndOfStatement();
8029 return Error(L, "unexpected input in .personality directive.");
8030 }
8031 StringRef Name(Parser.getTok().getIdentifier());
8032 Parser.Lex();
8033
8034 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008035 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00008036 return false;
8037}
8038
8039/// parseDirectiveHandlerData
8040/// ::= .handlerdata
8041bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8042 // Check the ordering of unwind directives
8043 HandlerDataLoc = L;
8044 if (!FnStartLoc.isValid())
8045 return Error(L, ".fnstart must precede .personality directive");
8046 if (CantUnwindLoc.isValid()) {
8047 Error(L, ".handlerdata can't be used with .cantunwind directive");
8048 Error(CantUnwindLoc, ".cantunwind was specified here");
8049 return true;
8050 }
8051
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008052 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00008053 return false;
8054}
8055
8056/// parseDirectiveSetFP
8057/// ::= .setfp fpreg, spreg [, offset]
8058bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8059 // Check the ordering of unwind directives
8060 if (!FnStartLoc.isValid())
8061 return Error(L, ".fnstart must precede .setfp directive");
8062 if (HandlerDataLoc.isValid())
8063 return Error(L, ".setfp must precede .handlerdata directive");
8064
8065 // Parse fpreg
8066 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8067 int NewFPReg = tryParseRegister();
8068 if (NewFPReg == -1)
8069 return Error(NewFPRegLoc, "frame pointer register expected");
8070
8071 // Consume comma
8072 if (!Parser.getTok().is(AsmToken::Comma))
8073 return Error(Parser.getTok().getLoc(), "comma expected");
8074 Parser.Lex(); // skip comma
8075
8076 // Parse spreg
8077 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8078 int NewSPReg = tryParseRegister();
8079 if (NewSPReg == -1)
8080 return Error(NewSPRegLoc, "stack pointer register expected");
8081
8082 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8083 return Error(NewSPRegLoc,
8084 "register should be either $sp or the latest fp register");
8085
8086 // Update the frame pointer register
8087 FPReg = NewFPReg;
8088
8089 // Parse offset
8090 int64_t Offset = 0;
8091 if (Parser.getTok().is(AsmToken::Comma)) {
8092 Parser.Lex(); // skip comma
8093
8094 if (Parser.getTok().isNot(AsmToken::Hash) &&
8095 Parser.getTok().isNot(AsmToken::Dollar)) {
8096 return Error(Parser.getTok().getLoc(), "'#' expected");
8097 }
8098 Parser.Lex(); // skip hash token.
8099
8100 const MCExpr *OffsetExpr;
8101 SMLoc ExLoc = Parser.getTok().getLoc();
8102 SMLoc EndLoc;
8103 if (getParser().parseExpression(OffsetExpr, EndLoc))
8104 return Error(ExLoc, "malformed setfp offset");
8105 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8106 if (!CE)
8107 return Error(ExLoc, "setfp offset must be an immediate");
8108
8109 Offset = CE->getValue();
8110 }
8111
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008112 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8113 static_cast<unsigned>(NewSPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00008114 return false;
8115}
8116
8117/// parseDirective
8118/// ::= .pad offset
8119bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8120 // Check the ordering of unwind directives
8121 if (!FnStartLoc.isValid())
8122 return Error(L, ".fnstart must precede .pad directive");
8123 if (HandlerDataLoc.isValid())
8124 return Error(L, ".pad must precede .handlerdata directive");
8125
8126 // Parse the offset
8127 if (Parser.getTok().isNot(AsmToken::Hash) &&
8128 Parser.getTok().isNot(AsmToken::Dollar)) {
8129 return Error(Parser.getTok().getLoc(), "'#' expected");
8130 }
8131 Parser.Lex(); // skip hash token.
8132
8133 const MCExpr *OffsetExpr;
8134 SMLoc ExLoc = Parser.getTok().getLoc();
8135 SMLoc EndLoc;
8136 if (getParser().parseExpression(OffsetExpr, EndLoc))
8137 return Error(ExLoc, "malformed pad offset");
8138 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8139 if (!CE)
8140 return Error(ExLoc, "pad offset must be an immediate");
8141
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008142 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00008143 return false;
8144}
8145
8146/// parseDirectiveRegSave
8147/// ::= .save { registers }
8148/// ::= .vsave { registers }
8149bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8150 // Check the ordering of unwind directives
8151 if (!FnStartLoc.isValid())
8152 return Error(L, ".fnstart must precede .save or .vsave directives");
8153 if (HandlerDataLoc.isValid())
8154 return Error(L, ".save or .vsave must precede .handlerdata directive");
8155
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008156 // RAII object to make sure parsed operands are deleted.
8157 struct CleanupObject {
8158 SmallVector<MCParsedAsmOperand *, 1> Operands;
8159 ~CleanupObject() {
8160 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8161 delete Operands[I];
8162 }
8163 } CO;
8164
Logan Chien4ea23b52013-05-10 16:17:24 +00008165 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008166 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008167 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008168 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008169 if (!IsVector && !Op->isRegList())
8170 return Error(L, ".save expects GPR registers");
8171 if (IsVector && !Op->isDPRRegList())
8172 return Error(L, ".vsave expects DPR registers");
8173
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008174 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00008175 return false;
8176}
8177
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008178/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008179extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008180 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8181 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008182}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008183
Chris Lattner3e4582a2010-09-06 19:11:01 +00008184#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008185#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008186#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008187#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008188
8189// Define this matcher function after the auto-generated include so we
8190// have the match class enum definitions.
8191unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8192 unsigned Kind) {
8193 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8194 // If the kind is a token for a literal immediate, check if our asm
8195 // operand matches. This is for InstAliases which have a fixed-value
8196 // immediate in the syntax.
8197 if (Kind == MCK__35_0 && Op->isImm()) {
8198 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8199 if (!CE)
8200 return Match_InvalidOperand;
8201 if (CE->getValue() == 0)
8202 return Match_Success;
8203 }
8204 return Match_InvalidOperand;
8205}