blob: 80e5c6edb4cee502142904484d021103c56ace47 [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
Evan Cheng11424442011-07-26 00:24:13 +000010#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMBaseInfo.h"
13#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000014#include "llvm/ADT/BitVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000015#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000016#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000017#include "llvm/ADT/SmallVector.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000018#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000019#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000021#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000023#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/MC/MCExpr.h"
25#include "llvm/MC/MCInst.h"
26#include "llvm/MC/MCInstrDesc.h"
27#include "llvm/MC/MCParser/MCAsmLexer.h"
28#include "llvm/MC/MCParser/MCAsmParser.h"
29#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
30#include "llvm/MC/MCRegisterInfo.h"
31#include "llvm/MC/MCStreamer.h"
32#include "llvm/MC/MCSubtargetInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000033#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/Support/MathExtras.h"
35#include "llvm/Support/SourceMgr.h"
36#include "llvm/Support/TargetRegistry.h"
37#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000038
Kevin Enderbyccab3172009-09-15 00:27:25 +000039using namespace llvm;
40
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000041namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000042
43class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000044
Jim Grosbach04945c42011-12-02 00:35:16 +000045enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000046
Evan Cheng11424442011-07-26 00:24:13 +000047class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000048 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000049 MCAsmParser &Parser;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000050 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000051
Logan Chien4ea23b52013-05-10 16:17:24 +000052 // Unwind directives state
53 SMLoc FnStartLoc;
54 SMLoc CantUnwindLoc;
55 SMLoc PersonalityLoc;
56 SMLoc HandlerDataLoc;
57 int FPReg;
58 void resetUnwindDirectiveParserState() {
59 FnStartLoc = SMLoc();
60 CantUnwindLoc = SMLoc();
61 PersonalityLoc = SMLoc();
62 HandlerDataLoc = SMLoc();
63 FPReg = -1;
64 }
65
Jim Grosbachab5830e2011-12-14 02:16:11 +000066 // Map of register aliases registers via the .req directive.
67 StringMap<unsigned> RegisterReqs;
68
Jim Grosbached16ec42011-08-29 22:24:09 +000069 struct {
70 ARMCC::CondCodes Cond; // Condition for IT block.
71 unsigned Mask:4; // Condition mask for instructions.
72 // Starting at first 1 (from lsb).
73 // '1' condition as indicated in IT.
74 // '0' inverse of condition (else).
75 // Count of instructions in IT block is
76 // 4 - trailingzeroes(mask)
77
78 bool FirstCond; // Explicit flag for when we're parsing the
79 // First instruction in the IT block. It's
80 // implied in the mask, so needs special
81 // handling.
82
83 unsigned CurPosition; // Current position in parsing of IT
84 // block. In range [0,3]. Initialized
85 // according to count of instructions in block.
86 // ~0U if no active IT block.
87 } ITState;
88 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000089 void forwardITPosition() {
90 if (!inITBlock()) return;
91 // Move to the next instruction in the IT block, if there is one. If not,
92 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +000093 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +000094 if (++ITState.CurPosition == 5 - TZ)
95 ITState.CurPosition = ~0U; // Done with the IT block after this.
96 }
Jim Grosbached16ec42011-08-29 22:24:09 +000097
98
Kevin Enderbyccab3172009-09-15 00:27:25 +000099 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000100 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
101
Benjamin Kramer673824b2012-04-15 17:04:27 +0000102 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000103 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000104 return Parser.Warning(L, Msg, Ranges);
105 }
106 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000107 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000108 return Parser.Error(L, Msg, Ranges);
109 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000110
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000111 int tryParseRegister();
112 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000113 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000114 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000115 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000116 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
117 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000118 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
119 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000120 bool parseDirectiveWord(unsigned Size, SMLoc L);
121 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000122 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000123 bool parseDirectiveThumbFunc(SMLoc L);
124 bool parseDirectiveCode(SMLoc L);
125 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000126 bool parseDirectiveReq(StringRef Name, SMLoc L);
127 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000128 bool parseDirectiveArch(SMLoc L);
129 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000130 bool parseDirectiveFnStart(SMLoc L);
131 bool parseDirectiveFnEnd(SMLoc L);
132 bool parseDirectiveCantUnwind(SMLoc L);
133 bool parseDirectivePersonality(SMLoc L);
134 bool parseDirectiveHandlerData(SMLoc L);
135 bool parseDirectiveSetFP(SMLoc L);
136 bool parseDirectivePad(SMLoc L);
137 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000138
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000139 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000140 bool &CarrySetting, unsigned &ProcessorIMod,
141 StringRef &ITMask);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000142 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000143 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000144
Evan Cheng4d1ca962011-07-08 01:53:10 +0000145 bool isThumb() const {
146 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000147 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000148 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000149 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000150 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000151 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000152 bool isThumbTwo() const {
153 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
154 }
Tim Northovera2292d02013-06-10 23:20:58 +0000155 bool hasThumb() const {
156 return STI.getFeatureBits() & ARM::HasV4TOps;
157 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000158 bool hasV6Ops() const {
159 return STI.getFeatureBits() & ARM::HasV6Ops;
160 }
James Molloy21efa7d2011-09-28 14:21:38 +0000161 bool hasV7Ops() const {
162 return STI.getFeatureBits() & ARM::HasV7Ops;
163 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000164 bool hasV8Ops() const {
165 return STI.getFeatureBits() & ARM::HasV8Ops;
166 }
Tim Northovera2292d02013-06-10 23:20:58 +0000167 bool hasARM() const {
168 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
169 }
170
Evan Cheng284b4672011-07-08 22:36:29 +0000171 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000172 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
173 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000174 }
James Molloy21efa7d2011-09-28 14:21:38 +0000175 bool isMClass() const {
176 return STI.getFeatureBits() & ARM::FeatureMClass;
177 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000178
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000179 /// @name Auto-generated Match Functions
180 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000181
Chris Lattner3e4582a2010-09-06 19:11:01 +0000182#define GET_ASSEMBLER_HEADER
183#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000184
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000185 /// }
186
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000187 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000188 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000189 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000190 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000191 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000192 OperandMatchResultTy parseCoprocOptionOperand(
193 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000194 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000195 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000196 OperandMatchResultTy parseInstSyncBarrierOptOperand(
197 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000198 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000199 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000200 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000201 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000202 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
203 StringRef Op, int Low, int High);
204 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
205 return parsePKHImm(O, "lsl", 0, 31);
206 }
207 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
208 return parsePKHImm(O, "asr", 1, 32);
209 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000210 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000211 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000212 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000213 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000214 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000215 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000216 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000217 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000218 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
219 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000220
221 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000222 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000223 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000224 bool validateInstruction(MCInst &Inst,
225 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000226 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000227 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000228 bool shouldOmitCCOutOperand(StringRef Mnemonic,
229 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000230 bool shouldOmitPredicateOperand(StringRef Mnemonic,
231 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Gouly5d0564d2013-08-02 19:18:12 +0000232 bool isDeprecated(MCInst &Inst, StringRef &Info);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000233
Kevin Enderbyccab3172009-09-15 00:27:25 +0000234public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000235 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000236 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000237 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000238 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000239 Match_RequiresThumb2,
240#define GET_OPERAND_DIAGNOSTIC_TYPES
241#include "ARMGenAsmMatcher.inc"
242
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000243 };
244
Evan Cheng91111d22011-07-09 05:47:46 +0000245 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Logan Chien4ea23b52013-05-10 16:17:24 +0000246 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000247 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000248
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000249 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000250 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000251
Evan Cheng4d1ca962011-07-08 01:53:10 +0000252 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000253 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000254
255 // Not in an ITBlock to start with.
256 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000257
258 // Set ELF header flags.
259 // FIXME: This should eventually end up somewhere else where more
260 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000261 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
262 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
263 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000264 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000265
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000266 // Implementation of the MCTargetAsmParser interface:
267 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000268 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
269 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000270 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000271 bool ParseDirective(AsmToken DirectiveID);
272
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000273 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000274 unsigned checkTargetMatchPredicate(MCInst &Inst);
275
Chad Rosier49963552012-10-13 00:26:04 +0000276 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000277 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000278 MCStreamer &Out, unsigned &ErrorInfo,
279 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000280};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000281} // end anonymous namespace
282
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000283namespace {
284
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000285/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000286/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000287class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000288 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000289 k_CondCode,
290 k_CCOut,
291 k_ITCondMask,
292 k_CoprocNum,
293 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000294 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000295 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000296 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000297 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000298 k_Memory,
299 k_PostIndexRegister,
300 k_MSRMask,
301 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000302 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000303 k_Register,
304 k_RegisterList,
305 k_DPRRegisterList,
306 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000307 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000308 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000309 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000310 k_ShiftedRegister,
311 k_ShiftedImmediate,
312 k_ShifterImmediate,
313 k_RotateImmediate,
314 k_BitfieldDescriptor,
315 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000316 } Kind;
317
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000318 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000319 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000320
Eric Christopher8996c5d2013-03-15 00:42:55 +0000321 struct CCOp {
322 ARMCC::CondCodes Val;
323 };
324
325 struct CopOp {
326 unsigned Val;
327 };
328
329 struct CoprocOptionOp {
330 unsigned Val;
331 };
332
333 struct ITMaskOp {
334 unsigned Mask:4;
335 };
336
337 struct MBOptOp {
338 ARM_MB::MemBOpt Val;
339 };
340
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000341 struct ISBOptOp {
342 ARM_ISB::InstSyncBOpt Val;
343 };
344
Eric Christopher8996c5d2013-03-15 00:42:55 +0000345 struct IFlagsOp {
346 ARM_PROC::IFlags Val;
347 };
348
349 struct MMaskOp {
350 unsigned Val;
351 };
352
353 struct TokOp {
354 const char *Data;
355 unsigned Length;
356 };
357
358 struct RegOp {
359 unsigned RegNum;
360 };
361
362 // A vector register list is a sequential list of 1 to 4 registers.
363 struct VectorListOp {
364 unsigned RegNum;
365 unsigned Count;
366 unsigned LaneIndex;
367 bool isDoubleSpaced;
368 };
369
370 struct VectorIndexOp {
371 unsigned Val;
372 };
373
374 struct ImmOp {
375 const MCExpr *Val;
376 };
377
378 /// Combined record for all forms of ARM address expressions.
379 struct MemoryOp {
380 unsigned BaseRegNum;
381 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
382 // was specified.
383 const MCConstantExpr *OffsetImm; // Offset immediate value
384 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
385 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
386 unsigned ShiftImm; // shift for OffsetReg.
387 unsigned Alignment; // 0 = no alignment specified
388 // n = alignment in bytes (2, 4, 8, 16, or 32)
389 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
390 };
391
392 struct PostIdxRegOp {
393 unsigned RegNum;
394 bool isAdd;
395 ARM_AM::ShiftOpc ShiftTy;
396 unsigned ShiftImm;
397 };
398
399 struct ShifterImmOp {
400 bool isASR;
401 unsigned Imm;
402 };
403
404 struct RegShiftedRegOp {
405 ARM_AM::ShiftOpc ShiftTy;
406 unsigned SrcReg;
407 unsigned ShiftReg;
408 unsigned ShiftImm;
409 };
410
411 struct RegShiftedImmOp {
412 ARM_AM::ShiftOpc ShiftTy;
413 unsigned SrcReg;
414 unsigned ShiftImm;
415 };
416
417 struct RotImmOp {
418 unsigned Imm;
419 };
420
421 struct BitfieldOp {
422 unsigned LSB;
423 unsigned Width;
424 };
425
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000426 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000427 struct CCOp CC;
428 struct CopOp Cop;
429 struct CoprocOptionOp CoprocOption;
430 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000431 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000432 struct ITMaskOp ITMask;
433 struct IFlagsOp IFlags;
434 struct MMaskOp MMask;
435 struct TokOp Tok;
436 struct RegOp Reg;
437 struct VectorListOp VectorList;
438 struct VectorIndexOp VectorIndex;
439 struct ImmOp Imm;
440 struct MemoryOp Memory;
441 struct PostIdxRegOp PostIdxReg;
442 struct ShifterImmOp ShifterImm;
443 struct RegShiftedRegOp RegShiftedReg;
444 struct RegShiftedImmOp RegShiftedImm;
445 struct RotImmOp RotImm;
446 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000447 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000448
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000449 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
450public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000451 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
452 Kind = o.Kind;
453 StartLoc = o.StartLoc;
454 EndLoc = o.EndLoc;
455 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000456 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000457 CC = o.CC;
458 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000459 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000460 ITMask = o.ITMask;
461 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000462 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000463 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000464 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000465 case k_CCOut:
466 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000467 Reg = o.Reg;
468 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000469 case k_RegisterList:
470 case k_DPRRegisterList:
471 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000472 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000473 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000474 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000475 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000476 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000477 VectorList = o.VectorList;
478 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000479 case k_CoprocNum:
480 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000481 Cop = o.Cop;
482 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000483 case k_CoprocOption:
484 CoprocOption = o.CoprocOption;
485 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000486 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000487 Imm = o.Imm;
488 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000489 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000490 MBOpt = o.MBOpt;
491 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000492 case k_InstSyncBarrierOpt:
493 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000494 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000495 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000496 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000497 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000498 PostIdxReg = o.PostIdxReg;
499 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000500 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000501 MMask = o.MMask;
502 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000503 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000504 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000505 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000506 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000507 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000508 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000509 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000510 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000511 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000512 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000513 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000514 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000515 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000516 RotImm = o.RotImm;
517 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000518 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000519 Bitfield = o.Bitfield;
520 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000521 case k_VectorIndex:
522 VectorIndex = o.VectorIndex;
523 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000524 }
525 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000526
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000527 /// getStartLoc - Get the location of the first token of this operand.
528 SMLoc getStartLoc() const { return StartLoc; }
529 /// getEndLoc - Get the location of the last token of this operand.
530 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000531 /// getLocRange - Get the range between the first and last token of this
532 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000533 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
534
Daniel Dunbard8042b72010-08-11 06:36:53 +0000535 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000536 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000537 return CC.Val;
538 }
539
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000540 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000541 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000542 return Cop.Val;
543 }
544
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000545 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000546 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000547 return StringRef(Tok.Data, Tok.Length);
548 }
549
550 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000551 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000552 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000553 }
554
Bill Wendlingbed94652010-11-09 23:28:44 +0000555 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000556 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
557 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000558 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000559 }
560
Kevin Enderbyf5079942009-10-13 22:19:02 +0000561 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000562 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000563 return Imm.Val;
564 }
565
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000566 unsigned getVectorIndex() const {
567 assert(Kind == k_VectorIndex && "Invalid access!");
568 return VectorIndex.Val;
569 }
570
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000571 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000572 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000573 return MBOpt.Val;
574 }
575
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000576 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
577 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
578 return ISBOpt.Val;
579 }
580
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000581 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000582 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000583 return IFlags.Val;
584 }
585
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000586 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000587 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000588 return MMask.Val;
589 }
590
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000591 bool isCoprocNum() const { return Kind == k_CoprocNum; }
592 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000593 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000594 bool isCondCode() const { return Kind == k_CondCode; }
595 bool isCCOut() const { return Kind == k_CCOut; }
596 bool isITMask() const { return Kind == k_ITCondMask; }
597 bool isITCondCode() const { return Kind == k_CondCode; }
598 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000599 // checks whether this operand is an unsigned offset which fits is a field
600 // of specified width and scaled by a specific number of bits
601 template<unsigned width, unsigned scale>
602 bool isUnsignedOffset() const {
603 if (!isImm()) return false;
604 if (dyn_cast<MCSymbolRefExpr>(Imm.Val)) return true;
605 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
606 int64_t Val = CE->getValue();
607 int64_t Align = 1LL << scale;
608 int64_t Max = Align * ((1LL << width) - 1);
609 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
610 }
611 return false;
612 }
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000613 // checks whether this operand is a memory operand computed as an offset
614 // applied to PC. the offset may have 8 bits of magnitude and is represented
615 // with two bits of shift. textually it may be either [pc, #imm], #imm or
616 // relocable expression...
617 bool isThumbMemPC() const {
618 int64_t Val = 0;
619 if (isImm()) {
620 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
621 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
622 if (!CE) return false;
623 Val = CE->getValue();
624 }
625 else if (isMem()) {
626 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
627 if(Memory.BaseRegNum != ARM::PC) return false;
628 Val = Memory.OffsetImm->getValue();
629 }
630 else return false;
631 return ((Val % 4) == 0) && (Val >= -1020) && (Val <= 1020);
632 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000633 bool isFPImm() const {
634 if (!isImm()) return false;
635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
636 if (!CE) return false;
637 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
638 return Val != -1;
639 }
Jim Grosbachea231912011-12-22 22:19:05 +0000640 bool isFBits16() const {
641 if (!isImm()) return false;
642 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
643 if (!CE) return false;
644 int64_t Value = CE->getValue();
645 return Value >= 0 && Value <= 16;
646 }
647 bool isFBits32() const {
648 if (!isImm()) return false;
649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
650 if (!CE) return false;
651 int64_t Value = CE->getValue();
652 return Value >= 1 && Value <= 32;
653 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000654 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000655 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
657 if (!CE) return false;
658 int64_t Value = CE->getValue();
659 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
660 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000661 bool isImm0_4() const {
662 if (!isImm()) return false;
663 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
664 if (!CE) return false;
665 int64_t Value = CE->getValue();
666 return Value >= 0 && Value < 5;
667 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000668 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000669 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
671 if (!CE) return false;
672 int64_t Value = CE->getValue();
673 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
674 }
675 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000676 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000677 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
678 if (!CE) return false;
679 int64_t Value = CE->getValue();
680 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
681 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000682 bool isImm0_508s4Neg() const {
683 if (!isImm()) return false;
684 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
685 if (!CE) return false;
686 int64_t Value = -CE->getValue();
687 // explicitly exclude zero. we want that to use the normal 0_508 version.
688 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
689 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000690 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000691 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000692 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
693 if (!CE) return false;
694 int64_t Value = CE->getValue();
695 return Value >= 0 && Value < 256;
696 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000697 bool isImm0_4095() const {
698 if (!isImm()) return false;
699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
700 if (!CE) return false;
701 int64_t Value = CE->getValue();
702 return Value >= 0 && Value < 4096;
703 }
704 bool isImm0_4095Neg() const {
705 if (!isImm()) return false;
706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
707 if (!CE) return false;
708 int64_t Value = -CE->getValue();
709 return Value > 0 && Value < 4096;
710 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000711 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000712 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
714 if (!CE) return false;
715 int64_t Value = CE->getValue();
716 return Value >= 0 && Value < 2;
717 }
718 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000719 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
721 if (!CE) return false;
722 int64_t Value = CE->getValue();
723 return Value >= 0 && Value < 4;
724 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000725 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000726 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000727 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
728 if (!CE) return false;
729 int64_t Value = CE->getValue();
730 return Value >= 0 && Value < 8;
731 }
732 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000733 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
735 if (!CE) return false;
736 int64_t Value = CE->getValue();
737 return Value >= 0 && Value < 16;
738 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000739 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000740 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000741 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
742 if (!CE) return false;
743 int64_t Value = CE->getValue();
744 return Value >= 0 && Value < 32;
745 }
Jim Grosbach00326402011-12-08 01:30:04 +0000746 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000747 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000748 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
749 if (!CE) return false;
750 int64_t Value = CE->getValue();
751 return Value >= 0 && Value < 64;
752 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000753 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000754 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000755 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
756 if (!CE) return false;
757 int64_t Value = CE->getValue();
758 return Value == 8;
759 }
760 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000761 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
763 if (!CE) return false;
764 int64_t Value = CE->getValue();
765 return Value == 16;
766 }
767 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000768 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000769 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
770 if (!CE) return false;
771 int64_t Value = CE->getValue();
772 return Value == 32;
773 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000774 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000775 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
777 if (!CE) return false;
778 int64_t Value = CE->getValue();
779 return Value > 0 && Value <= 8;
780 }
781 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000782 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
784 if (!CE) return false;
785 int64_t Value = CE->getValue();
786 return Value > 0 && Value <= 16;
787 }
788 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000789 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000790 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
791 if (!CE) return false;
792 int64_t Value = CE->getValue();
793 return Value > 0 && Value <= 32;
794 }
795 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000796 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000797 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
798 if (!CE) return false;
799 int64_t Value = CE->getValue();
800 return Value > 0 && Value <= 64;
801 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000802 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000803 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000804 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
805 if (!CE) return false;
806 int64_t Value = CE->getValue();
807 return Value > 0 && Value < 8;
808 }
809 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000810 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000811 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
812 if (!CE) return false;
813 int64_t Value = CE->getValue();
814 return Value > 0 && Value < 16;
815 }
816 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000817 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
819 if (!CE) return false;
820 int64_t Value = CE->getValue();
821 return Value > 0 && Value < 32;
822 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000823 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000824 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000825 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
826 if (!CE) return false;
827 int64_t Value = CE->getValue();
828 return Value > 0 && Value < 17;
829 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000830 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000831 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000832 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
833 if (!CE) return false;
834 int64_t Value = CE->getValue();
835 return Value > 0 && Value < 33;
836 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000837 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000838 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000839 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
840 if (!CE) return false;
841 int64_t Value = CE->getValue();
842 return Value >= 0 && Value < 33;
843 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000844 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000845 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000846 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
847 if (!CE) return false;
848 int64_t Value = CE->getValue();
849 return Value >= 0 && Value < 65536;
850 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000851 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000852 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
854 // If it's not a constant expression, it'll generate a fixup and be
855 // handled later.
856 if (!CE) return true;
857 int64_t Value = CE->getValue();
858 return Value >= 0 && Value < 65536;
859 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000860 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000861 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
863 if (!CE) return false;
864 int64_t Value = CE->getValue();
865 return Value >= 0 && Value <= 0xffffff;
866 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000867 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000868 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
870 if (!CE) return false;
871 int64_t Value = CE->getValue();
872 return Value > 0 && Value < 33;
873 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000874 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000875 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
877 if (!CE) return false;
878 int64_t Value = CE->getValue();
879 return Value >= 0 && Value < 32;
880 }
881 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000882 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
884 if (!CE) return false;
885 int64_t Value = CE->getValue();
886 return Value > 0 && Value <= 32;
887 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000888 bool isAdrLabel() const {
889 // If we have an immediate that's not a constant, treat it as a label
890 // reference needing a fixup. If it is a constant, but it can't fit
891 // into shift immediate encoding, we reject it.
892 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
893 else return (isARMSOImm() || isARMSOImmNeg());
894 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000895 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000896 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000897 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
898 if (!CE) return false;
899 int64_t Value = CE->getValue();
900 return ARM_AM::getSOImmVal(Value) != -1;
901 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000902 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000903 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000904 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
905 if (!CE) return false;
906 int64_t Value = CE->getValue();
907 return ARM_AM::getSOImmVal(~Value) != -1;
908 }
Jim Grosbach30506252011-12-08 00:31:07 +0000909 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000910 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000911 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
912 if (!CE) return false;
913 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000914 // Only use this when not representable as a plain so_imm.
915 return ARM_AM::getSOImmVal(Value) == -1 &&
916 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000917 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000918 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000919 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000920 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
921 if (!CE) return false;
922 int64_t Value = CE->getValue();
923 return ARM_AM::getT2SOImmVal(Value) != -1;
924 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000925 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000926 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
928 if (!CE) return false;
929 int64_t Value = CE->getValue();
930 return ARM_AM::getT2SOImmVal(~Value) != -1;
931 }
Jim Grosbach30506252011-12-08 00:31:07 +0000932 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000933 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
935 if (!CE) return false;
936 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000937 // Only use this when not representable as a plain so_imm.
938 return ARM_AM::getT2SOImmVal(Value) == -1 &&
939 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000940 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000941 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000942 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
944 if (!CE) return false;
945 int64_t Value = CE->getValue();
946 return Value == 1 || Value == 0;
947 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000948 bool isReg() const { return Kind == k_Register; }
949 bool isRegList() const { return Kind == k_RegisterList; }
950 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
951 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
952 bool isToken() const { return Kind == k_Token; }
953 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000954 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000955 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000956 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
957 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
958 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
959 bool isRotImm() const { return Kind == k_RotateImmediate; }
960 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
961 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000962 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000963 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000964 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000965 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000966 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000967 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000968 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000969 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
970 (alignOK || Memory.Alignment == 0);
971 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000972 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000973 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000974 return false;
975 // Base register must be PC.
976 if (Memory.BaseRegNum != ARM::PC)
977 return false;
978 // Immediate offset in range [-4095, 4095].
979 if (!Memory.OffsetImm) return true;
980 int64_t Val = Memory.OffsetImm->getValue();
981 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
982 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000983 bool isAlignedMemory() const {
984 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000985 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000986 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +0000987 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000988 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000989 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +0000990 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +0000991 if (!Memory.OffsetImm) return true;
992 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +0000993 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000994 }
Jim Grosbachcd17c122011-08-04 23:01:30 +0000995 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000996 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +0000997 // Immediate offset in range [-4095, 4095].
998 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
999 if (!CE) return false;
1000 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001001 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001002 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001003 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001004 // If we have an immediate that's not a constant, treat it as a label
1005 // reference needing a fixup. If it is a constant, it's something else
1006 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001007 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001008 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001009 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001010 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001011 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001012 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001013 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001014 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001015 if (!Memory.OffsetImm) return true;
1016 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001017 // The #-0 offset is encoded as INT32_MIN, and we have to check
1018 // for this too.
1019 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001020 }
1021 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001022 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001023 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001024 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001025 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1026 // Immediate offset in range [-255, 255].
1027 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1028 if (!CE) return false;
1029 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001030 // Special case, #-0 is INT32_MIN.
1031 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001032 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001033 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001034 // If we have an immediate that's not a constant, treat it as a label
1035 // reference needing a fixup. If it is a constant, it's something else
1036 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001037 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001038 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001039 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001040 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001041 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001042 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001043 if (!Memory.OffsetImm) return true;
1044 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001045 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001046 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001047 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001048 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001049 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001050 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001051 return false;
1052 return true;
1053 }
1054 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001055 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001056 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1057 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001058 return false;
1059 return true;
1060 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001061 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001062 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001063 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001064 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001065 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001066 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001067 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001068 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001069 return false;
1070 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001071 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001072 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001073 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001074 return false;
1075 return true;
1076 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001077 bool isMemThumbRR() const {
1078 // Thumb reg+reg addressing is simple. Just two registers, a base and
1079 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001080 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001081 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001082 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001083 return isARMLowRegister(Memory.BaseRegNum) &&
1084 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001085 }
1086 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001087 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001088 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001089 return false;
1090 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001091 if (!Memory.OffsetImm) return true;
1092 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001093 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1094 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001095 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001096 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001097 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001098 return false;
1099 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001100 if (!Memory.OffsetImm) return true;
1101 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001102 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1103 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001104 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001105 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001106 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001107 return false;
1108 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001109 if (!Memory.OffsetImm) return true;
1110 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001111 return Val >= 0 && Val <= 31;
1112 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001113 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001114 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001115 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001116 return false;
1117 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001118 if (!Memory.OffsetImm) return true;
1119 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001120 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001121 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001122 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001123 // If we have an immediate that's not a constant, treat it as a label
1124 // reference needing a fixup. If it is a constant, it's something else
1125 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001126 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001127 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001128 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001129 return false;
1130 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001131 if (!Memory.OffsetImm) return true;
1132 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001133 // Special case, #-0 is INT32_MIN.
1134 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001135 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001136 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001137 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001138 return false;
1139 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001140 if (!Memory.OffsetImm) return true;
1141 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001142 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1143 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001144 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001145 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001146 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001147 // Base reg of PC isn't allowed for these encodings.
1148 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001149 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001150 if (!Memory.OffsetImm) return true;
1151 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001152 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001153 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001154 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001155 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001156 return false;
1157 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001158 if (!Memory.OffsetImm) return true;
1159 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001160 return Val >= 0 && Val < 256;
1161 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001162 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001163 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001164 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001165 // Base reg of PC isn't allowed for these encodings.
1166 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001167 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001168 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001169 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001170 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001171 }
1172 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001173 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001174 return false;
1175 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001176 if (!Memory.OffsetImm) return true;
1177 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001178 return (Val >= 0 && Val < 4096);
1179 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001180 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001181 // If we have an immediate that's not a constant, treat it as a label
1182 // reference needing a fixup. If it is a constant, it's something else
1183 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001184 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001185 return true;
1186
Chad Rosier41099832012-09-11 23:02:35 +00001187 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001188 return false;
1189 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001190 if (!Memory.OffsetImm) return true;
1191 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001192 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001193 }
1194 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001195 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001196 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1197 if (!CE) return false;
1198 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001199 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001200 }
Jim Grosbach93981412011-10-11 21:55:36 +00001201 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001202 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001203 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1204 if (!CE) return false;
1205 int64_t Val = CE->getValue();
1206 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1207 (Val == INT32_MIN);
1208 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001209
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001210 bool isMSRMask() const { return Kind == k_MSRMask; }
1211 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001212
Jim Grosbach741cd732011-10-17 22:26:03 +00001213 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001214 bool isSingleSpacedVectorList() const {
1215 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1216 }
1217 bool isDoubleSpacedVectorList() const {
1218 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1219 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001220 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001221 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001222 return VectorList.Count == 1;
1223 }
1224
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001225 bool isVecListDPair() const {
1226 if (!isSingleSpacedVectorList()) return false;
1227 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1228 .contains(VectorList.RegNum));
1229 }
1230
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001231 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001232 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001233 return VectorList.Count == 3;
1234 }
1235
Jim Grosbach846bcff2011-10-21 20:35:01 +00001236 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001237 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001238 return VectorList.Count == 4;
1239 }
1240
Jim Grosbache5307f92012-03-05 21:43:40 +00001241 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001242 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001243 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1244 .contains(VectorList.RegNum));
1245 }
1246
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001247 bool isVecListThreeQ() const {
1248 if (!isDoubleSpacedVectorList()) return false;
1249 return VectorList.Count == 3;
1250 }
1251
Jim Grosbach1e946a42012-01-24 00:43:12 +00001252 bool isVecListFourQ() const {
1253 if (!isDoubleSpacedVectorList()) return false;
1254 return VectorList.Count == 4;
1255 }
1256
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001257 bool isSingleSpacedVectorAllLanes() const {
1258 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1259 }
1260 bool isDoubleSpacedVectorAllLanes() const {
1261 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1262 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001263 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001264 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001265 return VectorList.Count == 1;
1266 }
1267
Jim Grosbach13a292c2012-03-06 22:01:44 +00001268 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001269 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001270 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1271 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001272 }
1273
Jim Grosbached428bc2012-03-06 23:10:38 +00001274 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001275 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001276 return VectorList.Count == 2;
1277 }
1278
Jim Grosbachb78403c2012-01-24 23:47:04 +00001279 bool isVecListThreeDAllLanes() const {
1280 if (!isSingleSpacedVectorAllLanes()) return false;
1281 return VectorList.Count == 3;
1282 }
1283
1284 bool isVecListThreeQAllLanes() const {
1285 if (!isDoubleSpacedVectorAllLanes()) return false;
1286 return VectorList.Count == 3;
1287 }
1288
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001289 bool isVecListFourDAllLanes() const {
1290 if (!isSingleSpacedVectorAllLanes()) return false;
1291 return VectorList.Count == 4;
1292 }
1293
1294 bool isVecListFourQAllLanes() const {
1295 if (!isDoubleSpacedVectorAllLanes()) return false;
1296 return VectorList.Count == 4;
1297 }
1298
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001299 bool isSingleSpacedVectorIndexed() const {
1300 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1301 }
1302 bool isDoubleSpacedVectorIndexed() const {
1303 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1304 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001305 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001306 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001307 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1308 }
1309
Jim Grosbachda511042011-12-14 23:35:06 +00001310 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001311 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001312 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1313 }
1314
1315 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001316 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001317 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1318 }
1319
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001320 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001321 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001322 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1323 }
1324
Jim Grosbachda511042011-12-14 23:35:06 +00001325 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001326 if (!isSingleSpacedVectorIndexed()) return false;
1327 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1328 }
1329
1330 bool isVecListTwoQWordIndexed() const {
1331 if (!isDoubleSpacedVectorIndexed()) return false;
1332 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1333 }
1334
1335 bool isVecListTwoQHWordIndexed() const {
1336 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001337 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1338 }
1339
1340 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001341 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001342 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1343 }
1344
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001345 bool isVecListThreeDByteIndexed() const {
1346 if (!isSingleSpacedVectorIndexed()) return false;
1347 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1348 }
1349
1350 bool isVecListThreeDHWordIndexed() const {
1351 if (!isSingleSpacedVectorIndexed()) return false;
1352 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1353 }
1354
1355 bool isVecListThreeQWordIndexed() const {
1356 if (!isDoubleSpacedVectorIndexed()) return false;
1357 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1358 }
1359
1360 bool isVecListThreeQHWordIndexed() const {
1361 if (!isDoubleSpacedVectorIndexed()) return false;
1362 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1363 }
1364
1365 bool isVecListThreeDWordIndexed() const {
1366 if (!isSingleSpacedVectorIndexed()) return false;
1367 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1368 }
1369
Jim Grosbach14952a02012-01-24 18:37:25 +00001370 bool isVecListFourDByteIndexed() const {
1371 if (!isSingleSpacedVectorIndexed()) return false;
1372 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1373 }
1374
1375 bool isVecListFourDHWordIndexed() const {
1376 if (!isSingleSpacedVectorIndexed()) return false;
1377 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1378 }
1379
1380 bool isVecListFourQWordIndexed() const {
1381 if (!isDoubleSpacedVectorIndexed()) return false;
1382 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1383 }
1384
1385 bool isVecListFourQHWordIndexed() const {
1386 if (!isDoubleSpacedVectorIndexed()) return false;
1387 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1388 }
1389
1390 bool isVecListFourDWordIndexed() const {
1391 if (!isSingleSpacedVectorIndexed()) return false;
1392 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1393 }
1394
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001395 bool isVectorIndex8() const {
1396 if (Kind != k_VectorIndex) return false;
1397 return VectorIndex.Val < 8;
1398 }
1399 bool isVectorIndex16() const {
1400 if (Kind != k_VectorIndex) return false;
1401 return VectorIndex.Val < 4;
1402 }
1403 bool isVectorIndex32() const {
1404 if (Kind != k_VectorIndex) return false;
1405 return VectorIndex.Val < 2;
1406 }
1407
Jim Grosbach741cd732011-10-17 22:26:03 +00001408 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001409 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001410 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1411 // Must be a constant.
1412 if (!CE) return false;
1413 int64_t Value = CE->getValue();
1414 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1415 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001416 return Value >= 0 && Value < 256;
1417 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001418
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001419 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001420 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001421 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1422 // Must be a constant.
1423 if (!CE) return false;
1424 int64_t Value = CE->getValue();
1425 // i16 value in the range [0,255] or [0x0100, 0xff00]
1426 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1427 }
1428
Jim Grosbach8211c052011-10-18 00:22:00 +00001429 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001430 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001431 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1432 // Must be a constant.
1433 if (!CE) return false;
1434 int64_t Value = CE->getValue();
1435 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1436 return (Value >= 0 && Value < 256) ||
1437 (Value >= 0x0100 && Value <= 0xff00) ||
1438 (Value >= 0x010000 && Value <= 0xff0000) ||
1439 (Value >= 0x01000000 && Value <= 0xff000000);
1440 }
1441
1442 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001443 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001444 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1445 // Must be a constant.
1446 if (!CE) return false;
1447 int64_t Value = CE->getValue();
1448 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1449 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1450 return (Value >= 0 && Value < 256) ||
1451 (Value >= 0x0100 && Value <= 0xff00) ||
1452 (Value >= 0x010000 && Value <= 0xff0000) ||
1453 (Value >= 0x01000000 && Value <= 0xff000000) ||
1454 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1455 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1456 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001457 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001458 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001459 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1460 // Must be a constant.
1461 if (!CE) return false;
1462 int64_t Value = ~CE->getValue();
1463 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1464 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1465 return (Value >= 0 && Value < 256) ||
1466 (Value >= 0x0100 && Value <= 0xff00) ||
1467 (Value >= 0x010000 && Value <= 0xff0000) ||
1468 (Value >= 0x01000000 && Value <= 0xff000000) ||
1469 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1470 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1471 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001472
Jim Grosbache4454e02011-10-18 16:18:11 +00001473 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001474 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001475 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1476 // Must be a constant.
1477 if (!CE) return false;
1478 uint64_t Value = CE->getValue();
1479 // i64 value with each byte being either 0 or 0xff.
1480 for (unsigned i = 0; i < 8; ++i)
1481 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1482 return true;
1483 }
1484
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001485 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001486 // Add as immediates when possible. Null MCExpr = 0.
1487 if (Expr == 0)
1488 Inst.addOperand(MCOperand::CreateImm(0));
1489 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001490 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1491 else
1492 Inst.addOperand(MCOperand::CreateExpr(Expr));
1493 }
1494
Daniel Dunbard8042b72010-08-11 06:36:53 +00001495 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001496 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001497 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001498 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1499 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001500 }
1501
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001502 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1503 assert(N == 1 && "Invalid number of operands!");
1504 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1505 }
1506
Jim Grosbach48399582011-10-12 17:34:41 +00001507 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1508 assert(N == 1 && "Invalid number of operands!");
1509 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1510 }
1511
1512 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1513 assert(N == 1 && "Invalid number of operands!");
1514 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1515 }
1516
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001517 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1518 assert(N == 1 && "Invalid number of operands!");
1519 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1520 }
1521
1522 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1523 assert(N == 1 && "Invalid number of operands!");
1524 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1525 }
1526
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001527 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1528 assert(N == 1 && "Invalid number of operands!");
1529 Inst.addOperand(MCOperand::CreateReg(getReg()));
1530 }
1531
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001532 void addRegOperands(MCInst &Inst, unsigned N) const {
1533 assert(N == 1 && "Invalid number of operands!");
1534 Inst.addOperand(MCOperand::CreateReg(getReg()));
1535 }
1536
Jim Grosbachac798e12011-07-25 20:49:51 +00001537 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001538 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001539 assert(isRegShiftedReg() &&
1540 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001541 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1542 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001543 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001544 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001545 }
1546
Jim Grosbachac798e12011-07-25 20:49:51 +00001547 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001548 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001549 assert(isRegShiftedImm() &&
1550 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001551 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001552 // Shift of #32 is encoded as 0 where permitted
1553 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001554 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001555 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001556 }
1557
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001558 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001559 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001560 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1561 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001562 }
1563
Bill Wendling8d2aa032010-11-08 23:49:57 +00001564 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001565 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001566 const SmallVectorImpl<unsigned> &RegList = getRegList();
1567 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001568 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1569 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001570 }
1571
Bill Wendling9898ac92010-11-17 04:32:08 +00001572 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1573 addRegListOperands(Inst, N);
1574 }
1575
1576 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1577 addRegListOperands(Inst, N);
1578 }
1579
Jim Grosbach833b9d32011-07-27 20:15:40 +00001580 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1581 assert(N == 1 && "Invalid number of operands!");
1582 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1583 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1584 }
1585
Jim Grosbach864b6092011-07-28 21:34:26 +00001586 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1587 assert(N == 1 && "Invalid number of operands!");
1588 // Munge the lsb/width into a bitfield mask.
1589 unsigned lsb = Bitfield.LSB;
1590 unsigned width = Bitfield.Width;
1591 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1592 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1593 (32 - (lsb + width)));
1594 Inst.addOperand(MCOperand::CreateImm(Mask));
1595 }
1596
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001597 void addImmOperands(MCInst &Inst, unsigned N) const {
1598 assert(N == 1 && "Invalid number of operands!");
1599 addExpr(Inst, getImm());
1600 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001601
Jim Grosbachea231912011-12-22 22:19:05 +00001602 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1603 assert(N == 1 && "Invalid number of operands!");
1604 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1605 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1606 }
1607
1608 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1609 assert(N == 1 && "Invalid number of operands!");
1610 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1611 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1612 }
1613
Jim Grosbache7fbce72011-10-03 23:38:36 +00001614 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1615 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001616 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1617 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1618 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001619 }
1620
Jim Grosbach7db8d692011-09-08 22:07:06 +00001621 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1622 assert(N == 1 && "Invalid number of operands!");
1623 // FIXME: We really want to scale the value here, but the LDRD/STRD
1624 // instruction don't encode operands that way yet.
1625 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1626 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1627 }
1628
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001629 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1630 assert(N == 1 && "Invalid number of operands!");
1631 // The immediate is scaled by four in the encoding and is stored
1632 // in the MCInst as such. Lop off the low two bits here.
1633 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1634 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1635 }
1636
Jim Grosbach930f2f62012-04-05 20:57:13 +00001637 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1638 assert(N == 1 && "Invalid number of operands!");
1639 // The immediate is scaled by four in the encoding and is stored
1640 // in the MCInst as such. Lop off the low two bits here.
1641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1642 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1643 }
1644
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001645 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1646 assert(N == 1 && "Invalid number of operands!");
1647 // The immediate is scaled by four in the encoding and is stored
1648 // in the MCInst as such. Lop off the low two bits here.
1649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1650 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1651 }
1652
Jim Grosbach475c6db2011-07-25 23:09:14 +00001653 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1654 assert(N == 1 && "Invalid number of operands!");
1655 // The constant encodes as the immediate-1, and we store in the instruction
1656 // the bits as encoded, so subtract off one here.
1657 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1658 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1659 }
1660
Jim Grosbach801e0a32011-07-22 23:16:18 +00001661 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1662 assert(N == 1 && "Invalid number of operands!");
1663 // The constant encodes as the immediate-1, and we store in the instruction
1664 // the bits as encoded, so subtract off one here.
1665 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1666 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1667 }
1668
Jim Grosbach46dd4132011-08-17 21:51:27 +00001669 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1670 assert(N == 1 && "Invalid number of operands!");
1671 // The constant encodes as the immediate, except for 32, which encodes as
1672 // zero.
1673 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1674 unsigned Imm = CE->getValue();
1675 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1676 }
1677
Jim Grosbach27c1e252011-07-21 17:23:04 +00001678 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1679 assert(N == 1 && "Invalid number of operands!");
1680 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1681 // the instruction as well.
1682 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1683 int Val = CE->getValue();
1684 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1685 }
1686
Jim Grosbachb009a872011-10-28 22:36:30 +00001687 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1688 assert(N == 1 && "Invalid number of operands!");
1689 // The operand is actually a t2_so_imm, but we have its bitwise
1690 // negation in the assembly source, so twiddle it here.
1691 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1692 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1693 }
1694
Jim Grosbach30506252011-12-08 00:31:07 +00001695 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1696 assert(N == 1 && "Invalid number of operands!");
1697 // The operand is actually a t2_so_imm, but we have its
1698 // negation in the assembly source, so twiddle it here.
1699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1700 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1701 }
1702
Jim Grosbach930f2f62012-04-05 20:57:13 +00001703 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1704 assert(N == 1 && "Invalid number of operands!");
1705 // The operand is actually an imm0_4095, but we have its
1706 // negation in the assembly source, so twiddle it here.
1707 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1708 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1709 }
1710
Mihai Popad36cbaa2013-07-03 09:21:44 +00001711 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1712 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1713 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1714 return;
1715 }
1716
1717 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1718 assert(SR && "Unknown value type!");
1719 Inst.addOperand(MCOperand::CreateExpr(SR));
1720 }
1721
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001722 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1723 assert(N == 1 && "Invalid number of operands!");
1724 if (isImm()) {
1725 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1726 if (CE) {
1727 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1728 return;
1729 }
1730
1731 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1732 assert(SR && "Unknown value type!");
1733 Inst.addOperand(MCOperand::CreateExpr(SR));
1734 return;
1735 }
1736
1737 assert(isMem() && "Unknown value type!");
1738 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1739 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1740 }
1741
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001742 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1743 assert(N == 1 && "Invalid number of operands!");
1744 // The operand is actually a so_imm, but we have its bitwise
1745 // negation in the assembly source, so twiddle it here.
1746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1747 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1748 }
1749
Jim Grosbach30506252011-12-08 00:31:07 +00001750 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1751 assert(N == 1 && "Invalid number of operands!");
1752 // The operand is actually a so_imm, but we have its
1753 // negation in the assembly source, so twiddle it here.
1754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1755 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1756 }
1757
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001758 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1759 assert(N == 1 && "Invalid number of operands!");
1760 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1761 }
1762
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001763 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1764 assert(N == 1 && "Invalid number of operands!");
1765 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1766 }
1767
Jim Grosbachd3595712011-08-03 23:50:40 +00001768 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1769 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001770 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001771 }
1772
Jim Grosbach94298a92012-01-18 22:46:46 +00001773 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1774 assert(N == 1 && "Invalid number of operands!");
1775 int32_t Imm = Memory.OffsetImm->getValue();
1776 // FIXME: Handle #-0
1777 if (Imm == INT32_MIN) Imm = 0;
1778 Inst.addOperand(MCOperand::CreateImm(Imm));
1779 }
1780
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001781 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1782 assert(N == 1 && "Invalid number of operands!");
1783 assert(isImm() && "Not an immediate!");
1784
1785 // If we have an immediate that's not a constant, treat it as a label
1786 // reference needing a fixup.
1787 if (!isa<MCConstantExpr>(getImm())) {
1788 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1789 return;
1790 }
1791
1792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1793 int Val = CE->getValue();
1794 Inst.addOperand(MCOperand::CreateImm(Val));
1795 }
1796
Jim Grosbacha95ec992011-10-11 17:29:55 +00001797 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1798 assert(N == 2 && "Invalid number of operands!");
1799 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1800 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1801 }
1802
Jim Grosbachd3595712011-08-03 23:50:40 +00001803 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1804 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001805 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1806 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001807 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1808 // Special case for #-0
1809 if (Val == INT32_MIN) Val = 0;
1810 if (Val < 0) Val = -Val;
1811 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1812 } else {
1813 // For register offset, we encode the shift type and negation flag
1814 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001815 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1816 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001817 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001818 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1819 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001820 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001821 }
1822
Jim Grosbachcd17c122011-08-04 23:01:30 +00001823 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1824 assert(N == 2 && "Invalid number of operands!");
1825 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1826 assert(CE && "non-constant AM2OffsetImm operand!");
1827 int32_t Val = CE->getValue();
1828 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1829 // Special case for #-0
1830 if (Val == INT32_MIN) Val = 0;
1831 if (Val < 0) Val = -Val;
1832 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1833 Inst.addOperand(MCOperand::CreateReg(0));
1834 Inst.addOperand(MCOperand::CreateImm(Val));
1835 }
1836
Jim Grosbach5b96b802011-08-10 20:29:19 +00001837 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1838 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001839 // If we have an immediate that's not a constant, treat it as a label
1840 // reference needing a fixup. If it is a constant, it's something else
1841 // and we reject it.
1842 if (isImm()) {
1843 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1844 Inst.addOperand(MCOperand::CreateReg(0));
1845 Inst.addOperand(MCOperand::CreateImm(0));
1846 return;
1847 }
1848
Jim Grosbach871dff72011-10-11 15:59:20 +00001849 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1850 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001851 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1852 // Special case for #-0
1853 if (Val == INT32_MIN) Val = 0;
1854 if (Val < 0) Val = -Val;
1855 Val = ARM_AM::getAM3Opc(AddSub, Val);
1856 } else {
1857 // For register offset, we encode the shift type and negation flag
1858 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001859 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001860 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001861 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1862 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001863 Inst.addOperand(MCOperand::CreateImm(Val));
1864 }
1865
1866 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1867 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001868 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001869 int32_t Val =
1870 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1871 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1872 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001873 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001874 }
1875
1876 // Constant offset.
1877 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1878 int32_t Val = CE->getValue();
1879 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1880 // Special case for #-0
1881 if (Val == INT32_MIN) Val = 0;
1882 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001883 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001884 Inst.addOperand(MCOperand::CreateReg(0));
1885 Inst.addOperand(MCOperand::CreateImm(Val));
1886 }
1887
Jim Grosbachd3595712011-08-03 23:50:40 +00001888 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1889 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001890 // If we have an immediate that's not a constant, treat it as a label
1891 // reference needing a fixup. If it is a constant, it's something else
1892 // and we reject it.
1893 if (isImm()) {
1894 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1895 Inst.addOperand(MCOperand::CreateImm(0));
1896 return;
1897 }
1898
Jim Grosbachd3595712011-08-03 23:50:40 +00001899 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001900 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001901 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1902 // Special case for #-0
1903 if (Val == INT32_MIN) Val = 0;
1904 if (Val < 0) Val = -Val;
1905 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001906 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001907 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001908 }
1909
Jim Grosbach7db8d692011-09-08 22:07:06 +00001910 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1911 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001912 // If we have an immediate that's not a constant, treat it as a label
1913 // reference needing a fixup. If it is a constant, it's something else
1914 // and we reject it.
1915 if (isImm()) {
1916 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1917 Inst.addOperand(MCOperand::CreateImm(0));
1918 return;
1919 }
1920
Jim Grosbach871dff72011-10-11 15:59:20 +00001921 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1922 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001923 Inst.addOperand(MCOperand::CreateImm(Val));
1924 }
1925
Jim Grosbacha05627e2011-09-09 18:37:27 +00001926 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1927 assert(N == 2 && "Invalid number of operands!");
1928 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001929 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1930 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001931 Inst.addOperand(MCOperand::CreateImm(Val));
1932 }
1933
Jim Grosbachd3595712011-08-03 23:50:40 +00001934 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1935 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001936 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1937 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001938 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001939 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001940
Jim Grosbach2392c532011-09-07 23:39:14 +00001941 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1942 addMemImm8OffsetOperands(Inst, N);
1943 }
1944
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001945 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001946 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001947 }
1948
1949 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1950 assert(N == 2 && "Invalid number of operands!");
1951 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001952 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001953 addExpr(Inst, getImm());
1954 Inst.addOperand(MCOperand::CreateImm(0));
1955 return;
1956 }
1957
1958 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001959 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1960 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001961 Inst.addOperand(MCOperand::CreateImm(Val));
1962 }
1963
Jim Grosbachd3595712011-08-03 23:50:40 +00001964 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1965 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001966 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001967 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001968 addExpr(Inst, getImm());
1969 Inst.addOperand(MCOperand::CreateImm(0));
1970 return;
1971 }
1972
1973 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001974 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1975 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001976 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001977 }
Bill Wendling811c9362010-11-30 07:44:32 +00001978
Jim Grosbach05541f42011-09-19 22:21:13 +00001979 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1980 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001981 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1982 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001983 }
1984
1985 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1986 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001987 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1988 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001989 }
1990
Jim Grosbachd3595712011-08-03 23:50:40 +00001991 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1992 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001993 unsigned Val =
1994 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1995 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001996 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1997 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001998 Inst.addOperand(MCOperand::CreateImm(Val));
1999 }
2000
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002001 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2002 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002003 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2004 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2005 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002006 }
2007
Jim Grosbachd3595712011-08-03 23:50:40 +00002008 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2009 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002010 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2011 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002012 }
2013
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002014 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2015 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002016 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2017 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002018 Inst.addOperand(MCOperand::CreateImm(Val));
2019 }
2020
Jim Grosbach26d35872011-08-19 18:55:51 +00002021 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2022 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002023 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2024 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002025 Inst.addOperand(MCOperand::CreateImm(Val));
2026 }
2027
Jim Grosbacha32c7532011-08-19 18:49:59 +00002028 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2029 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002030 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2031 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002032 Inst.addOperand(MCOperand::CreateImm(Val));
2033 }
2034
Jim Grosbach23983d62011-08-19 18:13:48 +00002035 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2036 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002037 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2038 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002039 Inst.addOperand(MCOperand::CreateImm(Val));
2040 }
2041
Jim Grosbachd3595712011-08-03 23:50:40 +00002042 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2043 assert(N == 1 && "Invalid number of operands!");
2044 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2045 assert(CE && "non-constant post-idx-imm8 operand!");
2046 int Imm = CE->getValue();
2047 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002048 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002049 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2050 Inst.addOperand(MCOperand::CreateImm(Imm));
2051 }
2052
Jim Grosbach93981412011-10-11 21:55:36 +00002053 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2054 assert(N == 1 && "Invalid number of operands!");
2055 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2056 assert(CE && "non-constant post-idx-imm8s4 operand!");
2057 int Imm = CE->getValue();
2058 bool isAdd = Imm >= 0;
2059 if (Imm == INT32_MIN) Imm = 0;
2060 // Immediate is scaled by 4.
2061 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2062 Inst.addOperand(MCOperand::CreateImm(Imm));
2063 }
2064
Jim Grosbachd3595712011-08-03 23:50:40 +00002065 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2066 assert(N == 2 && "Invalid number of operands!");
2067 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002068 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2069 }
2070
2071 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2072 assert(N == 2 && "Invalid number of operands!");
2073 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2074 // The sign, shift type, and shift amount are encoded in a single operand
2075 // using the AM2 encoding helpers.
2076 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2077 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2078 PostIdxReg.ShiftTy);
2079 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002080 }
2081
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002082 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2083 assert(N == 1 && "Invalid number of operands!");
2084 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2085 }
2086
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002087 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2088 assert(N == 1 && "Invalid number of operands!");
2089 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2090 }
2091
Jim Grosbach182b6a02011-11-29 23:51:09 +00002092 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002093 assert(N == 1 && "Invalid number of operands!");
2094 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2095 }
2096
Jim Grosbach04945c42011-12-02 00:35:16 +00002097 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2098 assert(N == 2 && "Invalid number of operands!");
2099 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2100 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2101 }
2102
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002103 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2104 assert(N == 1 && "Invalid number of operands!");
2105 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2106 }
2107
2108 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2109 assert(N == 1 && "Invalid number of operands!");
2110 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2111 }
2112
2113 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2114 assert(N == 1 && "Invalid number of operands!");
2115 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2116 }
2117
Jim Grosbach741cd732011-10-17 22:26:03 +00002118 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2119 assert(N == 1 && "Invalid number of operands!");
2120 // The immediate encodes the type of constant as well as the value.
2121 // Mask in that this is an i8 splat.
2122 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2123 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2124 }
2125
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002126 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2127 assert(N == 1 && "Invalid number of operands!");
2128 // The immediate encodes the type of constant as well as the value.
2129 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2130 unsigned Value = CE->getValue();
2131 if (Value >= 256)
2132 Value = (Value >> 8) | 0xa00;
2133 else
2134 Value |= 0x800;
2135 Inst.addOperand(MCOperand::CreateImm(Value));
2136 }
2137
Jim Grosbach8211c052011-10-18 00:22:00 +00002138 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2139 assert(N == 1 && "Invalid number of operands!");
2140 // The immediate encodes the type of constant as well as the value.
2141 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2142 unsigned Value = CE->getValue();
2143 if (Value >= 256 && Value <= 0xff00)
2144 Value = (Value >> 8) | 0x200;
2145 else if (Value > 0xffff && Value <= 0xff0000)
2146 Value = (Value >> 16) | 0x400;
2147 else if (Value > 0xffffff)
2148 Value = (Value >> 24) | 0x600;
2149 Inst.addOperand(MCOperand::CreateImm(Value));
2150 }
2151
2152 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2153 assert(N == 1 && "Invalid number of operands!");
2154 // The immediate encodes the type of constant as well as the value.
2155 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2156 unsigned Value = CE->getValue();
2157 if (Value >= 256 && Value <= 0xffff)
2158 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2159 else if (Value > 0xffff && Value <= 0xffffff)
2160 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2161 else if (Value > 0xffffff)
2162 Value = (Value >> 24) | 0x600;
2163 Inst.addOperand(MCOperand::CreateImm(Value));
2164 }
2165
Jim Grosbach045b6c72011-12-19 23:51:07 +00002166 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2167 assert(N == 1 && "Invalid number of operands!");
2168 // The immediate encodes the type of constant as well as the value.
2169 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2170 unsigned Value = ~CE->getValue();
2171 if (Value >= 256 && Value <= 0xffff)
2172 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2173 else if (Value > 0xffff && Value <= 0xffffff)
2174 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2175 else if (Value > 0xffffff)
2176 Value = (Value >> 24) | 0x600;
2177 Inst.addOperand(MCOperand::CreateImm(Value));
2178 }
2179
Jim Grosbache4454e02011-10-18 16:18:11 +00002180 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2181 assert(N == 1 && "Invalid number of operands!");
2182 // The immediate encodes the type of constant as well as the value.
2183 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2184 uint64_t Value = CE->getValue();
2185 unsigned Imm = 0;
2186 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2187 Imm |= (Value & 1) << i;
2188 }
2189 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2190 }
2191
Jim Grosbach602aa902011-07-13 15:34:57 +00002192 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002193
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002194 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002195 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002196 Op->ITMask.Mask = Mask;
2197 Op->StartLoc = S;
2198 Op->EndLoc = S;
2199 return Op;
2200 }
2201
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002202 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002203 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002204 Op->CC.Val = CC;
2205 Op->StartLoc = S;
2206 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002207 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002208 }
2209
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002210 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002211 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002212 Op->Cop.Val = CopVal;
2213 Op->StartLoc = S;
2214 Op->EndLoc = S;
2215 return Op;
2216 }
2217
2218 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002219 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002220 Op->Cop.Val = CopVal;
2221 Op->StartLoc = S;
2222 Op->EndLoc = S;
2223 return Op;
2224 }
2225
Jim Grosbach48399582011-10-12 17:34:41 +00002226 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2227 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2228 Op->Cop.Val = Val;
2229 Op->StartLoc = S;
2230 Op->EndLoc = E;
2231 return Op;
2232 }
2233
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002234 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002235 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002236 Op->Reg.RegNum = RegNum;
2237 Op->StartLoc = S;
2238 Op->EndLoc = S;
2239 return Op;
2240 }
2241
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002242 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002243 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002244 Op->Tok.Data = Str.data();
2245 Op->Tok.Length = Str.size();
2246 Op->StartLoc = S;
2247 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002248 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002249 }
2250
Bill Wendling2063b842010-11-18 23:43:05 +00002251 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002252 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002253 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002254 Op->StartLoc = S;
2255 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002256 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002257 }
2258
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002259 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2260 unsigned SrcReg,
2261 unsigned ShiftReg,
2262 unsigned ShiftImm,
2263 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002264 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002265 Op->RegShiftedReg.ShiftTy = ShTy;
2266 Op->RegShiftedReg.SrcReg = SrcReg;
2267 Op->RegShiftedReg.ShiftReg = ShiftReg;
2268 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002269 Op->StartLoc = S;
2270 Op->EndLoc = E;
2271 return Op;
2272 }
2273
Owen Andersonb595ed02011-07-21 18:54:16 +00002274 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2275 unsigned SrcReg,
2276 unsigned ShiftImm,
2277 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002278 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002279 Op->RegShiftedImm.ShiftTy = ShTy;
2280 Op->RegShiftedImm.SrcReg = SrcReg;
2281 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002282 Op->StartLoc = S;
2283 Op->EndLoc = E;
2284 return Op;
2285 }
2286
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002287 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002288 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002289 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002290 Op->ShifterImm.isASR = isASR;
2291 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002292 Op->StartLoc = S;
2293 Op->EndLoc = E;
2294 return Op;
2295 }
2296
Jim Grosbach833b9d32011-07-27 20:15:40 +00002297 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002298 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002299 Op->RotImm.Imm = Imm;
2300 Op->StartLoc = S;
2301 Op->EndLoc = E;
2302 return Op;
2303 }
2304
Jim Grosbach864b6092011-07-28 21:34:26 +00002305 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2306 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002307 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002308 Op->Bitfield.LSB = LSB;
2309 Op->Bitfield.Width = Width;
2310 Op->StartLoc = S;
2311 Op->EndLoc = E;
2312 return Op;
2313 }
2314
Bill Wendling2cae3272010-11-09 22:44:22 +00002315 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002316 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002317 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002318 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002319 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002320
Chad Rosierfa705ee2013-07-01 20:49:23 +00002321 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002322 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002323 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002324 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002325 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002326
Chad Rosierfa705ee2013-07-01 20:49:23 +00002327 // Sort based on the register encoding values.
2328 array_pod_sort(Regs.begin(), Regs.end());
2329
Bill Wendling9898ac92010-11-17 04:32:08 +00002330 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002331 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002332 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002333 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002334 Op->StartLoc = StartLoc;
2335 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002336 return Op;
2337 }
2338
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002339 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002340 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002341 ARMOperand *Op = new ARMOperand(k_VectorList);
2342 Op->VectorList.RegNum = RegNum;
2343 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002344 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002345 Op->StartLoc = S;
2346 Op->EndLoc = E;
2347 return Op;
2348 }
2349
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002350 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002351 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002352 SMLoc S, SMLoc E) {
2353 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2354 Op->VectorList.RegNum = RegNum;
2355 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002356 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002357 Op->StartLoc = S;
2358 Op->EndLoc = E;
2359 return Op;
2360 }
2361
Jim Grosbach04945c42011-12-02 00:35:16 +00002362 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002363 unsigned Index,
2364 bool isDoubleSpaced,
2365 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002366 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2367 Op->VectorList.RegNum = RegNum;
2368 Op->VectorList.Count = Count;
2369 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002370 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002371 Op->StartLoc = S;
2372 Op->EndLoc = E;
2373 return Op;
2374 }
2375
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002376 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2377 MCContext &Ctx) {
2378 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2379 Op->VectorIndex.Val = Idx;
2380 Op->StartLoc = S;
2381 Op->EndLoc = E;
2382 return Op;
2383 }
2384
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002385 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002386 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002387 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002388 Op->StartLoc = S;
2389 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002390 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002391 }
2392
Jim Grosbachd3595712011-08-03 23:50:40 +00002393 static ARMOperand *CreateMem(unsigned BaseRegNum,
2394 const MCConstantExpr *OffsetImm,
2395 unsigned OffsetRegNum,
2396 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002397 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002398 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002399 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002400 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002401 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002402 Op->Memory.BaseRegNum = BaseRegNum;
2403 Op->Memory.OffsetImm = OffsetImm;
2404 Op->Memory.OffsetRegNum = OffsetRegNum;
2405 Op->Memory.ShiftType = ShiftType;
2406 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002407 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002408 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002409 Op->StartLoc = S;
2410 Op->EndLoc = E;
2411 return Op;
2412 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002413
Jim Grosbachc320c852011-08-05 21:28:30 +00002414 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2415 ARM_AM::ShiftOpc ShiftTy,
2416 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002417 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002418 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002419 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002420 Op->PostIdxReg.isAdd = isAdd;
2421 Op->PostIdxReg.ShiftTy = ShiftTy;
2422 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002423 Op->StartLoc = S;
2424 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002425 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002426 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002427
2428 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002429 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002430 Op->MBOpt.Val = Opt;
2431 Op->StartLoc = S;
2432 Op->EndLoc = S;
2433 return Op;
2434 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002435
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002436 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2437 SMLoc S) {
2438 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2439 Op->ISBOpt.Val = Opt;
2440 Op->StartLoc = S;
2441 Op->EndLoc = S;
2442 return Op;
2443 }
2444
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002445 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002446 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002447 Op->IFlags.Val = IFlags;
2448 Op->StartLoc = S;
2449 Op->EndLoc = S;
2450 return Op;
2451 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002452
2453 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002454 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002455 Op->MMask.Val = MMask;
2456 Op->StartLoc = S;
2457 Op->EndLoc = S;
2458 return Op;
2459 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002460};
2461
2462} // end anonymous namespace.
2463
Jim Grosbach602aa902011-07-13 15:34:57 +00002464void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002465 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002466 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002467 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002468 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002469 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002470 OS << "<ccout " << getReg() << ">";
2471 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002472 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002473 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002474 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2475 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2476 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002477 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2478 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2479 break;
2480 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002481 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002482 OS << "<coprocessor number: " << getCoproc() << ">";
2483 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002484 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002485 OS << "<coprocessor register: " << getCoproc() << ">";
2486 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002487 case k_CoprocOption:
2488 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2489 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002490 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002491 OS << "<mask: " << getMSRMask() << ">";
2492 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002493 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002494 getImm()->print(OS);
2495 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002496 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002497 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2498 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002499 case k_InstSyncBarrierOpt:
2500 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2501 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002502 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002503 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002504 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002505 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002506 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002507 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002508 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2509 << PostIdxReg.RegNum;
2510 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2511 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2512 << PostIdxReg.ShiftImm;
2513 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002514 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002515 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002516 OS << "<ARM_PROC::";
2517 unsigned IFlags = getProcIFlags();
2518 for (int i=2; i >= 0; --i)
2519 if (IFlags & (1 << i))
2520 OS << ARM_PROC::IFlagsToString(1 << i);
2521 OS << ">";
2522 break;
2523 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002524 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002525 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002526 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002527 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002528 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2529 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002530 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002531 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002532 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002533 << RegShiftedReg.SrcReg << " "
2534 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2535 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002536 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002537 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002538 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002539 << RegShiftedImm.SrcReg << " "
2540 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2541 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002542 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002543 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002544 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2545 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002546 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002547 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2548 << ", width: " << Bitfield.Width << ">";
2549 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002550 case k_RegisterList:
2551 case k_DPRRegisterList:
2552 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002553 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002554
Bill Wendlingbed94652010-11-09 23:28:44 +00002555 const SmallVectorImpl<unsigned> &RegList = getRegList();
2556 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002557 I = RegList.begin(), E = RegList.end(); I != E; ) {
2558 OS << *I;
2559 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002560 }
2561
2562 OS << ">";
2563 break;
2564 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002565 case k_VectorList:
2566 OS << "<vector_list " << VectorList.Count << " * "
2567 << VectorList.RegNum << ">";
2568 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002569 case k_VectorListAllLanes:
2570 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2571 << VectorList.RegNum << ">";
2572 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002573 case k_VectorListIndexed:
2574 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2575 << VectorList.Count << " * " << VectorList.RegNum << ">";
2576 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002577 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002578 OS << "'" << getToken() << "'";
2579 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002580 case k_VectorIndex:
2581 OS << "<vectorindex " << getVectorIndex() << ">";
2582 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002583 }
2584}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002585
2586/// @name Auto-generated Match Functions
2587/// {
2588
2589static unsigned MatchRegisterName(StringRef Name);
2590
2591/// }
2592
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002593bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2594 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002595 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002596 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002597 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002598
2599 return (RegNo == (unsigned)-1);
2600}
2601
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002602/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002603/// and if it is a register name the token is eaten and the register number is
2604/// returned. Otherwise return -1.
2605///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002606int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002607 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002608 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002609
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002610 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002611 unsigned RegNum = MatchRegisterName(lowerCase);
2612 if (!RegNum) {
2613 RegNum = StringSwitch<unsigned>(lowerCase)
2614 .Case("r13", ARM::SP)
2615 .Case("r14", ARM::LR)
2616 .Case("r15", ARM::PC)
2617 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002618 // Additional register name aliases for 'gas' compatibility.
2619 .Case("a1", ARM::R0)
2620 .Case("a2", ARM::R1)
2621 .Case("a3", ARM::R2)
2622 .Case("a4", ARM::R3)
2623 .Case("v1", ARM::R4)
2624 .Case("v2", ARM::R5)
2625 .Case("v3", ARM::R6)
2626 .Case("v4", ARM::R7)
2627 .Case("v5", ARM::R8)
2628 .Case("v6", ARM::R9)
2629 .Case("v7", ARM::R10)
2630 .Case("v8", ARM::R11)
2631 .Case("sb", ARM::R9)
2632 .Case("sl", ARM::R10)
2633 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002634 .Default(0);
2635 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002636 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002637 // Check for aliases registered via .req. Canonicalize to lower case.
2638 // That's more consistent since register names are case insensitive, and
2639 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2640 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002641 // If no match, return failure.
2642 if (Entry == RegisterReqs.end())
2643 return -1;
2644 Parser.Lex(); // Eat identifier token.
2645 return Entry->getValue();
2646 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002647
Chris Lattner44e5981c2010-10-30 04:09:10 +00002648 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002649
Chris Lattner44e5981c2010-10-30 04:09:10 +00002650 return RegNum;
2651}
Jim Grosbach99710a82010-11-01 16:44:21 +00002652
Jim Grosbachbb24c592011-07-13 18:49:30 +00002653// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2654// If a recoverable error occurs, return 1. If an irrecoverable error
2655// occurs, return -1. An irrecoverable error is one where tokens have been
2656// consumed in the process of trying to parse the shifter (i.e., when it is
2657// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002658int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002659 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2660 SMLoc S = Parser.getTok().getLoc();
2661 const AsmToken &Tok = Parser.getTok();
2662 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2663
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002664 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002665 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002666 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002667 .Case("lsl", ARM_AM::lsl)
2668 .Case("lsr", ARM_AM::lsr)
2669 .Case("asr", ARM_AM::asr)
2670 .Case("ror", ARM_AM::ror)
2671 .Case("rrx", ARM_AM::rrx)
2672 .Default(ARM_AM::no_shift);
2673
2674 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002675 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002676
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002677 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002678
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002679 // The source register for the shift has already been added to the
2680 // operand list, so we need to pop it off and combine it into the shifted
2681 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002682 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002683 if (!PrevOp->isReg())
2684 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2685 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002686
2687 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002688 int64_t Imm = 0;
2689 int ShiftReg = 0;
2690 if (ShiftTy == ARM_AM::rrx) {
2691 // RRX Doesn't have an explicit shift amount. The encoder expects
2692 // the shift register to be the same as the source register. Seems odd,
2693 // but OK.
2694 ShiftReg = SrcReg;
2695 } else {
2696 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002697 if (Parser.getTok().is(AsmToken::Hash) ||
2698 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002699 Parser.Lex(); // Eat hash.
2700 SMLoc ImmLoc = Parser.getTok().getLoc();
2701 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002702 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002703 Error(ImmLoc, "invalid immediate shift value");
2704 return -1;
2705 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002706 // The expression must be evaluatable as an immediate.
2707 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002708 if (!CE) {
2709 Error(ImmLoc, "invalid immediate shift value");
2710 return -1;
2711 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002712 // Range check the immediate.
2713 // lsl, ror: 0 <= imm <= 31
2714 // lsr, asr: 0 <= imm <= 32
2715 Imm = CE->getValue();
2716 if (Imm < 0 ||
2717 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2718 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002719 Error(ImmLoc, "immediate shift value out of range");
2720 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002721 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002722 // shift by zero is a nop. Always send it through as lsl.
2723 // ('as' compatibility)
2724 if (Imm == 0)
2725 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002726 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002727 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002728 EndLoc = Parser.getTok().getEndLoc();
2729 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002730 if (ShiftReg == -1) {
2731 Error (L, "expected immediate or register in shift operand");
2732 return -1;
2733 }
2734 } else {
2735 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002736 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002737 return -1;
2738 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002739 }
2740
Owen Andersonb595ed02011-07-21 18:54:16 +00002741 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2742 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002743 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002744 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002745 else
2746 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002747 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002748
Jim Grosbachbb24c592011-07-13 18:49:30 +00002749 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002750}
2751
2752
Bill Wendling2063b842010-11-18 23:43:05 +00002753/// Try to parse a register name. The token must be an Identifier when called.
2754/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2755/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002756///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002757/// TODO this is likely to change to allow different register types and or to
2758/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002759bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002760tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002761 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002762 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002763 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002764 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002765
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002766 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2767 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002768
Chris Lattner44e5981c2010-10-30 04:09:10 +00002769 const AsmToken &ExclaimTok = Parser.getTok();
2770 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002771 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2772 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002773 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002774 return false;
2775 }
2776
2777 // Also check for an index operand. This is only legal for vector registers,
2778 // but that'll get caught OK in operand matching, so we don't need to
2779 // explicitly filter everything else out here.
2780 if (Parser.getTok().is(AsmToken::LBrac)) {
2781 SMLoc SIdx = Parser.getTok().getLoc();
2782 Parser.Lex(); // Eat left bracket token.
2783
2784 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002785 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002786 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002787 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002788 if (!MCE)
2789 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002790
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002791 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002792 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002793
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002794 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002795 Parser.Lex(); // Eat right bracket token.
2796
2797 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2798 SIdx, E,
2799 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002800 }
2801
Bill Wendling2063b842010-11-18 23:43:05 +00002802 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002803}
2804
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002805/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2806/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2807/// "c5", ...
2808static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002809 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2810 // but efficient.
2811 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002812 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002813 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002814 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002815 return -1;
2816 switch (Name[1]) {
2817 default: return -1;
2818 case '0': return 0;
2819 case '1': return 1;
2820 case '2': return 2;
2821 case '3': return 3;
2822 case '4': return 4;
2823 case '5': return 5;
2824 case '6': return 6;
2825 case '7': return 7;
2826 case '8': return 8;
2827 case '9': return 9;
2828 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002829 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002830 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002831 return -1;
2832 switch (Name[2]) {
2833 default: return -1;
2834 case '0': return 10;
2835 case '1': return 11;
2836 case '2': return 12;
2837 case '3': return 13;
2838 case '4': return 14;
2839 case '5': return 15;
2840 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002841 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002842}
2843
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002844/// parseITCondCode - Try to parse a condition code for an IT instruction.
2845ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2846parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2847 SMLoc S = Parser.getTok().getLoc();
2848 const AsmToken &Tok = Parser.getTok();
2849 if (!Tok.is(AsmToken::Identifier))
2850 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002851 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002852 .Case("eq", ARMCC::EQ)
2853 .Case("ne", ARMCC::NE)
2854 .Case("hs", ARMCC::HS)
2855 .Case("cs", ARMCC::HS)
2856 .Case("lo", ARMCC::LO)
2857 .Case("cc", ARMCC::LO)
2858 .Case("mi", ARMCC::MI)
2859 .Case("pl", ARMCC::PL)
2860 .Case("vs", ARMCC::VS)
2861 .Case("vc", ARMCC::VC)
2862 .Case("hi", ARMCC::HI)
2863 .Case("ls", ARMCC::LS)
2864 .Case("ge", ARMCC::GE)
2865 .Case("lt", ARMCC::LT)
2866 .Case("gt", ARMCC::GT)
2867 .Case("le", ARMCC::LE)
2868 .Case("al", ARMCC::AL)
2869 .Default(~0U);
2870 if (CC == ~0U)
2871 return MatchOperand_NoMatch;
2872 Parser.Lex(); // Eat the token.
2873
2874 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2875
2876 return MatchOperand_Success;
2877}
2878
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002879/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002880/// token must be an Identifier when called, and if it is a coprocessor
2881/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002882ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002883parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002884 SMLoc S = Parser.getTok().getLoc();
2885 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002886 if (Tok.isNot(AsmToken::Identifier))
2887 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002888
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002889 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002890 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002891 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002892
2893 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002894 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002895 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002896}
2897
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002898/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002899/// token must be an Identifier when called, and if it is a coprocessor
2900/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002901ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002902parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002903 SMLoc S = Parser.getTok().getLoc();
2904 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002905 if (Tok.isNot(AsmToken::Identifier))
2906 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002907
2908 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2909 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002910 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002911
2912 Parser.Lex(); // Eat identifier token.
2913 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002914 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002915}
2916
Jim Grosbach48399582011-10-12 17:34:41 +00002917/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2918/// coproc_option : '{' imm0_255 '}'
2919ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2920parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2921 SMLoc S = Parser.getTok().getLoc();
2922
2923 // If this isn't a '{', this isn't a coprocessor immediate operand.
2924 if (Parser.getTok().isNot(AsmToken::LCurly))
2925 return MatchOperand_NoMatch;
2926 Parser.Lex(); // Eat the '{'
2927
2928 const MCExpr *Expr;
2929 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002930 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002931 Error(Loc, "illegal expression");
2932 return MatchOperand_ParseFail;
2933 }
2934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2935 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2936 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2937 return MatchOperand_ParseFail;
2938 }
2939 int Val = CE->getValue();
2940
2941 // Check for and consume the closing '}'
2942 if (Parser.getTok().isNot(AsmToken::RCurly))
2943 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002944 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002945 Parser.Lex(); // Eat the '}'
2946
2947 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2948 return MatchOperand_Success;
2949}
2950
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002951// For register list parsing, we need to map from raw GPR register numbering
2952// to the enumeration values. The enumeration values aren't sorted by
2953// register number due to our using "sp", "lr" and "pc" as canonical names.
2954static unsigned getNextRegister(unsigned Reg) {
2955 // If this is a GPR, we need to do it manually, otherwise we can rely
2956 // on the sort ordering of the enumeration since the other reg-classes
2957 // are sane.
2958 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2959 return Reg + 1;
2960 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002961 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002962 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2963 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2964 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2965 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2966 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2967 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2968 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2969 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2970 }
2971}
2972
Jim Grosbach85a23432011-11-11 21:27:40 +00002973// Return the low-subreg of a given Q register.
2974static unsigned getDRegFromQReg(unsigned QReg) {
2975 switch (QReg) {
2976 default: llvm_unreachable("expected a Q register!");
2977 case ARM::Q0: return ARM::D0;
2978 case ARM::Q1: return ARM::D2;
2979 case ARM::Q2: return ARM::D4;
2980 case ARM::Q3: return ARM::D6;
2981 case ARM::Q4: return ARM::D8;
2982 case ARM::Q5: return ARM::D10;
2983 case ARM::Q6: return ARM::D12;
2984 case ARM::Q7: return ARM::D14;
2985 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002986 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002987 case ARM::Q10: return ARM::D20;
2988 case ARM::Q11: return ARM::D22;
2989 case ARM::Q12: return ARM::D24;
2990 case ARM::Q13: return ARM::D26;
2991 case ARM::Q14: return ARM::D28;
2992 case ARM::Q15: return ARM::D30;
2993 }
2994}
2995
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002996/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002997bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002998parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002999 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003000 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003001 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003002 Parser.Lex(); // Eat '{' token.
3003 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003004
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003005 // Check the first register in the list to see what register class
3006 // this is a list of.
3007 int Reg = tryParseRegister();
3008 if (Reg == -1)
3009 return Error(RegLoc, "register expected");
3010
Jim Grosbach85a23432011-11-11 21:27:40 +00003011 // The reglist instructions have at most 16 registers, so reserve
3012 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003013 int EReg = 0;
3014 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003015
3016 // Allow Q regs and just interpret them as the two D sub-registers.
3017 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3018 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003019 EReg = MRI->getEncodingValue(Reg);
3020 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003021 ++Reg;
3022 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003023 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003024 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3025 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3026 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3027 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3028 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3029 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3030 else
3031 return Error(RegLoc, "invalid register in register list");
3032
Jim Grosbach85a23432011-11-11 21:27:40 +00003033 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003034 EReg = MRI->getEncodingValue(Reg);
3035 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003036
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003037 // This starts immediately after the first register token in the list,
3038 // so we can see either a comma or a minus (range separator) as a legal
3039 // next token.
3040 while (Parser.getTok().is(AsmToken::Comma) ||
3041 Parser.getTok().is(AsmToken::Minus)) {
3042 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003043 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003044 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003045 int EndReg = tryParseRegister();
3046 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003047 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003048 // Allow Q regs and just interpret them as the two D sub-registers.
3049 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3050 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003051 // If the register is the same as the start reg, there's nothing
3052 // more to do.
3053 if (Reg == EndReg)
3054 continue;
3055 // The register must be in the same register class as the first.
3056 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003057 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003058 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003059 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003060 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003061
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003062 // Add all the registers in the range to the register list.
3063 while (Reg != EndReg) {
3064 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003065 EReg = MRI->getEncodingValue(Reg);
3066 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003067 }
3068 continue;
3069 }
3070 Parser.Lex(); // Eat the comma.
3071 RegLoc = Parser.getTok().getLoc();
3072 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003073 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003074 Reg = tryParseRegister();
3075 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003076 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003077 // Allow Q regs and just interpret them as the two D sub-registers.
3078 bool isQReg = false;
3079 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3080 Reg = getDRegFromQReg(Reg);
3081 isQReg = true;
3082 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003083 // The register must be in the same register class as the first.
3084 if (!RC->contains(Reg))
3085 return Error(RegLoc, "invalid register in register list");
3086 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003087 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003088 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3089 Warning(RegLoc, "register list not in ascending order");
3090 else
3091 return Error(RegLoc, "register list not in ascending order");
3092 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003093 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003094 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3095 ") in register list");
3096 continue;
3097 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003098 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003099 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3100 Reg != OldReg + 1)
3101 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003102 EReg = MRI->getEncodingValue(Reg);
3103 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3104 if (isQReg) {
3105 EReg = MRI->getEncodingValue(++Reg);
3106 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3107 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003108 }
3109
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003110 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003111 return Error(Parser.getTok().getLoc(), "'}' expected");
3112 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003113 Parser.Lex(); // Eat '}' token.
3114
Jim Grosbach18bf3632011-12-13 21:48:29 +00003115 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003116 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003117
3118 // The ARM system instruction variants for LDM/STM have a '^' token here.
3119 if (Parser.getTok().is(AsmToken::Caret)) {
3120 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3121 Parser.Lex(); // Eat '^' token.
3122 }
3123
Bill Wendling2063b842010-11-18 23:43:05 +00003124 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003125}
3126
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003127// Helper function to parse the lane index for vector lists.
3128ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003129parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003130 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003131 if (Parser.getTok().is(AsmToken::LBrac)) {
3132 Parser.Lex(); // Eat the '['.
3133 if (Parser.getTok().is(AsmToken::RBrac)) {
3134 // "Dn[]" is the 'all lanes' syntax.
3135 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003136 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003137 Parser.Lex(); // Eat the ']'.
3138 return MatchOperand_Success;
3139 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003140
3141 // There's an optional '#' token here. Normally there wouldn't be, but
3142 // inline assemble puts one in, and it's friendly to accept that.
3143 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003144 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003145
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003146 const MCExpr *LaneIndex;
3147 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003148 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003149 Error(Loc, "illegal expression");
3150 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003151 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003152 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3153 if (!CE) {
3154 Error(Loc, "lane index must be empty or an integer");
3155 return MatchOperand_ParseFail;
3156 }
3157 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3158 Error(Parser.getTok().getLoc(), "']' expected");
3159 return MatchOperand_ParseFail;
3160 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003161 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003162 Parser.Lex(); // Eat the ']'.
3163 int64_t Val = CE->getValue();
3164
3165 // FIXME: Make this range check context sensitive for .8, .16, .32.
3166 if (Val < 0 || Val > 7) {
3167 Error(Parser.getTok().getLoc(), "lane index out of range");
3168 return MatchOperand_ParseFail;
3169 }
3170 Index = Val;
3171 LaneKind = IndexedLane;
3172 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003173 }
3174 LaneKind = NoLanes;
3175 return MatchOperand_Success;
3176}
3177
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003178// parse a vector register list
3179ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3180parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003181 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003182 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003183 SMLoc S = Parser.getTok().getLoc();
3184 // As an extension (to match gas), support a plain D register or Q register
3185 // (without encosing curly braces) as a single or double entry list,
3186 // respectively.
3187 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003188 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003189 int Reg = tryParseRegister();
3190 if (Reg == -1)
3191 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003192 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003193 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003194 if (Res != MatchOperand_Success)
3195 return Res;
3196 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003197 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003198 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003199 break;
3200 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003201 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3202 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003203 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003204 case IndexedLane:
3205 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003206 LaneIndex,
3207 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003208 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003209 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003210 return MatchOperand_Success;
3211 }
3212 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3213 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003214 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003215 if (Res != MatchOperand_Success)
3216 return Res;
3217 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003218 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003219 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003220 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003221 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003222 break;
3223 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003224 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3225 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003226 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3227 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003228 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003229 case IndexedLane:
3230 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003231 LaneIndex,
3232 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003233 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003234 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003235 return MatchOperand_Success;
3236 }
3237 Error(S, "vector register expected");
3238 return MatchOperand_ParseFail;
3239 }
3240
3241 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003242 return MatchOperand_NoMatch;
3243
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003244 Parser.Lex(); // Eat '{' token.
3245 SMLoc RegLoc = Parser.getTok().getLoc();
3246
3247 int Reg = tryParseRegister();
3248 if (Reg == -1) {
3249 Error(RegLoc, "register expected");
3250 return MatchOperand_ParseFail;
3251 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003252 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003253 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003254 unsigned FirstReg = Reg;
3255 // The list is of D registers, but we also allow Q regs and just interpret
3256 // them as the two D sub-registers.
3257 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3258 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003259 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3260 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003261 ++Reg;
3262 ++Count;
3263 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003264
3265 SMLoc E;
3266 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003267 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003268
Jim Grosbache891fe82011-11-15 23:19:15 +00003269 while (Parser.getTok().is(AsmToken::Comma) ||
3270 Parser.getTok().is(AsmToken::Minus)) {
3271 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003272 if (!Spacing)
3273 Spacing = 1; // Register range implies a single spaced list.
3274 else if (Spacing == 2) {
3275 Error(Parser.getTok().getLoc(),
3276 "sequential registers in double spaced list");
3277 return MatchOperand_ParseFail;
3278 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003279 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003280 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003281 int EndReg = tryParseRegister();
3282 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003283 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003284 return MatchOperand_ParseFail;
3285 }
3286 // Allow Q regs and just interpret them as the two D sub-registers.
3287 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3288 EndReg = getDRegFromQReg(EndReg) + 1;
3289 // If the register is the same as the start reg, there's nothing
3290 // more to do.
3291 if (Reg == EndReg)
3292 continue;
3293 // The register must be in the same register class as the first.
3294 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003295 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003296 return MatchOperand_ParseFail;
3297 }
3298 // Ranges must go from low to high.
3299 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003300 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003301 return MatchOperand_ParseFail;
3302 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003303 // Parse the lane specifier if present.
3304 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003305 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003306 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3307 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003308 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003309 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003310 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003311 return MatchOperand_ParseFail;
3312 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003313
3314 // Add all the registers in the range to the register list.
3315 Count += EndReg - Reg;
3316 Reg = EndReg;
3317 continue;
3318 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003319 Parser.Lex(); // Eat the comma.
3320 RegLoc = Parser.getTok().getLoc();
3321 int OldReg = Reg;
3322 Reg = tryParseRegister();
3323 if (Reg == -1) {
3324 Error(RegLoc, "register expected");
3325 return MatchOperand_ParseFail;
3326 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003327 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003328 // It's OK to use the enumeration values directly here rather, as the
3329 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003330 //
3331 // The list is of D registers, but we also allow Q regs and just interpret
3332 // them as the two D sub-registers.
3333 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003334 if (!Spacing)
3335 Spacing = 1; // Register range implies a single spaced list.
3336 else if (Spacing == 2) {
3337 Error(RegLoc,
3338 "invalid register in double-spaced list (must be 'D' register')");
3339 return MatchOperand_ParseFail;
3340 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003341 Reg = getDRegFromQReg(Reg);
3342 if (Reg != OldReg + 1) {
3343 Error(RegLoc, "non-contiguous register range");
3344 return MatchOperand_ParseFail;
3345 }
3346 ++Reg;
3347 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003348 // Parse the lane specifier if present.
3349 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003350 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003351 SMLoc LaneLoc = Parser.getTok().getLoc();
3352 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3353 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003354 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003355 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003356 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003357 return MatchOperand_ParseFail;
3358 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003359 continue;
3360 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003361 // Normal D register.
3362 // Figure out the register spacing (single or double) of the list if
3363 // we don't know it already.
3364 if (!Spacing)
3365 Spacing = 1 + (Reg == OldReg + 2);
3366
3367 // Just check that it's contiguous and keep going.
3368 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003369 Error(RegLoc, "non-contiguous register range");
3370 return MatchOperand_ParseFail;
3371 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003372 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003373 // Parse the lane specifier if present.
3374 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003375 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003376 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003377 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != 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) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003380 Error(EndLoc, "mismatched lane index in register list");
3381 return MatchOperand_ParseFail;
3382 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003383 }
3384
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003385 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003386 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003387 return MatchOperand_ParseFail;
3388 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003389 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003390 Parser.Lex(); // Eat '}' token.
3391
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003392 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003393 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003394 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003395 // composite register classes.
3396 if (Count == 2) {
3397 const MCRegisterClass *RC = (Spacing == 1) ?
3398 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3399 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3400 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3401 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003402
Jim Grosbach2f50e922011-12-15 21:44:33 +00003403 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3404 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003405 break;
3406 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003407 // Two-register operands have been converted to the
3408 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003409 if (Count == 2) {
3410 const MCRegisterClass *RC = (Spacing == 1) ?
3411 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3412 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003413 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3414 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003415 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003416 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003417 S, E));
3418 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003419 case IndexedLane:
3420 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003421 LaneIndex,
3422 (Spacing == 2),
3423 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003424 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003425 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003426 return MatchOperand_Success;
3427}
3428
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003429/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003430ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003431parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003432 SMLoc S = Parser.getTok().getLoc();
3433 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003434 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003435
Jiangning Liu288e1af2012-08-02 08:21:27 +00003436 if (Tok.is(AsmToken::Identifier)) {
3437 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003438
Jiangning Liu288e1af2012-08-02 08:21:27 +00003439 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3440 .Case("sy", ARM_MB::SY)
3441 .Case("st", ARM_MB::ST)
3442 .Case("sh", ARM_MB::ISH)
3443 .Case("ish", ARM_MB::ISH)
3444 .Case("shst", ARM_MB::ISHST)
3445 .Case("ishst", ARM_MB::ISHST)
3446 .Case("nsh", ARM_MB::NSH)
3447 .Case("un", ARM_MB::NSH)
3448 .Case("nshst", ARM_MB::NSHST)
3449 .Case("unst", ARM_MB::NSHST)
3450 .Case("osh", ARM_MB::OSH)
3451 .Case("oshst", ARM_MB::OSHST)
3452 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003453
Jiangning Liu288e1af2012-08-02 08:21:27 +00003454 if (Opt == ~0U)
3455 return MatchOperand_NoMatch;
3456
3457 Parser.Lex(); // Eat identifier token.
3458 } else if (Tok.is(AsmToken::Hash) ||
3459 Tok.is(AsmToken::Dollar) ||
3460 Tok.is(AsmToken::Integer)) {
3461 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003462 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003463 SMLoc Loc = Parser.getTok().getLoc();
3464
3465 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003466 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003467 Error(Loc, "illegal expression");
3468 return MatchOperand_ParseFail;
3469 }
3470
3471 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3472 if (!CE) {
3473 Error(Loc, "constant expression expected");
3474 return MatchOperand_ParseFail;
3475 }
3476
3477 int Val = CE->getValue();
3478 if (Val & ~0xf) {
3479 Error(Loc, "immediate value out of range");
3480 return MatchOperand_ParseFail;
3481 }
3482
3483 Opt = ARM_MB::RESERVED_0 + Val;
3484 } else
3485 return MatchOperand_ParseFail;
3486
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003487 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003488 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003489}
3490
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003491/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3492ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3493parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3494 SMLoc S = Parser.getTok().getLoc();
3495 const AsmToken &Tok = Parser.getTok();
3496 unsigned Opt;
3497
3498 if (Tok.is(AsmToken::Identifier)) {
3499 StringRef OptStr = Tok.getString();
3500
3501 if (OptStr.lower() == "sy")
3502 Opt = ARM_ISB::SY;
3503 else
3504 return MatchOperand_NoMatch;
3505
3506 Parser.Lex(); // Eat identifier token.
3507 } else if (Tok.is(AsmToken::Hash) ||
3508 Tok.is(AsmToken::Dollar) ||
3509 Tok.is(AsmToken::Integer)) {
3510 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003511 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003512 SMLoc Loc = Parser.getTok().getLoc();
3513
3514 const MCExpr *ISBarrierID;
3515 if (getParser().parseExpression(ISBarrierID)) {
3516 Error(Loc, "illegal expression");
3517 return MatchOperand_ParseFail;
3518 }
3519
3520 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3521 if (!CE) {
3522 Error(Loc, "constant expression expected");
3523 return MatchOperand_ParseFail;
3524 }
3525
3526 int Val = CE->getValue();
3527 if (Val & ~0xf) {
3528 Error(Loc, "immediate value out of range");
3529 return MatchOperand_ParseFail;
3530 }
3531
3532 Opt = ARM_ISB::RESERVED_0 + Val;
3533 } else
3534 return MatchOperand_ParseFail;
3535
3536 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3537 (ARM_ISB::InstSyncBOpt)Opt, S));
3538 return MatchOperand_Success;
3539}
3540
3541
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003542/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003543ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003544parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003545 SMLoc S = Parser.getTok().getLoc();
3546 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003547 if (!Tok.is(AsmToken::Identifier))
3548 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003549 StringRef IFlagsStr = Tok.getString();
3550
Owen Anderson10c5b122011-10-05 17:16:40 +00003551 // An iflags string of "none" is interpreted to mean that none of the AIF
3552 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003553 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003554 if (IFlagsStr != "none") {
3555 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3556 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3557 .Case("a", ARM_PROC::A)
3558 .Case("i", ARM_PROC::I)
3559 .Case("f", ARM_PROC::F)
3560 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003561
Owen Anderson10c5b122011-10-05 17:16:40 +00003562 // If some specific iflag is already set, it means that some letter is
3563 // present more than once, this is not acceptable.
3564 if (Flag == ~0U || (IFlags & Flag))
3565 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003566
Owen Anderson10c5b122011-10-05 17:16:40 +00003567 IFlags |= Flag;
3568 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003569 }
3570
3571 Parser.Lex(); // Eat identifier token.
3572 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3573 return MatchOperand_Success;
3574}
3575
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003576/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003577ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003578parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003579 SMLoc S = Parser.getTok().getLoc();
3580 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003581 if (!Tok.is(AsmToken::Identifier))
3582 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003583 StringRef Mask = Tok.getString();
3584
James Molloy21efa7d2011-09-28 14:21:38 +00003585 if (isMClass()) {
3586 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003587 std::string Name = Mask.lower();
3588 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003589 // Note: in the documentation:
3590 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3591 // for MSR APSR_nzcvq.
3592 // but we do make it an alias here. This is so to get the "mask encoding"
3593 // bits correct on MSR APSR writes.
3594 //
3595 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3596 // should really only be allowed when writing a special register. Note
3597 // they get dropped in the MRS instruction reading a special register as
3598 // the SYSm field is only 8 bits.
3599 //
3600 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3601 // includes the DSP extension but that is not checked.
3602 .Case("apsr", 0x800)
3603 .Case("apsr_nzcvq", 0x800)
3604 .Case("apsr_g", 0x400)
3605 .Case("apsr_nzcvqg", 0xc00)
3606 .Case("iapsr", 0x801)
3607 .Case("iapsr_nzcvq", 0x801)
3608 .Case("iapsr_g", 0x401)
3609 .Case("iapsr_nzcvqg", 0xc01)
3610 .Case("eapsr", 0x802)
3611 .Case("eapsr_nzcvq", 0x802)
3612 .Case("eapsr_g", 0x402)
3613 .Case("eapsr_nzcvqg", 0xc02)
3614 .Case("xpsr", 0x803)
3615 .Case("xpsr_nzcvq", 0x803)
3616 .Case("xpsr_g", 0x403)
3617 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003618 .Case("ipsr", 0x805)
3619 .Case("epsr", 0x806)
3620 .Case("iepsr", 0x807)
3621 .Case("msp", 0x808)
3622 .Case("psp", 0x809)
3623 .Case("primask", 0x810)
3624 .Case("basepri", 0x811)
3625 .Case("basepri_max", 0x812)
3626 .Case("faultmask", 0x813)
3627 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003628 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003629
James Molloy21efa7d2011-09-28 14:21:38 +00003630 if (FlagsVal == ~0U)
3631 return MatchOperand_NoMatch;
3632
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003633 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003634 // basepri, basepri_max and faultmask only valid for V7m.
3635 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003636
James Molloy21efa7d2011-09-28 14:21:38 +00003637 Parser.Lex(); // Eat identifier token.
3638 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3639 return MatchOperand_Success;
3640 }
3641
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003642 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3643 size_t Start = 0, Next = Mask.find('_');
3644 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003645 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003646 if (Next != StringRef::npos)
3647 Flags = Mask.slice(Next+1, Mask.size());
3648
3649 // FlagsVal contains the complete mask:
3650 // 3-0: Mask
3651 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3652 unsigned FlagsVal = 0;
3653
3654 if (SpecReg == "apsr") {
3655 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003656 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003657 .Case("g", 0x4) // same as CPSR_s
3658 .Case("nzcvqg", 0xc) // same as CPSR_fs
3659 .Default(~0U);
3660
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003661 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003662 if (!Flags.empty())
3663 return MatchOperand_NoMatch;
3664 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003665 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003666 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003667 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003668 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3669 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003670 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003671 for (int i = 0, e = Flags.size(); i != e; ++i) {
3672 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3673 .Case("c", 1)
3674 .Case("x", 2)
3675 .Case("s", 4)
3676 .Case("f", 8)
3677 .Default(~0U);
3678
3679 // If some specific flag is already set, it means that some letter is
3680 // present more than once, this is not acceptable.
3681 if (FlagsVal == ~0U || (FlagsVal & Flag))
3682 return MatchOperand_NoMatch;
3683 FlagsVal |= Flag;
3684 }
3685 } else // No match for special register.
3686 return MatchOperand_NoMatch;
3687
Owen Anderson03a173e2011-10-21 18:43:28 +00003688 // Special register without flags is NOT equivalent to "fc" flags.
3689 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3690 // two lines would enable gas compatibility at the expense of breaking
3691 // round-tripping.
3692 //
3693 // if (!FlagsVal)
3694 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003695
3696 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3697 if (SpecReg == "spsr")
3698 FlagsVal |= 16;
3699
3700 Parser.Lex(); // Eat identifier token.
3701 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3702 return MatchOperand_Success;
3703}
3704
Jim Grosbach27c1e252011-07-21 17:23:04 +00003705ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3706parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3707 int Low, int High) {
3708 const AsmToken &Tok = Parser.getTok();
3709 if (Tok.isNot(AsmToken::Identifier)) {
3710 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3711 return MatchOperand_ParseFail;
3712 }
3713 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003714 std::string LowerOp = Op.lower();
3715 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003716 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3717 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3718 return MatchOperand_ParseFail;
3719 }
3720 Parser.Lex(); // Eat shift type token.
3721
3722 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003723 if (Parser.getTok().isNot(AsmToken::Hash) &&
3724 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003725 Error(Parser.getTok().getLoc(), "'#' expected");
3726 return MatchOperand_ParseFail;
3727 }
3728 Parser.Lex(); // Eat hash token.
3729
3730 const MCExpr *ShiftAmount;
3731 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003732 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003733 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003734 Error(Loc, "illegal expression");
3735 return MatchOperand_ParseFail;
3736 }
3737 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3738 if (!CE) {
3739 Error(Loc, "constant expression expected");
3740 return MatchOperand_ParseFail;
3741 }
3742 int Val = CE->getValue();
3743 if (Val < Low || Val > High) {
3744 Error(Loc, "immediate value out of range");
3745 return MatchOperand_ParseFail;
3746 }
3747
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003748 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003749
3750 return MatchOperand_Success;
3751}
3752
Jim Grosbach0a547702011-07-22 17:44:50 +00003753ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3754parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3755 const AsmToken &Tok = Parser.getTok();
3756 SMLoc S = Tok.getLoc();
3757 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003758 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003759 return MatchOperand_ParseFail;
3760 }
Tim Northover4d141442013-05-31 15:58:45 +00003761 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003762 .Case("be", 1)
3763 .Case("le", 0)
3764 .Default(-1);
3765 Parser.Lex(); // Eat the token.
3766
3767 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003768 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003769 return MatchOperand_ParseFail;
3770 }
3771 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3772 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003773 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003774 return MatchOperand_Success;
3775}
3776
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003777/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3778/// instructions. Legal values are:
3779/// lsl #n 'n' in [0,31]
3780/// asr #n 'n' in [1,32]
3781/// n == 32 encoded as n == 0.
3782ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3783parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3784 const AsmToken &Tok = Parser.getTok();
3785 SMLoc S = Tok.getLoc();
3786 if (Tok.isNot(AsmToken::Identifier)) {
3787 Error(S, "shift operator 'asr' or 'lsl' expected");
3788 return MatchOperand_ParseFail;
3789 }
3790 StringRef ShiftName = Tok.getString();
3791 bool isASR;
3792 if (ShiftName == "lsl" || ShiftName == "LSL")
3793 isASR = false;
3794 else if (ShiftName == "asr" || ShiftName == "ASR")
3795 isASR = true;
3796 else {
3797 Error(S, "shift operator 'asr' or 'lsl' expected");
3798 return MatchOperand_ParseFail;
3799 }
3800 Parser.Lex(); // Eat the operator.
3801
3802 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003803 if (Parser.getTok().isNot(AsmToken::Hash) &&
3804 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003805 Error(Parser.getTok().getLoc(), "'#' expected");
3806 return MatchOperand_ParseFail;
3807 }
3808 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003809 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003810
3811 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003812 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003813 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003814 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003815 return MatchOperand_ParseFail;
3816 }
3817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3818 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003819 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003820 return MatchOperand_ParseFail;
3821 }
3822
3823 int64_t Val = CE->getValue();
3824 if (isASR) {
3825 // Shift amount must be in [1,32]
3826 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003827 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003828 return MatchOperand_ParseFail;
3829 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003830 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3831 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003832 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003833 return MatchOperand_ParseFail;
3834 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003835 if (Val == 32) Val = 0;
3836 } else {
3837 // Shift amount must be in [1,32]
3838 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003839 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003840 return MatchOperand_ParseFail;
3841 }
3842 }
3843
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003844 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003845
3846 return MatchOperand_Success;
3847}
3848
Jim Grosbach833b9d32011-07-27 20:15:40 +00003849/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3850/// of instructions. Legal values are:
3851/// ror #n 'n' in {0, 8, 16, 24}
3852ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3853parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3854 const AsmToken &Tok = Parser.getTok();
3855 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003856 if (Tok.isNot(AsmToken::Identifier))
3857 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003858 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003859 if (ShiftName != "ror" && ShiftName != "ROR")
3860 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003861 Parser.Lex(); // Eat the operator.
3862
3863 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003864 if (Parser.getTok().isNot(AsmToken::Hash) &&
3865 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003866 Error(Parser.getTok().getLoc(), "'#' expected");
3867 return MatchOperand_ParseFail;
3868 }
3869 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003870 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003871
3872 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003873 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003874 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003875 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003876 return MatchOperand_ParseFail;
3877 }
3878 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3879 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003880 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003881 return MatchOperand_ParseFail;
3882 }
3883
3884 int64_t Val = CE->getValue();
3885 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3886 // normally, zero is represented in asm by omitting the rotate operand
3887 // entirely.
3888 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003889 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003890 return MatchOperand_ParseFail;
3891 }
3892
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003893 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003894
3895 return MatchOperand_Success;
3896}
3897
Jim Grosbach864b6092011-07-28 21:34:26 +00003898ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3899parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3900 SMLoc S = Parser.getTok().getLoc();
3901 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003902 if (Parser.getTok().isNot(AsmToken::Hash) &&
3903 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003904 Error(Parser.getTok().getLoc(), "'#' expected");
3905 return MatchOperand_ParseFail;
3906 }
3907 Parser.Lex(); // Eat hash token.
3908
3909 const MCExpr *LSBExpr;
3910 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003911 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003912 Error(E, "malformed immediate expression");
3913 return MatchOperand_ParseFail;
3914 }
3915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3916 if (!CE) {
3917 Error(E, "'lsb' operand must be an immediate");
3918 return MatchOperand_ParseFail;
3919 }
3920
3921 int64_t LSB = CE->getValue();
3922 // The LSB must be in the range [0,31]
3923 if (LSB < 0 || LSB > 31) {
3924 Error(E, "'lsb' operand must be in the range [0,31]");
3925 return MatchOperand_ParseFail;
3926 }
3927 E = Parser.getTok().getLoc();
3928
3929 // Expect another immediate operand.
3930 if (Parser.getTok().isNot(AsmToken::Comma)) {
3931 Error(Parser.getTok().getLoc(), "too few operands");
3932 return MatchOperand_ParseFail;
3933 }
3934 Parser.Lex(); // Eat hash token.
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 *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003943 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003944 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003945 Error(E, "malformed immediate expression");
3946 return MatchOperand_ParseFail;
3947 }
3948 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3949 if (!CE) {
3950 Error(E, "'width' operand must be an immediate");
3951 return MatchOperand_ParseFail;
3952 }
3953
3954 int64_t Width = CE->getValue();
3955 // The LSB must be in the range [1,32-lsb]
3956 if (Width < 1 || Width > 32 - LSB) {
3957 Error(E, "'width' operand must be in the range [1,32-lsb]");
3958 return MatchOperand_ParseFail;
3959 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003960
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003961 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003962
3963 return MatchOperand_Success;
3964}
3965
Jim Grosbachd3595712011-08-03 23:50:40 +00003966ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3967parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3968 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003969 // postidx_reg := '+' register {, shift}
3970 // | '-' register {, shift}
3971 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003972
3973 // This method must return MatchOperand_NoMatch without consuming any tokens
3974 // in the case where there is no match, as other alternatives take other
3975 // parse methods.
3976 AsmToken Tok = Parser.getTok();
3977 SMLoc S = Tok.getLoc();
3978 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003979 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003980 if (Tok.is(AsmToken::Plus)) {
3981 Parser.Lex(); // Eat the '+' token.
3982 haveEaten = true;
3983 } else if (Tok.is(AsmToken::Minus)) {
3984 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003985 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003986 haveEaten = true;
3987 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003988
3989 SMLoc E = Parser.getTok().getEndLoc();
3990 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00003991 if (Reg == -1) {
3992 if (!haveEaten)
3993 return MatchOperand_NoMatch;
3994 Error(Parser.getTok().getLoc(), "register expected");
3995 return MatchOperand_ParseFail;
3996 }
Jim Grosbachd3595712011-08-03 23:50:40 +00003997
Jim Grosbachc320c852011-08-05 21:28:30 +00003998 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3999 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004000 if (Parser.getTok().is(AsmToken::Comma)) {
4001 Parser.Lex(); // Eat the ','.
4002 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4003 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004004
4005 // FIXME: Only approximates end...may include intervening whitespace.
4006 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004007 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004008
4009 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4010 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004011
4012 return MatchOperand_Success;
4013}
4014
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004015ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4016parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4017 // Check for a post-index addressing register operand. Specifically:
4018 // am3offset := '+' register
4019 // | '-' register
4020 // | register
4021 // | # imm
4022 // | # + imm
4023 // | # - imm
4024
4025 // This method must return MatchOperand_NoMatch without consuming any tokens
4026 // in the case where there is no match, as other alternatives take other
4027 // parse methods.
4028 AsmToken Tok = Parser.getTok();
4029 SMLoc S = Tok.getLoc();
4030
4031 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004032 if (Parser.getTok().is(AsmToken::Hash) ||
4033 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004034 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004035 // Explicitly look for a '-', as we need to encode negative zero
4036 // differently.
4037 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4038 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004039 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004040 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004041 return MatchOperand_ParseFail;
4042 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4043 if (!CE) {
4044 Error(S, "constant expression expected");
4045 return MatchOperand_ParseFail;
4046 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004047 // Negative zero is encoded as the flag value INT32_MIN.
4048 int32_t Val = CE->getValue();
4049 if (isNegative && Val == 0)
4050 Val = INT32_MIN;
4051
4052 Operands.push_back(
4053 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4054
4055 return MatchOperand_Success;
4056 }
4057
4058
4059 bool haveEaten = false;
4060 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004061 if (Tok.is(AsmToken::Plus)) {
4062 Parser.Lex(); // Eat the '+' token.
4063 haveEaten = true;
4064 } else if (Tok.is(AsmToken::Minus)) {
4065 Parser.Lex(); // Eat the '-' token.
4066 isAdd = false;
4067 haveEaten = true;
4068 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004069
4070 Tok = Parser.getTok();
4071 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004072 if (Reg == -1) {
4073 if (!haveEaten)
4074 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004075 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004076 return MatchOperand_ParseFail;
4077 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004078
4079 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004080 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004081
4082 return MatchOperand_Success;
4083}
4084
Tim Northovereb5e4d52013-07-22 09:06:12 +00004085/// Convert parsed operands to MCInst. Needed here because this instruction
4086/// only has two register operands, but multiplication is commutative so
4087/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004088void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004089cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004090 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004091 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4092 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004093 // If we have a three-operand form, make sure to set Rn to be the operand
4094 // that isn't the same as Rd.
4095 unsigned RegOp = 4;
4096 if (Operands.size() == 6 &&
4097 ((ARMOperand*)Operands[4])->getReg() ==
4098 ((ARMOperand*)Operands[3])->getReg())
4099 RegOp = 5;
4100 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4101 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004102 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004103}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004104
Bill Wendlinge18980a2010-11-06 22:36:58 +00004105/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004106/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004107bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004108parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004109 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004110 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004111 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004112 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004113 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004114
Sean Callanan936b0d32010-01-19 21:44:56 +00004115 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004116 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004117 if (BaseRegNum == -1)
4118 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004119
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004120 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004121 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004122 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4123 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004124 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004125
Jim Grosbachd3595712011-08-03 23:50:40 +00004126 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004127 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004128 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004129
Jim Grosbachd3595712011-08-03 23:50:40 +00004130 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004131 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004132
Jim Grosbach40700e02011-09-19 18:42:21 +00004133 // If there's a pre-indexing writeback marker, '!', just add it as a token
4134 // operand. It's rather odd, but syntactically valid.
4135 if (Parser.getTok().is(AsmToken::Exclaim)) {
4136 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4137 Parser.Lex(); // Eat the '!'.
4138 }
4139
Jim Grosbachd3595712011-08-03 23:50:40 +00004140 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004141 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004142
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004143 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4144 "Lost colon or comma in memory operand?!");
4145 if (Tok.is(AsmToken::Comma)) {
4146 Parser.Lex(); // Eat the comma.
4147 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004148
Jim Grosbacha95ec992011-10-11 17:29:55 +00004149 // If we have a ':', it's an alignment specifier.
4150 if (Parser.getTok().is(AsmToken::Colon)) {
4151 Parser.Lex(); // Eat the ':'.
4152 E = Parser.getTok().getLoc();
4153
4154 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004155 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004156 return true;
4157
4158 // The expression has to be a constant. Memory references with relocations
4159 // don't come through here, as they use the <label> forms of the relevant
4160 // instructions.
4161 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4162 if (!CE)
4163 return Error (E, "constant expression expected");
4164
4165 unsigned Align = 0;
4166 switch (CE->getValue()) {
4167 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004168 return Error(E,
4169 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4170 case 16: Align = 2; break;
4171 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004172 case 64: Align = 8; break;
4173 case 128: Align = 16; break;
4174 case 256: Align = 32; break;
4175 }
4176
4177 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004178 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004179 return Error(Parser.getTok().getLoc(), "']' expected");
4180 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004181 Parser.Lex(); // Eat right bracket token.
4182
4183 // Don't worry about range checking the value here. That's handled by
4184 // the is*() predicates.
4185 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4186 ARM_AM::no_shift, 0, Align,
4187 false, S, E));
4188
4189 // If there's a pre-indexing writeback marker, '!', just add it as a token
4190 // operand.
4191 if (Parser.getTok().is(AsmToken::Exclaim)) {
4192 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4193 Parser.Lex(); // Eat the '!'.
4194 }
4195
4196 return false;
4197 }
4198
4199 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004200 // offset. Be friendly and also accept a plain integer (without a leading
4201 // hash) for gas compatibility.
4202 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004203 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004204 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004205 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004206 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004207 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004208
Owen Anderson967674d2011-08-29 19:36:44 +00004209 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004210 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004211 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004212 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004213
4214 // The expression has to be a constant. Memory references with relocations
4215 // don't come through here, as they use the <label> forms of the relevant
4216 // instructions.
4217 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4218 if (!CE)
4219 return Error (E, "constant expression expected");
4220
Owen Anderson967674d2011-08-29 19:36:44 +00004221 // If the constant was #-0, represent it as INT32_MIN.
4222 int32_t Val = CE->getValue();
4223 if (isNegative && Val == 0)
4224 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4225
Jim Grosbachd3595712011-08-03 23:50:40 +00004226 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004227 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004228 return Error(Parser.getTok().getLoc(), "']' expected");
4229 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004230 Parser.Lex(); // Eat right bracket token.
4231
4232 // Don't worry about range checking the value here. That's handled by
4233 // the is*() predicates.
4234 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004235 ARM_AM::no_shift, 0, 0,
4236 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004237
4238 // If there's a pre-indexing writeback marker, '!', just add it as a token
4239 // operand.
4240 if (Parser.getTok().is(AsmToken::Exclaim)) {
4241 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4242 Parser.Lex(); // Eat the '!'.
4243 }
4244
4245 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004246 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004247
4248 // The register offset is optionally preceded by a '+' or '-'
4249 bool isNegative = false;
4250 if (Parser.getTok().is(AsmToken::Minus)) {
4251 isNegative = true;
4252 Parser.Lex(); // Eat the '-'.
4253 } else if (Parser.getTok().is(AsmToken::Plus)) {
4254 // Nothing to do.
4255 Parser.Lex(); // Eat the '+'.
4256 }
4257
4258 E = Parser.getTok().getLoc();
4259 int OffsetRegNum = tryParseRegister();
4260 if (OffsetRegNum == -1)
4261 return Error(E, "register expected");
4262
4263 // If there's a shift operator, handle it.
4264 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004265 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004266 if (Parser.getTok().is(AsmToken::Comma)) {
4267 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004268 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004269 return true;
4270 }
4271
4272 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004273 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004274 return Error(Parser.getTok().getLoc(), "']' expected");
4275 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004276 Parser.Lex(); // Eat right bracket token.
4277
4278 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004279 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004280 S, E));
4281
Jim Grosbachc320c852011-08-05 21:28:30 +00004282 // If there's a pre-indexing writeback marker, '!', just add it as a token
4283 // operand.
4284 if (Parser.getTok().is(AsmToken::Exclaim)) {
4285 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4286 Parser.Lex(); // Eat the '!'.
4287 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004288
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004289 return false;
4290}
4291
Jim Grosbachd3595712011-08-03 23:50:40 +00004292/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004293/// ( lsl | lsr | asr | ror ) , # shift_amount
4294/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004295/// return true if it parses a shift otherwise it returns false.
4296bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4297 unsigned &Amount) {
4298 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004299 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004300 if (Tok.isNot(AsmToken::Identifier))
4301 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004302 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004303 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4304 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004305 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004306 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004307 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004308 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004309 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004310 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004311 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004312 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004313 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004314 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004315 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004316 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004317
Jim Grosbachd3595712011-08-03 23:50:40 +00004318 // rrx stands alone.
4319 Amount = 0;
4320 if (St != ARM_AM::rrx) {
4321 Loc = Parser.getTok().getLoc();
4322 // A '#' and a shift amount.
4323 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004324 if (HashTok.isNot(AsmToken::Hash) &&
4325 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004326 return Error(HashTok.getLoc(), "'#' expected");
4327 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004328
Jim Grosbachd3595712011-08-03 23:50:40 +00004329 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004330 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004331 return true;
4332 // Range check the immediate.
4333 // lsl, ror: 0 <= imm <= 31
4334 // lsr, asr: 0 <= imm <= 32
4335 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4336 if (!CE)
4337 return Error(Loc, "shift amount must be an immediate");
4338 int64_t Imm = CE->getValue();
4339 if (Imm < 0 ||
4340 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4341 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4342 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004343 // If <ShiftTy> #0, turn it into a no_shift.
4344 if (Imm == 0)
4345 St = ARM_AM::lsl;
4346 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4347 if (Imm == 32)
4348 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004349 Amount = Imm;
4350 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004351
4352 return false;
4353}
4354
Jim Grosbache7fbce72011-10-03 23:38:36 +00004355/// parseFPImm - A floating point immediate expression operand.
4356ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4357parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004358 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004359 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004360 // integer only.
4361 //
4362 // This routine still creates a generic Immediate operand, containing
4363 // a bitcast of the 64-bit floating point value. The various operands
4364 // that accept floats can check whether the value is valid for them
4365 // via the standard is*() predicates.
4366
Jim Grosbache7fbce72011-10-03 23:38:36 +00004367 SMLoc S = Parser.getTok().getLoc();
4368
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004369 if (Parser.getTok().isNot(AsmToken::Hash) &&
4370 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004371 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004372
4373 // Disambiguate the VMOV forms that can accept an FP immediate.
4374 // vmov.f32 <sreg>, #imm
4375 // vmov.f64 <dreg>, #imm
4376 // vmov.f32 <dreg>, #imm @ vector f32x2
4377 // vmov.f32 <qreg>, #imm @ vector f32x4
4378 //
4379 // There are also the NEON VMOV instructions which expect an
4380 // integer constant. Make sure we don't try to parse an FPImm
4381 // for these:
4382 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4383 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4384 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4385 TyOp->getToken() != ".f64"))
4386 return MatchOperand_NoMatch;
4387
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004388 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004389
4390 // Handle negation, as that still comes through as a separate token.
4391 bool isNegative = false;
4392 if (Parser.getTok().is(AsmToken::Minus)) {
4393 isNegative = true;
4394 Parser.Lex();
4395 }
4396 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004397 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004398 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004399 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004400 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4401 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004402 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004403 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004404 Operands.push_back(ARMOperand::CreateImm(
4405 MCConstantExpr::Create(IntVal, getContext()),
4406 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004407 return MatchOperand_Success;
4408 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004409 // Also handle plain integers. Instructions which allow floating point
4410 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004411 if (Tok.is(AsmToken::Integer)) {
4412 int64_t Val = Tok.getIntVal();
4413 Parser.Lex(); // Eat the token.
4414 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004415 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004416 return MatchOperand_ParseFail;
4417 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004418 double RealVal = ARM_AM::getFPImmFloat(Val);
4419 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4420 Operands.push_back(ARMOperand::CreateImm(
4421 MCConstantExpr::Create(Val, getContext()), S,
4422 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004423 return MatchOperand_Success;
4424 }
4425
Jim Grosbach235c8d22012-01-19 02:47:30 +00004426 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004427 return MatchOperand_ParseFail;
4428}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004429
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004430/// Parse a arm instruction operand. For now this parses the operand regardless
4431/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004432bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004433 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004434 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004435
4436 // Check if the current operand has a custom associated parser, if so, try to
4437 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004438 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4439 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004440 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004441 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4442 // there was a match, but an error occurred, in which case, just return that
4443 // the operand parsing failed.
4444 if (ResTy == MatchOperand_ParseFail)
4445 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004446
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004447 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004448 default:
4449 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004450 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004451 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004452 // If we've seen a branch mnemonic, the next operand must be a label. This
4453 // is true even if the label is a register name. So "br r1" means branch to
4454 // label "r1".
4455 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4456 if (!ExpectLabel) {
4457 if (!tryParseRegisterWithWriteBack(Operands))
4458 return false;
4459 int Res = tryParseShiftRegister(Operands);
4460 if (Res == 0) // success
4461 return false;
4462 else if (Res == -1) // irrecoverable error
4463 return true;
4464 // If this is VMRS, check for the apsr_nzcv operand.
4465 if (Mnemonic == "vmrs" &&
4466 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4467 S = Parser.getTok().getLoc();
4468 Parser.Lex();
4469 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4470 return false;
4471 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004472 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004473
4474 // Fall though for the Identifier case that is not a register or a
4475 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004476 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004477 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004478 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004479 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004480 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004481 // This was not a register so parse other operands that start with an
4482 // identifier (like labels) as expressions and create them as immediates.
4483 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004484 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004485 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004486 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004487 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004488 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4489 return false;
4490 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004491 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004492 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004493 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004494 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004495 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004496 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004497 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004498 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004499 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004500
4501 if (Parser.getTok().isNot(AsmToken::Colon)) {
4502 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4503 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004504 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004505 return true;
4506 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4507 if (CE) {
4508 int32_t Val = CE->getValue();
4509 if (isNegative && Val == 0)
4510 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4511 }
4512 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4513 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004514
4515 // There can be a trailing '!' on operands that we want as a separate
4516 // '!' Token operand. Handle that here. For example, the compatibilty
4517 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4518 if (Parser.getTok().is(AsmToken::Exclaim)) {
4519 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4520 Parser.getTok().getLoc()));
4521 Parser.Lex(); // Eat exclaim token
4522 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004523 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004524 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004525 // w/ a ':' after the '#', it's just like a plain ':'.
4526 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004527 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004528 case AsmToken::Colon: {
4529 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004530 // FIXME: Check it's an expression prefix,
4531 // e.g. (FOO - :lower16:BAR) isn't legal.
4532 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004533 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004534 return true;
4535
Evan Cheng965b3c72011-01-13 07:58:56 +00004536 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004537 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004538 return true;
4539
Evan Cheng965b3c72011-01-13 07:58:56 +00004540 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004541 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004542 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004543 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004544 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004545 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004546 }
4547}
4548
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004549// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004550// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004551bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004552 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004553
4554 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004555 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004556 Parser.Lex(); // Eat ':'
4557
4558 if (getLexer().isNot(AsmToken::Identifier)) {
4559 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4560 return true;
4561 }
4562
4563 StringRef IDVal = Parser.getTok().getIdentifier();
4564 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004565 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004566 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004567 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004568 } else {
4569 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4570 return true;
4571 }
4572 Parser.Lex();
4573
4574 if (getLexer().isNot(AsmToken::Colon)) {
4575 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4576 return true;
4577 }
4578 Parser.Lex(); // Eat the last ':'
4579 return false;
4580}
4581
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004582/// \brief Given a mnemonic, split out possible predication code and carry
4583/// setting letters to form a canonical mnemonic and flags.
4584//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004585// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004586// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004587StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004588 unsigned &PredicationCode,
4589 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004590 unsigned &ProcessorIMod,
4591 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004592 PredicationCode = ARMCC::AL;
4593 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004594 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004595
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004596 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004597 //
4598 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004599 if ((Mnemonic == "movs" && isThumb()) ||
4600 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4601 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4602 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4603 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Jim Grosbach9b81a4f2013-04-15 22:42:50 +00004604 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004605 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4606 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004607 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004608 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004609 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4610 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4611 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004612 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004613
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004614 // First, split out any predication code. Ignore mnemonics we know aren't
4615 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004616 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004617 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004618 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004619 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004620 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4621 .Case("eq", ARMCC::EQ)
4622 .Case("ne", ARMCC::NE)
4623 .Case("hs", ARMCC::HS)
4624 .Case("cs", ARMCC::HS)
4625 .Case("lo", ARMCC::LO)
4626 .Case("cc", ARMCC::LO)
4627 .Case("mi", ARMCC::MI)
4628 .Case("pl", ARMCC::PL)
4629 .Case("vs", ARMCC::VS)
4630 .Case("vc", ARMCC::VC)
4631 .Case("hi", ARMCC::HI)
4632 .Case("ls", ARMCC::LS)
4633 .Case("ge", ARMCC::GE)
4634 .Case("lt", ARMCC::LT)
4635 .Case("gt", ARMCC::GT)
4636 .Case("le", ARMCC::LE)
4637 .Case("al", ARMCC::AL)
4638 .Default(~0U);
4639 if (CC != ~0U) {
4640 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4641 PredicationCode = CC;
4642 }
Bill Wendling193961b2010-10-29 23:50:21 +00004643 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004644
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004645 // Next, determine if we have a carry setting bit. We explicitly ignore all
4646 // the instructions we know end in 's'.
4647 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004648 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004649 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4650 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4651 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004652 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004653 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004654 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004655 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004656 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004657 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004658 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4659 CarrySetting = true;
4660 }
4661
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004662 // The "cps" instruction can have a interrupt mode operand which is glued into
4663 // the mnemonic. Check if this is the case, split it and parse the imod op
4664 if (Mnemonic.startswith("cps")) {
4665 // Split out any imod code.
4666 unsigned IMod =
4667 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4668 .Case("ie", ARM_PROC::IE)
4669 .Case("id", ARM_PROC::ID)
4670 .Default(~0U);
4671 if (IMod != ~0U) {
4672 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4673 ProcessorIMod = IMod;
4674 }
4675 }
4676
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004677 // The "it" instruction has the condition mask on the end of the mnemonic.
4678 if (Mnemonic.startswith("it")) {
4679 ITMask = Mnemonic.slice(2, Mnemonic.size());
4680 Mnemonic = Mnemonic.slice(0, 2);
4681 }
4682
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004683 return Mnemonic;
4684}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004685
4686/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4687/// inclusion of carry set or predication code operands.
4688//
4689// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004690void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004691getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004692 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004693 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4694 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004695 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004696 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004697 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004698 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004699 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004700 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004701 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004702 Mnemonic == "mla" || Mnemonic == "smlal" ||
4703 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004704 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004705 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004706 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004707
Tim Northover2c45a382013-06-26 16:52:40 +00004708 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4709 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4710 Mnemonic == "trap" || Mnemonic == "setend" ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004711 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4712 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004713 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4714 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4715 Mnemonic == "vrintm") {
Tim Northover2c45a382013-06-26 16:52:40 +00004716 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004717 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004718 } else if (!isThumb()) {
4719 // Some instructions are only predicable in Thumb mode
4720 CanAcceptPredicationCode
4721 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4722 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4723 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4724 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4725 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4726 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4727 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4728 } else if (isThumbOne()) {
4729 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004730 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004731 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004732}
4733
Jim Grosbach7283da92011-08-16 21:12:37 +00004734bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4735 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004736 // FIXME: This is all horribly hacky. We really need a better way to deal
4737 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004738
4739 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4740 // another does not. Specifically, the MOVW instruction does not. So we
4741 // special case it here and remove the defaulted (non-setting) cc_out
4742 // operand if that's the instruction we're trying to match.
4743 //
4744 // We do this as post-processing of the explicit operands rather than just
4745 // conditionally adding the cc_out in the first place because we need
4746 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004747 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004748 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4749 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4750 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4751 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004752
4753 // Register-register 'add' for thumb does not have a cc_out operand
4754 // when there are only two register operands.
4755 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4756 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4757 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4758 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4759 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004760 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004761 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4762 // have to check the immediate range here since Thumb2 has a variant
4763 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004764 if (((isThumb() && Mnemonic == "add") ||
4765 (isThumbTwo() && Mnemonic == "sub")) &&
4766 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004767 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4768 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4769 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004770 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004771 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004772 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004773 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004774 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4775 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004776 // selecting via the generic "add" mnemonic, so to know that we
4777 // should remove the cc_out operand, we have to explicitly check that
4778 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004779 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4780 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004781 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4782 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4783 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4784 // Nest conditions rather than one big 'if' statement for readability.
4785 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004786 // If both registers are low, we're in an IT block, and the immediate is
4787 // in range, we should use encoding T1 instead, which has a cc_out.
4788 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004789 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004790 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4791 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4792 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004793 // Check against T3. If the second register is the PC, this is an
4794 // alternate form of ADR, which uses encoding T4, so check for that too.
4795 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4796 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4797 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004798
4799 // Otherwise, we use encoding T4, which does not have a cc_out
4800 // operand.
4801 return true;
4802 }
4803
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004804 // The thumb2 multiply instruction doesn't have a CCOut register, so
4805 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4806 // use the 16-bit encoding or not.
4807 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4808 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4809 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4810 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4811 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4812 // If the registers aren't low regs, the destination reg isn't the
4813 // same as one of the source regs, or the cc_out operand is zero
4814 // outside of an IT block, we have to use the 32-bit encoding, so
4815 // remove the cc_out operand.
4816 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4817 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004818 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004819 !inITBlock() ||
4820 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4821 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4822 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4823 static_cast<ARMOperand*>(Operands[4])->getReg())))
4824 return true;
4825
Jim Grosbachefa7e952011-11-15 19:55:16 +00004826 // Also check the 'mul' syntax variant that doesn't specify an explicit
4827 // destination register.
4828 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4829 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4830 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4831 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4832 // If the registers aren't low regs or the cc_out operand is zero
4833 // outside of an IT block, we have to use the 32-bit encoding, so
4834 // remove the cc_out operand.
4835 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4836 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4837 !inITBlock()))
4838 return true;
4839
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004840
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004841
Jim Grosbach4b701af2011-08-24 21:42:27 +00004842 // Register-register 'add/sub' for thumb does not have a cc_out operand
4843 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4844 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4845 // right, this will result in better diagnostics (which operand is off)
4846 // anyway.
4847 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4848 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004849 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4850 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004851 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4852 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4853 (Operands.size() == 6 &&
4854 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004855 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004856
Jim Grosbach7283da92011-08-16 21:12:37 +00004857 return false;
4858}
4859
Joey Goulye8602552013-07-19 16:34:16 +00004860bool ARMAsmParser::shouldOmitPredicateOperand(
4861 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4862 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4863 unsigned RegIdx = 3;
4864 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4865 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4866 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4867 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4868 RegIdx = 4;
4869
4870 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4871 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4872 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4873 ARMMCRegisterClasses[ARM::QPRRegClassID]
4874 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4875 return true;
4876 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004877 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004878}
4879
Joey Gouly5d0564d2013-08-02 19:18:12 +00004880bool ARMAsmParser::isDeprecated(MCInst &Inst, StringRef &Info) {
4881 if (hasV8Ops() && Inst.getOpcode() == ARM::SETEND) {
4882 Info = "armv8";
4883 return true;
4884 }
Joey Goulyfcf67782013-08-02 20:50:01 +00004885 return false;
Joey Gouly5d0564d2013-08-02 19:18:12 +00004886}
4887
Jim Grosbach12952fe2011-11-11 23:08:10 +00004888static bool isDataTypeToken(StringRef Tok) {
4889 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4890 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4891 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4892 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4893 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4894 Tok == ".f" || Tok == ".d";
4895}
4896
4897// FIXME: This bit should probably be handled via an explicit match class
4898// in the .td files that matches the suffix instead of having it be
4899// a literal string token the way it is now.
4900static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4901 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4902}
Chad Rosier9f7a2212013-04-18 22:35:36 +00004903static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4904 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004905/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004906bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4907 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004908 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004909 // Apply mnemonic aliases before doing anything else, as the destination
4910 // mnemnonic may include suffices and we want to handle them normally.
4911 // The generic tblgen'erated code does this later, at the start of
4912 // MatchInstructionImpl(), but that's too late for aliases that include
4913 // any sort of suffix.
4914 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00004915 unsigned AssemblerDialect = getParser().getAssemblerDialect();
4916 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00004917
Jim Grosbachab5830e2011-12-14 02:16:11 +00004918 // First check for the ARM-specific .req directive.
4919 if (Parser.getTok().is(AsmToken::Identifier) &&
4920 Parser.getTok().getIdentifier() == ".req") {
4921 parseDirectiveReq(Name, NameLoc);
4922 // We always return 'error' for this, as we're done with this
4923 // statement and don't need to match the 'instruction."
4924 return true;
4925 }
4926
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004927 // Create the leading tokens for the mnemonic, split by '.' characters.
4928 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004929 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004930
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004931 // Split out the predication code and carry setting flag from the mnemonic.
4932 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004933 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004934 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004935 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004936 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004937 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004938
Jim Grosbach1c171b12011-08-25 17:23:55 +00004939 // In Thumb1, only the branch (B) instruction can be predicated.
4940 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004941 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00004942 return Error(NameLoc, "conditional execution not supported in Thumb1");
4943 }
4944
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004945 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4946
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004947 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4948 // is the mask as it will be for the IT encoding if the conditional
4949 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4950 // where the conditional bit0 is zero, the instruction post-processing
4951 // will adjust the mask accordingly.
4952 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00004953 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4954 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004955 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00004956 return Error(Loc, "too many conditions on IT instruction");
4957 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004958 unsigned Mask = 8;
4959 for (unsigned i = ITMask.size(); i != 0; --i) {
4960 char pos = ITMask[i - 1];
4961 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004962 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00004963 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004964 }
4965 Mask >>= 1;
4966 if (ITMask[i - 1] == 't')
4967 Mask |= 8;
4968 }
Jim Grosbached16ec42011-08-29 22:24:09 +00004969 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004970 }
4971
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004972 // FIXME: This is all a pretty gross hack. We should automatically handle
4973 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00004974
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004975 // Next, add the CCOut and ConditionCode operands, if needed.
4976 //
4977 // For mnemonics which can ever incorporate a carry setting bit or predication
4978 // code, our matching model involves us always generating CCOut and
4979 // ConditionCode operands to match the mnemonic "as written" and then we let
4980 // the matcher deal with finding the right instruction or generating an
4981 // appropriate error.
4982 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004983 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004984
Jim Grosbach03a8a162011-07-14 22:04:21 +00004985 // If we had a carry-set on an instruction that can't do that, issue an
4986 // error.
4987 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004988 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004989 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00004990 "' can not set flags, but 's' suffix specified");
4991 }
Jim Grosbach0a547702011-07-22 17:44:50 +00004992 // If we had a predication code on an instruction that can't do that, issue an
4993 // error.
4994 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004995 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00004996 return Error(NameLoc, "instruction '" + Mnemonic +
4997 "' is not predicable, but condition code specified");
4998 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00004999
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005000 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005001 if (CanAcceptCarrySet) {
5002 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005003 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005004 Loc));
5005 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005006
5007 // Add the predication code operand, if necessary.
5008 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005009 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5010 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005011 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005012 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005013 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005014
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005015 // Add the processor imod operand, if necessary.
5016 if (ProcessorIMod) {
5017 Operands.push_back(ARMOperand::CreateImm(
5018 MCConstantExpr::Create(ProcessorIMod, getContext()),
5019 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005020 }
5021
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005022 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005023 while (Next != StringRef::npos) {
5024 Start = Next;
5025 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005026 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005027
Jim Grosbach12952fe2011-11-11 23:08:10 +00005028 // Some NEON instructions have an optional datatype suffix that is
5029 // completely ignored. Check for that.
5030 if (isDataTypeToken(ExtraToken) &&
5031 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5032 continue;
5033
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005034 // For for ARM mode generate an error if the .n qualifier is used.
5035 if (ExtraToken == ".n" && !isThumb()) {
5036 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5037 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5038 "arm mode");
5039 }
5040
5041 // The .n qualifier is always discarded as that is what the tables
5042 // and matcher expect. In ARM mode the .w qualifier has no effect,
5043 // so discard it to avoid errors that can be caused by the matcher.
5044 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005045 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5046 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5047 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005048 }
5049
5050 // Read the remaining operands.
5051 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005052 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005053 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005054 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005055 return true;
5056 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005057
5058 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005059 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005060
5061 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005062 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005063 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005064 return true;
5065 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005066 }
5067 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005068
Chris Lattnera2a9d162010-09-11 16:18:25 +00005069 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005070 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005071 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005072 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005073 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005074
Chris Lattner91689c12010-09-08 05:10:46 +00005075 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005076
Jim Grosbach7283da92011-08-16 21:12:37 +00005077 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5078 // do and don't have a cc_out optional-def operand. With some spot-checks
5079 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005080 // parse and adjust accordingly before actually matching. We shouldn't ever
5081 // try to remove a cc_out operand that was explicitly set on the the
5082 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5083 // table driven matcher doesn't fit well with the ARM instruction set.
5084 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005085 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5086 Operands.erase(Operands.begin() + 1);
5087 delete Op;
5088 }
5089
Joey Goulye8602552013-07-19 16:34:16 +00005090 // Some instructions have the same mnemonic, but don't always
5091 // have a predicate. Distinguish them here and delete the
5092 // predicate if needed.
5093 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5094 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5095 Operands.erase(Operands.begin() + 1);
5096 delete Op;
5097 }
5098
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005099 // ARM mode 'blx' need special handling, as the register operand version
5100 // is predicable, but the label operand version is not. So, we can't rely
5101 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005102 // a k_CondCode operand in the list. If we're trying to match the label
5103 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005104 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5105 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5106 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5107 Operands.erase(Operands.begin() + 1);
5108 delete Op;
5109 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005110
Weiming Zhao8f56f882012-11-16 21:55:34 +00005111 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5112 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5113 // a single GPRPair reg operand is used in the .td file to replace the two
5114 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5115 // expressed as a GPRPair, so we have to manually merge them.
5116 // FIXME: We would really like to be able to tablegen'erate this.
5117 if (!isThumb() && Operands.size() > 4 &&
5118 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5119 bool isLoad = (Mnemonic == "ldrexd");
5120 unsigned Idx = isLoad ? 2 : 3;
5121 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5122 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5123
5124 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5125 // Adjust only if Op1 and Op2 are GPRs.
5126 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5127 MRC.contains(Op2->getReg())) {
5128 unsigned Reg1 = Op1->getReg();
5129 unsigned Reg2 = Op2->getReg();
5130 unsigned Rt = MRI->getEncodingValue(Reg1);
5131 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5132
5133 // Rt2 must be Rt + 1 and Rt must be even.
5134 if (Rt + 1 != Rt2 || (Rt & 1)) {
5135 Error(Op2->getStartLoc(), isLoad ?
5136 "destination operands must be sequential" :
5137 "source operands must be sequential");
5138 return true;
5139 }
5140 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5141 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5142 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5143 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5144 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5145 delete Op1;
5146 delete Op2;
5147 }
5148 }
5149
Kevin Enderby78f95722013-07-31 21:05:30 +00005150 // FIXME: As said above, this is all a pretty gross hack. This instruction
5151 // does not fit with other "subs" and tblgen.
5152 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5153 // so the Mnemonic is the original name "subs" and delete the predicate
5154 // operand so it will match the table entry.
5155 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5156 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5157 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5158 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5159 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5160 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5161 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5162 Operands.erase(Operands.begin());
5163 delete Op0;
5164 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5165
5166 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5167 Operands.erase(Operands.begin() + 1);
5168 delete Op1;
5169 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005170 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005171}
5172
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005173// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005174
5175// return 'true' if register list contains non-low GPR registers,
5176// 'false' otherwise. If Reg is in the register list or is HiReg, set
5177// 'containsReg' to true.
5178static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5179 unsigned HiReg, bool &containsReg) {
5180 containsReg = false;
5181 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5182 unsigned OpReg = Inst.getOperand(i).getReg();
5183 if (OpReg == Reg)
5184 containsReg = true;
5185 // Anything other than a low register isn't legal here.
5186 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5187 return true;
5188 }
5189 return false;
5190}
5191
Jim Grosbacha31f2232011-09-07 18:05:34 +00005192// Check if the specified regisgter is in the register list of the inst,
5193// starting at the indicated operand number.
5194static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5195 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5196 unsigned OpReg = Inst.getOperand(i).getReg();
5197 if (OpReg == Reg)
5198 return true;
5199 }
5200 return false;
5201}
5202
Jim Grosbached16ec42011-08-29 22:24:09 +00005203// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5204// the ARMInsts array) instead. Getting that here requires awkward
5205// API changes, though. Better way?
5206namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005207extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005208}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005209static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005210 return ARMInsts[Opcode];
5211}
5212
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005213// FIXME: We would really like to be able to tablegen'erate this.
5214bool ARMAsmParser::
5215validateInstruction(MCInst &Inst,
5216 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005217 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005218 SMLoc Loc = Operands[0]->getStartLoc();
5219 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005220 // NOTE: BKPT instruction has the interesting property of being
5221 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005222 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005223 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5224 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005225 unsigned bit = 1;
5226 if (ITState.FirstCond)
5227 ITState.FirstCond = false;
5228 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005229 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005230 // The instruction must be predicable.
5231 if (!MCID.isPredicable())
5232 return Error(Loc, "instructions in IT block must be predicable");
5233 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5234 unsigned ITCond = bit ? ITState.Cond :
5235 ARMCC::getOppositeCondition(ITState.Cond);
5236 if (Cond != ITCond) {
5237 // Find the condition code Operand to get its SMLoc information.
5238 SMLoc CondLoc;
5239 for (unsigned i = 1; i < Operands.size(); ++i)
5240 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5241 CondLoc = Operands[i]->getStartLoc();
5242 return Error(CondLoc, "incorrect condition in IT block; got '" +
5243 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5244 "', but expected '" +
5245 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5246 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005247 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005248 } else if (isThumbTwo() && MCID.isPredicable() &&
5249 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005250 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5251 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005252 return Error(Loc, "predicated instructions must be in IT block");
5253
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005254 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005255 case ARM::LDRD:
5256 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005257 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005258 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005259 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5260 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005261 if (Rt2 != Rt + 1)
5262 return Error(Operands[3]->getStartLoc(),
5263 "destination operands must be sequential");
5264 return false;
5265 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005266 case ARM::STRD: {
5267 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005268 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5269 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005270 if (Rt2 != Rt + 1)
5271 return Error(Operands[3]->getStartLoc(),
5272 "source operands must be sequential");
5273 return false;
5274 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005275 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005276 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005277 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005278 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5279 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005280 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005281 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005282 "source operands must be sequential");
5283 return false;
5284 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005285 case ARM::SBFX:
5286 case ARM::UBFX: {
5287 // width must be in range [1, 32-lsb]
5288 unsigned lsb = Inst.getOperand(2).getImm();
5289 unsigned widthm1 = Inst.getOperand(3).getImm();
5290 if (widthm1 >= 32 - lsb)
5291 return Error(Operands[5]->getStartLoc(),
5292 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005293 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005294 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005295 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005296 // If we're parsing Thumb2, the .w variant is available and handles
5297 // most cases that are normally illegal for a Thumb1 LDM
5298 // instruction. We'll make the transformation in processInstruction()
5299 // if necessary.
5300 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005301 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005302 // in the register list.
5303 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005304 bool hasWritebackToken =
5305 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5306 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005307 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005308 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005309 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5310 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005311 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005312 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005313 return Error(Operands[2]->getStartLoc(),
5314 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005315 // If we should not have writeback, there must not be a '!'. This is
5316 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005317 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005318 return Error(Operands[3]->getStartLoc(),
5319 "writeback operator '!' not allowed when base register "
5320 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005321
5322 break;
5323 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005324 case ARM::t2LDMIA_UPD: {
5325 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5326 return Error(Operands[4]->getStartLoc(),
5327 "writeback operator '!' not allowed when base register "
5328 "in register list");
5329 break;
5330 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005331 case ARM::tMUL: {
5332 // The second source operand must be the same register as the destination
5333 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005334 //
5335 // In this case, we must directly check the parsed operands because the
5336 // cvtThumbMultiply() function is written in such a way that it guarantees
5337 // this first statement is always true for the new Inst. Essentially, the
5338 // destination is unconditionally copied into the second source operand
5339 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005340 if (Operands.size() == 6 &&
5341 (((ARMOperand*)Operands[3])->getReg() !=
5342 ((ARMOperand*)Operands[5])->getReg()) &&
5343 (((ARMOperand*)Operands[3])->getReg() !=
5344 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005345 return Error(Operands[3]->getStartLoc(),
5346 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005347 }
5348 break;
5349 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005350 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5351 // so only issue a diagnostic for thumb1. The instructions will be
5352 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005353 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005354 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005355 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5356 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005357 return Error(Operands[2]->getStartLoc(),
5358 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005359 break;
5360 }
5361 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005362 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005363 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5364 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005365 return Error(Operands[2]->getStartLoc(),
5366 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005367 break;
5368 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005369 case ARM::tSTMIA_UPD: {
5370 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005371 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005372 return Error(Operands[4]->getStartLoc(),
5373 "registers must be in range r0-r7");
5374 break;
5375 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005376 case ARM::tADDrSP: {
5377 // If the non-SP source operand and the destination operand are not the
5378 // same, we need thumb2 (for the wide encoding), or we have an error.
5379 if (!isThumbTwo() &&
5380 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5381 return Error(Operands[4]->getStartLoc(),
5382 "source register must be the same as destination");
5383 }
5384 break;
5385 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005386 }
5387
Joey Gouly5d0564d2013-08-02 19:18:12 +00005388 StringRef DepInfo;
5389 if (isDeprecated(Inst, DepInfo))
5390 Warning(Loc, "deprecated on " + DepInfo);
5391
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005392 return false;
5393}
5394
Jim Grosbach1a747242012-01-23 23:45:44 +00005395static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005396 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005397 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005398 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005399 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5400 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5401 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5402 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5403 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5404 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5405 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5406 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5407 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005408
5409 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005410 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5411 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5412 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5413 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5414 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005415
Jim Grosbach1e946a42012-01-24 00:43:12 +00005416 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5417 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5418 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5419 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5420 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005421
Jim Grosbach1e946a42012-01-24 00:43:12 +00005422 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5423 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5424 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5425 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5426 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005427
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005428 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005429 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5430 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5431 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5432 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5433 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5434 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5435 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5436 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5437 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5438 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5439 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5440 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5441 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5442 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5443 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005444
Jim Grosbach1a747242012-01-23 23:45:44 +00005445 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005446 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5447 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5448 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5449 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5450 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5451 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5452 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5453 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5454 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5455 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5456 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5457 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5458 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5459 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5460 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5461 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5462 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5463 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005464
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005465 // VST4LN
5466 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5467 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5468 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5469 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5470 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5471 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5472 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5473 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5474 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5475 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5476 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5477 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5478 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5479 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5480 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5481
Jim Grosbachda70eac2012-01-24 00:58:13 +00005482 // VST4
5483 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5484 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5485 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5486 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5487 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5488 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5489 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5490 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5491 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5492 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5493 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5494 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5495 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5496 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5497 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5498 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5499 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5500 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005501 }
5502}
5503
Jim Grosbach1a747242012-01-23 23:45:44 +00005504static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005505 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005506 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005507 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005508 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5509 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5510 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5511 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5512 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5513 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5514 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5515 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5516 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005517
5518 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005519 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5520 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5521 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5522 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5523 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5524 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5525 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5526 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5527 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5528 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5529 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5530 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5531 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5532 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5533 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005534
Jim Grosbachb78403c2012-01-24 23:47:04 +00005535 // VLD3DUP
5536 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5537 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5538 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5539 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5540 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5541 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5542 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5543 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5544 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5545 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5546 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5547 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5548 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5549 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5550 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5551 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5552 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5553 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5554
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005555 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005556 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5557 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5558 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5559 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5560 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5561 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5562 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5563 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5564 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5565 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5566 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5567 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5568 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5569 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5570 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005571
5572 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005573 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5574 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5575 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5576 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5577 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5578 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5579 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5580 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5581 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5582 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5583 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5584 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5585 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5586 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5587 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5588 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5589 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5590 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005591
Jim Grosbach14952a02012-01-24 18:37:25 +00005592 // VLD4LN
5593 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5594 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5595 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5596 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5597 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5598 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5599 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5600 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5601 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5602 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5603 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5604 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5605 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5606 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5607 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5608
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005609 // VLD4DUP
5610 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5611 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5612 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5613 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5614 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5615 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5616 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5617 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5618 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5619 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5620 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5621 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5622 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5623 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5624 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5625 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5626 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5627 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5628
Jim Grosbached561fc2012-01-24 00:43:17 +00005629 // VLD4
5630 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5631 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5632 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5633 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5634 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5635 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5636 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5637 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5638 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5639 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5640 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5641 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5642 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5643 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5644 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5645 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5646 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5647 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005648 }
5649}
5650
Jim Grosbachafad0532011-11-10 23:42:14 +00005651bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005652processInstruction(MCInst &Inst,
5653 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5654 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005655 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5656 case ARM::ADDri: {
5657 if (Inst.getOperand(1).getReg() != ARM::PC ||
5658 Inst.getOperand(5).getReg() != 0)
5659 return false;
5660 MCInst TmpInst;
5661 TmpInst.setOpcode(ARM::ADR);
5662 TmpInst.addOperand(Inst.getOperand(0));
5663 TmpInst.addOperand(Inst.getOperand(2));
5664 TmpInst.addOperand(Inst.getOperand(3));
5665 TmpInst.addOperand(Inst.getOperand(4));
5666 Inst = TmpInst;
5667 return true;
5668 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005669 // Aliases for alternate PC+imm syntax of LDR instructions.
5670 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005671 // Select the narrow version if the immediate will fit.
5672 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005673 Inst.getOperand(1).getImm() <= 0xff &&
5674 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5675 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005676 Inst.setOpcode(ARM::tLDRpci);
5677 else
5678 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005679 return true;
5680 case ARM::t2LDRBpcrel:
5681 Inst.setOpcode(ARM::t2LDRBpci);
5682 return true;
5683 case ARM::t2LDRHpcrel:
5684 Inst.setOpcode(ARM::t2LDRHpci);
5685 return true;
5686 case ARM::t2LDRSBpcrel:
5687 Inst.setOpcode(ARM::t2LDRSBpci);
5688 return true;
5689 case ARM::t2LDRSHpcrel:
5690 Inst.setOpcode(ARM::t2LDRSHpci);
5691 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005692 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005693 case ARM::VST1LNdWB_register_Asm_8:
5694 case ARM::VST1LNdWB_register_Asm_16:
5695 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005696 MCInst TmpInst;
5697 // Shuffle the operands around so the lane index operand is in the
5698 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005699 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005700 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005701 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5702 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5703 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5704 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5705 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5706 TmpInst.addOperand(Inst.getOperand(1)); // lane
5707 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5708 TmpInst.addOperand(Inst.getOperand(6));
5709 Inst = TmpInst;
5710 return true;
5711 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005712
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005713 case ARM::VST2LNdWB_register_Asm_8:
5714 case ARM::VST2LNdWB_register_Asm_16:
5715 case ARM::VST2LNdWB_register_Asm_32:
5716 case ARM::VST2LNqWB_register_Asm_16:
5717 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005718 MCInst TmpInst;
5719 // Shuffle the operands around so the lane index operand is in the
5720 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005721 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005722 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005723 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5724 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5725 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5726 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5727 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005728 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5729 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005730 TmpInst.addOperand(Inst.getOperand(1)); // lane
5731 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5732 TmpInst.addOperand(Inst.getOperand(6));
5733 Inst = TmpInst;
5734 return true;
5735 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005736
5737 case ARM::VST3LNdWB_register_Asm_8:
5738 case ARM::VST3LNdWB_register_Asm_16:
5739 case ARM::VST3LNdWB_register_Asm_32:
5740 case ARM::VST3LNqWB_register_Asm_16:
5741 case ARM::VST3LNqWB_register_Asm_32: {
5742 MCInst TmpInst;
5743 // Shuffle the operands around so the lane index operand is in the
5744 // right place.
5745 unsigned Spacing;
5746 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5747 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5748 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5749 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5750 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5751 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5752 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5753 Spacing));
5754 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5755 Spacing * 2));
5756 TmpInst.addOperand(Inst.getOperand(1)); // lane
5757 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5758 TmpInst.addOperand(Inst.getOperand(6));
5759 Inst = TmpInst;
5760 return true;
5761 }
5762
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005763 case ARM::VST4LNdWB_register_Asm_8:
5764 case ARM::VST4LNdWB_register_Asm_16:
5765 case ARM::VST4LNdWB_register_Asm_32:
5766 case ARM::VST4LNqWB_register_Asm_16:
5767 case ARM::VST4LNqWB_register_Asm_32: {
5768 MCInst TmpInst;
5769 // Shuffle the operands around so the lane index operand is in the
5770 // right place.
5771 unsigned Spacing;
5772 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5773 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5774 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5775 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5776 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5777 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5778 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5779 Spacing));
5780 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5781 Spacing * 2));
5782 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5783 Spacing * 3));
5784 TmpInst.addOperand(Inst.getOperand(1)); // lane
5785 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5786 TmpInst.addOperand(Inst.getOperand(6));
5787 Inst = TmpInst;
5788 return true;
5789 }
5790
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005791 case ARM::VST1LNdWB_fixed_Asm_8:
5792 case ARM::VST1LNdWB_fixed_Asm_16:
5793 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005794 MCInst TmpInst;
5795 // Shuffle the operands around so the lane index operand is in the
5796 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005797 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005798 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005799 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5800 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5801 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5802 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5803 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5804 TmpInst.addOperand(Inst.getOperand(1)); // lane
5805 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5806 TmpInst.addOperand(Inst.getOperand(5));
5807 Inst = TmpInst;
5808 return true;
5809 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005810
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005811 case ARM::VST2LNdWB_fixed_Asm_8:
5812 case ARM::VST2LNdWB_fixed_Asm_16:
5813 case ARM::VST2LNdWB_fixed_Asm_32:
5814 case ARM::VST2LNqWB_fixed_Asm_16:
5815 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005816 MCInst TmpInst;
5817 // Shuffle the operands around so the lane index operand is in the
5818 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005819 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005820 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005821 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5822 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5823 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5824 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5825 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005826 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5827 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005828 TmpInst.addOperand(Inst.getOperand(1)); // lane
5829 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5830 TmpInst.addOperand(Inst.getOperand(5));
5831 Inst = TmpInst;
5832 return true;
5833 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005834
5835 case ARM::VST3LNdWB_fixed_Asm_8:
5836 case ARM::VST3LNdWB_fixed_Asm_16:
5837 case ARM::VST3LNdWB_fixed_Asm_32:
5838 case ARM::VST3LNqWB_fixed_Asm_16:
5839 case ARM::VST3LNqWB_fixed_Asm_32: {
5840 MCInst TmpInst;
5841 // Shuffle the operands around so the lane index operand is in the
5842 // right place.
5843 unsigned Spacing;
5844 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5845 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5846 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5847 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5848 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5849 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5850 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5851 Spacing));
5852 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5853 Spacing * 2));
5854 TmpInst.addOperand(Inst.getOperand(1)); // lane
5855 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5856 TmpInst.addOperand(Inst.getOperand(5));
5857 Inst = TmpInst;
5858 return true;
5859 }
5860
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005861 case ARM::VST4LNdWB_fixed_Asm_8:
5862 case ARM::VST4LNdWB_fixed_Asm_16:
5863 case ARM::VST4LNdWB_fixed_Asm_32:
5864 case ARM::VST4LNqWB_fixed_Asm_16:
5865 case ARM::VST4LNqWB_fixed_Asm_32: {
5866 MCInst TmpInst;
5867 // Shuffle the operands around so the lane index operand is in the
5868 // right place.
5869 unsigned Spacing;
5870 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5871 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5872 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5873 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5874 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5875 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5876 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5877 Spacing));
5878 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5879 Spacing * 2));
5880 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5881 Spacing * 3));
5882 TmpInst.addOperand(Inst.getOperand(1)); // lane
5883 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5884 TmpInst.addOperand(Inst.getOperand(5));
5885 Inst = TmpInst;
5886 return true;
5887 }
5888
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005889 case ARM::VST1LNdAsm_8:
5890 case ARM::VST1LNdAsm_16:
5891 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005892 MCInst TmpInst;
5893 // Shuffle the operands around so the lane index operand is in the
5894 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005895 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005896 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005897 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5898 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5899 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5900 TmpInst.addOperand(Inst.getOperand(1)); // lane
5901 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5902 TmpInst.addOperand(Inst.getOperand(5));
5903 Inst = TmpInst;
5904 return true;
5905 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005906
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005907 case ARM::VST2LNdAsm_8:
5908 case ARM::VST2LNdAsm_16:
5909 case ARM::VST2LNdAsm_32:
5910 case ARM::VST2LNqAsm_16:
5911 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005912 MCInst TmpInst;
5913 // Shuffle the operands around so the lane index operand is in the
5914 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005915 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005916 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005917 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5918 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5919 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005920 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5921 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005922 TmpInst.addOperand(Inst.getOperand(1)); // lane
5923 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5924 TmpInst.addOperand(Inst.getOperand(5));
5925 Inst = TmpInst;
5926 return true;
5927 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005928
5929 case ARM::VST3LNdAsm_8:
5930 case ARM::VST3LNdAsm_16:
5931 case ARM::VST3LNdAsm_32:
5932 case ARM::VST3LNqAsm_16:
5933 case ARM::VST3LNqAsm_32: {
5934 MCInst TmpInst;
5935 // Shuffle the operands around so the lane index operand is in the
5936 // right place.
5937 unsigned Spacing;
5938 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5939 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5940 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5941 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5942 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5943 Spacing));
5944 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5945 Spacing * 2));
5946 TmpInst.addOperand(Inst.getOperand(1)); // lane
5947 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5948 TmpInst.addOperand(Inst.getOperand(5));
5949 Inst = TmpInst;
5950 return true;
5951 }
5952
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005953 case ARM::VST4LNdAsm_8:
5954 case ARM::VST4LNdAsm_16:
5955 case ARM::VST4LNdAsm_32:
5956 case ARM::VST4LNqAsm_16:
5957 case ARM::VST4LNqAsm_32: {
5958 MCInst TmpInst;
5959 // Shuffle the operands around so the lane index operand is in the
5960 // right place.
5961 unsigned Spacing;
5962 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5963 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5964 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5965 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5966 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5967 Spacing));
5968 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5969 Spacing * 2));
5970 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5971 Spacing * 3));
5972 TmpInst.addOperand(Inst.getOperand(1)); // lane
5973 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5974 TmpInst.addOperand(Inst.getOperand(5));
5975 Inst = TmpInst;
5976 return true;
5977 }
5978
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005979 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005980 case ARM::VLD1LNdWB_register_Asm_8:
5981 case ARM::VLD1LNdWB_register_Asm_16:
5982 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00005983 MCInst TmpInst;
5984 // Shuffle the operands around so the lane index operand is in the
5985 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00005986 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005987 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00005988 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5989 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5990 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5991 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5992 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5993 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5994 TmpInst.addOperand(Inst.getOperand(1)); // lane
5995 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5996 TmpInst.addOperand(Inst.getOperand(6));
5997 Inst = TmpInst;
5998 return true;
5999 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006000
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006001 case ARM::VLD2LNdWB_register_Asm_8:
6002 case ARM::VLD2LNdWB_register_Asm_16:
6003 case ARM::VLD2LNdWB_register_Asm_32:
6004 case ARM::VLD2LNqWB_register_Asm_16:
6005 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006006 MCInst TmpInst;
6007 // Shuffle the operands around so the lane index operand is in the
6008 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006009 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006010 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006011 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006012 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6013 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006014 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6015 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6016 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6017 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6018 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006019 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6020 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006021 TmpInst.addOperand(Inst.getOperand(1)); // lane
6022 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6023 TmpInst.addOperand(Inst.getOperand(6));
6024 Inst = TmpInst;
6025 return true;
6026 }
6027
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006028 case ARM::VLD3LNdWB_register_Asm_8:
6029 case ARM::VLD3LNdWB_register_Asm_16:
6030 case ARM::VLD3LNdWB_register_Asm_32:
6031 case ARM::VLD3LNqWB_register_Asm_16:
6032 case ARM::VLD3LNqWB_register_Asm_32: {
6033 MCInst TmpInst;
6034 // Shuffle the operands around so the lane index operand is in the
6035 // right place.
6036 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006037 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006038 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6039 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6040 Spacing));
6041 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006042 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006043 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6044 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6045 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6046 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6047 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6048 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6049 Spacing));
6050 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006051 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006052 TmpInst.addOperand(Inst.getOperand(1)); // lane
6053 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6054 TmpInst.addOperand(Inst.getOperand(6));
6055 Inst = TmpInst;
6056 return true;
6057 }
6058
Jim Grosbach14952a02012-01-24 18:37:25 +00006059 case ARM::VLD4LNdWB_register_Asm_8:
6060 case ARM::VLD4LNdWB_register_Asm_16:
6061 case ARM::VLD4LNdWB_register_Asm_32:
6062 case ARM::VLD4LNqWB_register_Asm_16:
6063 case ARM::VLD4LNqWB_register_Asm_32: {
6064 MCInst TmpInst;
6065 // Shuffle the operands around so the lane index operand is in the
6066 // right place.
6067 unsigned Spacing;
6068 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6069 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6070 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6071 Spacing));
6072 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6073 Spacing * 2));
6074 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6075 Spacing * 3));
6076 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6077 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6078 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6079 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6080 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6081 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6082 Spacing));
6083 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6084 Spacing * 2));
6085 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6086 Spacing * 3));
6087 TmpInst.addOperand(Inst.getOperand(1)); // lane
6088 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6089 TmpInst.addOperand(Inst.getOperand(6));
6090 Inst = TmpInst;
6091 return true;
6092 }
6093
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006094 case ARM::VLD1LNdWB_fixed_Asm_8:
6095 case ARM::VLD1LNdWB_fixed_Asm_16:
6096 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006097 MCInst TmpInst;
6098 // Shuffle the operands around so the lane index operand is in the
6099 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006100 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006101 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006102 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6103 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6104 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6105 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6106 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6107 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6108 TmpInst.addOperand(Inst.getOperand(1)); // lane
6109 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6110 TmpInst.addOperand(Inst.getOperand(5));
6111 Inst = TmpInst;
6112 return true;
6113 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006114
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006115 case ARM::VLD2LNdWB_fixed_Asm_8:
6116 case ARM::VLD2LNdWB_fixed_Asm_16:
6117 case ARM::VLD2LNdWB_fixed_Asm_32:
6118 case ARM::VLD2LNqWB_fixed_Asm_16:
6119 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006120 MCInst TmpInst;
6121 // Shuffle the operands around so the lane index operand is in the
6122 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006123 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006124 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006125 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006126 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6127 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006128 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6129 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6130 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6131 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6132 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006133 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6134 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006135 TmpInst.addOperand(Inst.getOperand(1)); // lane
6136 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6137 TmpInst.addOperand(Inst.getOperand(5));
6138 Inst = TmpInst;
6139 return true;
6140 }
6141
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006142 case ARM::VLD3LNdWB_fixed_Asm_8:
6143 case ARM::VLD3LNdWB_fixed_Asm_16:
6144 case ARM::VLD3LNdWB_fixed_Asm_32:
6145 case ARM::VLD3LNqWB_fixed_Asm_16:
6146 case ARM::VLD3LNqWB_fixed_Asm_32: {
6147 MCInst TmpInst;
6148 // Shuffle the operands around so the lane index operand is in the
6149 // right place.
6150 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006151 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006152 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6153 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6154 Spacing));
6155 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006156 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006157 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6158 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6159 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6160 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6161 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6162 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6163 Spacing));
6164 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006165 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006166 TmpInst.addOperand(Inst.getOperand(1)); // lane
6167 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6168 TmpInst.addOperand(Inst.getOperand(5));
6169 Inst = TmpInst;
6170 return true;
6171 }
6172
Jim Grosbach14952a02012-01-24 18:37:25 +00006173 case ARM::VLD4LNdWB_fixed_Asm_8:
6174 case ARM::VLD4LNdWB_fixed_Asm_16:
6175 case ARM::VLD4LNdWB_fixed_Asm_32:
6176 case ARM::VLD4LNqWB_fixed_Asm_16:
6177 case ARM::VLD4LNqWB_fixed_Asm_32: {
6178 MCInst TmpInst;
6179 // Shuffle the operands around so the lane index operand is in the
6180 // right place.
6181 unsigned Spacing;
6182 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6183 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6184 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6185 Spacing));
6186 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6187 Spacing * 2));
6188 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6189 Spacing * 3));
6190 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6191 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6192 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6193 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6194 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6195 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6196 Spacing));
6197 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6198 Spacing * 2));
6199 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6200 Spacing * 3));
6201 TmpInst.addOperand(Inst.getOperand(1)); // lane
6202 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6203 TmpInst.addOperand(Inst.getOperand(5));
6204 Inst = TmpInst;
6205 return true;
6206 }
6207
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006208 case ARM::VLD1LNdAsm_8:
6209 case ARM::VLD1LNdAsm_16:
6210 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006211 MCInst TmpInst;
6212 // Shuffle the operands around so the lane index operand is in the
6213 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006214 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006215 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006216 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6217 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6218 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6219 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6220 TmpInst.addOperand(Inst.getOperand(1)); // lane
6221 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6222 TmpInst.addOperand(Inst.getOperand(5));
6223 Inst = TmpInst;
6224 return true;
6225 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006226
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006227 case ARM::VLD2LNdAsm_8:
6228 case ARM::VLD2LNdAsm_16:
6229 case ARM::VLD2LNdAsm_32:
6230 case ARM::VLD2LNqAsm_16:
6231 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006232 MCInst TmpInst;
6233 // Shuffle the operands around so the lane index operand is in the
6234 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006235 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006236 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006237 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006238 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6239 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006240 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6241 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6242 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006243 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6244 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006245 TmpInst.addOperand(Inst.getOperand(1)); // lane
6246 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6247 TmpInst.addOperand(Inst.getOperand(5));
6248 Inst = TmpInst;
6249 return true;
6250 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006251
6252 case ARM::VLD3LNdAsm_8:
6253 case ARM::VLD3LNdAsm_16:
6254 case ARM::VLD3LNdAsm_32:
6255 case ARM::VLD3LNqAsm_16:
6256 case ARM::VLD3LNqAsm_32: {
6257 MCInst TmpInst;
6258 // Shuffle the operands around so the lane index operand is in the
6259 // right place.
6260 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006261 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006262 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6263 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6264 Spacing));
6265 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006266 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006267 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6268 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6269 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6270 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6271 Spacing));
6272 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006273 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006274 TmpInst.addOperand(Inst.getOperand(1)); // lane
6275 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6276 TmpInst.addOperand(Inst.getOperand(5));
6277 Inst = TmpInst;
6278 return true;
6279 }
6280
Jim Grosbach14952a02012-01-24 18:37:25 +00006281 case ARM::VLD4LNdAsm_8:
6282 case ARM::VLD4LNdAsm_16:
6283 case ARM::VLD4LNdAsm_32:
6284 case ARM::VLD4LNqAsm_16:
6285 case ARM::VLD4LNqAsm_32: {
6286 MCInst TmpInst;
6287 // Shuffle the operands around so the lane index operand is in the
6288 // right place.
6289 unsigned Spacing;
6290 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6291 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6292 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6293 Spacing));
6294 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6295 Spacing * 2));
6296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6297 Spacing * 3));
6298 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6299 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6300 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6301 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6302 Spacing));
6303 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6304 Spacing * 2));
6305 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6306 Spacing * 3));
6307 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 Grosbachb78403c2012-01-24 23:47:04 +00006314 // VLD3DUP single 3-element structure to all lanes instructions.
6315 case ARM::VLD3DUPdAsm_8:
6316 case ARM::VLD3DUPdAsm_16:
6317 case ARM::VLD3DUPdAsm_32:
6318 case ARM::VLD3DUPqAsm_8:
6319 case ARM::VLD3DUPqAsm_16:
6320 case ARM::VLD3DUPqAsm_32: {
6321 MCInst TmpInst;
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(Inst.getOperand(1)); // Rn
6330 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6331 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6332 TmpInst.addOperand(Inst.getOperand(4));
6333 Inst = TmpInst;
6334 return true;
6335 }
6336
6337 case ARM::VLD3DUPdWB_fixed_Asm_8:
6338 case ARM::VLD3DUPdWB_fixed_Asm_16:
6339 case ARM::VLD3DUPdWB_fixed_Asm_32:
6340 case ARM::VLD3DUPqWB_fixed_Asm_8:
6341 case ARM::VLD3DUPqWB_fixed_Asm_16:
6342 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6343 MCInst TmpInst;
6344 unsigned Spacing;
6345 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6346 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6347 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6348 Spacing));
6349 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6350 Spacing * 2));
6351 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6352 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6353 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6354 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6355 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6356 TmpInst.addOperand(Inst.getOperand(4));
6357 Inst = TmpInst;
6358 return true;
6359 }
6360
6361 case ARM::VLD3DUPdWB_register_Asm_8:
6362 case ARM::VLD3DUPdWB_register_Asm_16:
6363 case ARM::VLD3DUPdWB_register_Asm_32:
6364 case ARM::VLD3DUPqWB_register_Asm_8:
6365 case ARM::VLD3DUPqWB_register_Asm_16:
6366 case ARM::VLD3DUPqWB_register_Asm_32: {
6367 MCInst TmpInst;
6368 unsigned Spacing;
6369 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6370 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6371 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6372 Spacing));
6373 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6374 Spacing * 2));
6375 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6376 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6377 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6378 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6379 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6380 TmpInst.addOperand(Inst.getOperand(5));
6381 Inst = TmpInst;
6382 return true;
6383 }
6384
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006385 // VLD3 multiple 3-element structure instructions.
6386 case ARM::VLD3dAsm_8:
6387 case ARM::VLD3dAsm_16:
6388 case ARM::VLD3dAsm_32:
6389 case ARM::VLD3qAsm_8:
6390 case ARM::VLD3qAsm_16:
6391 case ARM::VLD3qAsm_32: {
6392 MCInst TmpInst;
6393 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006394 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006395 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6396 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6397 Spacing));
6398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6399 Spacing * 2));
6400 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6401 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6402 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6403 TmpInst.addOperand(Inst.getOperand(4));
6404 Inst = TmpInst;
6405 return true;
6406 }
6407
6408 case ARM::VLD3dWB_fixed_Asm_8:
6409 case ARM::VLD3dWB_fixed_Asm_16:
6410 case ARM::VLD3dWB_fixed_Asm_32:
6411 case ARM::VLD3qWB_fixed_Asm_8:
6412 case ARM::VLD3qWB_fixed_Asm_16:
6413 case ARM::VLD3qWB_fixed_Asm_32: {
6414 MCInst TmpInst;
6415 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006416 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006417 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6418 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6419 Spacing));
6420 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6421 Spacing * 2));
6422 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6423 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6424 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6425 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6426 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6427 TmpInst.addOperand(Inst.getOperand(4));
6428 Inst = TmpInst;
6429 return true;
6430 }
6431
6432 case ARM::VLD3dWB_register_Asm_8:
6433 case ARM::VLD3dWB_register_Asm_16:
6434 case ARM::VLD3dWB_register_Asm_32:
6435 case ARM::VLD3qWB_register_Asm_8:
6436 case ARM::VLD3qWB_register_Asm_16:
6437 case ARM::VLD3qWB_register_Asm_32: {
6438 MCInst TmpInst;
6439 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006440 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006441 TmpInst.addOperand(Inst.getOperand(0)); // 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(Inst.getOperand(1)); // Rn
6447 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6448 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6449 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6450 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6451 TmpInst.addOperand(Inst.getOperand(5));
6452 Inst = TmpInst;
6453 return true;
6454 }
6455
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006456 // VLD4DUP single 3-element structure to all lanes instructions.
6457 case ARM::VLD4DUPdAsm_8:
6458 case ARM::VLD4DUPdAsm_16:
6459 case ARM::VLD4DUPdAsm_32:
6460 case ARM::VLD4DUPqAsm_8:
6461 case ARM::VLD4DUPqAsm_16:
6462 case ARM::VLD4DUPqAsm_32: {
6463 MCInst TmpInst;
6464 unsigned Spacing;
6465 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6466 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6467 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6468 Spacing));
6469 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6470 Spacing * 2));
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6472 Spacing * 3));
6473 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6474 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6475 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6476 TmpInst.addOperand(Inst.getOperand(4));
6477 Inst = TmpInst;
6478 return true;
6479 }
6480
6481 case ARM::VLD4DUPdWB_fixed_Asm_8:
6482 case ARM::VLD4DUPdWB_fixed_Asm_16:
6483 case ARM::VLD4DUPdWB_fixed_Asm_32:
6484 case ARM::VLD4DUPqWB_fixed_Asm_8:
6485 case ARM::VLD4DUPqWB_fixed_Asm_16:
6486 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6487 MCInst TmpInst;
6488 unsigned Spacing;
6489 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6490 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6491 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6492 Spacing));
6493 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6494 Spacing * 2));
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6496 Spacing * 3));
6497 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6498 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6499 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6500 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6501 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6502 TmpInst.addOperand(Inst.getOperand(4));
6503 Inst = TmpInst;
6504 return true;
6505 }
6506
6507 case ARM::VLD4DUPdWB_register_Asm_8:
6508 case ARM::VLD4DUPdWB_register_Asm_16:
6509 case ARM::VLD4DUPdWB_register_Asm_32:
6510 case ARM::VLD4DUPqWB_register_Asm_8:
6511 case ARM::VLD4DUPqWB_register_Asm_16:
6512 case ARM::VLD4DUPqWB_register_Asm_32: {
6513 MCInst TmpInst;
6514 unsigned Spacing;
6515 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6516 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6517 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6518 Spacing));
6519 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6520 Spacing * 2));
6521 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6522 Spacing * 3));
6523 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6524 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6525 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6526 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6527 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6528 TmpInst.addOperand(Inst.getOperand(5));
6529 Inst = TmpInst;
6530 return true;
6531 }
6532
6533 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006534 case ARM::VLD4dAsm_8:
6535 case ARM::VLD4dAsm_16:
6536 case ARM::VLD4dAsm_32:
6537 case ARM::VLD4qAsm_8:
6538 case ARM::VLD4qAsm_16:
6539 case ARM::VLD4qAsm_32: {
6540 MCInst TmpInst;
6541 unsigned Spacing;
6542 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6543 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6544 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6545 Spacing));
6546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6547 Spacing * 2));
6548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6549 Spacing * 3));
6550 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6551 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6552 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6553 TmpInst.addOperand(Inst.getOperand(4));
6554 Inst = TmpInst;
6555 return true;
6556 }
6557
6558 case ARM::VLD4dWB_fixed_Asm_8:
6559 case ARM::VLD4dWB_fixed_Asm_16:
6560 case ARM::VLD4dWB_fixed_Asm_32:
6561 case ARM::VLD4qWB_fixed_Asm_8:
6562 case ARM::VLD4qWB_fixed_Asm_16:
6563 case ARM::VLD4qWB_fixed_Asm_32: {
6564 MCInst TmpInst;
6565 unsigned Spacing;
6566 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6567 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6568 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6569 Spacing));
6570 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6571 Spacing * 2));
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6573 Spacing * 3));
6574 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6575 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6576 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6577 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6578 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6579 TmpInst.addOperand(Inst.getOperand(4));
6580 Inst = TmpInst;
6581 return true;
6582 }
6583
6584 case ARM::VLD4dWB_register_Asm_8:
6585 case ARM::VLD4dWB_register_Asm_16:
6586 case ARM::VLD4dWB_register_Asm_32:
6587 case ARM::VLD4qWB_register_Asm_8:
6588 case ARM::VLD4qWB_register_Asm_16:
6589 case ARM::VLD4qWB_register_Asm_32: {
6590 MCInst TmpInst;
6591 unsigned Spacing;
6592 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6593 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6594 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6595 Spacing));
6596 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6597 Spacing * 2));
6598 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6599 Spacing * 3));
6600 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6601 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6602 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6603 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6604 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6605 TmpInst.addOperand(Inst.getOperand(5));
6606 Inst = TmpInst;
6607 return true;
6608 }
6609
Jim Grosbach1a747242012-01-23 23:45:44 +00006610 // VST3 multiple 3-element structure instructions.
6611 case ARM::VST3dAsm_8:
6612 case ARM::VST3dAsm_16:
6613 case ARM::VST3dAsm_32:
6614 case ARM::VST3qAsm_8:
6615 case ARM::VST3qAsm_16:
6616 case ARM::VST3qAsm_32: {
6617 MCInst TmpInst;
6618 unsigned Spacing;
6619 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6620 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6621 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6622 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6624 Spacing));
6625 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6626 Spacing * 2));
6627 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6628 TmpInst.addOperand(Inst.getOperand(4));
6629 Inst = TmpInst;
6630 return true;
6631 }
6632
6633 case ARM::VST3dWB_fixed_Asm_8:
6634 case ARM::VST3dWB_fixed_Asm_16:
6635 case ARM::VST3dWB_fixed_Asm_32:
6636 case ARM::VST3qWB_fixed_Asm_8:
6637 case ARM::VST3qWB_fixed_Asm_16:
6638 case ARM::VST3qWB_fixed_Asm_32: {
6639 MCInst TmpInst;
6640 unsigned Spacing;
6641 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6642 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6643 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6644 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6645 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6646 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6647 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6648 Spacing));
6649 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6650 Spacing * 2));
6651 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6652 TmpInst.addOperand(Inst.getOperand(4));
6653 Inst = TmpInst;
6654 return true;
6655 }
6656
6657 case ARM::VST3dWB_register_Asm_8:
6658 case ARM::VST3dWB_register_Asm_16:
6659 case ARM::VST3dWB_register_Asm_32:
6660 case ARM::VST3qWB_register_Asm_8:
6661 case ARM::VST3qWB_register_Asm_16:
6662 case ARM::VST3qWB_register_Asm_32: {
6663 MCInst TmpInst;
6664 unsigned Spacing;
6665 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6666 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6667 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6668 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6669 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6670 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6671 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6672 Spacing));
6673 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6674 Spacing * 2));
6675 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6676 TmpInst.addOperand(Inst.getOperand(5));
6677 Inst = TmpInst;
6678 return true;
6679 }
6680
Jim Grosbachda70eac2012-01-24 00:58:13 +00006681 // VST4 multiple 3-element structure instructions.
6682 case ARM::VST4dAsm_8:
6683 case ARM::VST4dAsm_16:
6684 case ARM::VST4dAsm_32:
6685 case ARM::VST4qAsm_8:
6686 case ARM::VST4qAsm_16:
6687 case ARM::VST4qAsm_32: {
6688 MCInst TmpInst;
6689 unsigned Spacing;
6690 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6691 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6692 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6693 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6694 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6695 Spacing));
6696 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6697 Spacing * 2));
6698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6699 Spacing * 3));
6700 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6701 TmpInst.addOperand(Inst.getOperand(4));
6702 Inst = TmpInst;
6703 return true;
6704 }
6705
6706 case ARM::VST4dWB_fixed_Asm_8:
6707 case ARM::VST4dWB_fixed_Asm_16:
6708 case ARM::VST4dWB_fixed_Asm_32:
6709 case ARM::VST4qWB_fixed_Asm_8:
6710 case ARM::VST4qWB_fixed_Asm_16:
6711 case ARM::VST4qWB_fixed_Asm_32: {
6712 MCInst TmpInst;
6713 unsigned Spacing;
6714 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
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(0)); // Vd
6720 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6721 Spacing));
6722 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6723 Spacing * 2));
6724 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6725 Spacing * 3));
6726 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6727 TmpInst.addOperand(Inst.getOperand(4));
6728 Inst = TmpInst;
6729 return true;
6730 }
6731
6732 case ARM::VST4dWB_register_Asm_8:
6733 case ARM::VST4dWB_register_Asm_16:
6734 case ARM::VST4dWB_register_Asm_32:
6735 case ARM::VST4qWB_register_Asm_8:
6736 case ARM::VST4qWB_register_Asm_16:
6737 case ARM::VST4qWB_register_Asm_32: {
6738 MCInst TmpInst;
6739 unsigned Spacing;
6740 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
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(0)); // Vd
6746 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6747 Spacing));
6748 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6749 Spacing * 2));
6750 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6751 Spacing * 3));
6752 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6753 TmpInst.addOperand(Inst.getOperand(5));
6754 Inst = TmpInst;
6755 return true;
6756 }
6757
Jim Grosbachad66de12012-04-11 00:15:16 +00006758 // Handle encoding choice for the shift-immediate instructions.
6759 case ARM::t2LSLri:
6760 case ARM::t2LSRri:
6761 case ARM::t2ASRri: {
6762 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6763 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6764 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6765 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6766 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6767 unsigned NewOpc;
6768 switch (Inst.getOpcode()) {
6769 default: llvm_unreachable("unexpected opcode");
6770 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6771 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6772 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6773 }
6774 // The Thumb1 operands aren't in the same order. Awesome, eh?
6775 MCInst TmpInst;
6776 TmpInst.setOpcode(NewOpc);
6777 TmpInst.addOperand(Inst.getOperand(0));
6778 TmpInst.addOperand(Inst.getOperand(5));
6779 TmpInst.addOperand(Inst.getOperand(1));
6780 TmpInst.addOperand(Inst.getOperand(2));
6781 TmpInst.addOperand(Inst.getOperand(3));
6782 TmpInst.addOperand(Inst.getOperand(4));
6783 Inst = TmpInst;
6784 return true;
6785 }
6786 return false;
6787 }
6788
Jim Grosbach485e5622011-12-13 22:45:11 +00006789 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006790 case ARM::t2MOVsr:
6791 case ARM::t2MOVSsr: {
6792 // Which instruction to expand to depends on the CCOut operand and
6793 // whether we're in an IT block if the register operands are low
6794 // registers.
6795 bool isNarrow = false;
6796 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6797 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6798 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6799 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6800 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6801 isNarrow = true;
6802 MCInst TmpInst;
6803 unsigned newOpc;
6804 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6805 default: llvm_unreachable("unexpected opcode!");
6806 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6807 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6808 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6809 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6810 }
6811 TmpInst.setOpcode(newOpc);
6812 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6813 if (isNarrow)
6814 TmpInst.addOperand(MCOperand::CreateReg(
6815 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6816 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6817 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6818 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6819 TmpInst.addOperand(Inst.getOperand(5));
6820 if (!isNarrow)
6821 TmpInst.addOperand(MCOperand::CreateReg(
6822 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6823 Inst = TmpInst;
6824 return true;
6825 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006826 case ARM::t2MOVsi:
6827 case ARM::t2MOVSsi: {
6828 // Which instruction to expand to depends on the CCOut operand and
6829 // whether we're in an IT block if the register operands are low
6830 // registers.
6831 bool isNarrow = false;
6832 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6833 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6834 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6835 isNarrow = true;
6836 MCInst TmpInst;
6837 unsigned newOpc;
6838 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6839 default: llvm_unreachable("unexpected opcode!");
6840 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6841 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6842 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6843 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006844 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006845 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006846 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6847 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006848 TmpInst.setOpcode(newOpc);
6849 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6850 if (isNarrow)
6851 TmpInst.addOperand(MCOperand::CreateReg(
6852 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6853 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006854 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006855 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006856 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6857 TmpInst.addOperand(Inst.getOperand(4));
6858 if (!isNarrow)
6859 TmpInst.addOperand(MCOperand::CreateReg(
6860 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6861 Inst = TmpInst;
6862 return true;
6863 }
6864 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006865 case ARM::ASRr:
6866 case ARM::LSRr:
6867 case ARM::LSLr:
6868 case ARM::RORr: {
6869 ARM_AM::ShiftOpc ShiftTy;
6870 switch(Inst.getOpcode()) {
6871 default: llvm_unreachable("unexpected opcode!");
6872 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6873 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6874 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6875 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6876 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006877 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6878 MCInst TmpInst;
6879 TmpInst.setOpcode(ARM::MOVsr);
6880 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6881 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6882 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6883 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6884 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6885 TmpInst.addOperand(Inst.getOperand(4));
6886 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6887 Inst = TmpInst;
6888 return true;
6889 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00006890 case ARM::ASRi:
6891 case ARM::LSRi:
6892 case ARM::LSLi:
6893 case ARM::RORi: {
6894 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006895 switch(Inst.getOpcode()) {
6896 default: llvm_unreachable("unexpected opcode!");
6897 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6898 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6899 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6900 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6901 }
6902 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006903 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00006904 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00006905 // A shift by 32 should be encoded as 0 when permitted
6906 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6907 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006908 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006909 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006910 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006911 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6912 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00006913 if (Opc == ARM::MOVsi)
6914 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00006915 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6916 TmpInst.addOperand(Inst.getOperand(4));
6917 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6918 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006919 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00006920 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006921 case ARM::RRXi: {
6922 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6923 MCInst TmpInst;
6924 TmpInst.setOpcode(ARM::MOVsi);
6925 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6926 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6927 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6928 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6929 TmpInst.addOperand(Inst.getOperand(3));
6930 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6931 Inst = TmpInst;
6932 return true;
6933 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00006934 case ARM::t2LDMIA_UPD: {
6935 // If this is a load of a single register, then we should use
6936 // a post-indexed LDR instruction instead, per the ARM ARM.
6937 if (Inst.getNumOperands() != 5)
6938 return false;
6939 MCInst TmpInst;
6940 TmpInst.setOpcode(ARM::t2LDR_POST);
6941 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6942 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6943 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6944 TmpInst.addOperand(MCOperand::CreateImm(4));
6945 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6946 TmpInst.addOperand(Inst.getOperand(3));
6947 Inst = TmpInst;
6948 return true;
6949 }
6950 case ARM::t2STMDB_UPD: {
6951 // If this is a store of a single register, then we should use
6952 // a pre-indexed STR instruction instead, per the ARM ARM.
6953 if (Inst.getNumOperands() != 5)
6954 return false;
6955 MCInst TmpInst;
6956 TmpInst.setOpcode(ARM::t2STR_PRE);
6957 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6958 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6959 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6960 TmpInst.addOperand(MCOperand::CreateImm(-4));
6961 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6962 TmpInst.addOperand(Inst.getOperand(3));
6963 Inst = TmpInst;
6964 return true;
6965 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006966 case ARM::LDMIA_UPD:
6967 // If this is a load of a single register via a 'pop', then we should use
6968 // a post-indexed LDR instruction instead, per the ARM ARM.
6969 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6970 Inst.getNumOperands() == 5) {
6971 MCInst TmpInst;
6972 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6973 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6974 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6975 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6976 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6977 TmpInst.addOperand(MCOperand::CreateImm(4));
6978 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6979 TmpInst.addOperand(Inst.getOperand(3));
6980 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006981 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006982 }
6983 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00006984 case ARM::STMDB_UPD:
6985 // If this is a store of a single register via a 'push', then we should use
6986 // a pre-indexed STR instruction instead, per the ARM ARM.
6987 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6988 Inst.getNumOperands() == 5) {
6989 MCInst TmpInst;
6990 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6991 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6992 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6993 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6994 TmpInst.addOperand(MCOperand::CreateImm(-4));
6995 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6996 TmpInst.addOperand(Inst.getOperand(3));
6997 Inst = TmpInst;
6998 }
6999 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007000 case ARM::t2ADDri12:
7001 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7002 // mnemonic was used (not "addw"), encoding T3 is preferred.
7003 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7004 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7005 break;
7006 Inst.setOpcode(ARM::t2ADDri);
7007 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7008 break;
7009 case ARM::t2SUBri12:
7010 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7011 // mnemonic was used (not "subw"), encoding T3 is preferred.
7012 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7013 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7014 break;
7015 Inst.setOpcode(ARM::t2SUBri);
7016 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7017 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007018 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007019 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007020 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7021 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7022 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007023 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007024 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007025 return true;
7026 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007027 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007028 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007029 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007030 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7031 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7032 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007033 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007034 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007035 return true;
7036 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007037 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007038 case ARM::t2ADDri:
7039 case ARM::t2SUBri: {
7040 // If the destination and first source operand are the same, and
7041 // the flags are compatible with the current IT status, use encoding T2
7042 // instead of T3. For compatibility with the system 'as'. Make sure the
7043 // wide encoding wasn't explicit.
7044 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007045 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007046 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7047 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7048 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7049 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7050 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7051 break;
7052 MCInst TmpInst;
7053 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7054 ARM::tADDi8 : ARM::tSUBi8);
7055 TmpInst.addOperand(Inst.getOperand(0));
7056 TmpInst.addOperand(Inst.getOperand(5));
7057 TmpInst.addOperand(Inst.getOperand(0));
7058 TmpInst.addOperand(Inst.getOperand(2));
7059 TmpInst.addOperand(Inst.getOperand(3));
7060 TmpInst.addOperand(Inst.getOperand(4));
7061 Inst = TmpInst;
7062 return true;
7063 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007064 case ARM::t2ADDrr: {
7065 // If the destination and first source operand are the same, and
7066 // there's no setting of the flags, use encoding T2 instead of T3.
7067 // Note that this is only for ADD, not SUB. This mirrors the system
7068 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7069 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7070 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007071 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7072 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007073 break;
7074 MCInst TmpInst;
7075 TmpInst.setOpcode(ARM::tADDhirr);
7076 TmpInst.addOperand(Inst.getOperand(0));
7077 TmpInst.addOperand(Inst.getOperand(0));
7078 TmpInst.addOperand(Inst.getOperand(2));
7079 TmpInst.addOperand(Inst.getOperand(3));
7080 TmpInst.addOperand(Inst.getOperand(4));
7081 Inst = TmpInst;
7082 return true;
7083 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007084 case ARM::tADDrSP: {
7085 // If the non-SP source operand and the destination operand are not the
7086 // same, we need to use the 32-bit encoding if it's available.
7087 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7088 Inst.setOpcode(ARM::t2ADDrr);
7089 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7090 return true;
7091 }
7092 break;
7093 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007094 case ARM::tB:
7095 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007096 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007097 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007098 return true;
7099 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007100 break;
7101 case ARM::t2B:
7102 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007103 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007104 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007105 return true;
7106 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007107 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007108 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007109 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007110 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007111 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007112 return true;
7113 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007114 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007115 case ARM::tBcc:
7116 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007117 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007118 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007119 return true;
7120 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007121 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007122 case ARM::tLDMIA: {
7123 // If the register list contains any high registers, or if the writeback
7124 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7125 // instead if we're in Thumb2. Otherwise, this should have generated
7126 // an error in validateInstruction().
7127 unsigned Rn = Inst.getOperand(0).getReg();
7128 bool hasWritebackToken =
7129 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7130 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7131 bool listContainsBase;
7132 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7133 (!listContainsBase && !hasWritebackToken) ||
7134 (listContainsBase && hasWritebackToken)) {
7135 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7136 assert (isThumbTwo());
7137 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7138 // If we're switching to the updating version, we need to insert
7139 // the writeback tied operand.
7140 if (hasWritebackToken)
7141 Inst.insert(Inst.begin(),
7142 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007143 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007144 }
7145 break;
7146 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007147 case ARM::tSTMIA_UPD: {
7148 // If the register list contains any high registers, we need to use
7149 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7150 // should have generated an error in validateInstruction().
7151 unsigned Rn = Inst.getOperand(0).getReg();
7152 bool listContainsBase;
7153 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7154 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7155 assert (isThumbTwo());
7156 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007157 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007158 }
7159 break;
7160 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007161 case ARM::tPOP: {
7162 bool listContainsBase;
7163 // If the register list contains any high registers, we need to use
7164 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7165 // should have generated an error in validateInstruction().
7166 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007167 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007168 assert (isThumbTwo());
7169 Inst.setOpcode(ARM::t2LDMIA_UPD);
7170 // Add the base register and writeback operands.
7171 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7172 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007173 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007174 }
7175 case ARM::tPUSH: {
7176 bool listContainsBase;
7177 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007178 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007179 assert (isThumbTwo());
7180 Inst.setOpcode(ARM::t2STMDB_UPD);
7181 // Add the base register and writeback operands.
7182 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7183 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007184 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007185 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007186 case ARM::t2MOVi: {
7187 // If we can use the 16-bit encoding and the user didn't explicitly
7188 // request the 32-bit variant, transform it here.
7189 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007190 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007191 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7192 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7193 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007194 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7195 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7196 // The operands aren't in the same order for tMOVi8...
7197 MCInst TmpInst;
7198 TmpInst.setOpcode(ARM::tMOVi8);
7199 TmpInst.addOperand(Inst.getOperand(0));
7200 TmpInst.addOperand(Inst.getOperand(4));
7201 TmpInst.addOperand(Inst.getOperand(1));
7202 TmpInst.addOperand(Inst.getOperand(2));
7203 TmpInst.addOperand(Inst.getOperand(3));
7204 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007205 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007206 }
7207 break;
7208 }
7209 case ARM::t2MOVr: {
7210 // If we can use the 16-bit encoding and the user didn't explicitly
7211 // request the 32-bit variant, transform it here.
7212 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7213 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7214 Inst.getOperand(2).getImm() == ARMCC::AL &&
7215 Inst.getOperand(4).getReg() == ARM::CPSR &&
7216 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7217 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7218 // The operands aren't the same for tMOV[S]r... (no cc_out)
7219 MCInst TmpInst;
7220 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7221 TmpInst.addOperand(Inst.getOperand(0));
7222 TmpInst.addOperand(Inst.getOperand(1));
7223 TmpInst.addOperand(Inst.getOperand(2));
7224 TmpInst.addOperand(Inst.getOperand(3));
7225 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007226 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007227 }
7228 break;
7229 }
Jim Grosbach82213192011-09-19 20:29:33 +00007230 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007231 case ARM::t2SXTB:
7232 case ARM::t2UXTH:
7233 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007234 // If we can use the 16-bit encoding and the user didn't explicitly
7235 // request the 32-bit variant, transform it here.
7236 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7237 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7238 Inst.getOperand(2).getImm() == 0 &&
7239 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7240 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007241 unsigned NewOpc;
7242 switch (Inst.getOpcode()) {
7243 default: llvm_unreachable("Illegal opcode!");
7244 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7245 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7246 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7247 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7248 }
Jim Grosbach82213192011-09-19 20:29:33 +00007249 // The operands aren't the same for thumb1 (no rotate operand).
7250 MCInst TmpInst;
7251 TmpInst.setOpcode(NewOpc);
7252 TmpInst.addOperand(Inst.getOperand(0));
7253 TmpInst.addOperand(Inst.getOperand(1));
7254 TmpInst.addOperand(Inst.getOperand(3));
7255 TmpInst.addOperand(Inst.getOperand(4));
7256 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007257 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007258 }
7259 break;
7260 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007261 case ARM::MOVsi: {
7262 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007263 // rrx shifts and asr/lsr of #32 is encoded as 0
7264 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7265 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007266 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7267 // Shifting by zero is accepted as a vanilla 'MOVr'
7268 MCInst TmpInst;
7269 TmpInst.setOpcode(ARM::MOVr);
7270 TmpInst.addOperand(Inst.getOperand(0));
7271 TmpInst.addOperand(Inst.getOperand(1));
7272 TmpInst.addOperand(Inst.getOperand(3));
7273 TmpInst.addOperand(Inst.getOperand(4));
7274 TmpInst.addOperand(Inst.getOperand(5));
7275 Inst = TmpInst;
7276 return true;
7277 }
7278 return false;
7279 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007280 case ARM::ANDrsi:
7281 case ARM::ORRrsi:
7282 case ARM::EORrsi:
7283 case ARM::BICrsi:
7284 case ARM::SUBrsi:
7285 case ARM::ADDrsi: {
7286 unsigned newOpc;
7287 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7288 if (SOpc == ARM_AM::rrx) return false;
7289 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007290 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007291 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7292 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7293 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7294 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7295 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7296 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7297 }
7298 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007299 // The exception is for right shifts, where 0 == 32
7300 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7301 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007302 MCInst TmpInst;
7303 TmpInst.setOpcode(newOpc);
7304 TmpInst.addOperand(Inst.getOperand(0));
7305 TmpInst.addOperand(Inst.getOperand(1));
7306 TmpInst.addOperand(Inst.getOperand(2));
7307 TmpInst.addOperand(Inst.getOperand(4));
7308 TmpInst.addOperand(Inst.getOperand(5));
7309 TmpInst.addOperand(Inst.getOperand(6));
7310 Inst = TmpInst;
7311 return true;
7312 }
7313 return false;
7314 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007315 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007316 case ARM::t2IT: {
7317 // The mask bits for all but the first condition are represented as
7318 // the low bit of the condition code value implies 't'. We currently
7319 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007320 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007321 MCOperand &MO = Inst.getOperand(1);
7322 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007323 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007324 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007325 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007326 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007327 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007328 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007329 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007330
7331 // Set up the IT block state according to the IT instruction we just
7332 // matched.
7333 assert(!inITBlock() && "nested IT blocks?!");
7334 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7335 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7336 ITState.CurPosition = 0;
7337 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007338 break;
7339 }
Richard Bartona39625e2012-07-09 16:12:24 +00007340 case ARM::t2LSLrr:
7341 case ARM::t2LSRrr:
7342 case ARM::t2ASRrr:
7343 case ARM::t2SBCrr:
7344 case ARM::t2RORrr:
7345 case ARM::t2BICrr:
7346 {
Richard Bartond5660372012-07-09 16:14:28 +00007347 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007348 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7349 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7350 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007351 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7352 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007353 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7354 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7355 unsigned NewOpc;
7356 switch (Inst.getOpcode()) {
7357 default: llvm_unreachable("unexpected opcode");
7358 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7359 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7360 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7361 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7362 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7363 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7364 }
7365 MCInst TmpInst;
7366 TmpInst.setOpcode(NewOpc);
7367 TmpInst.addOperand(Inst.getOperand(0));
7368 TmpInst.addOperand(Inst.getOperand(5));
7369 TmpInst.addOperand(Inst.getOperand(1));
7370 TmpInst.addOperand(Inst.getOperand(2));
7371 TmpInst.addOperand(Inst.getOperand(3));
7372 TmpInst.addOperand(Inst.getOperand(4));
7373 Inst = TmpInst;
7374 return true;
7375 }
7376 return false;
7377 }
7378 case ARM::t2ANDrr:
7379 case ARM::t2EORrr:
7380 case ARM::t2ADCrr:
7381 case ARM::t2ORRrr:
7382 {
Richard Bartond5660372012-07-09 16:14:28 +00007383 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007384 // These instructions are special in that they are commutable, so shorter encodings
7385 // are available more often.
7386 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7387 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7388 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7389 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007390 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7391 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007392 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7393 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7394 unsigned NewOpc;
7395 switch (Inst.getOpcode()) {
7396 default: llvm_unreachable("unexpected opcode");
7397 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7398 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7399 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7400 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7401 }
7402 MCInst TmpInst;
7403 TmpInst.setOpcode(NewOpc);
7404 TmpInst.addOperand(Inst.getOperand(0));
7405 TmpInst.addOperand(Inst.getOperand(5));
7406 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7407 TmpInst.addOperand(Inst.getOperand(1));
7408 TmpInst.addOperand(Inst.getOperand(2));
7409 } else {
7410 TmpInst.addOperand(Inst.getOperand(2));
7411 TmpInst.addOperand(Inst.getOperand(1));
7412 }
7413 TmpInst.addOperand(Inst.getOperand(3));
7414 TmpInst.addOperand(Inst.getOperand(4));
7415 Inst = TmpInst;
7416 return true;
7417 }
7418 return false;
7419 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007420 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007421 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007422}
7423
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007424unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7425 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7426 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007427 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007428 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007429 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7430 assert(MCID.hasOptionalDef() &&
7431 "optionally flag setting instruction missing optional def operand");
7432 assert(MCID.NumOperands == Inst.getNumOperands() &&
7433 "operand count mismatch!");
7434 // Find the optional-def operand (cc_out).
7435 unsigned OpNo;
7436 for (OpNo = 0;
7437 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7438 ++OpNo)
7439 ;
7440 // If we're parsing Thumb1, reject it completely.
7441 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7442 return Match_MnemonicFail;
7443 // If we're parsing Thumb2, which form is legal depends on whether we're
7444 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007445 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7446 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007447 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007448 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7449 inITBlock())
7450 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007451 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007452 // Some high-register supporting Thumb1 encodings only allow both registers
7453 // to be from r0-r7 when in Thumb2.
7454 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7455 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7456 isARMLowRegister(Inst.getOperand(2).getReg()))
7457 return Match_RequiresThumb2;
7458 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007459 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007460 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7461 isARMLowRegister(Inst.getOperand(1).getReg()))
7462 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007463 return Match_Success;
7464}
7465
Jim Grosbach5117ef72012-04-24 22:40:08 +00007466static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007467bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007468MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007469 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007470 MCStreamer &Out, unsigned &ErrorInfo,
7471 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007472 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007473 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007474
Chad Rosier2f480a82012-10-12 22:53:36 +00007475 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007476 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007477 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007478 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007479 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007480 // Context sensitive operand constraints aren't handled by the matcher,
7481 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007482 if (validateInstruction(Inst, Operands)) {
7483 // Still progress the IT block, otherwise one wrong condition causes
7484 // nasty cascading errors.
7485 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007486 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007487 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007488
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007489 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007490 // encoding is selected. Loop on it while changes happen so the
7491 // individual transformations can chain off each other. E.g.,
7492 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7493 while (processInstruction(Inst, Operands))
7494 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007495
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007496 // Only move forward at the very end so that everything in validate
7497 // and process gets a consistent answer about whether we're in an IT
7498 // block.
7499 forwardITPosition();
7500
Jim Grosbach82f76d12012-01-25 19:52:01 +00007501 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7502 // doesn't actually encode.
7503 if (Inst.getOpcode() == ARM::ITasm)
7504 return false;
7505
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007506 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007507 Out.EmitInstruction(Inst);
7508 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007509 case Match_MissingFeature: {
7510 assert(ErrorInfo && "Unknown missing feature!");
7511 // Special case the error message for the very common case where only
7512 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7513 std::string Msg = "instruction requires:";
7514 unsigned Mask = 1;
7515 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7516 if (ErrorInfo & Mask) {
7517 Msg += " ";
7518 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7519 }
7520 Mask <<= 1;
7521 }
7522 return Error(IDLoc, Msg);
7523 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007524 case Match_InvalidOperand: {
7525 SMLoc ErrorLoc = IDLoc;
7526 if (ErrorInfo != ~0U) {
7527 if (ErrorInfo >= Operands.size())
7528 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007529
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007530 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7531 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7532 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007533
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007534 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007535 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007536 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007537 return Error(IDLoc, "invalid instruction",
7538 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007539 case Match_RequiresNotITBlock:
7540 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007541 case Match_RequiresITBlock:
7542 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007543 case Match_RequiresV6:
7544 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7545 case Match_RequiresThumb2:
7546 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007547 case Match_ImmRange0_4: {
7548 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7549 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7550 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7551 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007552 case Match_ImmRange0_15: {
7553 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7554 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7555 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7556 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007557 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007558
Eric Christopher91d7b902010-10-29 09:26:59 +00007559 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007560}
7561
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007562/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007563bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7564 StringRef IDVal = DirectiveID.getIdentifier();
7565 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007566 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007567 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007568 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007569 else if (IDVal == ".arm")
7570 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007571 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007572 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007573 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007574 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007575 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007576 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007577 else if (IDVal == ".unreq")
7578 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007579 else if (IDVal == ".arch")
7580 return parseDirectiveArch(DirectiveID.getLoc());
7581 else if (IDVal == ".eabi_attribute")
7582 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007583 else if (IDVal == ".fnstart")
7584 return parseDirectiveFnStart(DirectiveID.getLoc());
7585 else if (IDVal == ".fnend")
7586 return parseDirectiveFnEnd(DirectiveID.getLoc());
7587 else if (IDVal == ".cantunwind")
7588 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7589 else if (IDVal == ".personality")
7590 return parseDirectivePersonality(DirectiveID.getLoc());
7591 else if (IDVal == ".handlerdata")
7592 return parseDirectiveHandlerData(DirectiveID.getLoc());
7593 else if (IDVal == ".setfp")
7594 return parseDirectiveSetFP(DirectiveID.getLoc());
7595 else if (IDVal == ".pad")
7596 return parseDirectivePad(DirectiveID.getLoc());
7597 else if (IDVal == ".save")
7598 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7599 else if (IDVal == ".vsave")
7600 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007601 return true;
7602}
7603
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007604/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007605/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007606bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007607 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7608 for (;;) {
7609 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007610 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007611 return true;
7612
Eric Christopherbf7bc492013-01-09 03:52:05 +00007613 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007614
7615 if (getLexer().is(AsmToken::EndOfStatement))
7616 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007617
Kevin Enderbyccab3172009-09-15 00:27:25 +00007618 // FIXME: Improve diagnostic.
7619 if (getLexer().isNot(AsmToken::Comma))
7620 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007621 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007622 }
7623 }
7624
Sean Callanana83fd7d2010-01-19 20:27:46 +00007625 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007626 return false;
7627}
7628
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007629/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007630/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007631bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007632 if (getLexer().isNot(AsmToken::EndOfStatement))
7633 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007634 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007635
Tim Northovera2292d02013-06-10 23:20:58 +00007636 if (!hasThumb())
7637 return Error(L, "target does not support Thumb mode");
7638
Jim Grosbach7f882392011-12-07 18:04:19 +00007639 if (!isThumb())
7640 SwitchMode();
7641 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7642 return false;
7643}
7644
7645/// parseDirectiveARM
7646/// ::= .arm
7647bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7648 if (getLexer().isNot(AsmToken::EndOfStatement))
7649 return Error(L, "unexpected token in directive");
7650 Parser.Lex();
7651
Tim Northovera2292d02013-06-10 23:20:58 +00007652 if (!hasARM())
7653 return Error(L, "target does not support ARM mode");
7654
Jim Grosbach7f882392011-12-07 18:04:19 +00007655 if (isThumb())
7656 SwitchMode();
7657 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007658 return false;
7659}
7660
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007661/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007662/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007663bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007664 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7665 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007666 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007667 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007668
Jim Grosbach1152cc02011-12-21 22:30:16 +00007669 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007670 // ELF doesn't
7671 if (isMachO) {
7672 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007673 if (Tok.isNot(AsmToken::EndOfStatement)) {
7674 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7675 return Error(L, "unexpected token in .thumb_func directive");
7676 Name = Tok.getIdentifier();
7677 Parser.Lex(); // Consume the identifier token.
7678 needFuncName = false;
7679 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007680 }
7681
Jim Grosbach1152cc02011-12-21 22:30:16 +00007682 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007683 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007684
7685 // Eat the end of statement and any blank lines that follow.
7686 while (getLexer().is(AsmToken::EndOfStatement))
7687 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007688
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007689 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007690 // We really should be checking the next symbol definition even if there's
7691 // stuff in between.
7692 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007693 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007694 }
7695
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007696 // Mark symbol as a thumb symbol.
7697 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7698 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007699 return false;
7700}
7701
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007702/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007703/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007704bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007705 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007706 if (Tok.isNot(AsmToken::Identifier))
7707 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007708 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007709 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007710 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007711 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007712 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007713 else
7714 return Error(L, "unrecognized syntax mode in .syntax directive");
7715
7716 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007717 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007718 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007719
7720 // TODO tell the MC streamer the mode
7721 // getParser().getStreamer().Emit???();
7722 return false;
7723}
7724
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007725/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007726/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007727bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007728 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007729 if (Tok.isNot(AsmToken::Integer))
7730 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007731 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007732 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007733 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007734 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007735 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007736 else
7737 return Error(L, "invalid operand to .code directive");
7738
7739 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007740 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007741 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007742
Evan Cheng284b4672011-07-08 22:36:29 +00007743 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007744 if (!hasThumb())
7745 return Error(L, "target does not support Thumb mode");
7746
Jim Grosbachf471ac32011-09-06 18:46:23 +00007747 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007748 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007749 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007750 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007751 if (!hasARM())
7752 return Error(L, "target does not support ARM mode");
7753
Jim Grosbachf471ac32011-09-06 18:46:23 +00007754 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007755 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007756 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007757 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007758
Kevin Enderby146dcf22009-10-15 20:48:48 +00007759 return false;
7760}
7761
Jim Grosbachab5830e2011-12-14 02:16:11 +00007762/// parseDirectiveReq
7763/// ::= name .req registername
7764bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7765 Parser.Lex(); // Eat the '.req' token.
7766 unsigned Reg;
7767 SMLoc SRegLoc, ERegLoc;
7768 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007769 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007770 return Error(SRegLoc, "register name expected");
7771 }
7772
7773 // Shouldn't be anything else.
7774 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007775 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007776 return Error(Parser.getTok().getLoc(),
7777 "unexpected input in .req directive.");
7778 }
7779
7780 Parser.Lex(); // Consume the EndOfStatement
7781
7782 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7783 return Error(SRegLoc, "redefinition of '" + Name +
7784 "' does not match original.");
7785
7786 return false;
7787}
7788
7789/// parseDirectiveUneq
7790/// ::= .unreq registername
7791bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7792 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007793 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007794 return Error(L, "unexpected input in .unreq directive.");
7795 }
7796 RegisterReqs.erase(Parser.getTok().getIdentifier());
7797 Parser.Lex(); // Eat the identifier.
7798 return false;
7799}
7800
Jason W Kim135d2442011-12-20 17:38:12 +00007801/// parseDirectiveArch
7802/// ::= .arch token
7803bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7804 return true;
7805}
7806
7807/// parseDirectiveEabiAttr
7808/// ::= .eabi_attribute int, int
7809bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7810 return true;
7811}
7812
Logan Chien4ea23b52013-05-10 16:17:24 +00007813/// parseDirectiveFnStart
7814/// ::= .fnstart
7815bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7816 if (FnStartLoc.isValid()) {
7817 Error(L, ".fnstart starts before the end of previous one");
7818 Error(FnStartLoc, "previous .fnstart starts here");
7819 return true;
7820 }
7821
7822 FnStartLoc = L;
7823 getParser().getStreamer().EmitFnStart();
7824 return false;
7825}
7826
7827/// parseDirectiveFnEnd
7828/// ::= .fnend
7829bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7830 // Check the ordering of unwind directives
7831 if (!FnStartLoc.isValid())
7832 return Error(L, ".fnstart must precede .fnend directive");
7833
7834 // Reset the unwind directives parser state
7835 resetUnwindDirectiveParserState();
7836
7837 getParser().getStreamer().EmitFnEnd();
7838 return false;
7839}
7840
7841/// parseDirectiveCantUnwind
7842/// ::= .cantunwind
7843bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7844 // Check the ordering of unwind directives
7845 CantUnwindLoc = L;
7846 if (!FnStartLoc.isValid())
7847 return Error(L, ".fnstart must precede .cantunwind directive");
7848 if (HandlerDataLoc.isValid()) {
7849 Error(L, ".cantunwind can't be used with .handlerdata directive");
7850 Error(HandlerDataLoc, ".handlerdata was specified here");
7851 return true;
7852 }
7853 if (PersonalityLoc.isValid()) {
7854 Error(L, ".cantunwind can't be used with .personality directive");
7855 Error(PersonalityLoc, ".personality was specified here");
7856 return true;
7857 }
7858
7859 getParser().getStreamer().EmitCantUnwind();
7860 return false;
7861}
7862
7863/// parseDirectivePersonality
7864/// ::= .personality name
7865bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7866 // Check the ordering of unwind directives
7867 PersonalityLoc = L;
7868 if (!FnStartLoc.isValid())
7869 return Error(L, ".fnstart must precede .personality directive");
7870 if (CantUnwindLoc.isValid()) {
7871 Error(L, ".personality can't be used with .cantunwind directive");
7872 Error(CantUnwindLoc, ".cantunwind was specified here");
7873 return true;
7874 }
7875 if (HandlerDataLoc.isValid()) {
7876 Error(L, ".personality must precede .handlerdata directive");
7877 Error(HandlerDataLoc, ".handlerdata was specified here");
7878 return true;
7879 }
7880
7881 // Parse the name of the personality routine
7882 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7883 Parser.eatToEndOfStatement();
7884 return Error(L, "unexpected input in .personality directive.");
7885 }
7886 StringRef Name(Parser.getTok().getIdentifier());
7887 Parser.Lex();
7888
7889 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
7890 getParser().getStreamer().EmitPersonality(PR);
7891 return false;
7892}
7893
7894/// parseDirectiveHandlerData
7895/// ::= .handlerdata
7896bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
7897 // Check the ordering of unwind directives
7898 HandlerDataLoc = L;
7899 if (!FnStartLoc.isValid())
7900 return Error(L, ".fnstart must precede .personality directive");
7901 if (CantUnwindLoc.isValid()) {
7902 Error(L, ".handlerdata can't be used with .cantunwind directive");
7903 Error(CantUnwindLoc, ".cantunwind was specified here");
7904 return true;
7905 }
7906
7907 getParser().getStreamer().EmitHandlerData();
7908 return false;
7909}
7910
7911/// parseDirectiveSetFP
7912/// ::= .setfp fpreg, spreg [, offset]
7913bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
7914 // Check the ordering of unwind directives
7915 if (!FnStartLoc.isValid())
7916 return Error(L, ".fnstart must precede .setfp directive");
7917 if (HandlerDataLoc.isValid())
7918 return Error(L, ".setfp must precede .handlerdata directive");
7919
7920 // Parse fpreg
7921 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
7922 int NewFPReg = tryParseRegister();
7923 if (NewFPReg == -1)
7924 return Error(NewFPRegLoc, "frame pointer register expected");
7925
7926 // Consume comma
7927 if (!Parser.getTok().is(AsmToken::Comma))
7928 return Error(Parser.getTok().getLoc(), "comma expected");
7929 Parser.Lex(); // skip comma
7930
7931 // Parse spreg
7932 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
7933 int NewSPReg = tryParseRegister();
7934 if (NewSPReg == -1)
7935 return Error(NewSPRegLoc, "stack pointer register expected");
7936
7937 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
7938 return Error(NewSPRegLoc,
7939 "register should be either $sp or the latest fp register");
7940
7941 // Update the frame pointer register
7942 FPReg = NewFPReg;
7943
7944 // Parse offset
7945 int64_t Offset = 0;
7946 if (Parser.getTok().is(AsmToken::Comma)) {
7947 Parser.Lex(); // skip comma
7948
7949 if (Parser.getTok().isNot(AsmToken::Hash) &&
7950 Parser.getTok().isNot(AsmToken::Dollar)) {
7951 return Error(Parser.getTok().getLoc(), "'#' expected");
7952 }
7953 Parser.Lex(); // skip hash token.
7954
7955 const MCExpr *OffsetExpr;
7956 SMLoc ExLoc = Parser.getTok().getLoc();
7957 SMLoc EndLoc;
7958 if (getParser().parseExpression(OffsetExpr, EndLoc))
7959 return Error(ExLoc, "malformed setfp offset");
7960 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
7961 if (!CE)
7962 return Error(ExLoc, "setfp offset must be an immediate");
7963
7964 Offset = CE->getValue();
7965 }
7966
7967 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
7968 static_cast<unsigned>(NewSPReg),
7969 Offset);
7970 return false;
7971}
7972
7973/// parseDirective
7974/// ::= .pad offset
7975bool ARMAsmParser::parseDirectivePad(SMLoc L) {
7976 // Check the ordering of unwind directives
7977 if (!FnStartLoc.isValid())
7978 return Error(L, ".fnstart must precede .pad directive");
7979 if (HandlerDataLoc.isValid())
7980 return Error(L, ".pad must precede .handlerdata directive");
7981
7982 // Parse the offset
7983 if (Parser.getTok().isNot(AsmToken::Hash) &&
7984 Parser.getTok().isNot(AsmToken::Dollar)) {
7985 return Error(Parser.getTok().getLoc(), "'#' expected");
7986 }
7987 Parser.Lex(); // skip hash token.
7988
7989 const MCExpr *OffsetExpr;
7990 SMLoc ExLoc = Parser.getTok().getLoc();
7991 SMLoc EndLoc;
7992 if (getParser().parseExpression(OffsetExpr, EndLoc))
7993 return Error(ExLoc, "malformed pad offset");
7994 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
7995 if (!CE)
7996 return Error(ExLoc, "pad offset must be an immediate");
7997
7998 getParser().getStreamer().EmitPad(CE->getValue());
7999 return false;
8000}
8001
8002/// parseDirectiveRegSave
8003/// ::= .save { registers }
8004/// ::= .vsave { registers }
8005bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8006 // Check the ordering of unwind directives
8007 if (!FnStartLoc.isValid())
8008 return Error(L, ".fnstart must precede .save or .vsave directives");
8009 if (HandlerDataLoc.isValid())
8010 return Error(L, ".save or .vsave must precede .handlerdata directive");
8011
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008012 // RAII object to make sure parsed operands are deleted.
8013 struct CleanupObject {
8014 SmallVector<MCParsedAsmOperand *, 1> Operands;
8015 ~CleanupObject() {
8016 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8017 delete Operands[I];
8018 }
8019 } CO;
8020
Logan Chien4ea23b52013-05-10 16:17:24 +00008021 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008022 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008023 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008024 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008025 if (!IsVector && !Op->isRegList())
8026 return Error(L, ".save expects GPR registers");
8027 if (IsVector && !Op->isDPRRegList())
8028 return Error(L, ".vsave expects DPR registers");
8029
8030 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8031 return false;
8032}
8033
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008034/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008035extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008036 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8037 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008038}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008039
Chris Lattner3e4582a2010-09-06 19:11:01 +00008040#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008041#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008042#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008043#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008044
8045// Define this matcher function after the auto-generated include so we
8046// have the match class enum definitions.
8047unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8048 unsigned Kind) {
8049 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8050 // If the kind is a token for a literal immediate, check if our asm
8051 // operand matches. This is for InstAliases which have a fixed-value
8052 // immediate in the syntax.
8053 if (Kind == MCK__35_0 && Op->isImm()) {
8054 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8055 if (!CE)
8056 return Match_InvalidOperand;
8057 if (CE->getValue() == 0)
8058 return Match_Success;
8059 }
8060 return Match_InvalidOperand;
8061}