blob: 3d7baf5b28b21c25924cba44fddb62adbfae3807 [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*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000224 void cvtThumbBranches(MCInst &Inst,
225 const SmallVectorImpl<MCParsedAsmOperand*> &);
226
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000227 bool validateInstruction(MCInst &Inst,
228 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000229 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000230 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000231 bool shouldOmitCCOutOperand(StringRef Mnemonic,
232 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000233 bool shouldOmitPredicateOperand(StringRef Mnemonic,
234 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Gouly5d0564d2013-08-02 19:18:12 +0000235 bool isDeprecated(MCInst &Inst, StringRef &Info);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000236
Kevin Enderbyccab3172009-09-15 00:27:25 +0000237public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000238 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000239 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000240 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000241 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000242 Match_RequiresThumb2,
243#define GET_OPERAND_DIAGNOSTIC_TYPES
244#include "ARMGenAsmMatcher.inc"
245
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000246 };
247
Evan Cheng91111d22011-07-09 05:47:46 +0000248 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Logan Chien4ea23b52013-05-10 16:17:24 +0000249 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000250 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000251
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000252 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000253 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000254
Evan Cheng4d1ca962011-07-08 01:53:10 +0000255 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000256 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000257
258 // Not in an ITBlock to start with.
259 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000260
261 // Set ELF header flags.
262 // FIXME: This should eventually end up somewhere else where more
263 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000264 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
265 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
266 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000267 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000268
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000269 // Implementation of the MCTargetAsmParser interface:
270 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000271 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
272 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000273 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000274 bool ParseDirective(AsmToken DirectiveID);
275
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000276 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000277 unsigned checkTargetMatchPredicate(MCInst &Inst);
278
Chad Rosier49963552012-10-13 00:26:04 +0000279 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000280 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000281 MCStreamer &Out, unsigned &ErrorInfo,
282 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000283};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000284} // end anonymous namespace
285
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000286namespace {
287
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000288/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000289/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000290class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000291 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000292 k_CondCode,
293 k_CCOut,
294 k_ITCondMask,
295 k_CoprocNum,
296 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000297 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000298 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000299 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000300 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000301 k_Memory,
302 k_PostIndexRegister,
303 k_MSRMask,
304 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000305 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000306 k_Register,
307 k_RegisterList,
308 k_DPRRegisterList,
309 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000310 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000311 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000312 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000313 k_ShiftedRegister,
314 k_ShiftedImmediate,
315 k_ShifterImmediate,
316 k_RotateImmediate,
317 k_BitfieldDescriptor,
318 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000319 } Kind;
320
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000321 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000322 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000323
Eric Christopher8996c5d2013-03-15 00:42:55 +0000324 struct CCOp {
325 ARMCC::CondCodes Val;
326 };
327
328 struct CopOp {
329 unsigned Val;
330 };
331
332 struct CoprocOptionOp {
333 unsigned Val;
334 };
335
336 struct ITMaskOp {
337 unsigned Mask:4;
338 };
339
340 struct MBOptOp {
341 ARM_MB::MemBOpt Val;
342 };
343
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000344 struct ISBOptOp {
345 ARM_ISB::InstSyncBOpt Val;
346 };
347
Eric Christopher8996c5d2013-03-15 00:42:55 +0000348 struct IFlagsOp {
349 ARM_PROC::IFlags Val;
350 };
351
352 struct MMaskOp {
353 unsigned Val;
354 };
355
356 struct TokOp {
357 const char *Data;
358 unsigned Length;
359 };
360
361 struct RegOp {
362 unsigned RegNum;
363 };
364
365 // A vector register list is a sequential list of 1 to 4 registers.
366 struct VectorListOp {
367 unsigned RegNum;
368 unsigned Count;
369 unsigned LaneIndex;
370 bool isDoubleSpaced;
371 };
372
373 struct VectorIndexOp {
374 unsigned Val;
375 };
376
377 struct ImmOp {
378 const MCExpr *Val;
379 };
380
381 /// Combined record for all forms of ARM address expressions.
382 struct MemoryOp {
383 unsigned BaseRegNum;
384 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
385 // was specified.
386 const MCConstantExpr *OffsetImm; // Offset immediate value
387 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
388 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
389 unsigned ShiftImm; // shift for OffsetReg.
390 unsigned Alignment; // 0 = no alignment specified
391 // n = alignment in bytes (2, 4, 8, 16, or 32)
392 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
393 };
394
395 struct PostIdxRegOp {
396 unsigned RegNum;
397 bool isAdd;
398 ARM_AM::ShiftOpc ShiftTy;
399 unsigned ShiftImm;
400 };
401
402 struct ShifterImmOp {
403 bool isASR;
404 unsigned Imm;
405 };
406
407 struct RegShiftedRegOp {
408 ARM_AM::ShiftOpc ShiftTy;
409 unsigned SrcReg;
410 unsigned ShiftReg;
411 unsigned ShiftImm;
412 };
413
414 struct RegShiftedImmOp {
415 ARM_AM::ShiftOpc ShiftTy;
416 unsigned SrcReg;
417 unsigned ShiftImm;
418 };
419
420 struct RotImmOp {
421 unsigned Imm;
422 };
423
424 struct BitfieldOp {
425 unsigned LSB;
426 unsigned Width;
427 };
428
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000429 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000430 struct CCOp CC;
431 struct CopOp Cop;
432 struct CoprocOptionOp CoprocOption;
433 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000434 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000435 struct ITMaskOp ITMask;
436 struct IFlagsOp IFlags;
437 struct MMaskOp MMask;
438 struct TokOp Tok;
439 struct RegOp Reg;
440 struct VectorListOp VectorList;
441 struct VectorIndexOp VectorIndex;
442 struct ImmOp Imm;
443 struct MemoryOp Memory;
444 struct PostIdxRegOp PostIdxReg;
445 struct ShifterImmOp ShifterImm;
446 struct RegShiftedRegOp RegShiftedReg;
447 struct RegShiftedImmOp RegShiftedImm;
448 struct RotImmOp RotImm;
449 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000450 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000451
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000452 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
453public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000454 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
455 Kind = o.Kind;
456 StartLoc = o.StartLoc;
457 EndLoc = o.EndLoc;
458 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000459 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000460 CC = o.CC;
461 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000462 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000463 ITMask = o.ITMask;
464 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000465 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000466 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000467 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000468 case k_CCOut:
469 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000470 Reg = o.Reg;
471 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000472 case k_RegisterList:
473 case k_DPRRegisterList:
474 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000475 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000476 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000477 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000478 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000479 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000480 VectorList = o.VectorList;
481 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000482 case k_CoprocNum:
483 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000484 Cop = o.Cop;
485 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000486 case k_CoprocOption:
487 CoprocOption = o.CoprocOption;
488 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000489 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000490 Imm = o.Imm;
491 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000492 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000493 MBOpt = o.MBOpt;
494 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000495 case k_InstSyncBarrierOpt:
496 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000497 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000498 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000499 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000500 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000501 PostIdxReg = o.PostIdxReg;
502 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000503 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000504 MMask = o.MMask;
505 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000506 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000507 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000508 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000509 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000510 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000511 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000512 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000513 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000514 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000515 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000516 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000517 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000518 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000519 RotImm = o.RotImm;
520 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000521 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000522 Bitfield = o.Bitfield;
523 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000524 case k_VectorIndex:
525 VectorIndex = o.VectorIndex;
526 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000527 }
528 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000529
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000530 /// getStartLoc - Get the location of the first token of this operand.
531 SMLoc getStartLoc() const { return StartLoc; }
532 /// getEndLoc - Get the location of the last token of this operand.
533 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000534 /// getLocRange - Get the range between the first and last token of this
535 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000536 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
537
Daniel Dunbard8042b72010-08-11 06:36:53 +0000538 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000539 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000540 return CC.Val;
541 }
542
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000543 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000544 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000545 return Cop.Val;
546 }
547
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000548 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000549 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000550 return StringRef(Tok.Data, Tok.Length);
551 }
552
553 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000554 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000555 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000556 }
557
Bill Wendlingbed94652010-11-09 23:28:44 +0000558 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000559 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
560 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000561 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000562 }
563
Kevin Enderbyf5079942009-10-13 22:19:02 +0000564 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000565 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000566 return Imm.Val;
567 }
568
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000569 unsigned getVectorIndex() const {
570 assert(Kind == k_VectorIndex && "Invalid access!");
571 return VectorIndex.Val;
572 }
573
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000574 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000575 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000576 return MBOpt.Val;
577 }
578
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000579 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
580 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
581 return ISBOpt.Val;
582 }
583
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000584 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000585 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000586 return IFlags.Val;
587 }
588
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000589 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000590 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000591 return MMask.Val;
592 }
593
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000594 bool isCoprocNum() const { return Kind == k_CoprocNum; }
595 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000596 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000597 bool isCondCode() const { return Kind == k_CondCode; }
598 bool isCCOut() const { return Kind == k_CCOut; }
599 bool isITMask() const { return Kind == k_ITCondMask; }
600 bool isITCondCode() const { return Kind == k_CondCode; }
601 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000602 // checks whether this operand is an unsigned offset which fits is a field
603 // of specified width and scaled by a specific number of bits
604 template<unsigned width, unsigned scale>
605 bool isUnsignedOffset() const {
606 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000607 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000608 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
609 int64_t Val = CE->getValue();
610 int64_t Align = 1LL << scale;
611 int64_t Max = Align * ((1LL << width) - 1);
612 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
613 }
614 return false;
615 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000616 // checks whether this operand is an signed offset which fits is a field
617 // of specified width and scaled by a specific number of bits
618 template<unsigned width, unsigned scale>
619 bool isSignedOffset() const {
620 if (!isImm()) return false;
621 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
622 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
623 int64_t Val = CE->getValue();
624 int64_t Align = 1LL << scale;
625 int64_t Max = Align * ((1LL << (width-1)) - 1);
626 int64_t Min = -Align * (1LL << (width-1));
627 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
628 }
629 return false;
630 }
631
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000632 // checks whether this operand is a memory operand computed as an offset
633 // applied to PC. the offset may have 8 bits of magnitude and is represented
634 // with two bits of shift. textually it may be either [pc, #imm], #imm or
635 // relocable expression...
636 bool isThumbMemPC() const {
637 int64_t Val = 0;
638 if (isImm()) {
639 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
640 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
641 if (!CE) return false;
642 Val = CE->getValue();
643 }
644 else if (isMem()) {
645 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
646 if(Memory.BaseRegNum != ARM::PC) return false;
647 Val = Memory.OffsetImm->getValue();
648 }
649 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000650 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000651 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000652 bool isFPImm() const {
653 if (!isImm()) return false;
654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
655 if (!CE) return false;
656 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
657 return Val != -1;
658 }
Jim Grosbachea231912011-12-22 22:19:05 +0000659 bool isFBits16() const {
660 if (!isImm()) return false;
661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
662 if (!CE) return false;
663 int64_t Value = CE->getValue();
664 return Value >= 0 && Value <= 16;
665 }
666 bool isFBits32() const {
667 if (!isImm()) return false;
668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
669 if (!CE) return false;
670 int64_t Value = CE->getValue();
671 return Value >= 1 && Value <= 32;
672 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000673 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000674 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000675 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
676 if (!CE) return false;
677 int64_t Value = CE->getValue();
678 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
679 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000680 bool isImm0_4() const {
681 if (!isImm()) return false;
682 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
683 if (!CE) return false;
684 int64_t Value = CE->getValue();
685 return Value >= 0 && Value < 5;
686 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000687 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000688 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000689 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
690 if (!CE) return false;
691 int64_t Value = CE->getValue();
692 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
693 }
694 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000695 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
697 if (!CE) return false;
698 int64_t Value = CE->getValue();
699 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
700 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000701 bool isImm0_508s4Neg() const {
702 if (!isImm()) return false;
703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
704 if (!CE) return false;
705 int64_t Value = -CE->getValue();
706 // explicitly exclude zero. we want that to use the normal 0_508 version.
707 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
708 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000709 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000710 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000711 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
712 if (!CE) return false;
713 int64_t Value = CE->getValue();
714 return Value >= 0 && Value < 256;
715 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000716 bool isImm0_4095() const {
717 if (!isImm()) return false;
718 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
719 if (!CE) return false;
720 int64_t Value = CE->getValue();
721 return Value >= 0 && Value < 4096;
722 }
723 bool isImm0_4095Neg() const {
724 if (!isImm()) return false;
725 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
726 if (!CE) return false;
727 int64_t Value = -CE->getValue();
728 return Value > 0 && Value < 4096;
729 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000730 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000731 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000732 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
733 if (!CE) return false;
734 int64_t Value = CE->getValue();
735 return Value >= 0 && Value < 2;
736 }
737 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000738 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000739 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
740 if (!CE) return false;
741 int64_t Value = CE->getValue();
742 return Value >= 0 && Value < 4;
743 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000744 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000745 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
747 if (!CE) return false;
748 int64_t Value = CE->getValue();
749 return Value >= 0 && Value < 8;
750 }
751 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000752 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
754 if (!CE) return false;
755 int64_t Value = CE->getValue();
756 return Value >= 0 && Value < 16;
757 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000758 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000759 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000760 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
761 if (!CE) return false;
762 int64_t Value = CE->getValue();
763 return Value >= 0 && Value < 32;
764 }
Jim Grosbach00326402011-12-08 01:30:04 +0000765 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000766 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
768 if (!CE) return false;
769 int64_t Value = CE->getValue();
770 return Value >= 0 && Value < 64;
771 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000772 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000773 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000774 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
775 if (!CE) return false;
776 int64_t Value = CE->getValue();
777 return Value == 8;
778 }
779 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000780 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000781 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
782 if (!CE) return false;
783 int64_t Value = CE->getValue();
784 return Value == 16;
785 }
786 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000787 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000788 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
789 if (!CE) return false;
790 int64_t Value = CE->getValue();
791 return Value == 32;
792 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000793 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000794 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000795 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
796 if (!CE) return false;
797 int64_t Value = CE->getValue();
798 return Value > 0 && Value <= 8;
799 }
800 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000801 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000802 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
803 if (!CE) return false;
804 int64_t Value = CE->getValue();
805 return Value > 0 && Value <= 16;
806 }
807 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000808 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000809 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
810 if (!CE) return false;
811 int64_t Value = CE->getValue();
812 return Value > 0 && Value <= 32;
813 }
814 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000815 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000816 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
817 if (!CE) return false;
818 int64_t Value = CE->getValue();
819 return Value > 0 && Value <= 64;
820 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000821 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000822 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000823 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
824 if (!CE) return false;
825 int64_t Value = CE->getValue();
826 return Value > 0 && Value < 8;
827 }
828 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000829 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000830 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
831 if (!CE) return false;
832 int64_t Value = CE->getValue();
833 return Value > 0 && Value < 16;
834 }
835 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000836 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
838 if (!CE) return false;
839 int64_t Value = CE->getValue();
840 return Value > 0 && Value < 32;
841 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000842 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000843 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
845 if (!CE) return false;
846 int64_t Value = CE->getValue();
847 return Value > 0 && Value < 17;
848 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000849 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000850 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000851 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
852 if (!CE) return false;
853 int64_t Value = CE->getValue();
854 return Value > 0 && Value < 33;
855 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000856 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000857 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000858 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
859 if (!CE) return false;
860 int64_t Value = CE->getValue();
861 return Value >= 0 && Value < 33;
862 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000863 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000864 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000865 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
866 if (!CE) return false;
867 int64_t Value = CE->getValue();
868 return Value >= 0 && Value < 65536;
869 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000870 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000871 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000872 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
873 // If it's not a constant expression, it'll generate a fixup and be
874 // handled later.
875 if (!CE) return true;
876 int64_t Value = CE->getValue();
877 return Value >= 0 && Value < 65536;
878 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000879 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000880 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000881 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
882 if (!CE) return false;
883 int64_t Value = CE->getValue();
884 return Value >= 0 && Value <= 0xffffff;
885 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000886 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000887 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000888 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
889 if (!CE) return false;
890 int64_t Value = CE->getValue();
891 return Value > 0 && Value < 33;
892 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000893 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000894 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000895 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
896 if (!CE) return false;
897 int64_t Value = CE->getValue();
898 return Value >= 0 && Value < 32;
899 }
900 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000901 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000902 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
903 if (!CE) return false;
904 int64_t Value = CE->getValue();
905 return Value > 0 && Value <= 32;
906 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000907 bool isAdrLabel() const {
908 // If we have an immediate that's not a constant, treat it as a label
909 // reference needing a fixup. If it is a constant, but it can't fit
910 // into shift immediate encoding, we reject it.
911 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
912 else return (isARMSOImm() || isARMSOImmNeg());
913 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000914 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000915 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000916 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
917 if (!CE) return false;
918 int64_t Value = CE->getValue();
919 return ARM_AM::getSOImmVal(Value) != -1;
920 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000921 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000922 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000923 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
924 if (!CE) return false;
925 int64_t Value = CE->getValue();
926 return ARM_AM::getSOImmVal(~Value) != -1;
927 }
Jim Grosbach30506252011-12-08 00:31:07 +0000928 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000929 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000930 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
931 if (!CE) return false;
932 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000933 // Only use this when not representable as a plain so_imm.
934 return ARM_AM::getSOImmVal(Value) == -1 &&
935 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000936 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000937 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000938 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000939 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
940 if (!CE) return false;
941 int64_t Value = CE->getValue();
942 return ARM_AM::getT2SOImmVal(Value) != -1;
943 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000944 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000945 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000946 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
947 if (!CE) return false;
948 int64_t Value = CE->getValue();
949 return ARM_AM::getT2SOImmVal(~Value) != -1;
950 }
Jim Grosbach30506252011-12-08 00:31:07 +0000951 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000952 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
954 if (!CE) return false;
955 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000956 // Only use this when not representable as a plain so_imm.
957 return ARM_AM::getT2SOImmVal(Value) == -1 &&
958 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000959 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000960 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000961 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000962 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
963 if (!CE) return false;
964 int64_t Value = CE->getValue();
965 return Value == 1 || Value == 0;
966 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000967 bool isReg() const { return Kind == k_Register; }
968 bool isRegList() const { return Kind == k_RegisterList; }
969 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
970 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
971 bool isToken() const { return Kind == k_Token; }
972 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000973 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000974 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000975 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
976 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
977 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
978 bool isRotImm() const { return Kind == k_RotateImmediate; }
979 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
980 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000981 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000982 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000983 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000984 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000985 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000986 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000987 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000988 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
989 (alignOK || Memory.Alignment == 0);
990 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000991 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000992 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000993 return false;
994 // Base register must be PC.
995 if (Memory.BaseRegNum != ARM::PC)
996 return false;
997 // Immediate offset in range [-4095, 4095].
998 if (!Memory.OffsetImm) return true;
999 int64_t Val = Memory.OffsetImm->getValue();
1000 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1001 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001002 bool isAlignedMemory() const {
1003 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001004 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001005 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001006 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001007 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001008 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001009 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001010 if (!Memory.OffsetImm) return true;
1011 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001012 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001013 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001014 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001015 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001016 // Immediate offset in range [-4095, 4095].
1017 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1018 if (!CE) return false;
1019 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001020 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001021 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001022 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001023 // If we have an immediate that's not a constant, treat it as a label
1024 // reference needing a fixup. If it is a constant, it's something else
1025 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001026 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001027 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001028 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001029 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001030 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001031 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001032 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001033 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001034 if (!Memory.OffsetImm) return true;
1035 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001036 // The #-0 offset is encoded as INT32_MIN, and we have to check
1037 // for this too.
1038 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001039 }
1040 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001041 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001042 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001043 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001044 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1045 // Immediate offset in range [-255, 255].
1046 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1047 if (!CE) return false;
1048 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001049 // Special case, #-0 is INT32_MIN.
1050 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001051 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001052 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001053 // If we have an immediate that's not a constant, treat it as a label
1054 // reference needing a fixup. If it is a constant, it's something else
1055 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001056 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001057 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001058 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001059 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001060 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001061 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001062 if (!Memory.OffsetImm) return true;
1063 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001064 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001065 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001066 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001067 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001068 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001069 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001070 return false;
1071 return true;
1072 }
1073 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001074 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001075 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1076 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001077 return false;
1078 return true;
1079 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001080 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001081 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001082 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001083 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001084 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001085 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001086 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001087 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001088 return false;
1089 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001090 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001091 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001092 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001093 return false;
1094 return true;
1095 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001096 bool isMemThumbRR() const {
1097 // Thumb reg+reg addressing is simple. Just two registers, a base and
1098 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001099 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001100 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001101 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001102 return isARMLowRegister(Memory.BaseRegNum) &&
1103 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001104 }
1105 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001106 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001107 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001108 return false;
1109 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001110 if (!Memory.OffsetImm) return true;
1111 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001112 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1113 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001114 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001115 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001116 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001117 return false;
1118 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001119 if (!Memory.OffsetImm) return true;
1120 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001121 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1122 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001123 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001124 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001125 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001126 return false;
1127 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001128 if (!Memory.OffsetImm) return true;
1129 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001130 return Val >= 0 && Val <= 31;
1131 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001132 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001133 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001134 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001135 return false;
1136 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001137 if (!Memory.OffsetImm) return true;
1138 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001139 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001140 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001141 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001142 // If we have an immediate that's not a constant, treat it as a label
1143 // reference needing a fixup. If it is a constant, it's something else
1144 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001145 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001146 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001147 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001148 return false;
1149 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001150 if (!Memory.OffsetImm) return true;
1151 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001152 // Special case, #-0 is INT32_MIN.
1153 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001154 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001155 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001156 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001157 return false;
1158 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001159 if (!Memory.OffsetImm) return true;
1160 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001161 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1162 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001163 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001164 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001165 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001166 // Base reg of PC isn't allowed for these encodings.
1167 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001168 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001169 if (!Memory.OffsetImm) return true;
1170 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001171 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001172 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001173 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001174 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001175 return false;
1176 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001177 if (!Memory.OffsetImm) return true;
1178 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001179 return Val >= 0 && Val < 256;
1180 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001181 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001182 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001183 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001184 // Base reg of PC isn't allowed for these encodings.
1185 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001186 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001187 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001188 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001189 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001190 }
1191 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001192 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001193 return false;
1194 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001195 if (!Memory.OffsetImm) return true;
1196 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001197 return (Val >= 0 && Val < 4096);
1198 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001199 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001200 // If we have an immediate that's not a constant, treat it as a label
1201 // reference needing a fixup. If it is a constant, it's something else
1202 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001203 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001204 return true;
1205
Chad Rosier41099832012-09-11 23:02:35 +00001206 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001207 return false;
1208 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001209 if (!Memory.OffsetImm) return true;
1210 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001211 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001212 }
1213 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001214 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001215 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1216 if (!CE) return false;
1217 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001218 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001219 }
Jim Grosbach93981412011-10-11 21:55:36 +00001220 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001221 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001222 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1223 if (!CE) return false;
1224 int64_t Val = CE->getValue();
1225 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1226 (Val == INT32_MIN);
1227 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001228
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001229 bool isMSRMask() const { return Kind == k_MSRMask; }
1230 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001231
Jim Grosbach741cd732011-10-17 22:26:03 +00001232 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001233 bool isSingleSpacedVectorList() const {
1234 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1235 }
1236 bool isDoubleSpacedVectorList() const {
1237 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1238 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001239 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001240 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001241 return VectorList.Count == 1;
1242 }
1243
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001244 bool isVecListDPair() const {
1245 if (!isSingleSpacedVectorList()) return false;
1246 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1247 .contains(VectorList.RegNum));
1248 }
1249
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001250 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001251 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001252 return VectorList.Count == 3;
1253 }
1254
Jim Grosbach846bcff2011-10-21 20:35:01 +00001255 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001256 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001257 return VectorList.Count == 4;
1258 }
1259
Jim Grosbache5307f92012-03-05 21:43:40 +00001260 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001261 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001262 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1263 .contains(VectorList.RegNum));
1264 }
1265
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001266 bool isVecListThreeQ() const {
1267 if (!isDoubleSpacedVectorList()) return false;
1268 return VectorList.Count == 3;
1269 }
1270
Jim Grosbach1e946a42012-01-24 00:43:12 +00001271 bool isVecListFourQ() const {
1272 if (!isDoubleSpacedVectorList()) return false;
1273 return VectorList.Count == 4;
1274 }
1275
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001276 bool isSingleSpacedVectorAllLanes() const {
1277 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1278 }
1279 bool isDoubleSpacedVectorAllLanes() const {
1280 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1281 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001282 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001283 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001284 return VectorList.Count == 1;
1285 }
1286
Jim Grosbach13a292c2012-03-06 22:01:44 +00001287 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001288 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001289 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1290 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001291 }
1292
Jim Grosbached428bc2012-03-06 23:10:38 +00001293 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001294 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001295 return VectorList.Count == 2;
1296 }
1297
Jim Grosbachb78403c2012-01-24 23:47:04 +00001298 bool isVecListThreeDAllLanes() const {
1299 if (!isSingleSpacedVectorAllLanes()) return false;
1300 return VectorList.Count == 3;
1301 }
1302
1303 bool isVecListThreeQAllLanes() const {
1304 if (!isDoubleSpacedVectorAllLanes()) return false;
1305 return VectorList.Count == 3;
1306 }
1307
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001308 bool isVecListFourDAllLanes() const {
1309 if (!isSingleSpacedVectorAllLanes()) return false;
1310 return VectorList.Count == 4;
1311 }
1312
1313 bool isVecListFourQAllLanes() const {
1314 if (!isDoubleSpacedVectorAllLanes()) return false;
1315 return VectorList.Count == 4;
1316 }
1317
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001318 bool isSingleSpacedVectorIndexed() const {
1319 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1320 }
1321 bool isDoubleSpacedVectorIndexed() const {
1322 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1323 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001324 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001325 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001326 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1327 }
1328
Jim Grosbachda511042011-12-14 23:35:06 +00001329 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001330 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001331 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1332 }
1333
1334 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001335 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001336 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1337 }
1338
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001339 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001340 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001341 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1342 }
1343
Jim Grosbachda511042011-12-14 23:35:06 +00001344 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001345 if (!isSingleSpacedVectorIndexed()) return false;
1346 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1347 }
1348
1349 bool isVecListTwoQWordIndexed() const {
1350 if (!isDoubleSpacedVectorIndexed()) return false;
1351 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1352 }
1353
1354 bool isVecListTwoQHWordIndexed() const {
1355 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001356 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1357 }
1358
1359 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001360 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001361 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1362 }
1363
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001364 bool isVecListThreeDByteIndexed() const {
1365 if (!isSingleSpacedVectorIndexed()) return false;
1366 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1367 }
1368
1369 bool isVecListThreeDHWordIndexed() const {
1370 if (!isSingleSpacedVectorIndexed()) return false;
1371 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1372 }
1373
1374 bool isVecListThreeQWordIndexed() const {
1375 if (!isDoubleSpacedVectorIndexed()) return false;
1376 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1377 }
1378
1379 bool isVecListThreeQHWordIndexed() const {
1380 if (!isDoubleSpacedVectorIndexed()) return false;
1381 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1382 }
1383
1384 bool isVecListThreeDWordIndexed() const {
1385 if (!isSingleSpacedVectorIndexed()) return false;
1386 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1387 }
1388
Jim Grosbach14952a02012-01-24 18:37:25 +00001389 bool isVecListFourDByteIndexed() const {
1390 if (!isSingleSpacedVectorIndexed()) return false;
1391 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1392 }
1393
1394 bool isVecListFourDHWordIndexed() const {
1395 if (!isSingleSpacedVectorIndexed()) return false;
1396 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1397 }
1398
1399 bool isVecListFourQWordIndexed() const {
1400 if (!isDoubleSpacedVectorIndexed()) return false;
1401 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1402 }
1403
1404 bool isVecListFourQHWordIndexed() const {
1405 if (!isDoubleSpacedVectorIndexed()) return false;
1406 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1407 }
1408
1409 bool isVecListFourDWordIndexed() const {
1410 if (!isSingleSpacedVectorIndexed()) return false;
1411 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1412 }
1413
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001414 bool isVectorIndex8() const {
1415 if (Kind != k_VectorIndex) return false;
1416 return VectorIndex.Val < 8;
1417 }
1418 bool isVectorIndex16() const {
1419 if (Kind != k_VectorIndex) return false;
1420 return VectorIndex.Val < 4;
1421 }
1422 bool isVectorIndex32() const {
1423 if (Kind != k_VectorIndex) return false;
1424 return VectorIndex.Val < 2;
1425 }
1426
Jim Grosbach741cd732011-10-17 22:26:03 +00001427 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001428 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001429 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1430 // Must be a constant.
1431 if (!CE) return false;
1432 int64_t Value = CE->getValue();
1433 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1434 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001435 return Value >= 0 && Value < 256;
1436 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001437
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001438 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001439 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001440 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1441 // Must be a constant.
1442 if (!CE) return false;
1443 int64_t Value = CE->getValue();
1444 // i16 value in the range [0,255] or [0x0100, 0xff00]
1445 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1446 }
1447
Jim Grosbach8211c052011-10-18 00:22:00 +00001448 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001449 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001450 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1451 // Must be a constant.
1452 if (!CE) return false;
1453 int64_t Value = CE->getValue();
1454 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1455 return (Value >= 0 && Value < 256) ||
1456 (Value >= 0x0100 && Value <= 0xff00) ||
1457 (Value >= 0x010000 && Value <= 0xff0000) ||
1458 (Value >= 0x01000000 && Value <= 0xff000000);
1459 }
1460
1461 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001462 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001463 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1464 // Must be a constant.
1465 if (!CE) return false;
1466 int64_t Value = CE->getValue();
1467 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1468 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1469 return (Value >= 0 && Value < 256) ||
1470 (Value >= 0x0100 && Value <= 0xff00) ||
1471 (Value >= 0x010000 && Value <= 0xff0000) ||
1472 (Value >= 0x01000000 && Value <= 0xff000000) ||
1473 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1474 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1475 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001476 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001477 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001478 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1479 // Must be a constant.
1480 if (!CE) return false;
1481 int64_t Value = ~CE->getValue();
1482 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1483 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1484 return (Value >= 0 && Value < 256) ||
1485 (Value >= 0x0100 && Value <= 0xff00) ||
1486 (Value >= 0x010000 && Value <= 0xff0000) ||
1487 (Value >= 0x01000000 && Value <= 0xff000000) ||
1488 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1489 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1490 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001491
Jim Grosbache4454e02011-10-18 16:18:11 +00001492 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001493 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001494 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1495 // Must be a constant.
1496 if (!CE) return false;
1497 uint64_t Value = CE->getValue();
1498 // i64 value with each byte being either 0 or 0xff.
1499 for (unsigned i = 0; i < 8; ++i)
1500 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1501 return true;
1502 }
1503
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001504 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001505 // Add as immediates when possible. Null MCExpr = 0.
1506 if (Expr == 0)
1507 Inst.addOperand(MCOperand::CreateImm(0));
1508 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001509 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1510 else
1511 Inst.addOperand(MCOperand::CreateExpr(Expr));
1512 }
1513
Daniel Dunbard8042b72010-08-11 06:36:53 +00001514 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001515 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001516 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001517 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1518 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001519 }
1520
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001521 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1522 assert(N == 1 && "Invalid number of operands!");
1523 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1524 }
1525
Jim Grosbach48399582011-10-12 17:34:41 +00001526 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1527 assert(N == 1 && "Invalid number of operands!");
1528 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1529 }
1530
1531 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1532 assert(N == 1 && "Invalid number of operands!");
1533 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1534 }
1535
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001536 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1537 assert(N == 1 && "Invalid number of operands!");
1538 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1539 }
1540
1541 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1542 assert(N == 1 && "Invalid number of operands!");
1543 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1544 }
1545
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001546 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1547 assert(N == 1 && "Invalid number of operands!");
1548 Inst.addOperand(MCOperand::CreateReg(getReg()));
1549 }
1550
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001551 void addRegOperands(MCInst &Inst, unsigned N) const {
1552 assert(N == 1 && "Invalid number of operands!");
1553 Inst.addOperand(MCOperand::CreateReg(getReg()));
1554 }
1555
Jim Grosbachac798e12011-07-25 20:49:51 +00001556 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001557 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001558 assert(isRegShiftedReg() &&
1559 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001560 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1561 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001562 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001563 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001564 }
1565
Jim Grosbachac798e12011-07-25 20:49:51 +00001566 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001567 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001568 assert(isRegShiftedImm() &&
1569 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001570 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001571 // Shift of #32 is encoded as 0 where permitted
1572 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001573 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001574 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001575 }
1576
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001577 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001578 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001579 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1580 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001581 }
1582
Bill Wendling8d2aa032010-11-08 23:49:57 +00001583 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001584 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001585 const SmallVectorImpl<unsigned> &RegList = getRegList();
1586 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001587 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1588 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001589 }
1590
Bill Wendling9898ac92010-11-17 04:32:08 +00001591 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1592 addRegListOperands(Inst, N);
1593 }
1594
1595 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1596 addRegListOperands(Inst, N);
1597 }
1598
Jim Grosbach833b9d32011-07-27 20:15:40 +00001599 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1600 assert(N == 1 && "Invalid number of operands!");
1601 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1602 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1603 }
1604
Jim Grosbach864b6092011-07-28 21:34:26 +00001605 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1606 assert(N == 1 && "Invalid number of operands!");
1607 // Munge the lsb/width into a bitfield mask.
1608 unsigned lsb = Bitfield.LSB;
1609 unsigned width = Bitfield.Width;
1610 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1611 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1612 (32 - (lsb + width)));
1613 Inst.addOperand(MCOperand::CreateImm(Mask));
1614 }
1615
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001616 void addImmOperands(MCInst &Inst, unsigned N) const {
1617 assert(N == 1 && "Invalid number of operands!");
1618 addExpr(Inst, getImm());
1619 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001620
Jim Grosbachea231912011-12-22 22:19:05 +00001621 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1622 assert(N == 1 && "Invalid number of operands!");
1623 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1624 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1625 }
1626
1627 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1628 assert(N == 1 && "Invalid number of operands!");
1629 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1630 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1631 }
1632
Jim Grosbache7fbce72011-10-03 23:38:36 +00001633 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1634 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1636 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1637 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001638 }
1639
Jim Grosbach7db8d692011-09-08 22:07:06 +00001640 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1641 assert(N == 1 && "Invalid number of operands!");
1642 // FIXME: We really want to scale the value here, but the LDRD/STRD
1643 // instruction don't encode operands that way yet.
1644 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1645 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1646 }
1647
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001648 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1649 assert(N == 1 && "Invalid number of operands!");
1650 // The immediate is scaled by four in the encoding and is stored
1651 // in the MCInst as such. Lop off the low two bits here.
1652 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1653 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1654 }
1655
Jim Grosbach930f2f62012-04-05 20:57:13 +00001656 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1657 assert(N == 1 && "Invalid number of operands!");
1658 // The immediate is scaled by four in the encoding and is stored
1659 // in the MCInst as such. Lop off the low two bits here.
1660 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1661 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1662 }
1663
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001664 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1665 assert(N == 1 && "Invalid number of operands!");
1666 // The immediate is scaled by four in the encoding and is stored
1667 // in the MCInst as such. Lop off the low two bits here.
1668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1669 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1670 }
1671
Jim Grosbach475c6db2011-07-25 23:09:14 +00001672 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1673 assert(N == 1 && "Invalid number of operands!");
1674 // The constant encodes as the immediate-1, and we store in the instruction
1675 // the bits as encoded, so subtract off one here.
1676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1677 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1678 }
1679
Jim Grosbach801e0a32011-07-22 23:16:18 +00001680 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1681 assert(N == 1 && "Invalid number of operands!");
1682 // The constant encodes as the immediate-1, and we store in the instruction
1683 // the bits as encoded, so subtract off one here.
1684 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1685 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1686 }
1687
Jim Grosbach46dd4132011-08-17 21:51:27 +00001688 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1689 assert(N == 1 && "Invalid number of operands!");
1690 // The constant encodes as the immediate, except for 32, which encodes as
1691 // zero.
1692 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1693 unsigned Imm = CE->getValue();
1694 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1695 }
1696
Jim Grosbach27c1e252011-07-21 17:23:04 +00001697 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1698 assert(N == 1 && "Invalid number of operands!");
1699 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1700 // the instruction as well.
1701 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1702 int Val = CE->getValue();
1703 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1704 }
1705
Jim Grosbachb009a872011-10-28 22:36:30 +00001706 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1707 assert(N == 1 && "Invalid number of operands!");
1708 // The operand is actually a t2_so_imm, but we have its bitwise
1709 // negation in the assembly source, so twiddle it here.
1710 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1711 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1712 }
1713
Jim Grosbach30506252011-12-08 00:31:07 +00001714 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1715 assert(N == 1 && "Invalid number of operands!");
1716 // The operand is actually a t2_so_imm, but we have its
1717 // negation in the assembly source, so twiddle it here.
1718 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1719 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1720 }
1721
Jim Grosbach930f2f62012-04-05 20:57:13 +00001722 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1723 assert(N == 1 && "Invalid number of operands!");
1724 // The operand is actually an imm0_4095, but we have its
1725 // negation in the assembly source, so twiddle it here.
1726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1727 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1728 }
1729
Mihai Popad36cbaa2013-07-03 09:21:44 +00001730 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1731 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1732 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1733 return;
1734 }
1735
1736 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1737 assert(SR && "Unknown value type!");
1738 Inst.addOperand(MCOperand::CreateExpr(SR));
1739 }
1740
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001741 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1742 assert(N == 1 && "Invalid number of operands!");
1743 if (isImm()) {
1744 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1745 if (CE) {
1746 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1747 return;
1748 }
1749
1750 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1751 assert(SR && "Unknown value type!");
1752 Inst.addOperand(MCOperand::CreateExpr(SR));
1753 return;
1754 }
1755
1756 assert(isMem() && "Unknown value type!");
1757 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1758 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1759 }
1760
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001761 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1762 assert(N == 1 && "Invalid number of operands!");
1763 // The operand is actually a so_imm, but we have its bitwise
1764 // negation in the assembly source, so twiddle it here.
1765 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1766 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1767 }
1768
Jim Grosbach30506252011-12-08 00:31:07 +00001769 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1770 assert(N == 1 && "Invalid number of operands!");
1771 // The operand is actually a so_imm, but we have its
1772 // negation in the assembly source, so twiddle it here.
1773 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1774 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1775 }
1776
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001777 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1778 assert(N == 1 && "Invalid number of operands!");
1779 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1780 }
1781
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001782 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1783 assert(N == 1 && "Invalid number of operands!");
1784 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1785 }
1786
Jim Grosbachd3595712011-08-03 23:50:40 +00001787 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1788 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001789 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001790 }
1791
Jim Grosbach94298a92012-01-18 22:46:46 +00001792 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1793 assert(N == 1 && "Invalid number of operands!");
1794 int32_t Imm = Memory.OffsetImm->getValue();
1795 // FIXME: Handle #-0
1796 if (Imm == INT32_MIN) Imm = 0;
1797 Inst.addOperand(MCOperand::CreateImm(Imm));
1798 }
1799
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001800 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1801 assert(N == 1 && "Invalid number of operands!");
1802 assert(isImm() && "Not an immediate!");
1803
1804 // If we have an immediate that's not a constant, treat it as a label
1805 // reference needing a fixup.
1806 if (!isa<MCConstantExpr>(getImm())) {
1807 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1808 return;
1809 }
1810
1811 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1812 int Val = CE->getValue();
1813 Inst.addOperand(MCOperand::CreateImm(Val));
1814 }
1815
Jim Grosbacha95ec992011-10-11 17:29:55 +00001816 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1817 assert(N == 2 && "Invalid number of operands!");
1818 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1819 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1820 }
1821
Jim Grosbachd3595712011-08-03 23:50:40 +00001822 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1823 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001824 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1825 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001826 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1827 // Special case for #-0
1828 if (Val == INT32_MIN) Val = 0;
1829 if (Val < 0) Val = -Val;
1830 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1831 } else {
1832 // For register offset, we encode the shift type and negation flag
1833 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001834 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1835 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001836 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001837 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1838 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001839 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001840 }
1841
Jim Grosbachcd17c122011-08-04 23:01:30 +00001842 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1843 assert(N == 2 && "Invalid number of operands!");
1844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1845 assert(CE && "non-constant AM2OffsetImm operand!");
1846 int32_t Val = CE->getValue();
1847 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1848 // Special case for #-0
1849 if (Val == INT32_MIN) Val = 0;
1850 if (Val < 0) Val = -Val;
1851 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1852 Inst.addOperand(MCOperand::CreateReg(0));
1853 Inst.addOperand(MCOperand::CreateImm(Val));
1854 }
1855
Jim Grosbach5b96b802011-08-10 20:29:19 +00001856 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1857 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001858 // If we have an immediate that's not a constant, treat it as a label
1859 // reference needing a fixup. If it is a constant, it's something else
1860 // and we reject it.
1861 if (isImm()) {
1862 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1863 Inst.addOperand(MCOperand::CreateReg(0));
1864 Inst.addOperand(MCOperand::CreateImm(0));
1865 return;
1866 }
1867
Jim Grosbach871dff72011-10-11 15:59:20 +00001868 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1869 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001870 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1871 // Special case for #-0
1872 if (Val == INT32_MIN) Val = 0;
1873 if (Val < 0) Val = -Val;
1874 Val = ARM_AM::getAM3Opc(AddSub, Val);
1875 } else {
1876 // For register offset, we encode the shift type and negation flag
1877 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001878 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001879 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001880 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1881 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001882 Inst.addOperand(MCOperand::CreateImm(Val));
1883 }
1884
1885 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1886 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001887 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001888 int32_t Val =
1889 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1890 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1891 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001892 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001893 }
1894
1895 // Constant offset.
1896 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1897 int32_t Val = CE->getValue();
1898 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1899 // Special case for #-0
1900 if (Val == INT32_MIN) Val = 0;
1901 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001902 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001903 Inst.addOperand(MCOperand::CreateReg(0));
1904 Inst.addOperand(MCOperand::CreateImm(Val));
1905 }
1906
Jim Grosbachd3595712011-08-03 23:50:40 +00001907 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1908 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001909 // If we have an immediate that's not a constant, treat it as a label
1910 // reference needing a fixup. If it is a constant, it's something else
1911 // and we reject it.
1912 if (isImm()) {
1913 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1914 Inst.addOperand(MCOperand::CreateImm(0));
1915 return;
1916 }
1917
Jim Grosbachd3595712011-08-03 23:50:40 +00001918 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001919 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001920 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1921 // Special case for #-0
1922 if (Val == INT32_MIN) Val = 0;
1923 if (Val < 0) Val = -Val;
1924 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001925 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001926 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001927 }
1928
Jim Grosbach7db8d692011-09-08 22:07:06 +00001929 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1930 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001931 // If we have an immediate that's not a constant, treat it as a label
1932 // reference needing a fixup. If it is a constant, it's something else
1933 // and we reject it.
1934 if (isImm()) {
1935 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1936 Inst.addOperand(MCOperand::CreateImm(0));
1937 return;
1938 }
1939
Jim Grosbach871dff72011-10-11 15:59:20 +00001940 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1941 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001942 Inst.addOperand(MCOperand::CreateImm(Val));
1943 }
1944
Jim Grosbacha05627e2011-09-09 18:37:27 +00001945 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1946 assert(N == 2 && "Invalid number of operands!");
1947 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001948 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1949 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001950 Inst.addOperand(MCOperand::CreateImm(Val));
1951 }
1952
Jim Grosbachd3595712011-08-03 23:50:40 +00001953 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1954 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001955 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1956 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001957 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001958 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001959
Jim Grosbach2392c532011-09-07 23:39:14 +00001960 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1961 addMemImm8OffsetOperands(Inst, N);
1962 }
1963
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001964 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001965 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001966 }
1967
1968 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1969 assert(N == 2 && "Invalid number of operands!");
1970 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001971 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001972 addExpr(Inst, getImm());
1973 Inst.addOperand(MCOperand::CreateImm(0));
1974 return;
1975 }
1976
1977 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001978 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1979 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001980 Inst.addOperand(MCOperand::CreateImm(Val));
1981 }
1982
Jim Grosbachd3595712011-08-03 23:50:40 +00001983 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1984 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001985 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001986 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001987 addExpr(Inst, getImm());
1988 Inst.addOperand(MCOperand::CreateImm(0));
1989 return;
1990 }
1991
1992 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001993 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1994 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001995 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001996 }
Bill Wendling811c9362010-11-30 07:44:32 +00001997
Jim Grosbach05541f42011-09-19 22:21:13 +00001998 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1999 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002000 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2001 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002002 }
2003
2004 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2005 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002006 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2007 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002008 }
2009
Jim Grosbachd3595712011-08-03 23:50:40 +00002010 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2011 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002012 unsigned Val =
2013 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2014 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002015 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2016 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002017 Inst.addOperand(MCOperand::CreateImm(Val));
2018 }
2019
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002020 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2021 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002022 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2023 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2024 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002025 }
2026
Jim Grosbachd3595712011-08-03 23:50:40 +00002027 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2028 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002029 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2030 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002031 }
2032
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002033 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2034 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002035 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2036 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002037 Inst.addOperand(MCOperand::CreateImm(Val));
2038 }
2039
Jim Grosbach26d35872011-08-19 18:55:51 +00002040 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2041 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002042 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2043 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002044 Inst.addOperand(MCOperand::CreateImm(Val));
2045 }
2046
Jim Grosbacha32c7532011-08-19 18:49:59 +00002047 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2048 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002049 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2050 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002051 Inst.addOperand(MCOperand::CreateImm(Val));
2052 }
2053
Jim Grosbach23983d62011-08-19 18:13:48 +00002054 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2055 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002056 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2057 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002058 Inst.addOperand(MCOperand::CreateImm(Val));
2059 }
2060
Jim Grosbachd3595712011-08-03 23:50:40 +00002061 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2062 assert(N == 1 && "Invalid number of operands!");
2063 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2064 assert(CE && "non-constant post-idx-imm8 operand!");
2065 int Imm = CE->getValue();
2066 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002067 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002068 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2069 Inst.addOperand(MCOperand::CreateImm(Imm));
2070 }
2071
Jim Grosbach93981412011-10-11 21:55:36 +00002072 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2073 assert(N == 1 && "Invalid number of operands!");
2074 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2075 assert(CE && "non-constant post-idx-imm8s4 operand!");
2076 int Imm = CE->getValue();
2077 bool isAdd = Imm >= 0;
2078 if (Imm == INT32_MIN) Imm = 0;
2079 // Immediate is scaled by 4.
2080 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2081 Inst.addOperand(MCOperand::CreateImm(Imm));
2082 }
2083
Jim Grosbachd3595712011-08-03 23:50:40 +00002084 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2085 assert(N == 2 && "Invalid number of operands!");
2086 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002087 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2088 }
2089
2090 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2091 assert(N == 2 && "Invalid number of operands!");
2092 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2093 // The sign, shift type, and shift amount are encoded in a single operand
2094 // using the AM2 encoding helpers.
2095 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2096 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2097 PostIdxReg.ShiftTy);
2098 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002099 }
2100
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002101 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2102 assert(N == 1 && "Invalid number of operands!");
2103 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2104 }
2105
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002106 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2107 assert(N == 1 && "Invalid number of operands!");
2108 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2109 }
2110
Jim Grosbach182b6a02011-11-29 23:51:09 +00002111 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002112 assert(N == 1 && "Invalid number of operands!");
2113 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2114 }
2115
Jim Grosbach04945c42011-12-02 00:35:16 +00002116 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2117 assert(N == 2 && "Invalid number of operands!");
2118 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2119 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2120 }
2121
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002122 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2123 assert(N == 1 && "Invalid number of operands!");
2124 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2125 }
2126
2127 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2128 assert(N == 1 && "Invalid number of operands!");
2129 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2130 }
2131
2132 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2133 assert(N == 1 && "Invalid number of operands!");
2134 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2135 }
2136
Jim Grosbach741cd732011-10-17 22:26:03 +00002137 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2138 assert(N == 1 && "Invalid number of operands!");
2139 // The immediate encodes the type of constant as well as the value.
2140 // Mask in that this is an i8 splat.
2141 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2142 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2143 }
2144
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002145 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2146 assert(N == 1 && "Invalid number of operands!");
2147 // The immediate encodes the type of constant as well as the value.
2148 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2149 unsigned Value = CE->getValue();
2150 if (Value >= 256)
2151 Value = (Value >> 8) | 0xa00;
2152 else
2153 Value |= 0x800;
2154 Inst.addOperand(MCOperand::CreateImm(Value));
2155 }
2156
Jim Grosbach8211c052011-10-18 00:22:00 +00002157 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2158 assert(N == 1 && "Invalid number of operands!");
2159 // The immediate encodes the type of constant as well as the value.
2160 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2161 unsigned Value = CE->getValue();
2162 if (Value >= 256 && Value <= 0xff00)
2163 Value = (Value >> 8) | 0x200;
2164 else if (Value > 0xffff && Value <= 0xff0000)
2165 Value = (Value >> 16) | 0x400;
2166 else if (Value > 0xffffff)
2167 Value = (Value >> 24) | 0x600;
2168 Inst.addOperand(MCOperand::CreateImm(Value));
2169 }
2170
2171 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2172 assert(N == 1 && "Invalid number of operands!");
2173 // The immediate encodes the type of constant as well as the value.
2174 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2175 unsigned Value = CE->getValue();
2176 if (Value >= 256 && Value <= 0xffff)
2177 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2178 else if (Value > 0xffff && Value <= 0xffffff)
2179 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2180 else if (Value > 0xffffff)
2181 Value = (Value >> 24) | 0x600;
2182 Inst.addOperand(MCOperand::CreateImm(Value));
2183 }
2184
Jim Grosbach045b6c72011-12-19 23:51:07 +00002185 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2186 assert(N == 1 && "Invalid number of operands!");
2187 // The immediate encodes the type of constant as well as the value.
2188 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2189 unsigned Value = ~CE->getValue();
2190 if (Value >= 256 && Value <= 0xffff)
2191 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2192 else if (Value > 0xffff && Value <= 0xffffff)
2193 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2194 else if (Value > 0xffffff)
2195 Value = (Value >> 24) | 0x600;
2196 Inst.addOperand(MCOperand::CreateImm(Value));
2197 }
2198
Jim Grosbache4454e02011-10-18 16:18:11 +00002199 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2200 assert(N == 1 && "Invalid number of operands!");
2201 // The immediate encodes the type of constant as well as the value.
2202 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2203 uint64_t Value = CE->getValue();
2204 unsigned Imm = 0;
2205 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2206 Imm |= (Value & 1) << i;
2207 }
2208 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2209 }
2210
Jim Grosbach602aa902011-07-13 15:34:57 +00002211 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002212
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002213 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002214 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002215 Op->ITMask.Mask = Mask;
2216 Op->StartLoc = S;
2217 Op->EndLoc = S;
2218 return Op;
2219 }
2220
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002221 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002222 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002223 Op->CC.Val = CC;
2224 Op->StartLoc = S;
2225 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002226 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002227 }
2228
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002229 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002230 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002231 Op->Cop.Val = CopVal;
2232 Op->StartLoc = S;
2233 Op->EndLoc = S;
2234 return Op;
2235 }
2236
2237 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002238 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002239 Op->Cop.Val = CopVal;
2240 Op->StartLoc = S;
2241 Op->EndLoc = S;
2242 return Op;
2243 }
2244
Jim Grosbach48399582011-10-12 17:34:41 +00002245 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2246 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2247 Op->Cop.Val = Val;
2248 Op->StartLoc = S;
2249 Op->EndLoc = E;
2250 return Op;
2251 }
2252
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002253 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002254 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002255 Op->Reg.RegNum = RegNum;
2256 Op->StartLoc = S;
2257 Op->EndLoc = S;
2258 return Op;
2259 }
2260
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002261 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002262 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002263 Op->Tok.Data = Str.data();
2264 Op->Tok.Length = Str.size();
2265 Op->StartLoc = S;
2266 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002267 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002268 }
2269
Bill Wendling2063b842010-11-18 23:43:05 +00002270 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002271 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002272 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002273 Op->StartLoc = S;
2274 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002275 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002276 }
2277
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002278 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2279 unsigned SrcReg,
2280 unsigned ShiftReg,
2281 unsigned ShiftImm,
2282 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002283 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002284 Op->RegShiftedReg.ShiftTy = ShTy;
2285 Op->RegShiftedReg.SrcReg = SrcReg;
2286 Op->RegShiftedReg.ShiftReg = ShiftReg;
2287 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002288 Op->StartLoc = S;
2289 Op->EndLoc = E;
2290 return Op;
2291 }
2292
Owen Andersonb595ed02011-07-21 18:54:16 +00002293 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2294 unsigned SrcReg,
2295 unsigned ShiftImm,
2296 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002297 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002298 Op->RegShiftedImm.ShiftTy = ShTy;
2299 Op->RegShiftedImm.SrcReg = SrcReg;
2300 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002301 Op->StartLoc = S;
2302 Op->EndLoc = E;
2303 return Op;
2304 }
2305
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002306 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002307 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002308 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002309 Op->ShifterImm.isASR = isASR;
2310 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002311 Op->StartLoc = S;
2312 Op->EndLoc = E;
2313 return Op;
2314 }
2315
Jim Grosbach833b9d32011-07-27 20:15:40 +00002316 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002317 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002318 Op->RotImm.Imm = Imm;
2319 Op->StartLoc = S;
2320 Op->EndLoc = E;
2321 return Op;
2322 }
2323
Jim Grosbach864b6092011-07-28 21:34:26 +00002324 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2325 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002326 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002327 Op->Bitfield.LSB = LSB;
2328 Op->Bitfield.Width = Width;
2329 Op->StartLoc = S;
2330 Op->EndLoc = E;
2331 return Op;
2332 }
2333
Bill Wendling2cae3272010-11-09 22:44:22 +00002334 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002335 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002336 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002337 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002338 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002339
Chad Rosierfa705ee2013-07-01 20:49:23 +00002340 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002341 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002342 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002343 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002344 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002345
Chad Rosierfa705ee2013-07-01 20:49:23 +00002346 // Sort based on the register encoding values.
2347 array_pod_sort(Regs.begin(), Regs.end());
2348
Bill Wendling9898ac92010-11-17 04:32:08 +00002349 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002350 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002351 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002352 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002353 Op->StartLoc = StartLoc;
2354 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002355 return Op;
2356 }
2357
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002358 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002359 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002360 ARMOperand *Op = new ARMOperand(k_VectorList);
2361 Op->VectorList.RegNum = RegNum;
2362 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002363 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002364 Op->StartLoc = S;
2365 Op->EndLoc = E;
2366 return Op;
2367 }
2368
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002369 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002370 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002371 SMLoc S, SMLoc E) {
2372 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2373 Op->VectorList.RegNum = RegNum;
2374 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002375 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002376 Op->StartLoc = S;
2377 Op->EndLoc = E;
2378 return Op;
2379 }
2380
Jim Grosbach04945c42011-12-02 00:35:16 +00002381 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002382 unsigned Index,
2383 bool isDoubleSpaced,
2384 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002385 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2386 Op->VectorList.RegNum = RegNum;
2387 Op->VectorList.Count = Count;
2388 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002389 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002390 Op->StartLoc = S;
2391 Op->EndLoc = E;
2392 return Op;
2393 }
2394
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002395 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2396 MCContext &Ctx) {
2397 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2398 Op->VectorIndex.Val = Idx;
2399 Op->StartLoc = S;
2400 Op->EndLoc = E;
2401 return Op;
2402 }
2403
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002404 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002405 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002406 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002407 Op->StartLoc = S;
2408 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002409 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002410 }
2411
Jim Grosbachd3595712011-08-03 23:50:40 +00002412 static ARMOperand *CreateMem(unsigned BaseRegNum,
2413 const MCConstantExpr *OffsetImm,
2414 unsigned OffsetRegNum,
2415 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002416 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002417 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002418 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002419 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002420 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002421 Op->Memory.BaseRegNum = BaseRegNum;
2422 Op->Memory.OffsetImm = OffsetImm;
2423 Op->Memory.OffsetRegNum = OffsetRegNum;
2424 Op->Memory.ShiftType = ShiftType;
2425 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002426 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002427 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002428 Op->StartLoc = S;
2429 Op->EndLoc = E;
2430 return Op;
2431 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002432
Jim Grosbachc320c852011-08-05 21:28:30 +00002433 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2434 ARM_AM::ShiftOpc ShiftTy,
2435 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002436 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002437 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002438 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002439 Op->PostIdxReg.isAdd = isAdd;
2440 Op->PostIdxReg.ShiftTy = ShiftTy;
2441 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002442 Op->StartLoc = S;
2443 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002444 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002445 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002446
2447 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002448 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002449 Op->MBOpt.Val = Opt;
2450 Op->StartLoc = S;
2451 Op->EndLoc = S;
2452 return Op;
2453 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002454
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002455 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2456 SMLoc S) {
2457 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2458 Op->ISBOpt.Val = Opt;
2459 Op->StartLoc = S;
2460 Op->EndLoc = S;
2461 return Op;
2462 }
2463
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002464 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002465 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002466 Op->IFlags.Val = IFlags;
2467 Op->StartLoc = S;
2468 Op->EndLoc = S;
2469 return Op;
2470 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002471
2472 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002473 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002474 Op->MMask.Val = MMask;
2475 Op->StartLoc = S;
2476 Op->EndLoc = S;
2477 return Op;
2478 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002479};
2480
2481} // end anonymous namespace.
2482
Jim Grosbach602aa902011-07-13 15:34:57 +00002483void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002484 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002485 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002486 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002487 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002488 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002489 OS << "<ccout " << getReg() << ">";
2490 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002491 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002492 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002493 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2494 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2495 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002496 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2497 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2498 break;
2499 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002500 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002501 OS << "<coprocessor number: " << getCoproc() << ">";
2502 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002503 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002504 OS << "<coprocessor register: " << getCoproc() << ">";
2505 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002506 case k_CoprocOption:
2507 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2508 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002509 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002510 OS << "<mask: " << getMSRMask() << ">";
2511 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002512 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002513 getImm()->print(OS);
2514 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002515 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002516 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2517 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002518 case k_InstSyncBarrierOpt:
2519 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2520 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002521 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002522 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002523 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002524 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002525 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002526 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002527 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2528 << PostIdxReg.RegNum;
2529 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2530 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2531 << PostIdxReg.ShiftImm;
2532 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002533 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002534 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002535 OS << "<ARM_PROC::";
2536 unsigned IFlags = getProcIFlags();
2537 for (int i=2; i >= 0; --i)
2538 if (IFlags & (1 << i))
2539 OS << ARM_PROC::IFlagsToString(1 << i);
2540 OS << ">";
2541 break;
2542 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002543 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002544 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002545 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002546 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002547 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2548 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002549 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002550 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002551 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002552 << RegShiftedReg.SrcReg << " "
2553 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2554 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002555 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002556 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002557 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002558 << RegShiftedImm.SrcReg << " "
2559 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2560 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002561 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002562 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002563 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2564 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002565 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002566 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2567 << ", width: " << Bitfield.Width << ">";
2568 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002569 case k_RegisterList:
2570 case k_DPRRegisterList:
2571 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002572 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002573
Bill Wendlingbed94652010-11-09 23:28:44 +00002574 const SmallVectorImpl<unsigned> &RegList = getRegList();
2575 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002576 I = RegList.begin(), E = RegList.end(); I != E; ) {
2577 OS << *I;
2578 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002579 }
2580
2581 OS << ">";
2582 break;
2583 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002584 case k_VectorList:
2585 OS << "<vector_list " << VectorList.Count << " * "
2586 << VectorList.RegNum << ">";
2587 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002588 case k_VectorListAllLanes:
2589 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2590 << VectorList.RegNum << ">";
2591 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002592 case k_VectorListIndexed:
2593 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2594 << VectorList.Count << " * " << VectorList.RegNum << ">";
2595 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002596 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002597 OS << "'" << getToken() << "'";
2598 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002599 case k_VectorIndex:
2600 OS << "<vectorindex " << getVectorIndex() << ">";
2601 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002602 }
2603}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002604
2605/// @name Auto-generated Match Functions
2606/// {
2607
2608static unsigned MatchRegisterName(StringRef Name);
2609
2610/// }
2611
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002612bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2613 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002614 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002615 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002616 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002617
2618 return (RegNo == (unsigned)-1);
2619}
2620
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002621/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002622/// and if it is a register name the token is eaten and the register number is
2623/// returned. Otherwise return -1.
2624///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002625int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002626 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002627 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002628
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002629 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002630 unsigned RegNum = MatchRegisterName(lowerCase);
2631 if (!RegNum) {
2632 RegNum = StringSwitch<unsigned>(lowerCase)
2633 .Case("r13", ARM::SP)
2634 .Case("r14", ARM::LR)
2635 .Case("r15", ARM::PC)
2636 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002637 // Additional register name aliases for 'gas' compatibility.
2638 .Case("a1", ARM::R0)
2639 .Case("a2", ARM::R1)
2640 .Case("a3", ARM::R2)
2641 .Case("a4", ARM::R3)
2642 .Case("v1", ARM::R4)
2643 .Case("v2", ARM::R5)
2644 .Case("v3", ARM::R6)
2645 .Case("v4", ARM::R7)
2646 .Case("v5", ARM::R8)
2647 .Case("v6", ARM::R9)
2648 .Case("v7", ARM::R10)
2649 .Case("v8", ARM::R11)
2650 .Case("sb", ARM::R9)
2651 .Case("sl", ARM::R10)
2652 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002653 .Default(0);
2654 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002655 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002656 // Check for aliases registered via .req. Canonicalize to lower case.
2657 // That's more consistent since register names are case insensitive, and
2658 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2659 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002660 // If no match, return failure.
2661 if (Entry == RegisterReqs.end())
2662 return -1;
2663 Parser.Lex(); // Eat identifier token.
2664 return Entry->getValue();
2665 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002666
Chris Lattner44e5981c2010-10-30 04:09:10 +00002667 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002668
Chris Lattner44e5981c2010-10-30 04:09:10 +00002669 return RegNum;
2670}
Jim Grosbach99710a82010-11-01 16:44:21 +00002671
Jim Grosbachbb24c592011-07-13 18:49:30 +00002672// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2673// If a recoverable error occurs, return 1. If an irrecoverable error
2674// occurs, return -1. An irrecoverable error is one where tokens have been
2675// consumed in the process of trying to parse the shifter (i.e., when it is
2676// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002677int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002678 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2679 SMLoc S = Parser.getTok().getLoc();
2680 const AsmToken &Tok = Parser.getTok();
2681 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2682
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002683 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002684 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002685 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002686 .Case("lsl", ARM_AM::lsl)
2687 .Case("lsr", ARM_AM::lsr)
2688 .Case("asr", ARM_AM::asr)
2689 .Case("ror", ARM_AM::ror)
2690 .Case("rrx", ARM_AM::rrx)
2691 .Default(ARM_AM::no_shift);
2692
2693 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002694 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002695
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002696 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002697
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002698 // The source register for the shift has already been added to the
2699 // operand list, so we need to pop it off and combine it into the shifted
2700 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002701 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002702 if (!PrevOp->isReg())
2703 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2704 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002705
2706 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002707 int64_t Imm = 0;
2708 int ShiftReg = 0;
2709 if (ShiftTy == ARM_AM::rrx) {
2710 // RRX Doesn't have an explicit shift amount. The encoder expects
2711 // the shift register to be the same as the source register. Seems odd,
2712 // but OK.
2713 ShiftReg = SrcReg;
2714 } else {
2715 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002716 if (Parser.getTok().is(AsmToken::Hash) ||
2717 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002718 Parser.Lex(); // Eat hash.
2719 SMLoc ImmLoc = Parser.getTok().getLoc();
2720 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002721 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002722 Error(ImmLoc, "invalid immediate shift value");
2723 return -1;
2724 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002725 // The expression must be evaluatable as an immediate.
2726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002727 if (!CE) {
2728 Error(ImmLoc, "invalid immediate shift value");
2729 return -1;
2730 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002731 // Range check the immediate.
2732 // lsl, ror: 0 <= imm <= 31
2733 // lsr, asr: 0 <= imm <= 32
2734 Imm = CE->getValue();
2735 if (Imm < 0 ||
2736 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2737 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002738 Error(ImmLoc, "immediate shift value out of range");
2739 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002740 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002741 // shift by zero is a nop. Always send it through as lsl.
2742 // ('as' compatibility)
2743 if (Imm == 0)
2744 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002745 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002746 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002747 EndLoc = Parser.getTok().getEndLoc();
2748 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002749 if (ShiftReg == -1) {
2750 Error (L, "expected immediate or register in shift operand");
2751 return -1;
2752 }
2753 } else {
2754 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002755 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002756 return -1;
2757 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002758 }
2759
Owen Andersonb595ed02011-07-21 18:54:16 +00002760 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2761 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002762 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002763 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002764 else
2765 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002766 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002767
Jim Grosbachbb24c592011-07-13 18:49:30 +00002768 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002769}
2770
2771
Bill Wendling2063b842010-11-18 23:43:05 +00002772/// Try to parse a register name. The token must be an Identifier when called.
2773/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2774/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002775///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002776/// TODO this is likely to change to allow different register types and or to
2777/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002778bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002779tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002780 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002781 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002782 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002783 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002784
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002785 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2786 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002787
Chris Lattner44e5981c2010-10-30 04:09:10 +00002788 const AsmToken &ExclaimTok = Parser.getTok();
2789 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002790 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2791 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002792 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002793 return false;
2794 }
2795
2796 // Also check for an index operand. This is only legal for vector registers,
2797 // but that'll get caught OK in operand matching, so we don't need to
2798 // explicitly filter everything else out here.
2799 if (Parser.getTok().is(AsmToken::LBrac)) {
2800 SMLoc SIdx = Parser.getTok().getLoc();
2801 Parser.Lex(); // Eat left bracket token.
2802
2803 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002804 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002805 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002806 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002807 if (!MCE)
2808 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002809
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002810 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002811 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002812
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002813 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002814 Parser.Lex(); // Eat right bracket token.
2815
2816 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2817 SIdx, E,
2818 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002819 }
2820
Bill Wendling2063b842010-11-18 23:43:05 +00002821 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002822}
2823
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002824/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2825/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2826/// "c5", ...
2827static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002828 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2829 // but efficient.
2830 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002831 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002832 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002833 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002834 return -1;
2835 switch (Name[1]) {
2836 default: return -1;
2837 case '0': return 0;
2838 case '1': return 1;
2839 case '2': return 2;
2840 case '3': return 3;
2841 case '4': return 4;
2842 case '5': return 5;
2843 case '6': return 6;
2844 case '7': return 7;
2845 case '8': return 8;
2846 case '9': return 9;
2847 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002848 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002849 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002850 return -1;
2851 switch (Name[2]) {
2852 default: return -1;
2853 case '0': return 10;
2854 case '1': return 11;
2855 case '2': return 12;
2856 case '3': return 13;
2857 case '4': return 14;
2858 case '5': return 15;
2859 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002860 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002861}
2862
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002863/// parseITCondCode - Try to parse a condition code for an IT instruction.
2864ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2865parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2866 SMLoc S = Parser.getTok().getLoc();
2867 const AsmToken &Tok = Parser.getTok();
2868 if (!Tok.is(AsmToken::Identifier))
2869 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002870 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002871 .Case("eq", ARMCC::EQ)
2872 .Case("ne", ARMCC::NE)
2873 .Case("hs", ARMCC::HS)
2874 .Case("cs", ARMCC::HS)
2875 .Case("lo", ARMCC::LO)
2876 .Case("cc", ARMCC::LO)
2877 .Case("mi", ARMCC::MI)
2878 .Case("pl", ARMCC::PL)
2879 .Case("vs", ARMCC::VS)
2880 .Case("vc", ARMCC::VC)
2881 .Case("hi", ARMCC::HI)
2882 .Case("ls", ARMCC::LS)
2883 .Case("ge", ARMCC::GE)
2884 .Case("lt", ARMCC::LT)
2885 .Case("gt", ARMCC::GT)
2886 .Case("le", ARMCC::LE)
2887 .Case("al", ARMCC::AL)
2888 .Default(~0U);
2889 if (CC == ~0U)
2890 return MatchOperand_NoMatch;
2891 Parser.Lex(); // Eat the token.
2892
2893 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2894
2895 return MatchOperand_Success;
2896}
2897
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002898/// parseCoprocNumOperand - Try to parse an coprocessor number 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 +00002902parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +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;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002907
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002908 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002909 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002910 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002911
2912 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002913 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002914 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002915}
2916
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002917/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002918/// token must be an Identifier when called, and if it is a coprocessor
2919/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002920ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002921parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002922 SMLoc S = Parser.getTok().getLoc();
2923 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002924 if (Tok.isNot(AsmToken::Identifier))
2925 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002926
2927 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2928 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002929 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002930
2931 Parser.Lex(); // Eat identifier token.
2932 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002933 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002934}
2935
Jim Grosbach48399582011-10-12 17:34:41 +00002936/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2937/// coproc_option : '{' imm0_255 '}'
2938ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2939parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2940 SMLoc S = Parser.getTok().getLoc();
2941
2942 // If this isn't a '{', this isn't a coprocessor immediate operand.
2943 if (Parser.getTok().isNot(AsmToken::LCurly))
2944 return MatchOperand_NoMatch;
2945 Parser.Lex(); // Eat the '{'
2946
2947 const MCExpr *Expr;
2948 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002949 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002950 Error(Loc, "illegal expression");
2951 return MatchOperand_ParseFail;
2952 }
2953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2954 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2955 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2956 return MatchOperand_ParseFail;
2957 }
2958 int Val = CE->getValue();
2959
2960 // Check for and consume the closing '}'
2961 if (Parser.getTok().isNot(AsmToken::RCurly))
2962 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002963 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002964 Parser.Lex(); // Eat the '}'
2965
2966 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2967 return MatchOperand_Success;
2968}
2969
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002970// For register list parsing, we need to map from raw GPR register numbering
2971// to the enumeration values. The enumeration values aren't sorted by
2972// register number due to our using "sp", "lr" and "pc" as canonical names.
2973static unsigned getNextRegister(unsigned Reg) {
2974 // If this is a GPR, we need to do it manually, otherwise we can rely
2975 // on the sort ordering of the enumeration since the other reg-classes
2976 // are sane.
2977 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2978 return Reg + 1;
2979 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002980 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002981 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2982 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2983 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2984 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2985 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2986 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2987 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2988 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2989 }
2990}
2991
Jim Grosbach85a23432011-11-11 21:27:40 +00002992// Return the low-subreg of a given Q register.
2993static unsigned getDRegFromQReg(unsigned QReg) {
2994 switch (QReg) {
2995 default: llvm_unreachable("expected a Q register!");
2996 case ARM::Q0: return ARM::D0;
2997 case ARM::Q1: return ARM::D2;
2998 case ARM::Q2: return ARM::D4;
2999 case ARM::Q3: return ARM::D6;
3000 case ARM::Q4: return ARM::D8;
3001 case ARM::Q5: return ARM::D10;
3002 case ARM::Q6: return ARM::D12;
3003 case ARM::Q7: return ARM::D14;
3004 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003005 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003006 case ARM::Q10: return ARM::D20;
3007 case ARM::Q11: return ARM::D22;
3008 case ARM::Q12: return ARM::D24;
3009 case ARM::Q13: return ARM::D26;
3010 case ARM::Q14: return ARM::D28;
3011 case ARM::Q15: return ARM::D30;
3012 }
3013}
3014
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003015/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003016bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003017parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003018 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003019 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003020 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003021 Parser.Lex(); // Eat '{' token.
3022 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003023
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003024 // Check the first register in the list to see what register class
3025 // this is a list of.
3026 int Reg = tryParseRegister();
3027 if (Reg == -1)
3028 return Error(RegLoc, "register expected");
3029
Jim Grosbach85a23432011-11-11 21:27:40 +00003030 // The reglist instructions have at most 16 registers, so reserve
3031 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003032 int EReg = 0;
3033 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003034
3035 // Allow Q regs and just interpret them as the two D sub-registers.
3036 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3037 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003038 EReg = MRI->getEncodingValue(Reg);
3039 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003040 ++Reg;
3041 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003042 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003043 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3044 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3045 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3046 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3047 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3048 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3049 else
3050 return Error(RegLoc, "invalid register in register list");
3051
Jim Grosbach85a23432011-11-11 21:27:40 +00003052 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003053 EReg = MRI->getEncodingValue(Reg);
3054 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003055
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003056 // This starts immediately after the first register token in the list,
3057 // so we can see either a comma or a minus (range separator) as a legal
3058 // next token.
3059 while (Parser.getTok().is(AsmToken::Comma) ||
3060 Parser.getTok().is(AsmToken::Minus)) {
3061 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003062 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003063 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003064 int EndReg = tryParseRegister();
3065 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003066 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003067 // Allow Q regs and just interpret them as the two D sub-registers.
3068 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3069 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003070 // If the register is the same as the start reg, there's nothing
3071 // more to do.
3072 if (Reg == EndReg)
3073 continue;
3074 // The register must be in the same register class as the first.
3075 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003076 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003077 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003078 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003079 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003080
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003081 // Add all the registers in the range to the register list.
3082 while (Reg != EndReg) {
3083 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003084 EReg = MRI->getEncodingValue(Reg);
3085 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003086 }
3087 continue;
3088 }
3089 Parser.Lex(); // Eat the comma.
3090 RegLoc = Parser.getTok().getLoc();
3091 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003092 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003093 Reg = tryParseRegister();
3094 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003095 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003096 // Allow Q regs and just interpret them as the two D sub-registers.
3097 bool isQReg = false;
3098 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3099 Reg = getDRegFromQReg(Reg);
3100 isQReg = true;
3101 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003102 // The register must be in the same register class as the first.
3103 if (!RC->contains(Reg))
3104 return Error(RegLoc, "invalid register in register list");
3105 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003106 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003107 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3108 Warning(RegLoc, "register list not in ascending order");
3109 else
3110 return Error(RegLoc, "register list not in ascending order");
3111 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003112 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003113 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3114 ") in register list");
3115 continue;
3116 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003117 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003118 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3119 Reg != OldReg + 1)
3120 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003121 EReg = MRI->getEncodingValue(Reg);
3122 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3123 if (isQReg) {
3124 EReg = MRI->getEncodingValue(++Reg);
3125 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3126 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003127 }
3128
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003129 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003130 return Error(Parser.getTok().getLoc(), "'}' expected");
3131 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003132 Parser.Lex(); // Eat '}' token.
3133
Jim Grosbach18bf3632011-12-13 21:48:29 +00003134 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003135 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003136
3137 // The ARM system instruction variants for LDM/STM have a '^' token here.
3138 if (Parser.getTok().is(AsmToken::Caret)) {
3139 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3140 Parser.Lex(); // Eat '^' token.
3141 }
3142
Bill Wendling2063b842010-11-18 23:43:05 +00003143 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003144}
3145
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003146// Helper function to parse the lane index for vector lists.
3147ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003148parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003149 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003150 if (Parser.getTok().is(AsmToken::LBrac)) {
3151 Parser.Lex(); // Eat the '['.
3152 if (Parser.getTok().is(AsmToken::RBrac)) {
3153 // "Dn[]" is the 'all lanes' syntax.
3154 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003155 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003156 Parser.Lex(); // Eat the ']'.
3157 return MatchOperand_Success;
3158 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003159
3160 // There's an optional '#' token here. Normally there wouldn't be, but
3161 // inline assemble puts one in, and it's friendly to accept that.
3162 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003163 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003164
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003165 const MCExpr *LaneIndex;
3166 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003167 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003168 Error(Loc, "illegal expression");
3169 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003170 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003171 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3172 if (!CE) {
3173 Error(Loc, "lane index must be empty or an integer");
3174 return MatchOperand_ParseFail;
3175 }
3176 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3177 Error(Parser.getTok().getLoc(), "']' expected");
3178 return MatchOperand_ParseFail;
3179 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003180 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003181 Parser.Lex(); // Eat the ']'.
3182 int64_t Val = CE->getValue();
3183
3184 // FIXME: Make this range check context sensitive for .8, .16, .32.
3185 if (Val < 0 || Val > 7) {
3186 Error(Parser.getTok().getLoc(), "lane index out of range");
3187 return MatchOperand_ParseFail;
3188 }
3189 Index = Val;
3190 LaneKind = IndexedLane;
3191 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003192 }
3193 LaneKind = NoLanes;
3194 return MatchOperand_Success;
3195}
3196
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003197// parse a vector register list
3198ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3199parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003200 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003201 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003202 SMLoc S = Parser.getTok().getLoc();
3203 // As an extension (to match gas), support a plain D register or Q register
3204 // (without encosing curly braces) as a single or double entry list,
3205 // respectively.
3206 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003207 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003208 int Reg = tryParseRegister();
3209 if (Reg == -1)
3210 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003211 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003212 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003213 if (Res != MatchOperand_Success)
3214 return Res;
3215 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003216 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003217 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003218 break;
3219 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003220 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3221 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003222 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003223 case IndexedLane:
3224 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003225 LaneIndex,
3226 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003227 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003228 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003229 return MatchOperand_Success;
3230 }
3231 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3232 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003233 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003234 if (Res != MatchOperand_Success)
3235 return Res;
3236 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003237 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003238 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003239 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003240 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003241 break;
3242 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003243 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3244 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003245 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3246 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003247 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003248 case IndexedLane:
3249 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003250 LaneIndex,
3251 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003252 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003253 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003254 return MatchOperand_Success;
3255 }
3256 Error(S, "vector register expected");
3257 return MatchOperand_ParseFail;
3258 }
3259
3260 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003261 return MatchOperand_NoMatch;
3262
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003263 Parser.Lex(); // Eat '{' token.
3264 SMLoc RegLoc = Parser.getTok().getLoc();
3265
3266 int Reg = tryParseRegister();
3267 if (Reg == -1) {
3268 Error(RegLoc, "register expected");
3269 return MatchOperand_ParseFail;
3270 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003271 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003272 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003273 unsigned FirstReg = Reg;
3274 // The list is of D registers, but we also allow Q regs and just interpret
3275 // them as the two D sub-registers.
3276 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3277 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003278 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3279 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003280 ++Reg;
3281 ++Count;
3282 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003283
3284 SMLoc E;
3285 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003286 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003287
Jim Grosbache891fe82011-11-15 23:19:15 +00003288 while (Parser.getTok().is(AsmToken::Comma) ||
3289 Parser.getTok().is(AsmToken::Minus)) {
3290 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003291 if (!Spacing)
3292 Spacing = 1; // Register range implies a single spaced list.
3293 else if (Spacing == 2) {
3294 Error(Parser.getTok().getLoc(),
3295 "sequential registers in double spaced list");
3296 return MatchOperand_ParseFail;
3297 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003298 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003299 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003300 int EndReg = tryParseRegister();
3301 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003302 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003303 return MatchOperand_ParseFail;
3304 }
3305 // Allow Q regs and just interpret them as the two D sub-registers.
3306 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3307 EndReg = getDRegFromQReg(EndReg) + 1;
3308 // If the register is the same as the start reg, there's nothing
3309 // more to do.
3310 if (Reg == EndReg)
3311 continue;
3312 // The register must be in the same register class as the first.
3313 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003314 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003315 return MatchOperand_ParseFail;
3316 }
3317 // Ranges must go from low to high.
3318 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003319 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003320 return MatchOperand_ParseFail;
3321 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003322 // Parse the lane specifier if present.
3323 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003324 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003325 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3326 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003327 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003328 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003329 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003330 return MatchOperand_ParseFail;
3331 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003332
3333 // Add all the registers in the range to the register list.
3334 Count += EndReg - Reg;
3335 Reg = EndReg;
3336 continue;
3337 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003338 Parser.Lex(); // Eat the comma.
3339 RegLoc = Parser.getTok().getLoc();
3340 int OldReg = Reg;
3341 Reg = tryParseRegister();
3342 if (Reg == -1) {
3343 Error(RegLoc, "register expected");
3344 return MatchOperand_ParseFail;
3345 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003346 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003347 // It's OK to use the enumeration values directly here rather, as the
3348 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003349 //
3350 // The list is of D registers, but we also allow Q regs and just interpret
3351 // them as the two D sub-registers.
3352 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003353 if (!Spacing)
3354 Spacing = 1; // Register range implies a single spaced list.
3355 else if (Spacing == 2) {
3356 Error(RegLoc,
3357 "invalid register in double-spaced list (must be 'D' register')");
3358 return MatchOperand_ParseFail;
3359 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003360 Reg = getDRegFromQReg(Reg);
3361 if (Reg != OldReg + 1) {
3362 Error(RegLoc, "non-contiguous register range");
3363 return MatchOperand_ParseFail;
3364 }
3365 ++Reg;
3366 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003367 // Parse the lane specifier if present.
3368 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003369 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003370 SMLoc LaneLoc = Parser.getTok().getLoc();
3371 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3372 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003373 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003374 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003375 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003376 return MatchOperand_ParseFail;
3377 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003378 continue;
3379 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003380 // Normal D register.
3381 // Figure out the register spacing (single or double) of the list if
3382 // we don't know it already.
3383 if (!Spacing)
3384 Spacing = 1 + (Reg == OldReg + 2);
3385
3386 // Just check that it's contiguous and keep going.
3387 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003388 Error(RegLoc, "non-contiguous register range");
3389 return MatchOperand_ParseFail;
3390 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003391 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003392 // Parse the lane specifier if present.
3393 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003394 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003395 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003396 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003397 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003398 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003399 Error(EndLoc, "mismatched lane index in register list");
3400 return MatchOperand_ParseFail;
3401 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003402 }
3403
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003404 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003405 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003406 return MatchOperand_ParseFail;
3407 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003408 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003409 Parser.Lex(); // Eat '}' token.
3410
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003411 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003412 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003413 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003414 // composite register classes.
3415 if (Count == 2) {
3416 const MCRegisterClass *RC = (Spacing == 1) ?
3417 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3418 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3419 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3420 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003421
Jim Grosbach2f50e922011-12-15 21:44:33 +00003422 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3423 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003424 break;
3425 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003426 // Two-register operands have been converted to the
3427 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003428 if (Count == 2) {
3429 const MCRegisterClass *RC = (Spacing == 1) ?
3430 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3431 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003432 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3433 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003434 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003435 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003436 S, E));
3437 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003438 case IndexedLane:
3439 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003440 LaneIndex,
3441 (Spacing == 2),
3442 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003443 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003444 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003445 return MatchOperand_Success;
3446}
3447
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003448/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003449ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003450parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003451 SMLoc S = Parser.getTok().getLoc();
3452 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003453 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003454
Jiangning Liu288e1af2012-08-02 08:21:27 +00003455 if (Tok.is(AsmToken::Identifier)) {
3456 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003457
Jiangning Liu288e1af2012-08-02 08:21:27 +00003458 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3459 .Case("sy", ARM_MB::SY)
3460 .Case("st", ARM_MB::ST)
3461 .Case("sh", ARM_MB::ISH)
3462 .Case("ish", ARM_MB::ISH)
3463 .Case("shst", ARM_MB::ISHST)
3464 .Case("ishst", ARM_MB::ISHST)
3465 .Case("nsh", ARM_MB::NSH)
3466 .Case("un", ARM_MB::NSH)
3467 .Case("nshst", ARM_MB::NSHST)
3468 .Case("unst", ARM_MB::NSHST)
3469 .Case("osh", ARM_MB::OSH)
3470 .Case("oshst", ARM_MB::OSHST)
3471 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003472
Jiangning Liu288e1af2012-08-02 08:21:27 +00003473 if (Opt == ~0U)
3474 return MatchOperand_NoMatch;
3475
3476 Parser.Lex(); // Eat identifier token.
3477 } else if (Tok.is(AsmToken::Hash) ||
3478 Tok.is(AsmToken::Dollar) ||
3479 Tok.is(AsmToken::Integer)) {
3480 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003481 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003482 SMLoc Loc = Parser.getTok().getLoc();
3483
3484 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003485 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003486 Error(Loc, "illegal expression");
3487 return MatchOperand_ParseFail;
3488 }
3489
3490 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3491 if (!CE) {
3492 Error(Loc, "constant expression expected");
3493 return MatchOperand_ParseFail;
3494 }
3495
3496 int Val = CE->getValue();
3497 if (Val & ~0xf) {
3498 Error(Loc, "immediate value out of range");
3499 return MatchOperand_ParseFail;
3500 }
3501
3502 Opt = ARM_MB::RESERVED_0 + Val;
3503 } else
3504 return MatchOperand_ParseFail;
3505
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003506 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003507 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003508}
3509
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003510/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3511ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3512parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3513 SMLoc S = Parser.getTok().getLoc();
3514 const AsmToken &Tok = Parser.getTok();
3515 unsigned Opt;
3516
3517 if (Tok.is(AsmToken::Identifier)) {
3518 StringRef OptStr = Tok.getString();
3519
3520 if (OptStr.lower() == "sy")
3521 Opt = ARM_ISB::SY;
3522 else
3523 return MatchOperand_NoMatch;
3524
3525 Parser.Lex(); // Eat identifier token.
3526 } else if (Tok.is(AsmToken::Hash) ||
3527 Tok.is(AsmToken::Dollar) ||
3528 Tok.is(AsmToken::Integer)) {
3529 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003530 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003531 SMLoc Loc = Parser.getTok().getLoc();
3532
3533 const MCExpr *ISBarrierID;
3534 if (getParser().parseExpression(ISBarrierID)) {
3535 Error(Loc, "illegal expression");
3536 return MatchOperand_ParseFail;
3537 }
3538
3539 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3540 if (!CE) {
3541 Error(Loc, "constant expression expected");
3542 return MatchOperand_ParseFail;
3543 }
3544
3545 int Val = CE->getValue();
3546 if (Val & ~0xf) {
3547 Error(Loc, "immediate value out of range");
3548 return MatchOperand_ParseFail;
3549 }
3550
3551 Opt = ARM_ISB::RESERVED_0 + Val;
3552 } else
3553 return MatchOperand_ParseFail;
3554
3555 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3556 (ARM_ISB::InstSyncBOpt)Opt, S));
3557 return MatchOperand_Success;
3558}
3559
3560
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003561/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003562ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003563parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003564 SMLoc S = Parser.getTok().getLoc();
3565 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003566 if (!Tok.is(AsmToken::Identifier))
3567 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003568 StringRef IFlagsStr = Tok.getString();
3569
Owen Anderson10c5b122011-10-05 17:16:40 +00003570 // An iflags string of "none" is interpreted to mean that none of the AIF
3571 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003572 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003573 if (IFlagsStr != "none") {
3574 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3575 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3576 .Case("a", ARM_PROC::A)
3577 .Case("i", ARM_PROC::I)
3578 .Case("f", ARM_PROC::F)
3579 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003580
Owen Anderson10c5b122011-10-05 17:16:40 +00003581 // If some specific iflag is already set, it means that some letter is
3582 // present more than once, this is not acceptable.
3583 if (Flag == ~0U || (IFlags & Flag))
3584 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003585
Owen Anderson10c5b122011-10-05 17:16:40 +00003586 IFlags |= Flag;
3587 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003588 }
3589
3590 Parser.Lex(); // Eat identifier token.
3591 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3592 return MatchOperand_Success;
3593}
3594
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003595/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003596ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003597parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003598 SMLoc S = Parser.getTok().getLoc();
3599 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003600 if (!Tok.is(AsmToken::Identifier))
3601 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003602 StringRef Mask = Tok.getString();
3603
James Molloy21efa7d2011-09-28 14:21:38 +00003604 if (isMClass()) {
3605 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003606 std::string Name = Mask.lower();
3607 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003608 // Note: in the documentation:
3609 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3610 // for MSR APSR_nzcvq.
3611 // but we do make it an alias here. This is so to get the "mask encoding"
3612 // bits correct on MSR APSR writes.
3613 //
3614 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3615 // should really only be allowed when writing a special register. Note
3616 // they get dropped in the MRS instruction reading a special register as
3617 // the SYSm field is only 8 bits.
3618 //
3619 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3620 // includes the DSP extension but that is not checked.
3621 .Case("apsr", 0x800)
3622 .Case("apsr_nzcvq", 0x800)
3623 .Case("apsr_g", 0x400)
3624 .Case("apsr_nzcvqg", 0xc00)
3625 .Case("iapsr", 0x801)
3626 .Case("iapsr_nzcvq", 0x801)
3627 .Case("iapsr_g", 0x401)
3628 .Case("iapsr_nzcvqg", 0xc01)
3629 .Case("eapsr", 0x802)
3630 .Case("eapsr_nzcvq", 0x802)
3631 .Case("eapsr_g", 0x402)
3632 .Case("eapsr_nzcvqg", 0xc02)
3633 .Case("xpsr", 0x803)
3634 .Case("xpsr_nzcvq", 0x803)
3635 .Case("xpsr_g", 0x403)
3636 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003637 .Case("ipsr", 0x805)
3638 .Case("epsr", 0x806)
3639 .Case("iepsr", 0x807)
3640 .Case("msp", 0x808)
3641 .Case("psp", 0x809)
3642 .Case("primask", 0x810)
3643 .Case("basepri", 0x811)
3644 .Case("basepri_max", 0x812)
3645 .Case("faultmask", 0x813)
3646 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003647 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003648
James Molloy21efa7d2011-09-28 14:21:38 +00003649 if (FlagsVal == ~0U)
3650 return MatchOperand_NoMatch;
3651
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003652 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003653 // basepri, basepri_max and faultmask only valid for V7m.
3654 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003655
James Molloy21efa7d2011-09-28 14:21:38 +00003656 Parser.Lex(); // Eat identifier token.
3657 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3658 return MatchOperand_Success;
3659 }
3660
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003661 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3662 size_t Start = 0, Next = Mask.find('_');
3663 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003664 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003665 if (Next != StringRef::npos)
3666 Flags = Mask.slice(Next+1, Mask.size());
3667
3668 // FlagsVal contains the complete mask:
3669 // 3-0: Mask
3670 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3671 unsigned FlagsVal = 0;
3672
3673 if (SpecReg == "apsr") {
3674 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003675 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003676 .Case("g", 0x4) // same as CPSR_s
3677 .Case("nzcvqg", 0xc) // same as CPSR_fs
3678 .Default(~0U);
3679
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003680 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003681 if (!Flags.empty())
3682 return MatchOperand_NoMatch;
3683 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003684 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003685 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003686 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003687 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3688 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003689 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003690 for (int i = 0, e = Flags.size(); i != e; ++i) {
3691 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3692 .Case("c", 1)
3693 .Case("x", 2)
3694 .Case("s", 4)
3695 .Case("f", 8)
3696 .Default(~0U);
3697
3698 // If some specific flag is already set, it means that some letter is
3699 // present more than once, this is not acceptable.
3700 if (FlagsVal == ~0U || (FlagsVal & Flag))
3701 return MatchOperand_NoMatch;
3702 FlagsVal |= Flag;
3703 }
3704 } else // No match for special register.
3705 return MatchOperand_NoMatch;
3706
Owen Anderson03a173e2011-10-21 18:43:28 +00003707 // Special register without flags is NOT equivalent to "fc" flags.
3708 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3709 // two lines would enable gas compatibility at the expense of breaking
3710 // round-tripping.
3711 //
3712 // if (!FlagsVal)
3713 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003714
3715 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3716 if (SpecReg == "spsr")
3717 FlagsVal |= 16;
3718
3719 Parser.Lex(); // Eat identifier token.
3720 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3721 return MatchOperand_Success;
3722}
3723
Jim Grosbach27c1e252011-07-21 17:23:04 +00003724ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3725parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3726 int Low, int High) {
3727 const AsmToken &Tok = Parser.getTok();
3728 if (Tok.isNot(AsmToken::Identifier)) {
3729 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3730 return MatchOperand_ParseFail;
3731 }
3732 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003733 std::string LowerOp = Op.lower();
3734 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003735 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3736 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3737 return MatchOperand_ParseFail;
3738 }
3739 Parser.Lex(); // Eat shift type token.
3740
3741 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003742 if (Parser.getTok().isNot(AsmToken::Hash) &&
3743 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003744 Error(Parser.getTok().getLoc(), "'#' expected");
3745 return MatchOperand_ParseFail;
3746 }
3747 Parser.Lex(); // Eat hash token.
3748
3749 const MCExpr *ShiftAmount;
3750 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003751 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003752 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003753 Error(Loc, "illegal expression");
3754 return MatchOperand_ParseFail;
3755 }
3756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3757 if (!CE) {
3758 Error(Loc, "constant expression expected");
3759 return MatchOperand_ParseFail;
3760 }
3761 int Val = CE->getValue();
3762 if (Val < Low || Val > High) {
3763 Error(Loc, "immediate value out of range");
3764 return MatchOperand_ParseFail;
3765 }
3766
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003767 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003768
3769 return MatchOperand_Success;
3770}
3771
Jim Grosbach0a547702011-07-22 17:44:50 +00003772ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3773parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3774 const AsmToken &Tok = Parser.getTok();
3775 SMLoc S = Tok.getLoc();
3776 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003777 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003778 return MatchOperand_ParseFail;
3779 }
Tim Northover4d141442013-05-31 15:58:45 +00003780 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003781 .Case("be", 1)
3782 .Case("le", 0)
3783 .Default(-1);
3784 Parser.Lex(); // Eat the token.
3785
3786 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003787 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003788 return MatchOperand_ParseFail;
3789 }
3790 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3791 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003792 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003793 return MatchOperand_Success;
3794}
3795
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003796/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3797/// instructions. Legal values are:
3798/// lsl #n 'n' in [0,31]
3799/// asr #n 'n' in [1,32]
3800/// n == 32 encoded as n == 0.
3801ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3802parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3803 const AsmToken &Tok = Parser.getTok();
3804 SMLoc S = Tok.getLoc();
3805 if (Tok.isNot(AsmToken::Identifier)) {
3806 Error(S, "shift operator 'asr' or 'lsl' expected");
3807 return MatchOperand_ParseFail;
3808 }
3809 StringRef ShiftName = Tok.getString();
3810 bool isASR;
3811 if (ShiftName == "lsl" || ShiftName == "LSL")
3812 isASR = false;
3813 else if (ShiftName == "asr" || ShiftName == "ASR")
3814 isASR = true;
3815 else {
3816 Error(S, "shift operator 'asr' or 'lsl' expected");
3817 return MatchOperand_ParseFail;
3818 }
3819 Parser.Lex(); // Eat the operator.
3820
3821 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003822 if (Parser.getTok().isNot(AsmToken::Hash) &&
3823 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003824 Error(Parser.getTok().getLoc(), "'#' expected");
3825 return MatchOperand_ParseFail;
3826 }
3827 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003828 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003829
3830 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003831 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003832 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003833 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003834 return MatchOperand_ParseFail;
3835 }
3836 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3837 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003838 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003839 return MatchOperand_ParseFail;
3840 }
3841
3842 int64_t Val = CE->getValue();
3843 if (isASR) {
3844 // Shift amount must be in [1,32]
3845 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003846 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003847 return MatchOperand_ParseFail;
3848 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003849 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3850 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003851 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003852 return MatchOperand_ParseFail;
3853 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003854 if (Val == 32) Val = 0;
3855 } else {
3856 // Shift amount must be in [1,32]
3857 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003858 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003859 return MatchOperand_ParseFail;
3860 }
3861 }
3862
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003863 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003864
3865 return MatchOperand_Success;
3866}
3867
Jim Grosbach833b9d32011-07-27 20:15:40 +00003868/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3869/// of instructions. Legal values are:
3870/// ror #n 'n' in {0, 8, 16, 24}
3871ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3872parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3873 const AsmToken &Tok = Parser.getTok();
3874 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003875 if (Tok.isNot(AsmToken::Identifier))
3876 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003877 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003878 if (ShiftName != "ror" && ShiftName != "ROR")
3879 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003880 Parser.Lex(); // Eat the operator.
3881
3882 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003883 if (Parser.getTok().isNot(AsmToken::Hash) &&
3884 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003885 Error(Parser.getTok().getLoc(), "'#' expected");
3886 return MatchOperand_ParseFail;
3887 }
3888 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003889 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003890
3891 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003892 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003893 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003894 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003895 return MatchOperand_ParseFail;
3896 }
3897 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3898 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003899 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003900 return MatchOperand_ParseFail;
3901 }
3902
3903 int64_t Val = CE->getValue();
3904 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3905 // normally, zero is represented in asm by omitting the rotate operand
3906 // entirely.
3907 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003908 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003909 return MatchOperand_ParseFail;
3910 }
3911
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003912 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003913
3914 return MatchOperand_Success;
3915}
3916
Jim Grosbach864b6092011-07-28 21:34:26 +00003917ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3918parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3919 SMLoc S = Parser.getTok().getLoc();
3920 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003921 if (Parser.getTok().isNot(AsmToken::Hash) &&
3922 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003923 Error(Parser.getTok().getLoc(), "'#' expected");
3924 return MatchOperand_ParseFail;
3925 }
3926 Parser.Lex(); // Eat hash token.
3927
3928 const MCExpr *LSBExpr;
3929 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003930 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003931 Error(E, "malformed immediate expression");
3932 return MatchOperand_ParseFail;
3933 }
3934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3935 if (!CE) {
3936 Error(E, "'lsb' operand must be an immediate");
3937 return MatchOperand_ParseFail;
3938 }
3939
3940 int64_t LSB = CE->getValue();
3941 // The LSB must be in the range [0,31]
3942 if (LSB < 0 || LSB > 31) {
3943 Error(E, "'lsb' operand must be in the range [0,31]");
3944 return MatchOperand_ParseFail;
3945 }
3946 E = Parser.getTok().getLoc();
3947
3948 // Expect another immediate operand.
3949 if (Parser.getTok().isNot(AsmToken::Comma)) {
3950 Error(Parser.getTok().getLoc(), "too few operands");
3951 return MatchOperand_ParseFail;
3952 }
3953 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003954 if (Parser.getTok().isNot(AsmToken::Hash) &&
3955 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003956 Error(Parser.getTok().getLoc(), "'#' expected");
3957 return MatchOperand_ParseFail;
3958 }
3959 Parser.Lex(); // Eat hash token.
3960
3961 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003962 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003963 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003964 Error(E, "malformed immediate expression");
3965 return MatchOperand_ParseFail;
3966 }
3967 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3968 if (!CE) {
3969 Error(E, "'width' operand must be an immediate");
3970 return MatchOperand_ParseFail;
3971 }
3972
3973 int64_t Width = CE->getValue();
3974 // The LSB must be in the range [1,32-lsb]
3975 if (Width < 1 || Width > 32 - LSB) {
3976 Error(E, "'width' operand must be in the range [1,32-lsb]");
3977 return MatchOperand_ParseFail;
3978 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003979
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003980 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003981
3982 return MatchOperand_Success;
3983}
3984
Jim Grosbachd3595712011-08-03 23:50:40 +00003985ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3986parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3987 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003988 // postidx_reg := '+' register {, shift}
3989 // | '-' register {, shift}
3990 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003991
3992 // This method must return MatchOperand_NoMatch without consuming any tokens
3993 // in the case where there is no match, as other alternatives take other
3994 // parse methods.
3995 AsmToken Tok = Parser.getTok();
3996 SMLoc S = Tok.getLoc();
3997 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003998 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003999 if (Tok.is(AsmToken::Plus)) {
4000 Parser.Lex(); // Eat the '+' token.
4001 haveEaten = true;
4002 } else if (Tok.is(AsmToken::Minus)) {
4003 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004004 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004005 haveEaten = true;
4006 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004007
4008 SMLoc E = Parser.getTok().getEndLoc();
4009 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004010 if (Reg == -1) {
4011 if (!haveEaten)
4012 return MatchOperand_NoMatch;
4013 Error(Parser.getTok().getLoc(), "register expected");
4014 return MatchOperand_ParseFail;
4015 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004016
Jim Grosbachc320c852011-08-05 21:28:30 +00004017 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4018 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004019 if (Parser.getTok().is(AsmToken::Comma)) {
4020 Parser.Lex(); // Eat the ','.
4021 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4022 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004023
4024 // FIXME: Only approximates end...may include intervening whitespace.
4025 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004026 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004027
4028 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4029 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004030
4031 return MatchOperand_Success;
4032}
4033
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004034ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4035parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4036 // Check for a post-index addressing register operand. Specifically:
4037 // am3offset := '+' register
4038 // | '-' register
4039 // | register
4040 // | # imm
4041 // | # + imm
4042 // | # - imm
4043
4044 // This method must return MatchOperand_NoMatch without consuming any tokens
4045 // in the case where there is no match, as other alternatives take other
4046 // parse methods.
4047 AsmToken Tok = Parser.getTok();
4048 SMLoc S = Tok.getLoc();
4049
4050 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004051 if (Parser.getTok().is(AsmToken::Hash) ||
4052 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004053 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004054 // Explicitly look for a '-', as we need to encode negative zero
4055 // differently.
4056 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4057 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004058 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004059 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004060 return MatchOperand_ParseFail;
4061 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4062 if (!CE) {
4063 Error(S, "constant expression expected");
4064 return MatchOperand_ParseFail;
4065 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004066 // Negative zero is encoded as the flag value INT32_MIN.
4067 int32_t Val = CE->getValue();
4068 if (isNegative && Val == 0)
4069 Val = INT32_MIN;
4070
4071 Operands.push_back(
4072 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4073
4074 return MatchOperand_Success;
4075 }
4076
4077
4078 bool haveEaten = false;
4079 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004080 if (Tok.is(AsmToken::Plus)) {
4081 Parser.Lex(); // Eat the '+' token.
4082 haveEaten = true;
4083 } else if (Tok.is(AsmToken::Minus)) {
4084 Parser.Lex(); // Eat the '-' token.
4085 isAdd = false;
4086 haveEaten = true;
4087 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004088
4089 Tok = Parser.getTok();
4090 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004091 if (Reg == -1) {
4092 if (!haveEaten)
4093 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004094 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004095 return MatchOperand_ParseFail;
4096 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004097
4098 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004099 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004100
4101 return MatchOperand_Success;
4102}
4103
Tim Northovereb5e4d52013-07-22 09:06:12 +00004104/// Convert parsed operands to MCInst. Needed here because this instruction
4105/// only has two register operands, but multiplication is commutative so
4106/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004107void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004108cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004109 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004110 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4111 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004112 // If we have a three-operand form, make sure to set Rn to be the operand
4113 // that isn't the same as Rd.
4114 unsigned RegOp = 4;
4115 if (Operands.size() == 6 &&
4116 ((ARMOperand*)Operands[4])->getReg() ==
4117 ((ARMOperand*)Operands[3])->getReg())
4118 RegOp = 5;
4119 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4120 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004121 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004122}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004123
Mihai Popaad18d3c2013-08-09 10:38:32 +00004124void ARMAsmParser::
4125cvtThumbBranches(MCInst &Inst,
4126 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4127 int CondOp = -1, ImmOp = -1;
4128 switch(Inst.getOpcode()) {
4129 case ARM::tB:
4130 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4131
4132 case ARM::t2B:
4133 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4134
4135 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4136 }
4137 // first decide whether or not the branch should be conditional
4138 // by looking at it's location relative to an IT block
4139 if(inITBlock()) {
4140 // inside an IT block we cannot have any conditional branches. any
4141 // such instructions needs to be converted to unconditional form
4142 switch(Inst.getOpcode()) {
4143 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4144 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4145 }
4146 } else {
4147 // outside IT blocks we can only have unconditional branches with AL
4148 // condition code or conditional branches with non-AL condition code
4149 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4150 switch(Inst.getOpcode()) {
4151 case ARM::tB:
4152 case ARM::tBcc:
4153 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4154 break;
4155 case ARM::t2B:
4156 case ARM::t2Bcc:
4157 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4158 break;
4159 }
4160 }
4161
4162 // now decide on encoding size based on branch target range
4163 switch(Inst.getOpcode()) {
4164 // classify tB as either t2B or t1B based on range of immediate operand
4165 case ARM::tB: {
4166 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4167 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4168 Inst.setOpcode(ARM::t2B);
4169 break;
4170 }
4171 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4172 case ARM::tBcc: {
4173 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4174 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4175 Inst.setOpcode(ARM::t2Bcc);
4176 break;
4177 }
4178 }
4179 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4180 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4181}
4182
Bill Wendlinge18980a2010-11-06 22:36:58 +00004183/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004184/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004185bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004186parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004187 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004188 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004189 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004190 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004191 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004192
Sean Callanan936b0d32010-01-19 21:44:56 +00004193 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004194 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004195 if (BaseRegNum == -1)
4196 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004197
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004198 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004199 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004200 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4201 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004202 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004203
Jim Grosbachd3595712011-08-03 23:50:40 +00004204 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004205 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004206 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004207
Jim Grosbachd3595712011-08-03 23:50:40 +00004208 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004209 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004210
Jim Grosbach40700e02011-09-19 18:42:21 +00004211 // If there's a pre-indexing writeback marker, '!', just add it as a token
4212 // operand. It's rather odd, but syntactically valid.
4213 if (Parser.getTok().is(AsmToken::Exclaim)) {
4214 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4215 Parser.Lex(); // Eat the '!'.
4216 }
4217
Jim Grosbachd3595712011-08-03 23:50:40 +00004218 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004219 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004220
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004221 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4222 "Lost colon or comma in memory operand?!");
4223 if (Tok.is(AsmToken::Comma)) {
4224 Parser.Lex(); // Eat the comma.
4225 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004226
Jim Grosbacha95ec992011-10-11 17:29:55 +00004227 // If we have a ':', it's an alignment specifier.
4228 if (Parser.getTok().is(AsmToken::Colon)) {
4229 Parser.Lex(); // Eat the ':'.
4230 E = Parser.getTok().getLoc();
4231
4232 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004233 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004234 return true;
4235
4236 // The expression has to be a constant. Memory references with relocations
4237 // don't come through here, as they use the <label> forms of the relevant
4238 // instructions.
4239 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4240 if (!CE)
4241 return Error (E, "constant expression expected");
4242
4243 unsigned Align = 0;
4244 switch (CE->getValue()) {
4245 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004246 return Error(E,
4247 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4248 case 16: Align = 2; break;
4249 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004250 case 64: Align = 8; break;
4251 case 128: Align = 16; break;
4252 case 256: Align = 32; break;
4253 }
4254
4255 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004256 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004257 return Error(Parser.getTok().getLoc(), "']' expected");
4258 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004259 Parser.Lex(); // Eat right bracket token.
4260
4261 // Don't worry about range checking the value here. That's handled by
4262 // the is*() predicates.
4263 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4264 ARM_AM::no_shift, 0, Align,
4265 false, S, E));
4266
4267 // If there's a pre-indexing writeback marker, '!', just add it as a token
4268 // operand.
4269 if (Parser.getTok().is(AsmToken::Exclaim)) {
4270 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4271 Parser.Lex(); // Eat the '!'.
4272 }
4273
4274 return false;
4275 }
4276
4277 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004278 // offset. Be friendly and also accept a plain integer (without a leading
4279 // hash) for gas compatibility.
4280 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004281 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004282 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004283 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004284 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004285 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004286
Owen Anderson967674d2011-08-29 19:36:44 +00004287 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004288 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004289 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004290 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004291
4292 // The expression has to be a constant. Memory references with relocations
4293 // don't come through here, as they use the <label> forms of the relevant
4294 // instructions.
4295 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4296 if (!CE)
4297 return Error (E, "constant expression expected");
4298
Owen Anderson967674d2011-08-29 19:36:44 +00004299 // If the constant was #-0, represent it as INT32_MIN.
4300 int32_t Val = CE->getValue();
4301 if (isNegative && Val == 0)
4302 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4303
Jim Grosbachd3595712011-08-03 23:50:40 +00004304 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004305 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004306 return Error(Parser.getTok().getLoc(), "']' expected");
4307 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004308 Parser.Lex(); // Eat right bracket token.
4309
4310 // Don't worry about range checking the value here. That's handled by
4311 // the is*() predicates.
4312 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004313 ARM_AM::no_shift, 0, 0,
4314 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004315
4316 // If there's a pre-indexing writeback marker, '!', just add it as a token
4317 // operand.
4318 if (Parser.getTok().is(AsmToken::Exclaim)) {
4319 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4320 Parser.Lex(); // Eat the '!'.
4321 }
4322
4323 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004324 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004325
4326 // The register offset is optionally preceded by a '+' or '-'
4327 bool isNegative = false;
4328 if (Parser.getTok().is(AsmToken::Minus)) {
4329 isNegative = true;
4330 Parser.Lex(); // Eat the '-'.
4331 } else if (Parser.getTok().is(AsmToken::Plus)) {
4332 // Nothing to do.
4333 Parser.Lex(); // Eat the '+'.
4334 }
4335
4336 E = Parser.getTok().getLoc();
4337 int OffsetRegNum = tryParseRegister();
4338 if (OffsetRegNum == -1)
4339 return Error(E, "register expected");
4340
4341 // If there's a shift operator, handle it.
4342 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004343 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004344 if (Parser.getTok().is(AsmToken::Comma)) {
4345 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004346 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004347 return true;
4348 }
4349
4350 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004351 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004352 return Error(Parser.getTok().getLoc(), "']' expected");
4353 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004354 Parser.Lex(); // Eat right bracket token.
4355
4356 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004357 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004358 S, E));
4359
Jim Grosbachc320c852011-08-05 21:28:30 +00004360 // If there's a pre-indexing writeback marker, '!', just add it as a token
4361 // operand.
4362 if (Parser.getTok().is(AsmToken::Exclaim)) {
4363 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4364 Parser.Lex(); // Eat the '!'.
4365 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004366
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004367 return false;
4368}
4369
Jim Grosbachd3595712011-08-03 23:50:40 +00004370/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004371/// ( lsl | lsr | asr | ror ) , # shift_amount
4372/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004373/// return true if it parses a shift otherwise it returns false.
4374bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4375 unsigned &Amount) {
4376 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004377 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004378 if (Tok.isNot(AsmToken::Identifier))
4379 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004380 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004381 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4382 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004383 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004384 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004385 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004386 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004387 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004388 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004389 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004390 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004391 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004392 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004393 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004394 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004395
Jim Grosbachd3595712011-08-03 23:50:40 +00004396 // rrx stands alone.
4397 Amount = 0;
4398 if (St != ARM_AM::rrx) {
4399 Loc = Parser.getTok().getLoc();
4400 // A '#' and a shift amount.
4401 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004402 if (HashTok.isNot(AsmToken::Hash) &&
4403 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004404 return Error(HashTok.getLoc(), "'#' expected");
4405 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004406
Jim Grosbachd3595712011-08-03 23:50:40 +00004407 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004408 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004409 return true;
4410 // Range check the immediate.
4411 // lsl, ror: 0 <= imm <= 31
4412 // lsr, asr: 0 <= imm <= 32
4413 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4414 if (!CE)
4415 return Error(Loc, "shift amount must be an immediate");
4416 int64_t Imm = CE->getValue();
4417 if (Imm < 0 ||
4418 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4419 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4420 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004421 // If <ShiftTy> #0, turn it into a no_shift.
4422 if (Imm == 0)
4423 St = ARM_AM::lsl;
4424 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4425 if (Imm == 32)
4426 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004427 Amount = Imm;
4428 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004429
4430 return false;
4431}
4432
Jim Grosbache7fbce72011-10-03 23:38:36 +00004433/// parseFPImm - A floating point immediate expression operand.
4434ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4435parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004436 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004437 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004438 // integer only.
4439 //
4440 // This routine still creates a generic Immediate operand, containing
4441 // a bitcast of the 64-bit floating point value. The various operands
4442 // that accept floats can check whether the value is valid for them
4443 // via the standard is*() predicates.
4444
Jim Grosbache7fbce72011-10-03 23:38:36 +00004445 SMLoc S = Parser.getTok().getLoc();
4446
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004447 if (Parser.getTok().isNot(AsmToken::Hash) &&
4448 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004449 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004450
4451 // Disambiguate the VMOV forms that can accept an FP immediate.
4452 // vmov.f32 <sreg>, #imm
4453 // vmov.f64 <dreg>, #imm
4454 // vmov.f32 <dreg>, #imm @ vector f32x2
4455 // vmov.f32 <qreg>, #imm @ vector f32x4
4456 //
4457 // There are also the NEON VMOV instructions which expect an
4458 // integer constant. Make sure we don't try to parse an FPImm
4459 // for these:
4460 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4461 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4462 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4463 TyOp->getToken() != ".f64"))
4464 return MatchOperand_NoMatch;
4465
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004466 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004467
4468 // Handle negation, as that still comes through as a separate token.
4469 bool isNegative = false;
4470 if (Parser.getTok().is(AsmToken::Minus)) {
4471 isNegative = true;
4472 Parser.Lex();
4473 }
4474 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004475 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004476 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004477 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004478 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4479 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004480 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004481 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004482 Operands.push_back(ARMOperand::CreateImm(
4483 MCConstantExpr::Create(IntVal, getContext()),
4484 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004485 return MatchOperand_Success;
4486 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004487 // Also handle plain integers. Instructions which allow floating point
4488 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004489 if (Tok.is(AsmToken::Integer)) {
4490 int64_t Val = Tok.getIntVal();
4491 Parser.Lex(); // Eat the token.
4492 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004493 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004494 return MatchOperand_ParseFail;
4495 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004496 double RealVal = ARM_AM::getFPImmFloat(Val);
4497 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4498 Operands.push_back(ARMOperand::CreateImm(
4499 MCConstantExpr::Create(Val, getContext()), S,
4500 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004501 return MatchOperand_Success;
4502 }
4503
Jim Grosbach235c8d22012-01-19 02:47:30 +00004504 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004505 return MatchOperand_ParseFail;
4506}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004507
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004508/// Parse a arm instruction operand. For now this parses the operand regardless
4509/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004510bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004511 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004512 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004513
4514 // Check if the current operand has a custom associated parser, if so, try to
4515 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004516 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4517 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004518 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004519 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4520 // there was a match, but an error occurred, in which case, just return that
4521 // the operand parsing failed.
4522 if (ResTy == MatchOperand_ParseFail)
4523 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004524
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004525 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004526 default:
4527 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004528 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004529 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004530 // If we've seen a branch mnemonic, the next operand must be a label. This
4531 // is true even if the label is a register name. So "br r1" means branch to
4532 // label "r1".
4533 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4534 if (!ExpectLabel) {
4535 if (!tryParseRegisterWithWriteBack(Operands))
4536 return false;
4537 int Res = tryParseShiftRegister(Operands);
4538 if (Res == 0) // success
4539 return false;
4540 else if (Res == -1) // irrecoverable error
4541 return true;
4542 // If this is VMRS, check for the apsr_nzcv operand.
4543 if (Mnemonic == "vmrs" &&
4544 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4545 S = Parser.getTok().getLoc();
4546 Parser.Lex();
4547 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4548 return false;
4549 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004550 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004551
4552 // Fall though for the Identifier case that is not a register or a
4553 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004554 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004555 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004556 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004557 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004558 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004559 // This was not a register so parse other operands that start with an
4560 // identifier (like labels) as expressions and create them as immediates.
4561 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004562 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004563 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004564 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004565 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004566 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4567 return false;
4568 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004569 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004570 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004571 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004572 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004573 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004574 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004575 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004576 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004577 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004578
4579 if (Parser.getTok().isNot(AsmToken::Colon)) {
4580 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4581 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004582 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004583 return true;
4584 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4585 if (CE) {
4586 int32_t Val = CE->getValue();
4587 if (isNegative && Val == 0)
4588 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4589 }
4590 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4591 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004592
4593 // There can be a trailing '!' on operands that we want as a separate
4594 // '!' Token operand. Handle that here. For example, the compatibilty
4595 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4596 if (Parser.getTok().is(AsmToken::Exclaim)) {
4597 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4598 Parser.getTok().getLoc()));
4599 Parser.Lex(); // Eat exclaim token
4600 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004601 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004602 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004603 // w/ a ':' after the '#', it's just like a plain ':'.
4604 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004605 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004606 case AsmToken::Colon: {
4607 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004608 // FIXME: Check it's an expression prefix,
4609 // e.g. (FOO - :lower16:BAR) isn't legal.
4610 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004611 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004612 return true;
4613
Evan Cheng965b3c72011-01-13 07:58:56 +00004614 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004615 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004616 return true;
4617
Evan Cheng965b3c72011-01-13 07:58:56 +00004618 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004619 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004620 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004621 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004622 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004623 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004624 }
4625}
4626
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004627// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004628// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004629bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004630 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004631
4632 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004633 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004634 Parser.Lex(); // Eat ':'
4635
4636 if (getLexer().isNot(AsmToken::Identifier)) {
4637 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4638 return true;
4639 }
4640
4641 StringRef IDVal = Parser.getTok().getIdentifier();
4642 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004643 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004644 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004645 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004646 } else {
4647 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4648 return true;
4649 }
4650 Parser.Lex();
4651
4652 if (getLexer().isNot(AsmToken::Colon)) {
4653 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4654 return true;
4655 }
4656 Parser.Lex(); // Eat the last ':'
4657 return false;
4658}
4659
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004660/// \brief Given a mnemonic, split out possible predication code and carry
4661/// setting letters to form a canonical mnemonic and flags.
4662//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004663// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004664// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004665StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004666 unsigned &PredicationCode,
4667 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004668 unsigned &ProcessorIMod,
4669 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004670 PredicationCode = ARMCC::AL;
4671 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004672 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004673
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004674 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004675 //
4676 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004677 if ((Mnemonic == "movs" && isThumb()) ||
4678 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4679 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4680 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4681 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Jim Grosbach9b81a4f2013-04-15 22:42:50 +00004682 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004683 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4684 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004685 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004686 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004687 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4688 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4689 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004690 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004691
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004692 // First, split out any predication code. Ignore mnemonics we know aren't
4693 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004694 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004695 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004696 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004697 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004698 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4699 .Case("eq", ARMCC::EQ)
4700 .Case("ne", ARMCC::NE)
4701 .Case("hs", ARMCC::HS)
4702 .Case("cs", ARMCC::HS)
4703 .Case("lo", ARMCC::LO)
4704 .Case("cc", ARMCC::LO)
4705 .Case("mi", ARMCC::MI)
4706 .Case("pl", ARMCC::PL)
4707 .Case("vs", ARMCC::VS)
4708 .Case("vc", ARMCC::VC)
4709 .Case("hi", ARMCC::HI)
4710 .Case("ls", ARMCC::LS)
4711 .Case("ge", ARMCC::GE)
4712 .Case("lt", ARMCC::LT)
4713 .Case("gt", ARMCC::GT)
4714 .Case("le", ARMCC::LE)
4715 .Case("al", ARMCC::AL)
4716 .Default(~0U);
4717 if (CC != ~0U) {
4718 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4719 PredicationCode = CC;
4720 }
Bill Wendling193961b2010-10-29 23:50:21 +00004721 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004722
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004723 // Next, determine if we have a carry setting bit. We explicitly ignore all
4724 // the instructions we know end in 's'.
4725 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004726 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004727 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4728 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4729 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004730 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004731 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004732 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004733 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004734 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004735 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004736 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4737 CarrySetting = true;
4738 }
4739
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004740 // The "cps" instruction can have a interrupt mode operand which is glued into
4741 // the mnemonic. Check if this is the case, split it and parse the imod op
4742 if (Mnemonic.startswith("cps")) {
4743 // Split out any imod code.
4744 unsigned IMod =
4745 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4746 .Case("ie", ARM_PROC::IE)
4747 .Case("id", ARM_PROC::ID)
4748 .Default(~0U);
4749 if (IMod != ~0U) {
4750 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4751 ProcessorIMod = IMod;
4752 }
4753 }
4754
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004755 // The "it" instruction has the condition mask on the end of the mnemonic.
4756 if (Mnemonic.startswith("it")) {
4757 ITMask = Mnemonic.slice(2, Mnemonic.size());
4758 Mnemonic = Mnemonic.slice(0, 2);
4759 }
4760
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004761 return Mnemonic;
4762}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004763
4764/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4765/// inclusion of carry set or predication code operands.
4766//
4767// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004768void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004769getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004770 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004771 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4772 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004773 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004774 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004775 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004776 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004777 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004778 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004779 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004780 Mnemonic == "mla" || Mnemonic == "smlal" ||
4781 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004782 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004783 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004784 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004785
Tim Northover2c45a382013-06-26 16:52:40 +00004786 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4787 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4788 Mnemonic == "trap" || Mnemonic == "setend" ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004789 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4790 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004791 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4792 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4793 Mnemonic == "vrintm") {
Tim Northover2c45a382013-06-26 16:52:40 +00004794 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004795 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004796 } else if (!isThumb()) {
4797 // Some instructions are only predicable in Thumb mode
4798 CanAcceptPredicationCode
4799 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4800 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4801 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4802 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4803 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4804 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4805 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4806 } else if (isThumbOne()) {
4807 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004808 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004809 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004810}
4811
Jim Grosbach7283da92011-08-16 21:12:37 +00004812bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4813 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004814 // FIXME: This is all horribly hacky. We really need a better way to deal
4815 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004816
4817 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4818 // another does not. Specifically, the MOVW instruction does not. So we
4819 // special case it here and remove the defaulted (non-setting) cc_out
4820 // operand if that's the instruction we're trying to match.
4821 //
4822 // We do this as post-processing of the explicit operands rather than just
4823 // conditionally adding the cc_out in the first place because we need
4824 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004825 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004826 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4827 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4828 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4829 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004830
4831 // Register-register 'add' for thumb does not have a cc_out operand
4832 // when there are only two register operands.
4833 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4834 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4835 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4836 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4837 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004838 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004839 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4840 // have to check the immediate range here since Thumb2 has a variant
4841 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004842 if (((isThumb() && Mnemonic == "add") ||
4843 (isThumbTwo() && Mnemonic == "sub")) &&
4844 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004845 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4846 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4847 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004848 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004849 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004850 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004851 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004852 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4853 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004854 // selecting via the generic "add" mnemonic, so to know that we
4855 // should remove the cc_out operand, we have to explicitly check that
4856 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004857 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4858 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004859 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4860 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4861 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4862 // Nest conditions rather than one big 'if' statement for readability.
4863 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004864 // If both registers are low, we're in an IT block, and the immediate is
4865 // in range, we should use encoding T1 instead, which has a cc_out.
4866 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004867 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004868 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4869 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4870 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004871 // Check against T3. If the second register is the PC, this is an
4872 // alternate form of ADR, which uses encoding T4, so check for that too.
4873 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4874 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4875 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004876
4877 // Otherwise, we use encoding T4, which does not have a cc_out
4878 // operand.
4879 return true;
4880 }
4881
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004882 // The thumb2 multiply instruction doesn't have a CCOut register, so
4883 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4884 // use the 16-bit encoding or not.
4885 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4886 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4887 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4888 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4889 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4890 // If the registers aren't low regs, the destination reg isn't the
4891 // same as one of the source regs, or the cc_out operand is zero
4892 // outside of an IT block, we have to use the 32-bit encoding, so
4893 // remove the cc_out operand.
4894 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4895 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004896 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004897 !inITBlock() ||
4898 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4899 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4900 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4901 static_cast<ARMOperand*>(Operands[4])->getReg())))
4902 return true;
4903
Jim Grosbachefa7e952011-11-15 19:55:16 +00004904 // Also check the 'mul' syntax variant that doesn't specify an explicit
4905 // destination register.
4906 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4907 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4908 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4909 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4910 // If the registers aren't low regs or the cc_out operand is zero
4911 // outside of an IT block, we have to use the 32-bit encoding, so
4912 // remove the cc_out operand.
4913 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4914 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4915 !inITBlock()))
4916 return true;
4917
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004918
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004919
Jim Grosbach4b701af2011-08-24 21:42:27 +00004920 // Register-register 'add/sub' for thumb does not have a cc_out operand
4921 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4922 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4923 // right, this will result in better diagnostics (which operand is off)
4924 // anyway.
4925 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4926 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004927 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4928 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004929 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4930 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4931 (Operands.size() == 6 &&
4932 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004933 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004934
Jim Grosbach7283da92011-08-16 21:12:37 +00004935 return false;
4936}
4937
Joey Goulye8602552013-07-19 16:34:16 +00004938bool ARMAsmParser::shouldOmitPredicateOperand(
4939 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4940 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4941 unsigned RegIdx = 3;
4942 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4943 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4944 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4945 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4946 RegIdx = 4;
4947
4948 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4949 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4950 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4951 ARMMCRegisterClasses[ARM::QPRRegClassID]
4952 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4953 return true;
4954 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004955 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004956}
4957
Joey Gouly5d0564d2013-08-02 19:18:12 +00004958bool ARMAsmParser::isDeprecated(MCInst &Inst, StringRef &Info) {
4959 if (hasV8Ops() && Inst.getOpcode() == ARM::SETEND) {
4960 Info = "armv8";
4961 return true;
4962 }
Joey Goulyfcf67782013-08-02 20:50:01 +00004963 return false;
Joey Gouly5d0564d2013-08-02 19:18:12 +00004964}
4965
Jim Grosbach12952fe2011-11-11 23:08:10 +00004966static bool isDataTypeToken(StringRef Tok) {
4967 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4968 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4969 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4970 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4971 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4972 Tok == ".f" || Tok == ".d";
4973}
4974
4975// FIXME: This bit should probably be handled via an explicit match class
4976// in the .td files that matches the suffix instead of having it be
4977// a literal string token the way it is now.
4978static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4979 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4980}
Chad Rosier9f7a2212013-04-18 22:35:36 +00004981static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4982 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004983/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004984bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4985 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004986 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004987 // Apply mnemonic aliases before doing anything else, as the destination
4988 // mnemnonic may include suffices and we want to handle them normally.
4989 // The generic tblgen'erated code does this later, at the start of
4990 // MatchInstructionImpl(), but that's too late for aliases that include
4991 // any sort of suffix.
4992 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00004993 unsigned AssemblerDialect = getParser().getAssemblerDialect();
4994 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00004995
Jim Grosbachab5830e2011-12-14 02:16:11 +00004996 // First check for the ARM-specific .req directive.
4997 if (Parser.getTok().is(AsmToken::Identifier) &&
4998 Parser.getTok().getIdentifier() == ".req") {
4999 parseDirectiveReq(Name, NameLoc);
5000 // We always return 'error' for this, as we're done with this
5001 // statement and don't need to match the 'instruction."
5002 return true;
5003 }
5004
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005005 // Create the leading tokens for the mnemonic, split by '.' characters.
5006 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005007 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005008
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005009 // Split out the predication code and carry setting flag from the mnemonic.
5010 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005011 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005012 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005013 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005014 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005015 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005016
Jim Grosbach1c171b12011-08-25 17:23:55 +00005017 // In Thumb1, only the branch (B) instruction can be predicated.
5018 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005019 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005020 return Error(NameLoc, "conditional execution not supported in Thumb1");
5021 }
5022
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005023 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5024
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005025 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5026 // is the mask as it will be for the IT encoding if the conditional
5027 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5028 // where the conditional bit0 is zero, the instruction post-processing
5029 // will adjust the mask accordingly.
5030 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005031 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5032 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005033 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005034 return Error(Loc, "too many conditions on IT instruction");
5035 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005036 unsigned Mask = 8;
5037 for (unsigned i = ITMask.size(); i != 0; --i) {
5038 char pos = ITMask[i - 1];
5039 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005040 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005041 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005042 }
5043 Mask >>= 1;
5044 if (ITMask[i - 1] == 't')
5045 Mask |= 8;
5046 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005047 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005048 }
5049
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005050 // FIXME: This is all a pretty gross hack. We should automatically handle
5051 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005052
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005053 // Next, add the CCOut and ConditionCode operands, if needed.
5054 //
5055 // For mnemonics which can ever incorporate a carry setting bit or predication
5056 // code, our matching model involves us always generating CCOut and
5057 // ConditionCode operands to match the mnemonic "as written" and then we let
5058 // the matcher deal with finding the right instruction or generating an
5059 // appropriate error.
5060 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005061 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005062
Jim Grosbach03a8a162011-07-14 22:04:21 +00005063 // If we had a carry-set on an instruction that can't do that, issue an
5064 // error.
5065 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005066 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005067 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005068 "' can not set flags, but 's' suffix specified");
5069 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005070 // If we had a predication code on an instruction that can't do that, issue an
5071 // error.
5072 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005073 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005074 return Error(NameLoc, "instruction '" + Mnemonic +
5075 "' is not predicable, but condition code specified");
5076 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005077
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005078 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005079 if (CanAcceptCarrySet) {
5080 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005081 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005082 Loc));
5083 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005084
5085 // Add the predication code operand, if necessary.
5086 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005087 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5088 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005089 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005090 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005091 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005092
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005093 // Add the processor imod operand, if necessary.
5094 if (ProcessorIMod) {
5095 Operands.push_back(ARMOperand::CreateImm(
5096 MCConstantExpr::Create(ProcessorIMod, getContext()),
5097 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005098 }
5099
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005100 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005101 while (Next != StringRef::npos) {
5102 Start = Next;
5103 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005104 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005105
Jim Grosbach12952fe2011-11-11 23:08:10 +00005106 // Some NEON instructions have an optional datatype suffix that is
5107 // completely ignored. Check for that.
5108 if (isDataTypeToken(ExtraToken) &&
5109 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5110 continue;
5111
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005112 // For for ARM mode generate an error if the .n qualifier is used.
5113 if (ExtraToken == ".n" && !isThumb()) {
5114 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5115 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5116 "arm mode");
5117 }
5118
5119 // The .n qualifier is always discarded as that is what the tables
5120 // and matcher expect. In ARM mode the .w qualifier has no effect,
5121 // so discard it to avoid errors that can be caused by the matcher.
5122 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005123 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5124 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5125 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005126 }
5127
5128 // Read the remaining operands.
5129 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005130 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005131 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005132 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005133 return true;
5134 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005135
5136 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005137 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005138
5139 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005140 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005141 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005142 return true;
5143 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005144 }
5145 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005146
Chris Lattnera2a9d162010-09-11 16:18:25 +00005147 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005148 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005149 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005150 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005151 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005152
Chris Lattner91689c12010-09-08 05:10:46 +00005153 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005154
Jim Grosbach7283da92011-08-16 21:12:37 +00005155 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5156 // do and don't have a cc_out optional-def operand. With some spot-checks
5157 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005158 // parse and adjust accordingly before actually matching. We shouldn't ever
5159 // try to remove a cc_out operand that was explicitly set on the the
5160 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5161 // table driven matcher doesn't fit well with the ARM instruction set.
5162 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005163 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5164 Operands.erase(Operands.begin() + 1);
5165 delete Op;
5166 }
5167
Joey Goulye8602552013-07-19 16:34:16 +00005168 // Some instructions have the same mnemonic, but don't always
5169 // have a predicate. Distinguish them here and delete the
5170 // predicate if needed.
5171 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5172 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5173 Operands.erase(Operands.begin() + 1);
5174 delete Op;
5175 }
5176
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005177 // ARM mode 'blx' need special handling, as the register operand version
5178 // is predicable, but the label operand version is not. So, we can't rely
5179 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005180 // a k_CondCode operand in the list. If we're trying to match the label
5181 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005182 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5183 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5184 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5185 Operands.erase(Operands.begin() + 1);
5186 delete Op;
5187 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005188
Weiming Zhao8f56f882012-11-16 21:55:34 +00005189 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5190 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5191 // a single GPRPair reg operand is used in the .td file to replace the two
5192 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5193 // expressed as a GPRPair, so we have to manually merge them.
5194 // FIXME: We would really like to be able to tablegen'erate this.
5195 if (!isThumb() && Operands.size() > 4 &&
5196 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5197 bool isLoad = (Mnemonic == "ldrexd");
5198 unsigned Idx = isLoad ? 2 : 3;
5199 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5200 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5201
5202 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5203 // Adjust only if Op1 and Op2 are GPRs.
5204 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5205 MRC.contains(Op2->getReg())) {
5206 unsigned Reg1 = Op1->getReg();
5207 unsigned Reg2 = Op2->getReg();
5208 unsigned Rt = MRI->getEncodingValue(Reg1);
5209 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5210
5211 // Rt2 must be Rt + 1 and Rt must be even.
5212 if (Rt + 1 != Rt2 || (Rt & 1)) {
5213 Error(Op2->getStartLoc(), isLoad ?
5214 "destination operands must be sequential" :
5215 "source operands must be sequential");
5216 return true;
5217 }
5218 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5219 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5220 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5221 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5222 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5223 delete Op1;
5224 delete Op2;
5225 }
5226 }
5227
Kevin Enderby78f95722013-07-31 21:05:30 +00005228 // FIXME: As said above, this is all a pretty gross hack. This instruction
5229 // does not fit with other "subs" and tblgen.
5230 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5231 // so the Mnemonic is the original name "subs" and delete the predicate
5232 // operand so it will match the table entry.
5233 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5234 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5235 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5236 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5237 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5238 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5239 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5240 Operands.erase(Operands.begin());
5241 delete Op0;
5242 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5243
5244 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5245 Operands.erase(Operands.begin() + 1);
5246 delete Op1;
5247 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005248 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005249}
5250
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005251// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005252
5253// return 'true' if register list contains non-low GPR registers,
5254// 'false' otherwise. If Reg is in the register list or is HiReg, set
5255// 'containsReg' to true.
5256static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5257 unsigned HiReg, bool &containsReg) {
5258 containsReg = false;
5259 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5260 unsigned OpReg = Inst.getOperand(i).getReg();
5261 if (OpReg == Reg)
5262 containsReg = true;
5263 // Anything other than a low register isn't legal here.
5264 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5265 return true;
5266 }
5267 return false;
5268}
5269
Jim Grosbacha31f2232011-09-07 18:05:34 +00005270// Check if the specified regisgter is in the register list of the inst,
5271// starting at the indicated operand number.
5272static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5273 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5274 unsigned OpReg = Inst.getOperand(i).getReg();
5275 if (OpReg == Reg)
5276 return true;
5277 }
5278 return false;
5279}
5280
Jim Grosbached16ec42011-08-29 22:24:09 +00005281// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5282// the ARMInsts array) instead. Getting that here requires awkward
5283// API changes, though. Better way?
5284namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005285extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005286}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005287static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005288 return ARMInsts[Opcode];
5289}
5290
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005291// FIXME: We would really like to be able to tablegen'erate this.
5292bool ARMAsmParser::
5293validateInstruction(MCInst &Inst,
5294 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005295 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005296 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005297
Jim Grosbached16ec42011-08-29 22:24:09 +00005298 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005299 // NOTE: BKPT instruction has the interesting property of being
5300 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005301 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005302 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5303 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005304 unsigned bit = 1;
5305 if (ITState.FirstCond)
5306 ITState.FirstCond = false;
5307 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005308 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005309 // The instruction must be predicable.
5310 if (!MCID.isPredicable())
5311 return Error(Loc, "instructions in IT block must be predicable");
5312 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5313 unsigned ITCond = bit ? ITState.Cond :
5314 ARMCC::getOppositeCondition(ITState.Cond);
5315 if (Cond != ITCond) {
5316 // Find the condition code Operand to get its SMLoc information.
5317 SMLoc CondLoc;
5318 for (unsigned i = 1; i < Operands.size(); ++i)
5319 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5320 CondLoc = Operands[i]->getStartLoc();
5321 return Error(CondLoc, "incorrect condition in IT block; got '" +
5322 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5323 "', but expected '" +
5324 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5325 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005326 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005327 } else if (isThumbTwo() && MCID.isPredicable() &&
5328 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005329 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5330 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005331 return Error(Loc, "predicated instructions must be in IT block");
5332
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005333 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005334 case ARM::LDRD:
5335 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005336 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005337 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005338 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5339 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005340 if (Rt2 != Rt + 1)
5341 return Error(Operands[3]->getStartLoc(),
5342 "destination operands must be sequential");
5343 return false;
5344 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005345 case ARM::STRD: {
5346 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005347 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5348 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005349 if (Rt2 != Rt + 1)
5350 return Error(Operands[3]->getStartLoc(),
5351 "source operands must be sequential");
5352 return false;
5353 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005354 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005355 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005356 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005357 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5358 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005359 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005360 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005361 "source operands must be sequential");
5362 return false;
5363 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005364 case ARM::SBFX:
5365 case ARM::UBFX: {
5366 // width must be in range [1, 32-lsb]
5367 unsigned lsb = Inst.getOperand(2).getImm();
5368 unsigned widthm1 = Inst.getOperand(3).getImm();
5369 if (widthm1 >= 32 - lsb)
5370 return Error(Operands[5]->getStartLoc(),
5371 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005372 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005373 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005374 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005375 // If we're parsing Thumb2, the .w variant is available and handles
5376 // most cases that are normally illegal for a Thumb1 LDM
5377 // instruction. We'll make the transformation in processInstruction()
5378 // if necessary.
5379 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005380 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005381 // in the register list.
5382 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005383 bool hasWritebackToken =
5384 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5385 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005386 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005387 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005388 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5389 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005390 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005391 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005392 return Error(Operands[2]->getStartLoc(),
5393 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005394 // If we should not have writeback, there must not be a '!'. This is
5395 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005396 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005397 return Error(Operands[3]->getStartLoc(),
5398 "writeback operator '!' not allowed when base register "
5399 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005400
5401 break;
5402 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005403 case ARM::t2LDMIA_UPD: {
5404 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5405 return Error(Operands[4]->getStartLoc(),
5406 "writeback operator '!' not allowed when base register "
5407 "in register list");
5408 break;
5409 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005410 case ARM::tMUL: {
5411 // The second source operand must be the same register as the destination
5412 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005413 //
5414 // In this case, we must directly check the parsed operands because the
5415 // cvtThumbMultiply() function is written in such a way that it guarantees
5416 // this first statement is always true for the new Inst. Essentially, the
5417 // destination is unconditionally copied into the second source operand
5418 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005419 if (Operands.size() == 6 &&
5420 (((ARMOperand*)Operands[3])->getReg() !=
5421 ((ARMOperand*)Operands[5])->getReg()) &&
5422 (((ARMOperand*)Operands[3])->getReg() !=
5423 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005424 return Error(Operands[3]->getStartLoc(),
5425 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005426 }
5427 break;
5428 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005429 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5430 // so only issue a diagnostic for thumb1. The instructions will be
5431 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005432 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005433 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005434 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5435 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005436 return Error(Operands[2]->getStartLoc(),
5437 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005438 break;
5439 }
5440 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005441 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005442 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5443 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005444 return Error(Operands[2]->getStartLoc(),
5445 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005446 break;
5447 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005448 case ARM::tSTMIA_UPD: {
5449 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005450 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005451 return Error(Operands[4]->getStartLoc(),
5452 "registers must be in range r0-r7");
5453 break;
5454 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005455 case ARM::tADDrSP: {
5456 // If the non-SP source operand and the destination operand are not the
5457 // same, we need thumb2 (for the wide encoding), or we have an error.
5458 if (!isThumbTwo() &&
5459 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5460 return Error(Operands[4]->getStartLoc(),
5461 "source register must be the same as destination");
5462 }
5463 break;
5464 }
Mihai Popaad18d3c2013-08-09 10:38:32 +00005465 // final range checking for Thumb unconditional branch instructions
5466 case ARM::tB:
5467 if(!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5468 return Error(Operands[2]->getStartLoc(), "Branch target out of range");
5469 break;
5470 case ARM::t2B: {
5471 int op = (Operands[2]->isImm()) ? 2 : 3;
5472 if(!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5473 return Error(Operands[op]->getStartLoc(), "Branch target out of range");
5474 break;
5475 }
5476 // final range checking for Thumb conditional branch instructions
5477 case ARM::tBcc:
5478 if(!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5479 return Error(Operands[2]->getStartLoc(), "Branch target out of range");
5480 break;
5481 case ARM::t2Bcc: {
5482 int op = (Operands[2]->isImm()) ? 2 : 3;
5483 if(!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<20, 1>())
5484 return Error(Operands[op]->getStartLoc(), "Branch target out of range");
5485 break;
5486 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005487 }
5488
Joey Gouly5d0564d2013-08-02 19:18:12 +00005489 StringRef DepInfo;
5490 if (isDeprecated(Inst, DepInfo))
5491 Warning(Loc, "deprecated on " + DepInfo);
5492
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005493 return false;
5494}
5495
Jim Grosbach1a747242012-01-23 23:45:44 +00005496static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005497 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005498 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005499 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005500 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5501 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5502 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5503 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5504 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5505 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5506 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5507 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5508 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005509
5510 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005511 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5512 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5513 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5514 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5515 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005516
Jim Grosbach1e946a42012-01-24 00:43:12 +00005517 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5518 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5519 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5520 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5521 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005522
Jim Grosbach1e946a42012-01-24 00:43:12 +00005523 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5524 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5525 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5526 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5527 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005528
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005529 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005530 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5531 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5532 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5533 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5534 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5535 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5536 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5537 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5538 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5539 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5540 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5541 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5542 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5543 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5544 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005545
Jim Grosbach1a747242012-01-23 23:45:44 +00005546 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005547 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5548 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5549 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5550 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5551 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5552 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5553 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5554 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5555 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5556 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5557 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5558 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5559 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5560 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5561 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5562 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5563 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5564 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005565
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005566 // VST4LN
5567 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5568 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5569 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5570 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5571 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5572 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5573 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5574 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5575 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5576 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5577 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5578 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5579 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5580 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5581 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5582
Jim Grosbachda70eac2012-01-24 00:58:13 +00005583 // VST4
5584 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5585 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5586 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5587 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5588 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5589 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5590 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5591 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5592 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5593 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5594 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5595 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5596 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5597 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5598 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5599 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5600 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5601 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005602 }
5603}
5604
Jim Grosbach1a747242012-01-23 23:45:44 +00005605static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005606 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005607 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005608 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005609 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5610 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5611 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5612 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5613 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5614 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5615 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5616 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5617 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005618
5619 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005620 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5621 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5622 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5623 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5624 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5625 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5626 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5627 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5628 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5629 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5630 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5631 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5632 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5633 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5634 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005635
Jim Grosbachb78403c2012-01-24 23:47:04 +00005636 // VLD3DUP
5637 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5638 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5639 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5640 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5641 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5642 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5643 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5644 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5645 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5646 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5647 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5648 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5649 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5650 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5651 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5652 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5653 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5654 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5655
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005656 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005657 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5658 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5659 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5660 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5661 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5662 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5663 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5664 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5665 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5666 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5667 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5668 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5669 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5670 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5671 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005672
5673 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005674 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5675 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5676 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5677 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5678 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5679 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5680 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5681 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5682 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5683 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5684 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5685 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5686 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5687 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5688 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5689 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5690 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5691 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005692
Jim Grosbach14952a02012-01-24 18:37:25 +00005693 // VLD4LN
5694 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5695 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5696 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5697 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5698 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5699 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5700 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5701 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5702 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5703 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5704 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5705 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5706 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5707 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5708 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5709
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005710 // VLD4DUP
5711 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5712 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5713 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5714 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5715 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5716 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5717 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5718 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5719 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5720 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5721 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5722 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5723 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5724 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5725 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5726 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5727 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5728 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5729
Jim Grosbached561fc2012-01-24 00:43:17 +00005730 // VLD4
5731 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5732 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5733 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5734 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5735 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5736 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5737 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5738 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5739 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5740 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5741 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5742 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5743 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5744 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5745 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5746 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5747 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5748 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005749 }
5750}
5751
Jim Grosbachafad0532011-11-10 23:42:14 +00005752bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005753processInstruction(MCInst &Inst,
5754 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5755 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005756 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5757 case ARM::ADDri: {
5758 if (Inst.getOperand(1).getReg() != ARM::PC ||
5759 Inst.getOperand(5).getReg() != 0)
5760 return false;
5761 MCInst TmpInst;
5762 TmpInst.setOpcode(ARM::ADR);
5763 TmpInst.addOperand(Inst.getOperand(0));
5764 TmpInst.addOperand(Inst.getOperand(2));
5765 TmpInst.addOperand(Inst.getOperand(3));
5766 TmpInst.addOperand(Inst.getOperand(4));
5767 Inst = TmpInst;
5768 return true;
5769 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005770 // Aliases for alternate PC+imm syntax of LDR instructions.
5771 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005772 // Select the narrow version if the immediate will fit.
5773 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005774 Inst.getOperand(1).getImm() <= 0xff &&
5775 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5776 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005777 Inst.setOpcode(ARM::tLDRpci);
5778 else
5779 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005780 return true;
5781 case ARM::t2LDRBpcrel:
5782 Inst.setOpcode(ARM::t2LDRBpci);
5783 return true;
5784 case ARM::t2LDRHpcrel:
5785 Inst.setOpcode(ARM::t2LDRHpci);
5786 return true;
5787 case ARM::t2LDRSBpcrel:
5788 Inst.setOpcode(ARM::t2LDRSBpci);
5789 return true;
5790 case ARM::t2LDRSHpcrel:
5791 Inst.setOpcode(ARM::t2LDRSHpci);
5792 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005793 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005794 case ARM::VST1LNdWB_register_Asm_8:
5795 case ARM::VST1LNdWB_register_Asm_16:
5796 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005797 MCInst TmpInst;
5798 // Shuffle the operands around so the lane index operand is in the
5799 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005800 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005801 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005802 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5803 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5804 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5805 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5806 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5807 TmpInst.addOperand(Inst.getOperand(1)); // lane
5808 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5809 TmpInst.addOperand(Inst.getOperand(6));
5810 Inst = TmpInst;
5811 return true;
5812 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005813
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005814 case ARM::VST2LNdWB_register_Asm_8:
5815 case ARM::VST2LNdWB_register_Asm_16:
5816 case ARM::VST2LNdWB_register_Asm_32:
5817 case ARM::VST2LNqWB_register_Asm_16:
5818 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005819 MCInst TmpInst;
5820 // Shuffle the operands around so the lane index operand is in the
5821 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005822 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005823 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005824 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5825 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5826 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5827 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5828 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005829 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5830 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005831 TmpInst.addOperand(Inst.getOperand(1)); // lane
5832 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5833 TmpInst.addOperand(Inst.getOperand(6));
5834 Inst = TmpInst;
5835 return true;
5836 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005837
5838 case ARM::VST3LNdWB_register_Asm_8:
5839 case ARM::VST3LNdWB_register_Asm_16:
5840 case ARM::VST3LNdWB_register_Asm_32:
5841 case ARM::VST3LNqWB_register_Asm_16:
5842 case ARM::VST3LNqWB_register_Asm_32: {
5843 MCInst TmpInst;
5844 // Shuffle the operands around so the lane index operand is in the
5845 // right place.
5846 unsigned Spacing;
5847 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5848 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5849 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5850 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5851 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5852 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5853 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5854 Spacing));
5855 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5856 Spacing * 2));
5857 TmpInst.addOperand(Inst.getOperand(1)); // lane
5858 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5859 TmpInst.addOperand(Inst.getOperand(6));
5860 Inst = TmpInst;
5861 return true;
5862 }
5863
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005864 case ARM::VST4LNdWB_register_Asm_8:
5865 case ARM::VST4LNdWB_register_Asm_16:
5866 case ARM::VST4LNdWB_register_Asm_32:
5867 case ARM::VST4LNqWB_register_Asm_16:
5868 case ARM::VST4LNqWB_register_Asm_32: {
5869 MCInst TmpInst;
5870 // Shuffle the operands around so the lane index operand is in the
5871 // right place.
5872 unsigned Spacing;
5873 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5874 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5875 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5876 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5877 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5878 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5879 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5880 Spacing));
5881 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5882 Spacing * 2));
5883 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5884 Spacing * 3));
5885 TmpInst.addOperand(Inst.getOperand(1)); // lane
5886 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5887 TmpInst.addOperand(Inst.getOperand(6));
5888 Inst = TmpInst;
5889 return true;
5890 }
5891
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005892 case ARM::VST1LNdWB_fixed_Asm_8:
5893 case ARM::VST1LNdWB_fixed_Asm_16:
5894 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005895 MCInst TmpInst;
5896 // Shuffle the operands around so the lane index operand is in the
5897 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005898 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005899 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005900 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5901 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5902 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5903 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5904 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5905 TmpInst.addOperand(Inst.getOperand(1)); // lane
5906 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5907 TmpInst.addOperand(Inst.getOperand(5));
5908 Inst = TmpInst;
5909 return true;
5910 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005911
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005912 case ARM::VST2LNdWB_fixed_Asm_8:
5913 case ARM::VST2LNdWB_fixed_Asm_16:
5914 case ARM::VST2LNdWB_fixed_Asm_32:
5915 case ARM::VST2LNqWB_fixed_Asm_16:
5916 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005917 MCInst TmpInst;
5918 // Shuffle the operands around so the lane index operand is in the
5919 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005920 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005921 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005922 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5923 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5924 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5925 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5926 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005927 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5928 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005929 TmpInst.addOperand(Inst.getOperand(1)); // lane
5930 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5931 TmpInst.addOperand(Inst.getOperand(5));
5932 Inst = TmpInst;
5933 return true;
5934 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005935
5936 case ARM::VST3LNdWB_fixed_Asm_8:
5937 case ARM::VST3LNdWB_fixed_Asm_16:
5938 case ARM::VST3LNdWB_fixed_Asm_32:
5939 case ARM::VST3LNqWB_fixed_Asm_16:
5940 case ARM::VST3LNqWB_fixed_Asm_32: {
5941 MCInst TmpInst;
5942 // Shuffle the operands around so the lane index operand is in the
5943 // right place.
5944 unsigned Spacing;
5945 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5946 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5947 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5948 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5949 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5950 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5951 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5952 Spacing));
5953 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5954 Spacing * 2));
5955 TmpInst.addOperand(Inst.getOperand(1)); // lane
5956 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5957 TmpInst.addOperand(Inst.getOperand(5));
5958 Inst = TmpInst;
5959 return true;
5960 }
5961
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005962 case ARM::VST4LNdWB_fixed_Asm_8:
5963 case ARM::VST4LNdWB_fixed_Asm_16:
5964 case ARM::VST4LNdWB_fixed_Asm_32:
5965 case ARM::VST4LNqWB_fixed_Asm_16:
5966 case ARM::VST4LNqWB_fixed_Asm_32: {
5967 MCInst TmpInst;
5968 // Shuffle the operands around so the lane index operand is in the
5969 // right place.
5970 unsigned Spacing;
5971 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5972 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5973 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5974 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5975 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5976 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5977 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5978 Spacing));
5979 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5980 Spacing * 2));
5981 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5982 Spacing * 3));
5983 TmpInst.addOperand(Inst.getOperand(1)); // lane
5984 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5985 TmpInst.addOperand(Inst.getOperand(5));
5986 Inst = TmpInst;
5987 return true;
5988 }
5989
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005990 case ARM::VST1LNdAsm_8:
5991 case ARM::VST1LNdAsm_16:
5992 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005993 MCInst TmpInst;
5994 // Shuffle the operands around so the lane index operand is in the
5995 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005996 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005997 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005998 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5999 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6000 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6001 TmpInst.addOperand(Inst.getOperand(1)); // lane
6002 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6003 TmpInst.addOperand(Inst.getOperand(5));
6004 Inst = TmpInst;
6005 return true;
6006 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006007
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006008 case ARM::VST2LNdAsm_8:
6009 case ARM::VST2LNdAsm_16:
6010 case ARM::VST2LNdAsm_32:
6011 case ARM::VST2LNqAsm_16:
6012 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006013 MCInst TmpInst;
6014 // Shuffle the operands around so the lane index operand is in the
6015 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006016 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006017 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006018 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6019 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6020 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006021 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6022 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006023 TmpInst.addOperand(Inst.getOperand(1)); // lane
6024 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6025 TmpInst.addOperand(Inst.getOperand(5));
6026 Inst = TmpInst;
6027 return true;
6028 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006029
6030 case ARM::VST3LNdAsm_8:
6031 case ARM::VST3LNdAsm_16:
6032 case ARM::VST3LNdAsm_32:
6033 case ARM::VST3LNqAsm_16:
6034 case ARM::VST3LNqAsm_32: {
6035 MCInst TmpInst;
6036 // Shuffle the operands around so the lane index operand is in the
6037 // right place.
6038 unsigned Spacing;
6039 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6040 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6041 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6042 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6043 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6044 Spacing));
6045 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6046 Spacing * 2));
6047 TmpInst.addOperand(Inst.getOperand(1)); // lane
6048 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6049 TmpInst.addOperand(Inst.getOperand(5));
6050 Inst = TmpInst;
6051 return true;
6052 }
6053
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006054 case ARM::VST4LNdAsm_8:
6055 case ARM::VST4LNdAsm_16:
6056 case ARM::VST4LNdAsm_32:
6057 case ARM::VST4LNqAsm_16:
6058 case ARM::VST4LNqAsm_32: {
6059 MCInst TmpInst;
6060 // Shuffle the operands around so the lane index operand is in the
6061 // right place.
6062 unsigned Spacing;
6063 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6064 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6065 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6066 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6067 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6068 Spacing));
6069 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6070 Spacing * 2));
6071 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6072 Spacing * 3));
6073 TmpInst.addOperand(Inst.getOperand(1)); // lane
6074 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6075 TmpInst.addOperand(Inst.getOperand(5));
6076 Inst = TmpInst;
6077 return true;
6078 }
6079
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006080 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006081 case ARM::VLD1LNdWB_register_Asm_8:
6082 case ARM::VLD1LNdWB_register_Asm_16:
6083 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006084 MCInst TmpInst;
6085 // Shuffle the operands around so the lane index operand is in the
6086 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006087 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006088 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006089 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6090 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6091 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6092 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6093 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6094 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6095 TmpInst.addOperand(Inst.getOperand(1)); // lane
6096 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6097 TmpInst.addOperand(Inst.getOperand(6));
6098 Inst = TmpInst;
6099 return true;
6100 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006101
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006102 case ARM::VLD2LNdWB_register_Asm_8:
6103 case ARM::VLD2LNdWB_register_Asm_16:
6104 case ARM::VLD2LNdWB_register_Asm_32:
6105 case ARM::VLD2LNqWB_register_Asm_16:
6106 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006107 MCInst TmpInst;
6108 // Shuffle the operands around so the lane index operand is in the
6109 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006110 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006111 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006112 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006113 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6114 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006115 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6116 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6117 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6118 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6119 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006120 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6121 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006122 TmpInst.addOperand(Inst.getOperand(1)); // lane
6123 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6124 TmpInst.addOperand(Inst.getOperand(6));
6125 Inst = TmpInst;
6126 return true;
6127 }
6128
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006129 case ARM::VLD3LNdWB_register_Asm_8:
6130 case ARM::VLD3LNdWB_register_Asm_16:
6131 case ARM::VLD3LNdWB_register_Asm_32:
6132 case ARM::VLD3LNqWB_register_Asm_16:
6133 case ARM::VLD3LNqWB_register_Asm_32: {
6134 MCInst TmpInst;
6135 // Shuffle the operands around so the lane index operand is in the
6136 // right place.
6137 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006138 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006139 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6140 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6141 Spacing));
6142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006143 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006144 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6145 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6146 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6147 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6148 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6149 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6150 Spacing));
6151 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006152 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006153 TmpInst.addOperand(Inst.getOperand(1)); // lane
6154 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6155 TmpInst.addOperand(Inst.getOperand(6));
6156 Inst = TmpInst;
6157 return true;
6158 }
6159
Jim Grosbach14952a02012-01-24 18:37:25 +00006160 case ARM::VLD4LNdWB_register_Asm_8:
6161 case ARM::VLD4LNdWB_register_Asm_16:
6162 case ARM::VLD4LNdWB_register_Asm_32:
6163 case ARM::VLD4LNqWB_register_Asm_16:
6164 case ARM::VLD4LNqWB_register_Asm_32: {
6165 MCInst TmpInst;
6166 // Shuffle the operands around so the lane index operand is in the
6167 // right place.
6168 unsigned Spacing;
6169 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6170 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6171 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6172 Spacing));
6173 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6174 Spacing * 2));
6175 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6176 Spacing * 3));
6177 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6178 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6179 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6180 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6181 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6182 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6183 Spacing));
6184 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6185 Spacing * 2));
6186 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6187 Spacing * 3));
6188 TmpInst.addOperand(Inst.getOperand(1)); // lane
6189 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6190 TmpInst.addOperand(Inst.getOperand(6));
6191 Inst = TmpInst;
6192 return true;
6193 }
6194
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006195 case ARM::VLD1LNdWB_fixed_Asm_8:
6196 case ARM::VLD1LNdWB_fixed_Asm_16:
6197 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006198 MCInst TmpInst;
6199 // Shuffle the operands around so the lane index operand is in the
6200 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006201 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006202 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006203 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6204 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6205 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6206 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6207 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6208 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6209 TmpInst.addOperand(Inst.getOperand(1)); // lane
6210 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6211 TmpInst.addOperand(Inst.getOperand(5));
6212 Inst = TmpInst;
6213 return true;
6214 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006215
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006216 case ARM::VLD2LNdWB_fixed_Asm_8:
6217 case ARM::VLD2LNdWB_fixed_Asm_16:
6218 case ARM::VLD2LNdWB_fixed_Asm_32:
6219 case ARM::VLD2LNqWB_fixed_Asm_16:
6220 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006221 MCInst TmpInst;
6222 // Shuffle the operands around so the lane index operand is in the
6223 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006224 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006225 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006226 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006227 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6228 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006229 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6230 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6231 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6232 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6233 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006234 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6235 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006236 TmpInst.addOperand(Inst.getOperand(1)); // lane
6237 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6238 TmpInst.addOperand(Inst.getOperand(5));
6239 Inst = TmpInst;
6240 return true;
6241 }
6242
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006243 case ARM::VLD3LNdWB_fixed_Asm_8:
6244 case ARM::VLD3LNdWB_fixed_Asm_16:
6245 case ARM::VLD3LNdWB_fixed_Asm_32:
6246 case ARM::VLD3LNqWB_fixed_Asm_16:
6247 case ARM::VLD3LNqWB_fixed_Asm_32: {
6248 MCInst TmpInst;
6249 // Shuffle the operands around so the lane index operand is in the
6250 // right place.
6251 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006252 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006253 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6254 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6255 Spacing));
6256 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006257 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006258 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6259 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6260 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6261 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6262 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== 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(1)); // lane
6268 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6269 TmpInst.addOperand(Inst.getOperand(5));
6270 Inst = TmpInst;
6271 return true;
6272 }
6273
Jim Grosbach14952a02012-01-24 18:37:25 +00006274 case ARM::VLD4LNdWB_fixed_Asm_8:
6275 case ARM::VLD4LNdWB_fixed_Asm_16:
6276 case ARM::VLD4LNdWB_fixed_Asm_32:
6277 case ARM::VLD4LNqWB_fixed_Asm_16:
6278 case ARM::VLD4LNqWB_fixed_Asm_32: {
6279 MCInst TmpInst;
6280 // Shuffle the operands around so the lane index operand is in the
6281 // right place.
6282 unsigned Spacing;
6283 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6284 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6285 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6286 Spacing));
6287 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6288 Spacing * 2));
6289 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6290 Spacing * 3));
6291 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6292 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6293 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6294 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6295 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6297 Spacing));
6298 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6299 Spacing * 2));
6300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6301 Spacing * 3));
6302 TmpInst.addOperand(Inst.getOperand(1)); // lane
6303 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6304 TmpInst.addOperand(Inst.getOperand(5));
6305 Inst = TmpInst;
6306 return true;
6307 }
6308
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006309 case ARM::VLD1LNdAsm_8:
6310 case ARM::VLD1LNdAsm_16:
6311 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006312 MCInst TmpInst;
6313 // Shuffle the operands around so the lane index operand is in the
6314 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006315 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006316 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006317 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6318 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6319 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6320 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6321 TmpInst.addOperand(Inst.getOperand(1)); // lane
6322 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6323 TmpInst.addOperand(Inst.getOperand(5));
6324 Inst = TmpInst;
6325 return true;
6326 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006327
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006328 case ARM::VLD2LNdAsm_8:
6329 case ARM::VLD2LNdAsm_16:
6330 case ARM::VLD2LNdAsm_32:
6331 case ARM::VLD2LNqAsm_16:
6332 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006333 MCInst TmpInst;
6334 // Shuffle the operands around so the lane index operand is in the
6335 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006336 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006337 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006338 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006339 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6340 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006341 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6342 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6343 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006344 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6345 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006346 TmpInst.addOperand(Inst.getOperand(1)); // lane
6347 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6348 TmpInst.addOperand(Inst.getOperand(5));
6349 Inst = TmpInst;
6350 return true;
6351 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006352
6353 case ARM::VLD3LNdAsm_8:
6354 case ARM::VLD3LNdAsm_16:
6355 case ARM::VLD3LNdAsm_32:
6356 case ARM::VLD3LNqAsm_16:
6357 case ARM::VLD3LNqAsm_32: {
6358 MCInst TmpInst;
6359 // Shuffle the operands around so the lane index operand is in the
6360 // right place.
6361 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006362 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006363 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6365 Spacing));
6366 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006367 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006368 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6369 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6370 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6371 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6372 Spacing));
6373 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006374 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006375 TmpInst.addOperand(Inst.getOperand(1)); // lane
6376 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6377 TmpInst.addOperand(Inst.getOperand(5));
6378 Inst = TmpInst;
6379 return true;
6380 }
6381
Jim Grosbach14952a02012-01-24 18:37:25 +00006382 case ARM::VLD4LNdAsm_8:
6383 case ARM::VLD4LNdAsm_16:
6384 case ARM::VLD4LNdAsm_32:
6385 case ARM::VLD4LNqAsm_16:
6386 case ARM::VLD4LNqAsm_32: {
6387 MCInst TmpInst;
6388 // Shuffle the operands around so the lane index operand is in the
6389 // right place.
6390 unsigned Spacing;
6391 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6392 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6393 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6394 Spacing));
6395 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6396 Spacing * 2));
6397 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6398 Spacing * 3));
6399 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6400 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6401 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6403 Spacing));
6404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6405 Spacing * 2));
6406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6407 Spacing * 3));
6408 TmpInst.addOperand(Inst.getOperand(1)); // lane
6409 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6410 TmpInst.addOperand(Inst.getOperand(5));
6411 Inst = TmpInst;
6412 return true;
6413 }
6414
Jim Grosbachb78403c2012-01-24 23:47:04 +00006415 // VLD3DUP single 3-element structure to all lanes instructions.
6416 case ARM::VLD3DUPdAsm_8:
6417 case ARM::VLD3DUPdAsm_16:
6418 case ARM::VLD3DUPdAsm_32:
6419 case ARM::VLD3DUPqAsm_8:
6420 case ARM::VLD3DUPqAsm_16:
6421 case ARM::VLD3DUPqAsm_32: {
6422 MCInst TmpInst;
6423 unsigned Spacing;
6424 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6425 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6426 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6427 Spacing));
6428 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6429 Spacing * 2));
6430 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6431 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6432 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6433 TmpInst.addOperand(Inst.getOperand(4));
6434 Inst = TmpInst;
6435 return true;
6436 }
6437
6438 case ARM::VLD3DUPdWB_fixed_Asm_8:
6439 case ARM::VLD3DUPdWB_fixed_Asm_16:
6440 case ARM::VLD3DUPdWB_fixed_Asm_32:
6441 case ARM::VLD3DUPqWB_fixed_Asm_8:
6442 case ARM::VLD3DUPqWB_fixed_Asm_16:
6443 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6444 MCInst TmpInst;
6445 unsigned Spacing;
6446 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6447 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6448 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6449 Spacing));
6450 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6451 Spacing * 2));
6452 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6453 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6454 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6455 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6456 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6457 TmpInst.addOperand(Inst.getOperand(4));
6458 Inst = TmpInst;
6459 return true;
6460 }
6461
6462 case ARM::VLD3DUPdWB_register_Asm_8:
6463 case ARM::VLD3DUPdWB_register_Asm_16:
6464 case ARM::VLD3DUPdWB_register_Asm_32:
6465 case ARM::VLD3DUPqWB_register_Asm_8:
6466 case ARM::VLD3DUPqWB_register_Asm_16:
6467 case ARM::VLD3DUPqWB_register_Asm_32: {
6468 MCInst TmpInst;
6469 unsigned Spacing;
6470 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6471 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6472 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6473 Spacing));
6474 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6475 Spacing * 2));
6476 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6477 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6478 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6479 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6480 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6481 TmpInst.addOperand(Inst.getOperand(5));
6482 Inst = TmpInst;
6483 return true;
6484 }
6485
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006486 // VLD3 multiple 3-element structure instructions.
6487 case ARM::VLD3dAsm_8:
6488 case ARM::VLD3dAsm_16:
6489 case ARM::VLD3dAsm_32:
6490 case ARM::VLD3qAsm_8:
6491 case ARM::VLD3qAsm_16:
6492 case ARM::VLD3qAsm_32: {
6493 MCInst TmpInst;
6494 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006495 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006496 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6497 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6498 Spacing));
6499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6500 Spacing * 2));
6501 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6502 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6503 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6504 TmpInst.addOperand(Inst.getOperand(4));
6505 Inst = TmpInst;
6506 return true;
6507 }
6508
6509 case ARM::VLD3dWB_fixed_Asm_8:
6510 case ARM::VLD3dWB_fixed_Asm_16:
6511 case ARM::VLD3dWB_fixed_Asm_32:
6512 case ARM::VLD3qWB_fixed_Asm_8:
6513 case ARM::VLD3qWB_fixed_Asm_16:
6514 case ARM::VLD3qWB_fixed_Asm_32: {
6515 MCInst TmpInst;
6516 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006517 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006518 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6519 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6520 Spacing));
6521 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6522 Spacing * 2));
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(MCOperand::CreateReg(0)); // Rm
6527 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6528 TmpInst.addOperand(Inst.getOperand(4));
6529 Inst = TmpInst;
6530 return true;
6531 }
6532
6533 case ARM::VLD3dWB_register_Asm_8:
6534 case ARM::VLD3dWB_register_Asm_16:
6535 case ARM::VLD3dWB_register_Asm_32:
6536 case ARM::VLD3qWB_register_Asm_8:
6537 case ARM::VLD3qWB_register_Asm_16:
6538 case ARM::VLD3qWB_register_Asm_32: {
6539 MCInst TmpInst;
6540 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006541 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006542 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6543 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6544 Spacing));
6545 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6546 Spacing * 2));
6547 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6548 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6549 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6550 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6551 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6552 TmpInst.addOperand(Inst.getOperand(5));
6553 Inst = TmpInst;
6554 return true;
6555 }
6556
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006557 // VLD4DUP single 3-element structure to all lanes instructions.
6558 case ARM::VLD4DUPdAsm_8:
6559 case ARM::VLD4DUPdAsm_16:
6560 case ARM::VLD4DUPdAsm_32:
6561 case ARM::VLD4DUPqAsm_8:
6562 case ARM::VLD4DUPqAsm_16:
6563 case ARM::VLD4DUPqAsm_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(2)); // alignment
6576 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6577 TmpInst.addOperand(Inst.getOperand(4));
6578 Inst = TmpInst;
6579 return true;
6580 }
6581
6582 case ARM::VLD4DUPdWB_fixed_Asm_8:
6583 case ARM::VLD4DUPdWB_fixed_Asm_16:
6584 case ARM::VLD4DUPdWB_fixed_Asm_32:
6585 case ARM::VLD4DUPqWB_fixed_Asm_8:
6586 case ARM::VLD4DUPqWB_fixed_Asm_16:
6587 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6588 MCInst TmpInst;
6589 unsigned Spacing;
6590 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6591 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6592 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6593 Spacing));
6594 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6595 Spacing * 2));
6596 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6597 Spacing * 3));
6598 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6599 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6600 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6601 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6602 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6603 TmpInst.addOperand(Inst.getOperand(4));
6604 Inst = TmpInst;
6605 return true;
6606 }
6607
6608 case ARM::VLD4DUPdWB_register_Asm_8:
6609 case ARM::VLD4DUPdWB_register_Asm_16:
6610 case ARM::VLD4DUPdWB_register_Asm_32:
6611 case ARM::VLD4DUPqWB_register_Asm_8:
6612 case ARM::VLD4DUPqWB_register_Asm_16:
6613 case ARM::VLD4DUPqWB_register_Asm_32: {
6614 MCInst TmpInst;
6615 unsigned Spacing;
6616 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6617 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6618 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6619 Spacing));
6620 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6621 Spacing * 2));
6622 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6623 Spacing * 3));
6624 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6625 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6626 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6627 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6628 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6629 TmpInst.addOperand(Inst.getOperand(5));
6630 Inst = TmpInst;
6631 return true;
6632 }
6633
6634 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006635 case ARM::VLD4dAsm_8:
6636 case ARM::VLD4dAsm_16:
6637 case ARM::VLD4dAsm_32:
6638 case ARM::VLD4qAsm_8:
6639 case ARM::VLD4qAsm_16:
6640 case ARM::VLD4qAsm_32: {
6641 MCInst TmpInst;
6642 unsigned Spacing;
6643 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6644 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6645 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6646 Spacing));
6647 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6648 Spacing * 2));
6649 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6650 Spacing * 3));
6651 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6652 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6653 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6654 TmpInst.addOperand(Inst.getOperand(4));
6655 Inst = TmpInst;
6656 return true;
6657 }
6658
6659 case ARM::VLD4dWB_fixed_Asm_8:
6660 case ARM::VLD4dWB_fixed_Asm_16:
6661 case ARM::VLD4dWB_fixed_Asm_32:
6662 case ARM::VLD4qWB_fixed_Asm_8:
6663 case ARM::VLD4qWB_fixed_Asm_16:
6664 case ARM::VLD4qWB_fixed_Asm_32: {
6665 MCInst TmpInst;
6666 unsigned Spacing;
6667 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6668 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6669 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6670 Spacing));
6671 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6672 Spacing * 2));
6673 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6674 Spacing * 3));
6675 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6676 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6677 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6678 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6679 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6680 TmpInst.addOperand(Inst.getOperand(4));
6681 Inst = TmpInst;
6682 return true;
6683 }
6684
6685 case ARM::VLD4dWB_register_Asm_8:
6686 case ARM::VLD4dWB_register_Asm_16:
6687 case ARM::VLD4dWB_register_Asm_32:
6688 case ARM::VLD4qWB_register_Asm_8:
6689 case ARM::VLD4qWB_register_Asm_16:
6690 case ARM::VLD4qWB_register_Asm_32: {
6691 MCInst TmpInst;
6692 unsigned Spacing;
6693 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6694 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6695 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6696 Spacing));
6697 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6698 Spacing * 2));
6699 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6700 Spacing * 3));
6701 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6702 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6703 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6704 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6705 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6706 TmpInst.addOperand(Inst.getOperand(5));
6707 Inst = TmpInst;
6708 return true;
6709 }
6710
Jim Grosbach1a747242012-01-23 23:45:44 +00006711 // VST3 multiple 3-element structure instructions.
6712 case ARM::VST3dAsm_8:
6713 case ARM::VST3dAsm_16:
6714 case ARM::VST3dAsm_32:
6715 case ARM::VST3qAsm_8:
6716 case ARM::VST3qAsm_16:
6717 case ARM::VST3qAsm_32: {
6718 MCInst TmpInst;
6719 unsigned Spacing;
6720 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6721 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6722 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6723 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6724 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6725 Spacing));
6726 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6727 Spacing * 2));
6728 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6729 TmpInst.addOperand(Inst.getOperand(4));
6730 Inst = TmpInst;
6731 return true;
6732 }
6733
6734 case ARM::VST3dWB_fixed_Asm_8:
6735 case ARM::VST3dWB_fixed_Asm_16:
6736 case ARM::VST3dWB_fixed_Asm_32:
6737 case ARM::VST3qWB_fixed_Asm_8:
6738 case ARM::VST3qWB_fixed_Asm_16:
6739 case ARM::VST3qWB_fixed_Asm_32: {
6740 MCInst TmpInst;
6741 unsigned Spacing;
6742 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6743 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6744 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6745 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6746 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6747 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6748 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6749 Spacing));
6750 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6751 Spacing * 2));
6752 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6753 TmpInst.addOperand(Inst.getOperand(4));
6754 Inst = TmpInst;
6755 return true;
6756 }
6757
6758 case ARM::VST3dWB_register_Asm_8:
6759 case ARM::VST3dWB_register_Asm_16:
6760 case ARM::VST3dWB_register_Asm_32:
6761 case ARM::VST3qWB_register_Asm_8:
6762 case ARM::VST3qWB_register_Asm_16:
6763 case ARM::VST3qWB_register_Asm_32: {
6764 MCInst TmpInst;
6765 unsigned Spacing;
6766 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6767 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6768 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6769 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6770 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6771 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6772 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6773 Spacing));
6774 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6775 Spacing * 2));
6776 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6777 TmpInst.addOperand(Inst.getOperand(5));
6778 Inst = TmpInst;
6779 return true;
6780 }
6781
Jim Grosbachda70eac2012-01-24 00:58:13 +00006782 // VST4 multiple 3-element structure instructions.
6783 case ARM::VST4dAsm_8:
6784 case ARM::VST4dAsm_16:
6785 case ARM::VST4dAsm_32:
6786 case ARM::VST4qAsm_8:
6787 case ARM::VST4qAsm_16:
6788 case ARM::VST4qAsm_32: {
6789 MCInst TmpInst;
6790 unsigned Spacing;
6791 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6792 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6793 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6794 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6795 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6796 Spacing));
6797 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6798 Spacing * 2));
6799 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6800 Spacing * 3));
6801 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6802 TmpInst.addOperand(Inst.getOperand(4));
6803 Inst = TmpInst;
6804 return true;
6805 }
6806
6807 case ARM::VST4dWB_fixed_Asm_8:
6808 case ARM::VST4dWB_fixed_Asm_16:
6809 case ARM::VST4dWB_fixed_Asm_32:
6810 case ARM::VST4qWB_fixed_Asm_8:
6811 case ARM::VST4qWB_fixed_Asm_16:
6812 case ARM::VST4qWB_fixed_Asm_32: {
6813 MCInst TmpInst;
6814 unsigned Spacing;
6815 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6816 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6817 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6818 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6819 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6820 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6821 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6822 Spacing));
6823 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6824 Spacing * 2));
6825 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6826 Spacing * 3));
6827 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6828 TmpInst.addOperand(Inst.getOperand(4));
6829 Inst = TmpInst;
6830 return true;
6831 }
6832
6833 case ARM::VST4dWB_register_Asm_8:
6834 case ARM::VST4dWB_register_Asm_16:
6835 case ARM::VST4dWB_register_Asm_32:
6836 case ARM::VST4qWB_register_Asm_8:
6837 case ARM::VST4qWB_register_Asm_16:
6838 case ARM::VST4qWB_register_Asm_32: {
6839 MCInst TmpInst;
6840 unsigned Spacing;
6841 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6842 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6843 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6844 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6845 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6846 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6847 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6848 Spacing));
6849 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6850 Spacing * 2));
6851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6852 Spacing * 3));
6853 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6854 TmpInst.addOperand(Inst.getOperand(5));
6855 Inst = TmpInst;
6856 return true;
6857 }
6858
Jim Grosbachad66de12012-04-11 00:15:16 +00006859 // Handle encoding choice for the shift-immediate instructions.
6860 case ARM::t2LSLri:
6861 case ARM::t2LSRri:
6862 case ARM::t2ASRri: {
6863 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6864 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6865 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6866 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6867 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6868 unsigned NewOpc;
6869 switch (Inst.getOpcode()) {
6870 default: llvm_unreachable("unexpected opcode");
6871 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6872 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6873 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6874 }
6875 // The Thumb1 operands aren't in the same order. Awesome, eh?
6876 MCInst TmpInst;
6877 TmpInst.setOpcode(NewOpc);
6878 TmpInst.addOperand(Inst.getOperand(0));
6879 TmpInst.addOperand(Inst.getOperand(5));
6880 TmpInst.addOperand(Inst.getOperand(1));
6881 TmpInst.addOperand(Inst.getOperand(2));
6882 TmpInst.addOperand(Inst.getOperand(3));
6883 TmpInst.addOperand(Inst.getOperand(4));
6884 Inst = TmpInst;
6885 return true;
6886 }
6887 return false;
6888 }
6889
Jim Grosbach485e5622011-12-13 22:45:11 +00006890 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006891 case ARM::t2MOVsr:
6892 case ARM::t2MOVSsr: {
6893 // Which instruction to expand to depends on the CCOut operand and
6894 // whether we're in an IT block if the register operands are low
6895 // registers.
6896 bool isNarrow = false;
6897 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6898 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6899 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6900 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6901 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6902 isNarrow = true;
6903 MCInst TmpInst;
6904 unsigned newOpc;
6905 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6906 default: llvm_unreachable("unexpected opcode!");
6907 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6908 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6909 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6910 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6911 }
6912 TmpInst.setOpcode(newOpc);
6913 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6914 if (isNarrow)
6915 TmpInst.addOperand(MCOperand::CreateReg(
6916 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6917 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6918 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6919 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6920 TmpInst.addOperand(Inst.getOperand(5));
6921 if (!isNarrow)
6922 TmpInst.addOperand(MCOperand::CreateReg(
6923 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6924 Inst = TmpInst;
6925 return true;
6926 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006927 case ARM::t2MOVsi:
6928 case ARM::t2MOVSsi: {
6929 // Which instruction to expand to depends on the CCOut operand and
6930 // whether we're in an IT block if the register operands are low
6931 // registers.
6932 bool isNarrow = false;
6933 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6934 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6935 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6936 isNarrow = true;
6937 MCInst TmpInst;
6938 unsigned newOpc;
6939 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6940 default: llvm_unreachable("unexpected opcode!");
6941 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6942 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6943 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6944 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006945 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006946 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006947 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6948 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006949 TmpInst.setOpcode(newOpc);
6950 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6951 if (isNarrow)
6952 TmpInst.addOperand(MCOperand::CreateReg(
6953 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6954 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006955 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006956 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006957 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6958 TmpInst.addOperand(Inst.getOperand(4));
6959 if (!isNarrow)
6960 TmpInst.addOperand(MCOperand::CreateReg(
6961 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6962 Inst = TmpInst;
6963 return true;
6964 }
6965 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006966 case ARM::ASRr:
6967 case ARM::LSRr:
6968 case ARM::LSLr:
6969 case ARM::RORr: {
6970 ARM_AM::ShiftOpc ShiftTy;
6971 switch(Inst.getOpcode()) {
6972 default: llvm_unreachable("unexpected opcode!");
6973 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6974 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6975 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6976 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6977 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006978 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6979 MCInst TmpInst;
6980 TmpInst.setOpcode(ARM::MOVsr);
6981 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6982 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6983 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6984 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6985 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6986 TmpInst.addOperand(Inst.getOperand(4));
6987 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6988 Inst = TmpInst;
6989 return true;
6990 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00006991 case ARM::ASRi:
6992 case ARM::LSRi:
6993 case ARM::LSLi:
6994 case ARM::RORi: {
6995 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006996 switch(Inst.getOpcode()) {
6997 default: llvm_unreachable("unexpected opcode!");
6998 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6999 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7000 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7001 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7002 }
7003 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007004 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007005 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007006 // A shift by 32 should be encoded as 0 when permitted
7007 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7008 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007009 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007010 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007011 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007012 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7013 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007014 if (Opc == ARM::MOVsi)
7015 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007016 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7017 TmpInst.addOperand(Inst.getOperand(4));
7018 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7019 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007020 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007021 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007022 case ARM::RRXi: {
7023 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7024 MCInst TmpInst;
7025 TmpInst.setOpcode(ARM::MOVsi);
7026 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7027 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7028 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7029 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7030 TmpInst.addOperand(Inst.getOperand(3));
7031 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7032 Inst = TmpInst;
7033 return true;
7034 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007035 case ARM::t2LDMIA_UPD: {
7036 // If this is a load of a single register, then we should use
7037 // a post-indexed LDR instruction instead, per the ARM ARM.
7038 if (Inst.getNumOperands() != 5)
7039 return false;
7040 MCInst TmpInst;
7041 TmpInst.setOpcode(ARM::t2LDR_POST);
7042 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7043 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7044 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7045 TmpInst.addOperand(MCOperand::CreateImm(4));
7046 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7047 TmpInst.addOperand(Inst.getOperand(3));
7048 Inst = TmpInst;
7049 return true;
7050 }
7051 case ARM::t2STMDB_UPD: {
7052 // If this is a store of a single register, then we should use
7053 // a pre-indexed STR instruction instead, per the ARM ARM.
7054 if (Inst.getNumOperands() != 5)
7055 return false;
7056 MCInst TmpInst;
7057 TmpInst.setOpcode(ARM::t2STR_PRE);
7058 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7059 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7060 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7061 TmpInst.addOperand(MCOperand::CreateImm(-4));
7062 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7063 TmpInst.addOperand(Inst.getOperand(3));
7064 Inst = TmpInst;
7065 return true;
7066 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007067 case ARM::LDMIA_UPD:
7068 // If this is a load of a single register via a 'pop', then we should use
7069 // a post-indexed LDR instruction instead, per the ARM ARM.
7070 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7071 Inst.getNumOperands() == 5) {
7072 MCInst TmpInst;
7073 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7074 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7075 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7076 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7077 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7078 TmpInst.addOperand(MCOperand::CreateImm(4));
7079 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7080 TmpInst.addOperand(Inst.getOperand(3));
7081 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007082 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007083 }
7084 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007085 case ARM::STMDB_UPD:
7086 // If this is a store of a single register via a 'push', then we should use
7087 // a pre-indexed STR instruction instead, per the ARM ARM.
7088 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7089 Inst.getNumOperands() == 5) {
7090 MCInst TmpInst;
7091 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7092 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7093 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7094 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7095 TmpInst.addOperand(MCOperand::CreateImm(-4));
7096 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7097 TmpInst.addOperand(Inst.getOperand(3));
7098 Inst = TmpInst;
7099 }
7100 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007101 case ARM::t2ADDri12:
7102 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7103 // mnemonic was used (not "addw"), encoding T3 is preferred.
7104 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7105 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7106 break;
7107 Inst.setOpcode(ARM::t2ADDri);
7108 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7109 break;
7110 case ARM::t2SUBri12:
7111 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7112 // mnemonic was used (not "subw"), encoding T3 is preferred.
7113 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7114 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7115 break;
7116 Inst.setOpcode(ARM::t2SUBri);
7117 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7118 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007119 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007120 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007121 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7122 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7123 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007124 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007125 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007126 return true;
7127 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007128 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007129 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007130 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007131 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7132 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7133 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007134 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007135 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007136 return true;
7137 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007138 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007139 case ARM::t2ADDri:
7140 case ARM::t2SUBri: {
7141 // If the destination and first source operand are the same, and
7142 // the flags are compatible with the current IT status, use encoding T2
7143 // instead of T3. For compatibility with the system 'as'. Make sure the
7144 // wide encoding wasn't explicit.
7145 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007146 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007147 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7148 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7149 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7150 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7151 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7152 break;
7153 MCInst TmpInst;
7154 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7155 ARM::tADDi8 : ARM::tSUBi8);
7156 TmpInst.addOperand(Inst.getOperand(0));
7157 TmpInst.addOperand(Inst.getOperand(5));
7158 TmpInst.addOperand(Inst.getOperand(0));
7159 TmpInst.addOperand(Inst.getOperand(2));
7160 TmpInst.addOperand(Inst.getOperand(3));
7161 TmpInst.addOperand(Inst.getOperand(4));
7162 Inst = TmpInst;
7163 return true;
7164 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007165 case ARM::t2ADDrr: {
7166 // If the destination and first source operand are the same, and
7167 // there's no setting of the flags, use encoding T2 instead of T3.
7168 // Note that this is only for ADD, not SUB. This mirrors the system
7169 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7170 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7171 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007172 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7173 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007174 break;
7175 MCInst TmpInst;
7176 TmpInst.setOpcode(ARM::tADDhirr);
7177 TmpInst.addOperand(Inst.getOperand(0));
7178 TmpInst.addOperand(Inst.getOperand(0));
7179 TmpInst.addOperand(Inst.getOperand(2));
7180 TmpInst.addOperand(Inst.getOperand(3));
7181 TmpInst.addOperand(Inst.getOperand(4));
7182 Inst = TmpInst;
7183 return true;
7184 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007185 case ARM::tADDrSP: {
7186 // If the non-SP source operand and the destination operand are not the
7187 // same, we need to use the 32-bit encoding if it's available.
7188 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7189 Inst.setOpcode(ARM::t2ADDrr);
7190 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7191 return true;
7192 }
7193 break;
7194 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007195 case ARM::tB:
7196 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007197 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007198 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007199 return true;
7200 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007201 break;
7202 case ARM::t2B:
7203 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007204 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007205 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007206 return true;
7207 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007208 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007209 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007210 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007211 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007212 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007213 return true;
7214 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007215 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007216 case ARM::tBcc:
7217 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007218 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007219 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007220 return true;
7221 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007222 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007223 case ARM::tLDMIA: {
7224 // If the register list contains any high registers, or if the writeback
7225 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7226 // instead if we're in Thumb2. Otherwise, this should have generated
7227 // an error in validateInstruction().
7228 unsigned Rn = Inst.getOperand(0).getReg();
7229 bool hasWritebackToken =
7230 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7231 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7232 bool listContainsBase;
7233 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7234 (!listContainsBase && !hasWritebackToken) ||
7235 (listContainsBase && hasWritebackToken)) {
7236 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7237 assert (isThumbTwo());
7238 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7239 // If we're switching to the updating version, we need to insert
7240 // the writeback tied operand.
7241 if (hasWritebackToken)
7242 Inst.insert(Inst.begin(),
7243 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007244 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007245 }
7246 break;
7247 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007248 case ARM::tSTMIA_UPD: {
7249 // If the register list contains any high registers, we need to use
7250 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7251 // should have generated an error in validateInstruction().
7252 unsigned Rn = Inst.getOperand(0).getReg();
7253 bool listContainsBase;
7254 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7255 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7256 assert (isThumbTwo());
7257 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007258 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007259 }
7260 break;
7261 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007262 case ARM::tPOP: {
7263 bool listContainsBase;
7264 // If the register list contains any high registers, we need to use
7265 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7266 // should have generated an error in validateInstruction().
7267 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007268 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007269 assert (isThumbTwo());
7270 Inst.setOpcode(ARM::t2LDMIA_UPD);
7271 // Add the base register and writeback operands.
7272 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7273 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007274 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007275 }
7276 case ARM::tPUSH: {
7277 bool listContainsBase;
7278 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007279 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007280 assert (isThumbTwo());
7281 Inst.setOpcode(ARM::t2STMDB_UPD);
7282 // Add the base register and writeback operands.
7283 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7284 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007285 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007286 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007287 case ARM::t2MOVi: {
7288 // If we can use the 16-bit encoding and the user didn't explicitly
7289 // request the 32-bit variant, transform it here.
7290 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007291 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007292 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7293 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7294 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007295 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7296 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7297 // The operands aren't in the same order for tMOVi8...
7298 MCInst TmpInst;
7299 TmpInst.setOpcode(ARM::tMOVi8);
7300 TmpInst.addOperand(Inst.getOperand(0));
7301 TmpInst.addOperand(Inst.getOperand(4));
7302 TmpInst.addOperand(Inst.getOperand(1));
7303 TmpInst.addOperand(Inst.getOperand(2));
7304 TmpInst.addOperand(Inst.getOperand(3));
7305 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007306 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007307 }
7308 break;
7309 }
7310 case ARM::t2MOVr: {
7311 // If we can use the 16-bit encoding and the user didn't explicitly
7312 // request the 32-bit variant, transform it here.
7313 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7314 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7315 Inst.getOperand(2).getImm() == ARMCC::AL &&
7316 Inst.getOperand(4).getReg() == ARM::CPSR &&
7317 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7318 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7319 // The operands aren't the same for tMOV[S]r... (no cc_out)
7320 MCInst TmpInst;
7321 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7322 TmpInst.addOperand(Inst.getOperand(0));
7323 TmpInst.addOperand(Inst.getOperand(1));
7324 TmpInst.addOperand(Inst.getOperand(2));
7325 TmpInst.addOperand(Inst.getOperand(3));
7326 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007327 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007328 }
7329 break;
7330 }
Jim Grosbach82213192011-09-19 20:29:33 +00007331 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007332 case ARM::t2SXTB:
7333 case ARM::t2UXTH:
7334 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007335 // If we can use the 16-bit encoding and the user didn't explicitly
7336 // request the 32-bit variant, transform it here.
7337 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7338 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7339 Inst.getOperand(2).getImm() == 0 &&
7340 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7341 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007342 unsigned NewOpc;
7343 switch (Inst.getOpcode()) {
7344 default: llvm_unreachable("Illegal opcode!");
7345 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7346 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7347 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7348 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7349 }
Jim Grosbach82213192011-09-19 20:29:33 +00007350 // The operands aren't the same for thumb1 (no rotate operand).
7351 MCInst TmpInst;
7352 TmpInst.setOpcode(NewOpc);
7353 TmpInst.addOperand(Inst.getOperand(0));
7354 TmpInst.addOperand(Inst.getOperand(1));
7355 TmpInst.addOperand(Inst.getOperand(3));
7356 TmpInst.addOperand(Inst.getOperand(4));
7357 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007358 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007359 }
7360 break;
7361 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007362 case ARM::MOVsi: {
7363 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007364 // rrx shifts and asr/lsr of #32 is encoded as 0
7365 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7366 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007367 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7368 // Shifting by zero is accepted as a vanilla 'MOVr'
7369 MCInst TmpInst;
7370 TmpInst.setOpcode(ARM::MOVr);
7371 TmpInst.addOperand(Inst.getOperand(0));
7372 TmpInst.addOperand(Inst.getOperand(1));
7373 TmpInst.addOperand(Inst.getOperand(3));
7374 TmpInst.addOperand(Inst.getOperand(4));
7375 TmpInst.addOperand(Inst.getOperand(5));
7376 Inst = TmpInst;
7377 return true;
7378 }
7379 return false;
7380 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007381 case ARM::ANDrsi:
7382 case ARM::ORRrsi:
7383 case ARM::EORrsi:
7384 case ARM::BICrsi:
7385 case ARM::SUBrsi:
7386 case ARM::ADDrsi: {
7387 unsigned newOpc;
7388 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7389 if (SOpc == ARM_AM::rrx) return false;
7390 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007391 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007392 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7393 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7394 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7395 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7396 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7397 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7398 }
7399 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007400 // The exception is for right shifts, where 0 == 32
7401 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7402 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007403 MCInst TmpInst;
7404 TmpInst.setOpcode(newOpc);
7405 TmpInst.addOperand(Inst.getOperand(0));
7406 TmpInst.addOperand(Inst.getOperand(1));
7407 TmpInst.addOperand(Inst.getOperand(2));
7408 TmpInst.addOperand(Inst.getOperand(4));
7409 TmpInst.addOperand(Inst.getOperand(5));
7410 TmpInst.addOperand(Inst.getOperand(6));
7411 Inst = TmpInst;
7412 return true;
7413 }
7414 return false;
7415 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007416 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007417 case ARM::t2IT: {
7418 // The mask bits for all but the first condition are represented as
7419 // the low bit of the condition code value implies 't'. We currently
7420 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007421 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007422 MCOperand &MO = Inst.getOperand(1);
7423 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007424 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007425 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007426 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007427 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007428 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007429 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007430 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007431
7432 // Set up the IT block state according to the IT instruction we just
7433 // matched.
7434 assert(!inITBlock() && "nested IT blocks?!");
7435 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7436 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7437 ITState.CurPosition = 0;
7438 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007439 break;
7440 }
Richard Bartona39625e2012-07-09 16:12:24 +00007441 case ARM::t2LSLrr:
7442 case ARM::t2LSRrr:
7443 case ARM::t2ASRrr:
7444 case ARM::t2SBCrr:
7445 case ARM::t2RORrr:
7446 case ARM::t2BICrr:
7447 {
Richard Bartond5660372012-07-09 16:14:28 +00007448 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007449 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7450 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7451 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007452 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7453 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007454 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7455 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7456 unsigned NewOpc;
7457 switch (Inst.getOpcode()) {
7458 default: llvm_unreachable("unexpected opcode");
7459 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7460 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7461 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7462 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7463 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7464 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7465 }
7466 MCInst TmpInst;
7467 TmpInst.setOpcode(NewOpc);
7468 TmpInst.addOperand(Inst.getOperand(0));
7469 TmpInst.addOperand(Inst.getOperand(5));
7470 TmpInst.addOperand(Inst.getOperand(1));
7471 TmpInst.addOperand(Inst.getOperand(2));
7472 TmpInst.addOperand(Inst.getOperand(3));
7473 TmpInst.addOperand(Inst.getOperand(4));
7474 Inst = TmpInst;
7475 return true;
7476 }
7477 return false;
7478 }
7479 case ARM::t2ANDrr:
7480 case ARM::t2EORrr:
7481 case ARM::t2ADCrr:
7482 case ARM::t2ORRrr:
7483 {
Richard Bartond5660372012-07-09 16:14:28 +00007484 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007485 // These instructions are special in that they are commutable, so shorter encodings
7486 // are available more often.
7487 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7488 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7489 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7490 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007491 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7492 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007493 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7494 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7495 unsigned NewOpc;
7496 switch (Inst.getOpcode()) {
7497 default: llvm_unreachable("unexpected opcode");
7498 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7499 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7500 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7501 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7502 }
7503 MCInst TmpInst;
7504 TmpInst.setOpcode(NewOpc);
7505 TmpInst.addOperand(Inst.getOperand(0));
7506 TmpInst.addOperand(Inst.getOperand(5));
7507 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7508 TmpInst.addOperand(Inst.getOperand(1));
7509 TmpInst.addOperand(Inst.getOperand(2));
7510 } else {
7511 TmpInst.addOperand(Inst.getOperand(2));
7512 TmpInst.addOperand(Inst.getOperand(1));
7513 }
7514 TmpInst.addOperand(Inst.getOperand(3));
7515 TmpInst.addOperand(Inst.getOperand(4));
7516 Inst = TmpInst;
7517 return true;
7518 }
7519 return false;
7520 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007521 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007522 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007523}
7524
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007525unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7526 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7527 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007528 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007529 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007530 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7531 assert(MCID.hasOptionalDef() &&
7532 "optionally flag setting instruction missing optional def operand");
7533 assert(MCID.NumOperands == Inst.getNumOperands() &&
7534 "operand count mismatch!");
7535 // Find the optional-def operand (cc_out).
7536 unsigned OpNo;
7537 for (OpNo = 0;
7538 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7539 ++OpNo)
7540 ;
7541 // If we're parsing Thumb1, reject it completely.
7542 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7543 return Match_MnemonicFail;
7544 // If we're parsing Thumb2, which form is legal depends on whether we're
7545 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007546 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7547 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007548 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007549 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7550 inITBlock())
7551 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007552 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007553 // Some high-register supporting Thumb1 encodings only allow both registers
7554 // to be from r0-r7 when in Thumb2.
7555 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7556 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7557 isARMLowRegister(Inst.getOperand(2).getReg()))
7558 return Match_RequiresThumb2;
7559 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007560 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007561 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7562 isARMLowRegister(Inst.getOperand(1).getReg()))
7563 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007564 return Match_Success;
7565}
7566
Jim Grosbach5117ef72012-04-24 22:40:08 +00007567static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007568bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007569MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007570 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007571 MCStreamer &Out, unsigned &ErrorInfo,
7572 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007573 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007574 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007575
Chad Rosier2f480a82012-10-12 22:53:36 +00007576 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007577 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007578 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007579 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007580 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007581 // Context sensitive operand constraints aren't handled by the matcher,
7582 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007583 if (validateInstruction(Inst, Operands)) {
7584 // Still progress the IT block, otherwise one wrong condition causes
7585 // nasty cascading errors.
7586 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007587 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007588 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007589
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007590 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007591 // encoding is selected. Loop on it while changes happen so the
7592 // individual transformations can chain off each other. E.g.,
7593 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7594 while (processInstruction(Inst, Operands))
7595 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007596
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007597 // Only move forward at the very end so that everything in validate
7598 // and process gets a consistent answer about whether we're in an IT
7599 // block.
7600 forwardITPosition();
7601
Jim Grosbach82f76d12012-01-25 19:52:01 +00007602 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7603 // doesn't actually encode.
7604 if (Inst.getOpcode() == ARM::ITasm)
7605 return false;
7606
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007607 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007608 Out.EmitInstruction(Inst);
7609 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007610 case Match_MissingFeature: {
7611 assert(ErrorInfo && "Unknown missing feature!");
7612 // Special case the error message for the very common case where only
7613 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7614 std::string Msg = "instruction requires:";
7615 unsigned Mask = 1;
7616 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7617 if (ErrorInfo & Mask) {
7618 Msg += " ";
7619 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7620 }
7621 Mask <<= 1;
7622 }
7623 return Error(IDLoc, Msg);
7624 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007625 case Match_InvalidOperand: {
7626 SMLoc ErrorLoc = IDLoc;
7627 if (ErrorInfo != ~0U) {
7628 if (ErrorInfo >= Operands.size())
7629 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007630
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007631 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7632 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7633 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007634
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007635 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007636 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007637 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007638 return Error(IDLoc, "invalid instruction",
7639 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007640 case Match_RequiresNotITBlock:
7641 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007642 case Match_RequiresITBlock:
7643 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007644 case Match_RequiresV6:
7645 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7646 case Match_RequiresThumb2:
7647 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007648 case Match_ImmRange0_4: {
7649 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7650 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7651 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7652 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007653 case Match_ImmRange0_15: {
7654 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7655 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7656 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7657 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007658 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007659
Eric Christopher91d7b902010-10-29 09:26:59 +00007660 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007661}
7662
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007663/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007664bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7665 StringRef IDVal = DirectiveID.getIdentifier();
7666 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007667 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007668 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007669 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007670 else if (IDVal == ".arm")
7671 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007672 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007673 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007674 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007675 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007676 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007677 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007678 else if (IDVal == ".unreq")
7679 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007680 else if (IDVal == ".arch")
7681 return parseDirectiveArch(DirectiveID.getLoc());
7682 else if (IDVal == ".eabi_attribute")
7683 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007684 else if (IDVal == ".fnstart")
7685 return parseDirectiveFnStart(DirectiveID.getLoc());
7686 else if (IDVal == ".fnend")
7687 return parseDirectiveFnEnd(DirectiveID.getLoc());
7688 else if (IDVal == ".cantunwind")
7689 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7690 else if (IDVal == ".personality")
7691 return parseDirectivePersonality(DirectiveID.getLoc());
7692 else if (IDVal == ".handlerdata")
7693 return parseDirectiveHandlerData(DirectiveID.getLoc());
7694 else if (IDVal == ".setfp")
7695 return parseDirectiveSetFP(DirectiveID.getLoc());
7696 else if (IDVal == ".pad")
7697 return parseDirectivePad(DirectiveID.getLoc());
7698 else if (IDVal == ".save")
7699 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7700 else if (IDVal == ".vsave")
7701 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007702 return true;
7703}
7704
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007705/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007706/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007707bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007708 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7709 for (;;) {
7710 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007711 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007712 return true;
7713
Eric Christopherbf7bc492013-01-09 03:52:05 +00007714 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007715
7716 if (getLexer().is(AsmToken::EndOfStatement))
7717 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007718
Kevin Enderbyccab3172009-09-15 00:27:25 +00007719 // FIXME: Improve diagnostic.
7720 if (getLexer().isNot(AsmToken::Comma))
7721 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007722 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007723 }
7724 }
7725
Sean Callanana83fd7d2010-01-19 20:27:46 +00007726 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007727 return false;
7728}
7729
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007730/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007731/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007732bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007733 if (getLexer().isNot(AsmToken::EndOfStatement))
7734 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007735 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007736
Tim Northovera2292d02013-06-10 23:20:58 +00007737 if (!hasThumb())
7738 return Error(L, "target does not support Thumb mode");
7739
Jim Grosbach7f882392011-12-07 18:04:19 +00007740 if (!isThumb())
7741 SwitchMode();
7742 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7743 return false;
7744}
7745
7746/// parseDirectiveARM
7747/// ::= .arm
7748bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7749 if (getLexer().isNot(AsmToken::EndOfStatement))
7750 return Error(L, "unexpected token in directive");
7751 Parser.Lex();
7752
Tim Northovera2292d02013-06-10 23:20:58 +00007753 if (!hasARM())
7754 return Error(L, "target does not support ARM mode");
7755
Jim Grosbach7f882392011-12-07 18:04:19 +00007756 if (isThumb())
7757 SwitchMode();
7758 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007759 return false;
7760}
7761
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007762/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007763/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007764bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007765 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7766 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007767 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007768 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007769
Jim Grosbach1152cc02011-12-21 22:30:16 +00007770 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007771 // ELF doesn't
7772 if (isMachO) {
7773 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007774 if (Tok.isNot(AsmToken::EndOfStatement)) {
7775 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7776 return Error(L, "unexpected token in .thumb_func directive");
7777 Name = Tok.getIdentifier();
7778 Parser.Lex(); // Consume the identifier token.
7779 needFuncName = false;
7780 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007781 }
7782
Jim Grosbach1152cc02011-12-21 22:30:16 +00007783 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007784 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007785
7786 // Eat the end of statement and any blank lines that follow.
7787 while (getLexer().is(AsmToken::EndOfStatement))
7788 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007789
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007790 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007791 // We really should be checking the next symbol definition even if there's
7792 // stuff in between.
7793 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007794 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007795 }
7796
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007797 // Mark symbol as a thumb symbol.
7798 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7799 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007800 return false;
7801}
7802
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007803/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007804/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007805bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007806 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007807 if (Tok.isNot(AsmToken::Identifier))
7808 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007809 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007810 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007811 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007812 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007813 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007814 else
7815 return Error(L, "unrecognized syntax mode in .syntax directive");
7816
7817 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007818 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007819 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007820
7821 // TODO tell the MC streamer the mode
7822 // getParser().getStreamer().Emit???();
7823 return false;
7824}
7825
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007826/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007827/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007828bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007829 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007830 if (Tok.isNot(AsmToken::Integer))
7831 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007832 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007833 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007834 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007835 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007836 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007837 else
7838 return Error(L, "invalid operand to .code directive");
7839
7840 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007841 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007842 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007843
Evan Cheng284b4672011-07-08 22:36:29 +00007844 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007845 if (!hasThumb())
7846 return Error(L, "target does not support Thumb mode");
7847
Jim Grosbachf471ac32011-09-06 18:46:23 +00007848 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007849 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007850 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007851 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007852 if (!hasARM())
7853 return Error(L, "target does not support ARM mode");
7854
Jim Grosbachf471ac32011-09-06 18:46:23 +00007855 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007856 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007857 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007858 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007859
Kevin Enderby146dcf22009-10-15 20:48:48 +00007860 return false;
7861}
7862
Jim Grosbachab5830e2011-12-14 02:16:11 +00007863/// parseDirectiveReq
7864/// ::= name .req registername
7865bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7866 Parser.Lex(); // Eat the '.req' token.
7867 unsigned Reg;
7868 SMLoc SRegLoc, ERegLoc;
7869 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007870 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007871 return Error(SRegLoc, "register name expected");
7872 }
7873
7874 // Shouldn't be anything else.
7875 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007876 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007877 return Error(Parser.getTok().getLoc(),
7878 "unexpected input in .req directive.");
7879 }
7880
7881 Parser.Lex(); // Consume the EndOfStatement
7882
7883 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7884 return Error(SRegLoc, "redefinition of '" + Name +
7885 "' does not match original.");
7886
7887 return false;
7888}
7889
7890/// parseDirectiveUneq
7891/// ::= .unreq registername
7892bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7893 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007894 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007895 return Error(L, "unexpected input in .unreq directive.");
7896 }
7897 RegisterReqs.erase(Parser.getTok().getIdentifier());
7898 Parser.Lex(); // Eat the identifier.
7899 return false;
7900}
7901
Jason W Kim135d2442011-12-20 17:38:12 +00007902/// parseDirectiveArch
7903/// ::= .arch token
7904bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7905 return true;
7906}
7907
7908/// parseDirectiveEabiAttr
7909/// ::= .eabi_attribute int, int
7910bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7911 return true;
7912}
7913
Logan Chien4ea23b52013-05-10 16:17:24 +00007914/// parseDirectiveFnStart
7915/// ::= .fnstart
7916bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7917 if (FnStartLoc.isValid()) {
7918 Error(L, ".fnstart starts before the end of previous one");
7919 Error(FnStartLoc, "previous .fnstart starts here");
7920 return true;
7921 }
7922
7923 FnStartLoc = L;
7924 getParser().getStreamer().EmitFnStart();
7925 return false;
7926}
7927
7928/// parseDirectiveFnEnd
7929/// ::= .fnend
7930bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7931 // Check the ordering of unwind directives
7932 if (!FnStartLoc.isValid())
7933 return Error(L, ".fnstart must precede .fnend directive");
7934
7935 // Reset the unwind directives parser state
7936 resetUnwindDirectiveParserState();
7937
7938 getParser().getStreamer().EmitFnEnd();
7939 return false;
7940}
7941
7942/// parseDirectiveCantUnwind
7943/// ::= .cantunwind
7944bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7945 // Check the ordering of unwind directives
7946 CantUnwindLoc = L;
7947 if (!FnStartLoc.isValid())
7948 return Error(L, ".fnstart must precede .cantunwind directive");
7949 if (HandlerDataLoc.isValid()) {
7950 Error(L, ".cantunwind can't be used with .handlerdata directive");
7951 Error(HandlerDataLoc, ".handlerdata was specified here");
7952 return true;
7953 }
7954 if (PersonalityLoc.isValid()) {
7955 Error(L, ".cantunwind can't be used with .personality directive");
7956 Error(PersonalityLoc, ".personality was specified here");
7957 return true;
7958 }
7959
7960 getParser().getStreamer().EmitCantUnwind();
7961 return false;
7962}
7963
7964/// parseDirectivePersonality
7965/// ::= .personality name
7966bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7967 // Check the ordering of unwind directives
7968 PersonalityLoc = L;
7969 if (!FnStartLoc.isValid())
7970 return Error(L, ".fnstart must precede .personality directive");
7971 if (CantUnwindLoc.isValid()) {
7972 Error(L, ".personality can't be used with .cantunwind directive");
7973 Error(CantUnwindLoc, ".cantunwind was specified here");
7974 return true;
7975 }
7976 if (HandlerDataLoc.isValid()) {
7977 Error(L, ".personality must precede .handlerdata directive");
7978 Error(HandlerDataLoc, ".handlerdata was specified here");
7979 return true;
7980 }
7981
7982 // Parse the name of the personality routine
7983 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7984 Parser.eatToEndOfStatement();
7985 return Error(L, "unexpected input in .personality directive.");
7986 }
7987 StringRef Name(Parser.getTok().getIdentifier());
7988 Parser.Lex();
7989
7990 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
7991 getParser().getStreamer().EmitPersonality(PR);
7992 return false;
7993}
7994
7995/// parseDirectiveHandlerData
7996/// ::= .handlerdata
7997bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
7998 // Check the ordering of unwind directives
7999 HandlerDataLoc = L;
8000 if (!FnStartLoc.isValid())
8001 return Error(L, ".fnstart must precede .personality directive");
8002 if (CantUnwindLoc.isValid()) {
8003 Error(L, ".handlerdata can't be used with .cantunwind directive");
8004 Error(CantUnwindLoc, ".cantunwind was specified here");
8005 return true;
8006 }
8007
8008 getParser().getStreamer().EmitHandlerData();
8009 return false;
8010}
8011
8012/// parseDirectiveSetFP
8013/// ::= .setfp fpreg, spreg [, offset]
8014bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8015 // Check the ordering of unwind directives
8016 if (!FnStartLoc.isValid())
8017 return Error(L, ".fnstart must precede .setfp directive");
8018 if (HandlerDataLoc.isValid())
8019 return Error(L, ".setfp must precede .handlerdata directive");
8020
8021 // Parse fpreg
8022 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8023 int NewFPReg = tryParseRegister();
8024 if (NewFPReg == -1)
8025 return Error(NewFPRegLoc, "frame pointer register expected");
8026
8027 // Consume comma
8028 if (!Parser.getTok().is(AsmToken::Comma))
8029 return Error(Parser.getTok().getLoc(), "comma expected");
8030 Parser.Lex(); // skip comma
8031
8032 // Parse spreg
8033 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8034 int NewSPReg = tryParseRegister();
8035 if (NewSPReg == -1)
8036 return Error(NewSPRegLoc, "stack pointer register expected");
8037
8038 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8039 return Error(NewSPRegLoc,
8040 "register should be either $sp or the latest fp register");
8041
8042 // Update the frame pointer register
8043 FPReg = NewFPReg;
8044
8045 // Parse offset
8046 int64_t Offset = 0;
8047 if (Parser.getTok().is(AsmToken::Comma)) {
8048 Parser.Lex(); // skip comma
8049
8050 if (Parser.getTok().isNot(AsmToken::Hash) &&
8051 Parser.getTok().isNot(AsmToken::Dollar)) {
8052 return Error(Parser.getTok().getLoc(), "'#' expected");
8053 }
8054 Parser.Lex(); // skip hash token.
8055
8056 const MCExpr *OffsetExpr;
8057 SMLoc ExLoc = Parser.getTok().getLoc();
8058 SMLoc EndLoc;
8059 if (getParser().parseExpression(OffsetExpr, EndLoc))
8060 return Error(ExLoc, "malformed setfp offset");
8061 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8062 if (!CE)
8063 return Error(ExLoc, "setfp offset must be an immediate");
8064
8065 Offset = CE->getValue();
8066 }
8067
8068 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8069 static_cast<unsigned>(NewSPReg),
8070 Offset);
8071 return false;
8072}
8073
8074/// parseDirective
8075/// ::= .pad offset
8076bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8077 // Check the ordering of unwind directives
8078 if (!FnStartLoc.isValid())
8079 return Error(L, ".fnstart must precede .pad directive");
8080 if (HandlerDataLoc.isValid())
8081 return Error(L, ".pad must precede .handlerdata directive");
8082
8083 // Parse the offset
8084 if (Parser.getTok().isNot(AsmToken::Hash) &&
8085 Parser.getTok().isNot(AsmToken::Dollar)) {
8086 return Error(Parser.getTok().getLoc(), "'#' expected");
8087 }
8088 Parser.Lex(); // skip hash token.
8089
8090 const MCExpr *OffsetExpr;
8091 SMLoc ExLoc = Parser.getTok().getLoc();
8092 SMLoc EndLoc;
8093 if (getParser().parseExpression(OffsetExpr, EndLoc))
8094 return Error(ExLoc, "malformed pad offset");
8095 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8096 if (!CE)
8097 return Error(ExLoc, "pad offset must be an immediate");
8098
8099 getParser().getStreamer().EmitPad(CE->getValue());
8100 return false;
8101}
8102
8103/// parseDirectiveRegSave
8104/// ::= .save { registers }
8105/// ::= .vsave { registers }
8106bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8107 // Check the ordering of unwind directives
8108 if (!FnStartLoc.isValid())
8109 return Error(L, ".fnstart must precede .save or .vsave directives");
8110 if (HandlerDataLoc.isValid())
8111 return Error(L, ".save or .vsave must precede .handlerdata directive");
8112
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008113 // RAII object to make sure parsed operands are deleted.
8114 struct CleanupObject {
8115 SmallVector<MCParsedAsmOperand *, 1> Operands;
8116 ~CleanupObject() {
8117 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8118 delete Operands[I];
8119 }
8120 } CO;
8121
Logan Chien4ea23b52013-05-10 16:17:24 +00008122 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008123 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008124 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008125 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008126 if (!IsVector && !Op->isRegList())
8127 return Error(L, ".save expects GPR registers");
8128 if (IsVector && !Op->isDPRRegList())
8129 return Error(L, ".vsave expects DPR registers");
8130
8131 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8132 return false;
8133}
8134
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008135/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008136extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008137 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8138 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008139}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008140
Chris Lattner3e4582a2010-09-06 19:11:01 +00008141#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008142#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008143#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008144#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008145
8146// Define this matcher function after the auto-generated include so we
8147// have the match class enum definitions.
8148unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8149 unsigned Kind) {
8150 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8151 // If the kind is a token for a literal immediate, check if our asm
8152 // operand matches. This is for InstAliases which have a fixed-value
8153 // immediate in the syntax.
8154 if (Kind == MCK__35_0 && Op->isImm()) {
8155 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8156 if (!CE)
8157 return Match_InvalidOperand;
8158 if (CE->getValue() == 0)
8159 return Match_Success;
8160 }
8161 return Match_InvalidOperand;
8162}