blob: 862e1166027c05b57239b1d62ccc46f47085428e [file] [log] [blame]
Kevin Enderbyccab3172009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Evan Cheng11424442011-07-26 00:24:13 +000010#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMBaseInfo.h"
13#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000014#include "llvm/ADT/BitVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000015#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000016#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000017#include "llvm/ADT/SmallVector.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000018#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000019#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000021#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000023#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/MC/MCExpr.h"
25#include "llvm/MC/MCInst.h"
26#include "llvm/MC/MCInstrDesc.h"
27#include "llvm/MC/MCParser/MCAsmLexer.h"
28#include "llvm/MC/MCParser/MCAsmParser.h"
29#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
30#include "llvm/MC/MCRegisterInfo.h"
31#include "llvm/MC/MCStreamer.h"
32#include "llvm/MC/MCSubtargetInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000033#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/Support/MathExtras.h"
35#include "llvm/Support/SourceMgr.h"
36#include "llvm/Support/TargetRegistry.h"
37#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000038
Kevin Enderbyccab3172009-09-15 00:27:25 +000039using namespace llvm;
40
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000041namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000042
43class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000044
Jim Grosbach04945c42011-12-02 00:35:16 +000045enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000046
Evan Cheng11424442011-07-26 00:24:13 +000047class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +000048 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000049 MCAsmParser &Parser;
Jim Grosbachc988e0c2012-03-05 19:33:30 +000050 const MCRegisterInfo *MRI;
Kevin Enderbyccab3172009-09-15 00:27:25 +000051
Logan Chien4ea23b52013-05-10 16:17:24 +000052 // Unwind directives state
53 SMLoc FnStartLoc;
54 SMLoc CantUnwindLoc;
55 SMLoc PersonalityLoc;
56 SMLoc HandlerDataLoc;
57 int FPReg;
58 void resetUnwindDirectiveParserState() {
59 FnStartLoc = SMLoc();
60 CantUnwindLoc = SMLoc();
61 PersonalityLoc = SMLoc();
62 HandlerDataLoc = SMLoc();
63 FPReg = -1;
64 }
65
Jim Grosbachab5830e2011-12-14 02:16:11 +000066 // Map of register aliases registers via the .req directive.
67 StringMap<unsigned> RegisterReqs;
68
Jim Grosbached16ec42011-08-29 22:24:09 +000069 struct {
70 ARMCC::CondCodes Cond; // Condition for IT block.
71 unsigned Mask:4; // Condition mask for instructions.
72 // Starting at first 1 (from lsb).
73 // '1' condition as indicated in IT.
74 // '0' inverse of condition (else).
75 // Count of instructions in IT block is
76 // 4 - trailingzeroes(mask)
77
78 bool FirstCond; // Explicit flag for when we're parsing the
79 // First instruction in the IT block. It's
80 // implied in the mask, so needs special
81 // handling.
82
83 unsigned CurPosition; // Current position in parsing of IT
84 // block. In range [0,3]. Initialized
85 // according to count of instructions in block.
86 // ~0U if no active IT block.
87 } ITState;
88 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +000089 void forwardITPosition() {
90 if (!inITBlock()) return;
91 // Move to the next instruction in the IT block, if there is one. If not,
92 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +000093 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +000094 if (++ITState.CurPosition == 5 - TZ)
95 ITState.CurPosition = ~0U; // Done with the IT block after this.
96 }
Jim Grosbached16ec42011-08-29 22:24:09 +000097
98
Kevin Enderbyccab3172009-09-15 00:27:25 +000099 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000100 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
101
Benjamin Kramer673824b2012-04-15 17:04:27 +0000102 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000103 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000104 return Parser.Warning(L, Msg, Ranges);
105 }
106 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000107 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000108 return Parser.Error(L, Msg, Ranges);
109 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000110
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000111 int tryParseRegister();
112 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000113 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000114 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000115 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000116 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
117 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000118 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
119 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000120 bool parseDirectiveWord(unsigned Size, SMLoc L);
121 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000122 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000123 bool parseDirectiveThumbFunc(SMLoc L);
124 bool parseDirectiveCode(SMLoc L);
125 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000126 bool parseDirectiveReq(StringRef Name, SMLoc L);
127 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000128 bool parseDirectiveArch(SMLoc L);
129 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000130 bool parseDirectiveFnStart(SMLoc L);
131 bool parseDirectiveFnEnd(SMLoc L);
132 bool parseDirectiveCantUnwind(SMLoc L);
133 bool parseDirectivePersonality(SMLoc L);
134 bool parseDirectiveHandlerData(SMLoc L);
135 bool parseDirectiveSetFP(SMLoc L);
136 bool parseDirectivePad(SMLoc L);
137 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000138
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000139 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000140 bool &CarrySetting, unsigned &ProcessorIMod,
141 StringRef &ITMask);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000142 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000143 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000144
Evan Cheng4d1ca962011-07-08 01:53:10 +0000145 bool isThumb() const {
146 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000147 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000148 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000149 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000150 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000151 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000152 bool isThumbTwo() const {
153 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
154 }
Tim Northovera2292d02013-06-10 23:20:58 +0000155 bool hasThumb() const {
156 return STI.getFeatureBits() & ARM::HasV4TOps;
157 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000158 bool hasV6Ops() const {
159 return STI.getFeatureBits() & ARM::HasV6Ops;
160 }
James Molloy21efa7d2011-09-28 14:21:38 +0000161 bool hasV7Ops() const {
162 return STI.getFeatureBits() & ARM::HasV7Ops;
163 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000164 bool hasV8Ops() const {
165 return STI.getFeatureBits() & ARM::HasV8Ops;
166 }
Tim Northovera2292d02013-06-10 23:20:58 +0000167 bool hasARM() const {
168 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
169 }
170
Evan Cheng284b4672011-07-08 22:36:29 +0000171 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000172 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
173 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000174 }
James Molloy21efa7d2011-09-28 14:21:38 +0000175 bool isMClass() const {
176 return STI.getFeatureBits() & ARM::FeatureMClass;
177 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000178
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000179 /// @name Auto-generated Match Functions
180 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000181
Chris Lattner3e4582a2010-09-06 19:11:01 +0000182#define GET_ASSEMBLER_HEADER
183#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000184
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000185 /// }
186
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000187 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000188 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000189 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000190 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000191 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000192 OperandMatchResultTy parseCoprocOptionOperand(
193 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000194 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000195 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000196 OperandMatchResultTy parseInstSyncBarrierOptOperand(
197 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000198 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000199 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000200 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000201 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000202 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
203 StringRef Op, int Low, int High);
204 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
205 return parsePKHImm(O, "lsl", 0, 31);
206 }
207 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
208 return parsePKHImm(O, "asr", 1, 32);
209 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000210 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000211 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000212 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000213 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000214 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000215 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000216 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000217 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000218 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
219 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000220
221 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000222 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000223 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000224 bool validateInstruction(MCInst &Inst,
225 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000226 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000227 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000228 bool shouldOmitCCOutOperand(StringRef Mnemonic,
229 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000230 bool shouldOmitPredicateOperand(StringRef Mnemonic,
231 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Gouly5d0564d2013-08-02 19:18:12 +0000232 bool isDeprecated(MCInst &Inst, StringRef &Info);
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000233
Kevin Enderbyccab3172009-09-15 00:27:25 +0000234public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000235 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000236 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000237 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000238 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000239 Match_RequiresThumb2,
240#define GET_OPERAND_DIAGNOSTIC_TYPES
241#include "ARMGenAsmMatcher.inc"
242
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000243 };
244
Evan Cheng91111d22011-07-09 05:47:46 +0000245 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Logan Chien4ea23b52013-05-10 16:17:24 +0000246 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000247 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000248
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000249 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000250 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000251
Evan Cheng4d1ca962011-07-08 01:53:10 +0000252 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000253 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000254
255 // Not in an ITBlock to start with.
256 ITState.CurPosition = ~0U;
Jack Carter718da0b2013-01-30 02:24:33 +0000257
258 // Set ELF header flags.
259 // FIXME: This should eventually end up somewhere else where more
260 // intelligent flag decisions can be made. For now we are just maintaining
Chandler Carruthe5d8d0d2013-01-31 23:43:14 +0000261 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
262 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
263 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000264 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000265
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000266 // Implementation of the MCTargetAsmParser interface:
267 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000268 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
269 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000270 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000271 bool ParseDirective(AsmToken DirectiveID);
272
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000273 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000274 unsigned checkTargetMatchPredicate(MCInst &Inst);
275
Chad Rosier49963552012-10-13 00:26:04 +0000276 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000277 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000278 MCStreamer &Out, unsigned &ErrorInfo,
279 bool MatchingInlineAsm);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000280};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000281} // end anonymous namespace
282
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000283namespace {
284
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000285/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000286/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000287class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000288 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000289 k_CondCode,
290 k_CCOut,
291 k_ITCondMask,
292 k_CoprocNum,
293 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000294 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000295 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000296 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000297 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000298 k_Memory,
299 k_PostIndexRegister,
300 k_MSRMask,
301 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000302 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000303 k_Register,
304 k_RegisterList,
305 k_DPRRegisterList,
306 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000307 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000308 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000309 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000310 k_ShiftedRegister,
311 k_ShiftedImmediate,
312 k_ShifterImmediate,
313 k_RotateImmediate,
314 k_BitfieldDescriptor,
315 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000316 } Kind;
317
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000318 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000319 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000320
Eric Christopher8996c5d2013-03-15 00:42:55 +0000321 struct CCOp {
322 ARMCC::CondCodes Val;
323 };
324
325 struct CopOp {
326 unsigned Val;
327 };
328
329 struct CoprocOptionOp {
330 unsigned Val;
331 };
332
333 struct ITMaskOp {
334 unsigned Mask:4;
335 };
336
337 struct MBOptOp {
338 ARM_MB::MemBOpt Val;
339 };
340
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000341 struct ISBOptOp {
342 ARM_ISB::InstSyncBOpt Val;
343 };
344
Eric Christopher8996c5d2013-03-15 00:42:55 +0000345 struct IFlagsOp {
346 ARM_PROC::IFlags Val;
347 };
348
349 struct MMaskOp {
350 unsigned Val;
351 };
352
353 struct TokOp {
354 const char *Data;
355 unsigned Length;
356 };
357
358 struct RegOp {
359 unsigned RegNum;
360 };
361
362 // A vector register list is a sequential list of 1 to 4 registers.
363 struct VectorListOp {
364 unsigned RegNum;
365 unsigned Count;
366 unsigned LaneIndex;
367 bool isDoubleSpaced;
368 };
369
370 struct VectorIndexOp {
371 unsigned Val;
372 };
373
374 struct ImmOp {
375 const MCExpr *Val;
376 };
377
378 /// Combined record for all forms of ARM address expressions.
379 struct MemoryOp {
380 unsigned BaseRegNum;
381 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
382 // was specified.
383 const MCConstantExpr *OffsetImm; // Offset immediate value
384 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
385 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
386 unsigned ShiftImm; // shift for OffsetReg.
387 unsigned Alignment; // 0 = no alignment specified
388 // n = alignment in bytes (2, 4, 8, 16, or 32)
389 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
390 };
391
392 struct PostIdxRegOp {
393 unsigned RegNum;
394 bool isAdd;
395 ARM_AM::ShiftOpc ShiftTy;
396 unsigned ShiftImm;
397 };
398
399 struct ShifterImmOp {
400 bool isASR;
401 unsigned Imm;
402 };
403
404 struct RegShiftedRegOp {
405 ARM_AM::ShiftOpc ShiftTy;
406 unsigned SrcReg;
407 unsigned ShiftReg;
408 unsigned ShiftImm;
409 };
410
411 struct RegShiftedImmOp {
412 ARM_AM::ShiftOpc ShiftTy;
413 unsigned SrcReg;
414 unsigned ShiftImm;
415 };
416
417 struct RotImmOp {
418 unsigned Imm;
419 };
420
421 struct BitfieldOp {
422 unsigned LSB;
423 unsigned Width;
424 };
425
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000426 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000427 struct CCOp CC;
428 struct CopOp Cop;
429 struct CoprocOptionOp CoprocOption;
430 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000431 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000432 struct ITMaskOp ITMask;
433 struct IFlagsOp IFlags;
434 struct MMaskOp MMask;
435 struct TokOp Tok;
436 struct RegOp Reg;
437 struct VectorListOp VectorList;
438 struct VectorIndexOp VectorIndex;
439 struct ImmOp Imm;
440 struct MemoryOp Memory;
441 struct PostIdxRegOp PostIdxReg;
442 struct ShifterImmOp ShifterImm;
443 struct RegShiftedRegOp RegShiftedReg;
444 struct RegShiftedImmOp RegShiftedImm;
445 struct RotImmOp RotImm;
446 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000447 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000448
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000449 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
450public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000451 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
452 Kind = o.Kind;
453 StartLoc = o.StartLoc;
454 EndLoc = o.EndLoc;
455 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000456 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000457 CC = o.CC;
458 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000459 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000460 ITMask = o.ITMask;
461 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000462 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000463 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000464 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000465 case k_CCOut:
466 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000467 Reg = o.Reg;
468 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000469 case k_RegisterList:
470 case k_DPRRegisterList:
471 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000472 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000473 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000474 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000475 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000476 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000477 VectorList = o.VectorList;
478 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000479 case k_CoprocNum:
480 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000481 Cop = o.Cop;
482 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000483 case k_CoprocOption:
484 CoprocOption = o.CoprocOption;
485 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000486 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000487 Imm = o.Imm;
488 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000489 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000490 MBOpt = o.MBOpt;
491 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000492 case k_InstSyncBarrierOpt:
493 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000494 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000495 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000496 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000497 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000498 PostIdxReg = o.PostIdxReg;
499 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000500 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000501 MMask = o.MMask;
502 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000503 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000504 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000505 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000506 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000507 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000508 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000509 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000510 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000511 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000512 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000513 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000514 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000515 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000516 RotImm = o.RotImm;
517 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000518 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000519 Bitfield = o.Bitfield;
520 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000521 case k_VectorIndex:
522 VectorIndex = o.VectorIndex;
523 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000524 }
525 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000526
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000527 /// getStartLoc - Get the location of the first token of this operand.
528 SMLoc getStartLoc() const { return StartLoc; }
529 /// getEndLoc - Get the location of the last token of this operand.
530 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000531 /// getLocRange - Get the range between the first and last token of this
532 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000533 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
534
Daniel Dunbard8042b72010-08-11 06:36:53 +0000535 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000536 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000537 return CC.Val;
538 }
539
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000540 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000541 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000542 return Cop.Val;
543 }
544
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000545 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000546 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000547 return StringRef(Tok.Data, Tok.Length);
548 }
549
550 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000551 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000552 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000553 }
554
Bill Wendlingbed94652010-11-09 23:28:44 +0000555 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000556 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
557 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000558 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000559 }
560
Kevin Enderbyf5079942009-10-13 22:19:02 +0000561 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000562 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000563 return Imm.Val;
564 }
565
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000566 unsigned getVectorIndex() const {
567 assert(Kind == k_VectorIndex && "Invalid access!");
568 return VectorIndex.Val;
569 }
570
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000571 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000572 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000573 return MBOpt.Val;
574 }
575
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000576 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
577 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
578 return ISBOpt.Val;
579 }
580
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000581 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000582 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000583 return IFlags.Val;
584 }
585
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000586 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000587 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000588 return MMask.Val;
589 }
590
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000591 bool isCoprocNum() const { return Kind == k_CoprocNum; }
592 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000593 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000594 bool isCondCode() const { return Kind == k_CondCode; }
595 bool isCCOut() const { return Kind == k_CCOut; }
596 bool isITMask() const { return Kind == k_ITCondMask; }
597 bool isITCondCode() const { return Kind == k_CondCode; }
598 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000599 // checks whether this operand is an unsigned offset which fits is a field
600 // of specified width and scaled by a specific number of bits
601 template<unsigned width, unsigned scale>
602 bool isUnsignedOffset() const {
603 if (!isImm()) return false;
604 if (dyn_cast<MCSymbolRefExpr>(Imm.Val)) return true;
605 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
606 int64_t Val = CE->getValue();
607 int64_t Align = 1LL << scale;
608 int64_t Max = Align * ((1LL << width) - 1);
609 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
610 }
611 return false;
612 }
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000613 // checks whether this operand is a memory operand computed as an offset
614 // applied to PC. the offset may have 8 bits of magnitude and is represented
615 // with two bits of shift. textually it may be either [pc, #imm], #imm or
616 // relocable expression...
617 bool isThumbMemPC() const {
618 int64_t Val = 0;
619 if (isImm()) {
620 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
621 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
622 if (!CE) return false;
623 Val = CE->getValue();
624 }
625 else if (isMem()) {
626 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
627 if(Memory.BaseRegNum != ARM::PC) return false;
628 Val = Memory.OffsetImm->getValue();
629 }
630 else return false;
631 return ((Val % 4) == 0) && (Val >= -1020) && (Val <= 1020);
632 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000633 bool isFPImm() const {
634 if (!isImm()) return false;
635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
636 if (!CE) return false;
637 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
638 return Val != -1;
639 }
Jim Grosbachea231912011-12-22 22:19:05 +0000640 bool isFBits16() const {
641 if (!isImm()) return false;
642 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
643 if (!CE) return false;
644 int64_t Value = CE->getValue();
645 return Value >= 0 && Value <= 16;
646 }
647 bool isFBits32() const {
648 if (!isImm()) return false;
649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
650 if (!CE) return false;
651 int64_t Value = CE->getValue();
652 return Value >= 1 && Value <= 32;
653 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000654 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000655 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
657 if (!CE) return false;
658 int64_t Value = CE->getValue();
659 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
660 }
Quentin Colombet6f03f622013-04-17 18:46:12 +0000661 bool isImm0_4() const {
662 if (!isImm()) return false;
663 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
664 if (!CE) return false;
665 int64_t Value = CE->getValue();
666 return Value >= 0 && Value < 5;
667 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000668 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000669 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
671 if (!CE) return false;
672 int64_t Value = CE->getValue();
673 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
674 }
675 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000676 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000677 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
678 if (!CE) return false;
679 int64_t Value = CE->getValue();
680 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
681 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000682 bool isImm0_508s4Neg() const {
683 if (!isImm()) return false;
684 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
685 if (!CE) return false;
686 int64_t Value = -CE->getValue();
687 // explicitly exclude zero. we want that to use the normal 0_508 version.
688 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
689 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000690 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000691 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000692 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
693 if (!CE) return false;
694 int64_t Value = CE->getValue();
695 return Value >= 0 && Value < 256;
696 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000697 bool isImm0_4095() const {
698 if (!isImm()) return false;
699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
700 if (!CE) return false;
701 int64_t Value = CE->getValue();
702 return Value >= 0 && Value < 4096;
703 }
704 bool isImm0_4095Neg() const {
705 if (!isImm()) return false;
706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
707 if (!CE) return false;
708 int64_t Value = -CE->getValue();
709 return Value > 0 && Value < 4096;
710 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000711 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000712 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
714 if (!CE) return false;
715 int64_t Value = CE->getValue();
716 return Value >= 0 && Value < 2;
717 }
718 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000719 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
721 if (!CE) return false;
722 int64_t Value = CE->getValue();
723 return Value >= 0 && Value < 4;
724 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000725 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000726 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000727 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
728 if (!CE) return false;
729 int64_t Value = CE->getValue();
730 return Value >= 0 && Value < 8;
731 }
732 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000733 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
735 if (!CE) return false;
736 int64_t Value = CE->getValue();
737 return Value >= 0 && Value < 16;
738 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000739 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000740 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000741 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
742 if (!CE) return false;
743 int64_t Value = CE->getValue();
744 return Value >= 0 && Value < 32;
745 }
Jim Grosbach00326402011-12-08 01:30:04 +0000746 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000747 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000748 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
749 if (!CE) return false;
750 int64_t Value = CE->getValue();
751 return Value >= 0 && Value < 64;
752 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000753 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000754 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000755 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
756 if (!CE) return false;
757 int64_t Value = CE->getValue();
758 return Value == 8;
759 }
760 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000761 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
763 if (!CE) return false;
764 int64_t Value = CE->getValue();
765 return Value == 16;
766 }
767 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000768 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000769 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
770 if (!CE) return false;
771 int64_t Value = CE->getValue();
772 return Value == 32;
773 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000774 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000775 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
777 if (!CE) return false;
778 int64_t Value = CE->getValue();
779 return Value > 0 && Value <= 8;
780 }
781 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000782 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
784 if (!CE) return false;
785 int64_t Value = CE->getValue();
786 return Value > 0 && Value <= 16;
787 }
788 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000789 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000790 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
791 if (!CE) return false;
792 int64_t Value = CE->getValue();
793 return Value > 0 && Value <= 32;
794 }
795 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000796 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000797 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
798 if (!CE) return false;
799 int64_t Value = CE->getValue();
800 return Value > 0 && Value <= 64;
801 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000802 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000803 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000804 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
805 if (!CE) return false;
806 int64_t Value = CE->getValue();
807 return Value > 0 && Value < 8;
808 }
809 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000810 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000811 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
812 if (!CE) return false;
813 int64_t Value = CE->getValue();
814 return Value > 0 && Value < 16;
815 }
816 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000817 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
819 if (!CE) return false;
820 int64_t Value = CE->getValue();
821 return Value > 0 && Value < 32;
822 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000823 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000824 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000825 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
826 if (!CE) return false;
827 int64_t Value = CE->getValue();
828 return Value > 0 && Value < 17;
829 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000830 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000831 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000832 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
833 if (!CE) return false;
834 int64_t Value = CE->getValue();
835 return Value > 0 && Value < 33;
836 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000837 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000838 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000839 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
840 if (!CE) return false;
841 int64_t Value = CE->getValue();
842 return Value >= 0 && Value < 33;
843 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000844 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000845 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000846 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
847 if (!CE) return false;
848 int64_t Value = CE->getValue();
849 return Value >= 0 && Value < 65536;
850 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000851 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000852 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
854 // If it's not a constant expression, it'll generate a fixup and be
855 // handled later.
856 if (!CE) return true;
857 int64_t Value = CE->getValue();
858 return Value >= 0 && Value < 65536;
859 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000860 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000861 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
863 if (!CE) return false;
864 int64_t Value = CE->getValue();
865 return Value >= 0 && Value <= 0xffffff;
866 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000867 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000868 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
870 if (!CE) return false;
871 int64_t Value = CE->getValue();
872 return Value > 0 && Value < 33;
873 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000874 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000875 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
877 if (!CE) return false;
878 int64_t Value = CE->getValue();
879 return Value >= 0 && Value < 32;
880 }
881 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000882 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
884 if (!CE) return false;
885 int64_t Value = CE->getValue();
886 return Value > 0 && Value <= 32;
887 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000888 bool isAdrLabel() const {
889 // If we have an immediate that's not a constant, treat it as a label
890 // reference needing a fixup. If it is a constant, but it can't fit
891 // into shift immediate encoding, we reject it.
892 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
893 else return (isARMSOImm() || isARMSOImmNeg());
894 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000895 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000896 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +0000897 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
898 if (!CE) return false;
899 int64_t Value = CE->getValue();
900 return ARM_AM::getSOImmVal(Value) != -1;
901 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000902 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000903 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +0000904 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
905 if (!CE) return false;
906 int64_t Value = CE->getValue();
907 return ARM_AM::getSOImmVal(~Value) != -1;
908 }
Jim Grosbach30506252011-12-08 00:31:07 +0000909 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000910 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000911 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
912 if (!CE) return false;
913 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000914 // Only use this when not representable as a plain so_imm.
915 return ARM_AM::getSOImmVal(Value) == -1 &&
916 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000917 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000918 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000919 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000920 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
921 if (!CE) return false;
922 int64_t Value = CE->getValue();
923 return ARM_AM::getT2SOImmVal(Value) != -1;
924 }
Jim Grosbachb009a872011-10-28 22:36:30 +0000925 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000926 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +0000927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
928 if (!CE) return false;
929 int64_t Value = CE->getValue();
930 return ARM_AM::getT2SOImmVal(~Value) != -1;
931 }
Jim Grosbach30506252011-12-08 00:31:07 +0000932 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000933 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +0000934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
935 if (!CE) return false;
936 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +0000937 // Only use this when not representable as a plain so_imm.
938 return ARM_AM::getT2SOImmVal(Value) == -1 &&
939 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +0000940 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000941 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000942 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +0000943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
944 if (!CE) return false;
945 int64_t Value = CE->getValue();
946 return Value == 1 || Value == 0;
947 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000948 bool isReg() const { return Kind == k_Register; }
949 bool isRegList() const { return Kind == k_RegisterList; }
950 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
951 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
952 bool isToken() const { return Kind == k_Token; }
953 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000954 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +0000955 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000956 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
957 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
958 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
959 bool isRotImm() const { return Kind == k_RotateImmediate; }
960 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
961 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +0000962 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +0000963 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +0000964 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000965 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +0000966 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000967 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000968 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +0000969 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
970 (alignOK || Memory.Alignment == 0);
971 }
Jim Grosbach94298a92012-01-18 22:46:46 +0000972 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +0000973 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +0000974 return false;
975 // Base register must be PC.
976 if (Memory.BaseRegNum != ARM::PC)
977 return false;
978 // Immediate offset in range [-4095, 4095].
979 if (!Memory.OffsetImm) return true;
980 int64_t Val = Memory.OffsetImm->getValue();
981 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
982 }
Jim Grosbacha95ec992011-10-11 17:29:55 +0000983 bool isAlignedMemory() const {
984 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000985 }
Jim Grosbachd3595712011-08-03 23:50:40 +0000986 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +0000987 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +0000988 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +0000989 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +0000990 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +0000991 if (!Memory.OffsetImm) return true;
992 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +0000993 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000994 }
Jim Grosbachcd17c122011-08-04 23:01:30 +0000995 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000996 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +0000997 // Immediate offset in range [-4095, 4095].
998 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
999 if (!CE) return false;
1000 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001001 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001002 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001003 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001004 // If we have an immediate that's not a constant, treat it as a label
1005 // reference needing a fixup. If it is a constant, it's something else
1006 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001007 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001008 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001009 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001010 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001011 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001012 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001013 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001014 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001015 if (!Memory.OffsetImm) return true;
1016 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001017 // The #-0 offset is encoded as INT32_MIN, and we have to check
1018 // for this too.
1019 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001020 }
1021 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001022 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001023 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001024 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001025 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1026 // Immediate offset in range [-255, 255].
1027 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1028 if (!CE) return false;
1029 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001030 // Special case, #-0 is INT32_MIN.
1031 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001032 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001033 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001034 // If we have an immediate that's not a constant, treat it as a label
1035 // reference needing a fixup. If it is a constant, it's something else
1036 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001037 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001038 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001039 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001040 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001041 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001042 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001043 if (!Memory.OffsetImm) return true;
1044 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001045 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001046 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001047 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001048 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001049 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001050 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001051 return false;
1052 return true;
1053 }
1054 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001055 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001056 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1057 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001058 return false;
1059 return true;
1060 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001061 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001062 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001063 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001064 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001065 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001066 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001067 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001068 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001069 return false;
1070 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001071 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001072 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001073 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001074 return false;
1075 return true;
1076 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001077 bool isMemThumbRR() const {
1078 // Thumb reg+reg addressing is simple. Just two registers, a base and
1079 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001080 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001081 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001082 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001083 return isARMLowRegister(Memory.BaseRegNum) &&
1084 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001085 }
1086 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001087 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001088 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001089 return false;
1090 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001091 if (!Memory.OffsetImm) return true;
1092 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001093 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1094 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001095 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001096 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001097 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001098 return false;
1099 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001100 if (!Memory.OffsetImm) return true;
1101 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001102 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1103 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001104 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001105 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001106 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001107 return false;
1108 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001109 if (!Memory.OffsetImm) return true;
1110 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001111 return Val >= 0 && Val <= 31;
1112 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001113 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001114 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001115 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001116 return false;
1117 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001118 if (!Memory.OffsetImm) return true;
1119 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001120 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001121 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001122 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001123 // If we have an immediate that's not a constant, treat it as a label
1124 // reference needing a fixup. If it is a constant, it's something else
1125 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001126 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001127 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001128 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001129 return false;
1130 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001131 if (!Memory.OffsetImm) return true;
1132 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001133 // Special case, #-0 is INT32_MIN.
1134 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001135 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001136 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001137 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001138 return false;
1139 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001140 if (!Memory.OffsetImm) return true;
1141 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001142 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1143 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001144 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001145 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001146 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001147 // Base reg of PC isn't allowed for these encodings.
1148 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001149 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001150 if (!Memory.OffsetImm) return true;
1151 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001152 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001153 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001154 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001155 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001156 return false;
1157 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001158 if (!Memory.OffsetImm) return true;
1159 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001160 return Val >= 0 && Val < 256;
1161 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001162 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001163 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001164 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001165 // Base reg of PC isn't allowed for these encodings.
1166 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001167 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001168 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001169 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001170 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001171 }
1172 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001173 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001174 return false;
1175 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001176 if (!Memory.OffsetImm) return true;
1177 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001178 return (Val >= 0 && Val < 4096);
1179 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001180 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001181 // If we have an immediate that's not a constant, treat it as a label
1182 // reference needing a fixup. If it is a constant, it's something else
1183 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001184 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001185 return true;
1186
Chad Rosier41099832012-09-11 23:02:35 +00001187 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001188 return false;
1189 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001190 if (!Memory.OffsetImm) return true;
1191 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001192 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001193 }
1194 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001195 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001196 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1197 if (!CE) return false;
1198 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001199 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001200 }
Jim Grosbach93981412011-10-11 21:55:36 +00001201 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001202 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001203 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1204 if (!CE) return false;
1205 int64_t Val = CE->getValue();
1206 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1207 (Val == INT32_MIN);
1208 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001209
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001210 bool isMSRMask() const { return Kind == k_MSRMask; }
1211 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001212
Jim Grosbach741cd732011-10-17 22:26:03 +00001213 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001214 bool isSingleSpacedVectorList() const {
1215 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1216 }
1217 bool isDoubleSpacedVectorList() const {
1218 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1219 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001220 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001221 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001222 return VectorList.Count == 1;
1223 }
1224
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001225 bool isVecListDPair() const {
1226 if (!isSingleSpacedVectorList()) return false;
1227 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1228 .contains(VectorList.RegNum));
1229 }
1230
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001231 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001232 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001233 return VectorList.Count == 3;
1234 }
1235
Jim Grosbach846bcff2011-10-21 20:35:01 +00001236 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001237 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001238 return VectorList.Count == 4;
1239 }
1240
Jim Grosbache5307f92012-03-05 21:43:40 +00001241 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001242 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001243 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1244 .contains(VectorList.RegNum));
1245 }
1246
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001247 bool isVecListThreeQ() const {
1248 if (!isDoubleSpacedVectorList()) return false;
1249 return VectorList.Count == 3;
1250 }
1251
Jim Grosbach1e946a42012-01-24 00:43:12 +00001252 bool isVecListFourQ() const {
1253 if (!isDoubleSpacedVectorList()) return false;
1254 return VectorList.Count == 4;
1255 }
1256
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001257 bool isSingleSpacedVectorAllLanes() const {
1258 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1259 }
1260 bool isDoubleSpacedVectorAllLanes() const {
1261 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1262 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001263 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001264 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001265 return VectorList.Count == 1;
1266 }
1267
Jim Grosbach13a292c2012-03-06 22:01:44 +00001268 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001269 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001270 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1271 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001272 }
1273
Jim Grosbached428bc2012-03-06 23:10:38 +00001274 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001275 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001276 return VectorList.Count == 2;
1277 }
1278
Jim Grosbachb78403c2012-01-24 23:47:04 +00001279 bool isVecListThreeDAllLanes() const {
1280 if (!isSingleSpacedVectorAllLanes()) return false;
1281 return VectorList.Count == 3;
1282 }
1283
1284 bool isVecListThreeQAllLanes() const {
1285 if (!isDoubleSpacedVectorAllLanes()) return false;
1286 return VectorList.Count == 3;
1287 }
1288
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001289 bool isVecListFourDAllLanes() const {
1290 if (!isSingleSpacedVectorAllLanes()) return false;
1291 return VectorList.Count == 4;
1292 }
1293
1294 bool isVecListFourQAllLanes() const {
1295 if (!isDoubleSpacedVectorAllLanes()) return false;
1296 return VectorList.Count == 4;
1297 }
1298
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001299 bool isSingleSpacedVectorIndexed() const {
1300 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1301 }
1302 bool isDoubleSpacedVectorIndexed() const {
1303 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1304 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001305 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001306 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001307 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1308 }
1309
Jim Grosbachda511042011-12-14 23:35:06 +00001310 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001311 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001312 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1313 }
1314
1315 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001316 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001317 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1318 }
1319
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001320 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001321 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001322 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1323 }
1324
Jim Grosbachda511042011-12-14 23:35:06 +00001325 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001326 if (!isSingleSpacedVectorIndexed()) return false;
1327 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1328 }
1329
1330 bool isVecListTwoQWordIndexed() const {
1331 if (!isDoubleSpacedVectorIndexed()) return false;
1332 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1333 }
1334
1335 bool isVecListTwoQHWordIndexed() const {
1336 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001337 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1338 }
1339
1340 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001341 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001342 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1343 }
1344
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001345 bool isVecListThreeDByteIndexed() const {
1346 if (!isSingleSpacedVectorIndexed()) return false;
1347 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1348 }
1349
1350 bool isVecListThreeDHWordIndexed() const {
1351 if (!isSingleSpacedVectorIndexed()) return false;
1352 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1353 }
1354
1355 bool isVecListThreeQWordIndexed() const {
1356 if (!isDoubleSpacedVectorIndexed()) return false;
1357 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1358 }
1359
1360 bool isVecListThreeQHWordIndexed() const {
1361 if (!isDoubleSpacedVectorIndexed()) return false;
1362 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1363 }
1364
1365 bool isVecListThreeDWordIndexed() const {
1366 if (!isSingleSpacedVectorIndexed()) return false;
1367 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1368 }
1369
Jim Grosbach14952a02012-01-24 18:37:25 +00001370 bool isVecListFourDByteIndexed() const {
1371 if (!isSingleSpacedVectorIndexed()) return false;
1372 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1373 }
1374
1375 bool isVecListFourDHWordIndexed() const {
1376 if (!isSingleSpacedVectorIndexed()) return false;
1377 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1378 }
1379
1380 bool isVecListFourQWordIndexed() const {
1381 if (!isDoubleSpacedVectorIndexed()) return false;
1382 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1383 }
1384
1385 bool isVecListFourQHWordIndexed() const {
1386 if (!isDoubleSpacedVectorIndexed()) return false;
1387 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1388 }
1389
1390 bool isVecListFourDWordIndexed() const {
1391 if (!isSingleSpacedVectorIndexed()) return false;
1392 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1393 }
1394
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001395 bool isVectorIndex8() const {
1396 if (Kind != k_VectorIndex) return false;
1397 return VectorIndex.Val < 8;
1398 }
1399 bool isVectorIndex16() const {
1400 if (Kind != k_VectorIndex) return false;
1401 return VectorIndex.Val < 4;
1402 }
1403 bool isVectorIndex32() const {
1404 if (Kind != k_VectorIndex) return false;
1405 return VectorIndex.Val < 2;
1406 }
1407
Jim Grosbach741cd732011-10-17 22:26:03 +00001408 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001409 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001410 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1411 // Must be a constant.
1412 if (!CE) return false;
1413 int64_t Value = CE->getValue();
1414 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1415 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001416 return Value >= 0 && Value < 256;
1417 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001418
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001419 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001420 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001421 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1422 // Must be a constant.
1423 if (!CE) return false;
1424 int64_t Value = CE->getValue();
1425 // i16 value in the range [0,255] or [0x0100, 0xff00]
1426 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1427 }
1428
Jim Grosbach8211c052011-10-18 00:22:00 +00001429 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001430 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001431 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1432 // Must be a constant.
1433 if (!CE) return false;
1434 int64_t Value = CE->getValue();
1435 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1436 return (Value >= 0 && Value < 256) ||
1437 (Value >= 0x0100 && Value <= 0xff00) ||
1438 (Value >= 0x010000 && Value <= 0xff0000) ||
1439 (Value >= 0x01000000 && Value <= 0xff000000);
1440 }
1441
1442 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001443 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001444 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1445 // Must be a constant.
1446 if (!CE) return false;
1447 int64_t Value = CE->getValue();
1448 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1449 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1450 return (Value >= 0 && Value < 256) ||
1451 (Value >= 0x0100 && Value <= 0xff00) ||
1452 (Value >= 0x010000 && Value <= 0xff0000) ||
1453 (Value >= 0x01000000 && Value <= 0xff000000) ||
1454 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1455 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1456 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001457 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001458 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001459 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1460 // Must be a constant.
1461 if (!CE) return false;
1462 int64_t Value = ~CE->getValue();
1463 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1464 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1465 return (Value >= 0 && Value < 256) ||
1466 (Value >= 0x0100 && Value <= 0xff00) ||
1467 (Value >= 0x010000 && Value <= 0xff0000) ||
1468 (Value >= 0x01000000 && Value <= 0xff000000) ||
1469 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1470 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1471 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001472
Jim Grosbache4454e02011-10-18 16:18:11 +00001473 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001474 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001475 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1476 // Must be a constant.
1477 if (!CE) return false;
1478 uint64_t Value = CE->getValue();
1479 // i64 value with each byte being either 0 or 0xff.
1480 for (unsigned i = 0; i < 8; ++i)
1481 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1482 return true;
1483 }
1484
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001485 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001486 // Add as immediates when possible. Null MCExpr = 0.
1487 if (Expr == 0)
1488 Inst.addOperand(MCOperand::CreateImm(0));
1489 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001490 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1491 else
1492 Inst.addOperand(MCOperand::CreateExpr(Expr));
1493 }
1494
Daniel Dunbard8042b72010-08-11 06:36:53 +00001495 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001496 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001497 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001498 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1499 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001500 }
1501
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001502 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1503 assert(N == 1 && "Invalid number of operands!");
1504 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1505 }
1506
Jim Grosbach48399582011-10-12 17:34:41 +00001507 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1508 assert(N == 1 && "Invalid number of operands!");
1509 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1510 }
1511
1512 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1513 assert(N == 1 && "Invalid number of operands!");
1514 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1515 }
1516
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001517 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1518 assert(N == 1 && "Invalid number of operands!");
1519 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1520 }
1521
1522 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1523 assert(N == 1 && "Invalid number of operands!");
1524 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1525 }
1526
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001527 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1528 assert(N == 1 && "Invalid number of operands!");
1529 Inst.addOperand(MCOperand::CreateReg(getReg()));
1530 }
1531
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001532 void addRegOperands(MCInst &Inst, unsigned N) const {
1533 assert(N == 1 && "Invalid number of operands!");
1534 Inst.addOperand(MCOperand::CreateReg(getReg()));
1535 }
1536
Jim Grosbachac798e12011-07-25 20:49:51 +00001537 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001538 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001539 assert(isRegShiftedReg() &&
1540 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001541 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1542 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001543 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001544 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001545 }
1546
Jim Grosbachac798e12011-07-25 20:49:51 +00001547 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001548 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001549 assert(isRegShiftedImm() &&
1550 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001551 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001552 // Shift of #32 is encoded as 0 where permitted
1553 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001554 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001555 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001556 }
1557
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001558 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001559 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001560 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1561 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001562 }
1563
Bill Wendling8d2aa032010-11-08 23:49:57 +00001564 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001565 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001566 const SmallVectorImpl<unsigned> &RegList = getRegList();
1567 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001568 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1569 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001570 }
1571
Bill Wendling9898ac92010-11-17 04:32:08 +00001572 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1573 addRegListOperands(Inst, N);
1574 }
1575
1576 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1577 addRegListOperands(Inst, N);
1578 }
1579
Jim Grosbach833b9d32011-07-27 20:15:40 +00001580 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1581 assert(N == 1 && "Invalid number of operands!");
1582 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1583 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1584 }
1585
Jim Grosbach864b6092011-07-28 21:34:26 +00001586 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1587 assert(N == 1 && "Invalid number of operands!");
1588 // Munge the lsb/width into a bitfield mask.
1589 unsigned lsb = Bitfield.LSB;
1590 unsigned width = Bitfield.Width;
1591 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1592 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1593 (32 - (lsb + width)));
1594 Inst.addOperand(MCOperand::CreateImm(Mask));
1595 }
1596
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001597 void addImmOperands(MCInst &Inst, unsigned N) const {
1598 assert(N == 1 && "Invalid number of operands!");
1599 addExpr(Inst, getImm());
1600 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001601
Jim Grosbachea231912011-12-22 22:19:05 +00001602 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1603 assert(N == 1 && "Invalid number of operands!");
1604 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1605 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1606 }
1607
1608 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1609 assert(N == 1 && "Invalid number of operands!");
1610 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1611 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1612 }
1613
Jim Grosbache7fbce72011-10-03 23:38:36 +00001614 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1615 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001616 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1617 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1618 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001619 }
1620
Jim Grosbach7db8d692011-09-08 22:07:06 +00001621 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1622 assert(N == 1 && "Invalid number of operands!");
1623 // FIXME: We really want to scale the value here, but the LDRD/STRD
1624 // instruction don't encode operands that way yet.
1625 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1626 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1627 }
1628
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001629 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1630 assert(N == 1 && "Invalid number of operands!");
1631 // The immediate is scaled by four in the encoding and is stored
1632 // in the MCInst as such. Lop off the low two bits here.
1633 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1634 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1635 }
1636
Jim Grosbach930f2f62012-04-05 20:57:13 +00001637 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1638 assert(N == 1 && "Invalid number of operands!");
1639 // The immediate is scaled by four in the encoding and is stored
1640 // in the MCInst as such. Lop off the low two bits here.
1641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1642 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1643 }
1644
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001645 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1646 assert(N == 1 && "Invalid number of operands!");
1647 // The immediate is scaled by four in the encoding and is stored
1648 // in the MCInst as such. Lop off the low two bits here.
1649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1650 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1651 }
1652
Jim Grosbach475c6db2011-07-25 23:09:14 +00001653 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1654 assert(N == 1 && "Invalid number of operands!");
1655 // The constant encodes as the immediate-1, and we store in the instruction
1656 // the bits as encoded, so subtract off one here.
1657 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1658 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1659 }
1660
Jim Grosbach801e0a32011-07-22 23:16:18 +00001661 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1662 assert(N == 1 && "Invalid number of operands!");
1663 // The constant encodes as the immediate-1, and we store in the instruction
1664 // the bits as encoded, so subtract off one here.
1665 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1666 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1667 }
1668
Jim Grosbach46dd4132011-08-17 21:51:27 +00001669 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1670 assert(N == 1 && "Invalid number of operands!");
1671 // The constant encodes as the immediate, except for 32, which encodes as
1672 // zero.
1673 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1674 unsigned Imm = CE->getValue();
1675 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1676 }
1677
Jim Grosbach27c1e252011-07-21 17:23:04 +00001678 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1679 assert(N == 1 && "Invalid number of operands!");
1680 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1681 // the instruction as well.
1682 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1683 int Val = CE->getValue();
1684 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1685 }
1686
Jim Grosbachb009a872011-10-28 22:36:30 +00001687 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1688 assert(N == 1 && "Invalid number of operands!");
1689 // The operand is actually a t2_so_imm, but we have its bitwise
1690 // negation in the assembly source, so twiddle it here.
1691 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1692 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1693 }
1694
Jim Grosbach30506252011-12-08 00:31:07 +00001695 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1696 assert(N == 1 && "Invalid number of operands!");
1697 // The operand is actually a t2_so_imm, but we have its
1698 // negation in the assembly source, so twiddle it here.
1699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1700 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1701 }
1702
Jim Grosbach930f2f62012-04-05 20:57:13 +00001703 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1704 assert(N == 1 && "Invalid number of operands!");
1705 // The operand is actually an imm0_4095, but we have its
1706 // negation in the assembly source, so twiddle it here.
1707 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1708 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1709 }
1710
Mihai Popad36cbaa2013-07-03 09:21:44 +00001711 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1712 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1713 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1714 return;
1715 }
1716
1717 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1718 assert(SR && "Unknown value type!");
1719 Inst.addOperand(MCOperand::CreateExpr(SR));
1720 }
1721
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001722 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1723 assert(N == 1 && "Invalid number of operands!");
1724 if (isImm()) {
1725 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1726 if (CE) {
1727 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1728 return;
1729 }
1730
1731 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1732 assert(SR && "Unknown value type!");
1733 Inst.addOperand(MCOperand::CreateExpr(SR));
1734 return;
1735 }
1736
1737 assert(isMem() && "Unknown value type!");
1738 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1739 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1740 }
1741
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001742 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1743 assert(N == 1 && "Invalid number of operands!");
1744 // The operand is actually a so_imm, but we have its bitwise
1745 // negation in the assembly source, so twiddle it here.
1746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1747 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1748 }
1749
Jim Grosbach30506252011-12-08 00:31:07 +00001750 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1751 assert(N == 1 && "Invalid number of operands!");
1752 // The operand is actually a so_imm, but we have its
1753 // negation in the assembly source, so twiddle it here.
1754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1755 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1756 }
1757
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001758 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1759 assert(N == 1 && "Invalid number of operands!");
1760 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1761 }
1762
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001763 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1764 assert(N == 1 && "Invalid number of operands!");
1765 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1766 }
1767
Jim Grosbachd3595712011-08-03 23:50:40 +00001768 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1769 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001770 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001771 }
1772
Jim Grosbach94298a92012-01-18 22:46:46 +00001773 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1774 assert(N == 1 && "Invalid number of operands!");
1775 int32_t Imm = Memory.OffsetImm->getValue();
1776 // FIXME: Handle #-0
1777 if (Imm == INT32_MIN) Imm = 0;
1778 Inst.addOperand(MCOperand::CreateImm(Imm));
1779 }
1780
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001781 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1782 assert(N == 1 && "Invalid number of operands!");
1783 assert(isImm() && "Not an immediate!");
1784
1785 // If we have an immediate that's not a constant, treat it as a label
1786 // reference needing a fixup.
1787 if (!isa<MCConstantExpr>(getImm())) {
1788 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1789 return;
1790 }
1791
1792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1793 int Val = CE->getValue();
1794 Inst.addOperand(MCOperand::CreateImm(Val));
1795 }
1796
Jim Grosbacha95ec992011-10-11 17:29:55 +00001797 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1798 assert(N == 2 && "Invalid number of operands!");
1799 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1800 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1801 }
1802
Jim Grosbachd3595712011-08-03 23:50:40 +00001803 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1804 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001805 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1806 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001807 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1808 // Special case for #-0
1809 if (Val == INT32_MIN) Val = 0;
1810 if (Val < 0) Val = -Val;
1811 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1812 } else {
1813 // For register offset, we encode the shift type and negation flag
1814 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001815 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1816 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001817 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001818 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1819 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001820 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001821 }
1822
Jim Grosbachcd17c122011-08-04 23:01:30 +00001823 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1824 assert(N == 2 && "Invalid number of operands!");
1825 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1826 assert(CE && "non-constant AM2OffsetImm operand!");
1827 int32_t Val = CE->getValue();
1828 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1829 // Special case for #-0
1830 if (Val == INT32_MIN) Val = 0;
1831 if (Val < 0) Val = -Val;
1832 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1833 Inst.addOperand(MCOperand::CreateReg(0));
1834 Inst.addOperand(MCOperand::CreateImm(Val));
1835 }
1836
Jim Grosbach5b96b802011-08-10 20:29:19 +00001837 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1838 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001839 // If we have an immediate that's not a constant, treat it as a label
1840 // reference needing a fixup. If it is a constant, it's something else
1841 // and we reject it.
1842 if (isImm()) {
1843 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1844 Inst.addOperand(MCOperand::CreateReg(0));
1845 Inst.addOperand(MCOperand::CreateImm(0));
1846 return;
1847 }
1848
Jim Grosbach871dff72011-10-11 15:59:20 +00001849 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1850 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001851 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1852 // Special case for #-0
1853 if (Val == INT32_MIN) Val = 0;
1854 if (Val < 0) Val = -Val;
1855 Val = ARM_AM::getAM3Opc(AddSub, Val);
1856 } else {
1857 // For register offset, we encode the shift type and negation flag
1858 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001859 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001860 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001861 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1862 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001863 Inst.addOperand(MCOperand::CreateImm(Val));
1864 }
1865
1866 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1867 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001868 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001869 int32_t Val =
1870 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1871 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1872 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001873 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001874 }
1875
1876 // Constant offset.
1877 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1878 int32_t Val = CE->getValue();
1879 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1880 // Special case for #-0
1881 if (Val == INT32_MIN) Val = 0;
1882 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001883 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001884 Inst.addOperand(MCOperand::CreateReg(0));
1885 Inst.addOperand(MCOperand::CreateImm(Val));
1886 }
1887
Jim Grosbachd3595712011-08-03 23:50:40 +00001888 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1889 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001890 // If we have an immediate that's not a constant, treat it as a label
1891 // reference needing a fixup. If it is a constant, it's something else
1892 // and we reject it.
1893 if (isImm()) {
1894 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1895 Inst.addOperand(MCOperand::CreateImm(0));
1896 return;
1897 }
1898
Jim Grosbachd3595712011-08-03 23:50:40 +00001899 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001900 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00001901 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1902 // Special case for #-0
1903 if (Val == INT32_MIN) Val = 0;
1904 if (Val < 0) Val = -Val;
1905 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00001906 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001907 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001908 }
1909
Jim Grosbach7db8d692011-09-08 22:07:06 +00001910 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1911 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001912 // If we have an immediate that's not a constant, treat it as a label
1913 // reference needing a fixup. If it is a constant, it's something else
1914 // and we reject it.
1915 if (isImm()) {
1916 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1917 Inst.addOperand(MCOperand::CreateImm(0));
1918 return;
1919 }
1920
Jim Grosbach871dff72011-10-11 15:59:20 +00001921 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1922 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00001923 Inst.addOperand(MCOperand::CreateImm(Val));
1924 }
1925
Jim Grosbacha05627e2011-09-09 18:37:27 +00001926 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1927 assert(N == 2 && "Invalid number of operands!");
1928 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00001929 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1930 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00001931 Inst.addOperand(MCOperand::CreateImm(Val));
1932 }
1933
Jim Grosbachd3595712011-08-03 23:50:40 +00001934 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1935 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001936 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1937 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001938 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001939 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001940
Jim Grosbach2392c532011-09-07 23:39:14 +00001941 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1942 addMemImm8OffsetOperands(Inst, N);
1943 }
1944
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001945 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00001946 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001947 }
1948
1949 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1950 assert(N == 2 && "Invalid number of operands!");
1951 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001952 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001953 addExpr(Inst, getImm());
1954 Inst.addOperand(MCOperand::CreateImm(0));
1955 return;
1956 }
1957
1958 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001959 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1960 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001961 Inst.addOperand(MCOperand::CreateImm(Val));
1962 }
1963
Jim Grosbachd3595712011-08-03 23:50:40 +00001964 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1965 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00001966 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001967 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001968 addExpr(Inst, getImm());
1969 Inst.addOperand(MCOperand::CreateImm(0));
1970 return;
1971 }
1972
1973 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001974 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1975 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001976 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00001977 }
Bill Wendling811c9362010-11-30 07:44:32 +00001978
Jim Grosbach05541f42011-09-19 22:21:13 +00001979 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1980 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001981 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1982 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001983 }
1984
1985 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1986 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001987 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1988 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00001989 }
1990
Jim Grosbachd3595712011-08-03 23:50:40 +00001991 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1992 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001993 unsigned Val =
1994 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1995 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00001996 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1997 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001998 Inst.addOperand(MCOperand::CreateImm(Val));
1999 }
2000
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002001 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2002 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002003 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2004 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2005 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002006 }
2007
Jim Grosbachd3595712011-08-03 23:50:40 +00002008 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2009 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002010 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2011 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002012 }
2013
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002014 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2015 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002016 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2017 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002018 Inst.addOperand(MCOperand::CreateImm(Val));
2019 }
2020
Jim Grosbach26d35872011-08-19 18:55:51 +00002021 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2022 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002023 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2024 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002025 Inst.addOperand(MCOperand::CreateImm(Val));
2026 }
2027
Jim Grosbacha32c7532011-08-19 18:49:59 +00002028 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2029 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002030 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2031 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002032 Inst.addOperand(MCOperand::CreateImm(Val));
2033 }
2034
Jim Grosbach23983d62011-08-19 18:13:48 +00002035 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2036 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002037 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2038 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002039 Inst.addOperand(MCOperand::CreateImm(Val));
2040 }
2041
Jim Grosbachd3595712011-08-03 23:50:40 +00002042 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2043 assert(N == 1 && "Invalid number of operands!");
2044 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2045 assert(CE && "non-constant post-idx-imm8 operand!");
2046 int Imm = CE->getValue();
2047 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002048 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002049 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2050 Inst.addOperand(MCOperand::CreateImm(Imm));
2051 }
2052
Jim Grosbach93981412011-10-11 21:55:36 +00002053 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2054 assert(N == 1 && "Invalid number of operands!");
2055 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2056 assert(CE && "non-constant post-idx-imm8s4 operand!");
2057 int Imm = CE->getValue();
2058 bool isAdd = Imm >= 0;
2059 if (Imm == INT32_MIN) Imm = 0;
2060 // Immediate is scaled by 4.
2061 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2062 Inst.addOperand(MCOperand::CreateImm(Imm));
2063 }
2064
Jim Grosbachd3595712011-08-03 23:50:40 +00002065 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2066 assert(N == 2 && "Invalid number of operands!");
2067 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002068 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2069 }
2070
2071 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2072 assert(N == 2 && "Invalid number of operands!");
2073 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2074 // The sign, shift type, and shift amount are encoded in a single operand
2075 // using the AM2 encoding helpers.
2076 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2077 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2078 PostIdxReg.ShiftTy);
2079 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002080 }
2081
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002082 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2083 assert(N == 1 && "Invalid number of operands!");
2084 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2085 }
2086
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002087 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2088 assert(N == 1 && "Invalid number of operands!");
2089 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2090 }
2091
Jim Grosbach182b6a02011-11-29 23:51:09 +00002092 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002093 assert(N == 1 && "Invalid number of operands!");
2094 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2095 }
2096
Jim Grosbach04945c42011-12-02 00:35:16 +00002097 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2098 assert(N == 2 && "Invalid number of operands!");
2099 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2100 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2101 }
2102
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002103 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2104 assert(N == 1 && "Invalid number of operands!");
2105 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2106 }
2107
2108 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2109 assert(N == 1 && "Invalid number of operands!");
2110 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2111 }
2112
2113 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2114 assert(N == 1 && "Invalid number of operands!");
2115 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2116 }
2117
Jim Grosbach741cd732011-10-17 22:26:03 +00002118 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2119 assert(N == 1 && "Invalid number of operands!");
2120 // The immediate encodes the type of constant as well as the value.
2121 // Mask in that this is an i8 splat.
2122 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2123 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2124 }
2125
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002126 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2127 assert(N == 1 && "Invalid number of operands!");
2128 // The immediate encodes the type of constant as well as the value.
2129 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2130 unsigned Value = CE->getValue();
2131 if (Value >= 256)
2132 Value = (Value >> 8) | 0xa00;
2133 else
2134 Value |= 0x800;
2135 Inst.addOperand(MCOperand::CreateImm(Value));
2136 }
2137
Jim Grosbach8211c052011-10-18 00:22:00 +00002138 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2139 assert(N == 1 && "Invalid number of operands!");
2140 // The immediate encodes the type of constant as well as the value.
2141 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2142 unsigned Value = CE->getValue();
2143 if (Value >= 256 && Value <= 0xff00)
2144 Value = (Value >> 8) | 0x200;
2145 else if (Value > 0xffff && Value <= 0xff0000)
2146 Value = (Value >> 16) | 0x400;
2147 else if (Value > 0xffffff)
2148 Value = (Value >> 24) | 0x600;
2149 Inst.addOperand(MCOperand::CreateImm(Value));
2150 }
2151
2152 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2153 assert(N == 1 && "Invalid number of operands!");
2154 // The immediate encodes the type of constant as well as the value.
2155 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2156 unsigned Value = CE->getValue();
2157 if (Value >= 256 && Value <= 0xffff)
2158 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2159 else if (Value > 0xffff && Value <= 0xffffff)
2160 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2161 else if (Value > 0xffffff)
2162 Value = (Value >> 24) | 0x600;
2163 Inst.addOperand(MCOperand::CreateImm(Value));
2164 }
2165
Jim Grosbach045b6c72011-12-19 23:51:07 +00002166 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2167 assert(N == 1 && "Invalid number of operands!");
2168 // The immediate encodes the type of constant as well as the value.
2169 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2170 unsigned Value = ~CE->getValue();
2171 if (Value >= 256 && Value <= 0xffff)
2172 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2173 else if (Value > 0xffff && Value <= 0xffffff)
2174 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2175 else if (Value > 0xffffff)
2176 Value = (Value >> 24) | 0x600;
2177 Inst.addOperand(MCOperand::CreateImm(Value));
2178 }
2179
Jim Grosbache4454e02011-10-18 16:18:11 +00002180 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2181 assert(N == 1 && "Invalid number of operands!");
2182 // The immediate encodes the type of constant as well as the value.
2183 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2184 uint64_t Value = CE->getValue();
2185 unsigned Imm = 0;
2186 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2187 Imm |= (Value & 1) << i;
2188 }
2189 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2190 }
2191
Jim Grosbach602aa902011-07-13 15:34:57 +00002192 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002193
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002194 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002195 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002196 Op->ITMask.Mask = Mask;
2197 Op->StartLoc = S;
2198 Op->EndLoc = S;
2199 return Op;
2200 }
2201
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002202 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002203 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002204 Op->CC.Val = CC;
2205 Op->StartLoc = S;
2206 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002207 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002208 }
2209
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002210 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002211 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002212 Op->Cop.Val = CopVal;
2213 Op->StartLoc = S;
2214 Op->EndLoc = S;
2215 return Op;
2216 }
2217
2218 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002219 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002220 Op->Cop.Val = CopVal;
2221 Op->StartLoc = S;
2222 Op->EndLoc = S;
2223 return Op;
2224 }
2225
Jim Grosbach48399582011-10-12 17:34:41 +00002226 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2227 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2228 Op->Cop.Val = Val;
2229 Op->StartLoc = S;
2230 Op->EndLoc = E;
2231 return Op;
2232 }
2233
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002234 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002235 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002236 Op->Reg.RegNum = RegNum;
2237 Op->StartLoc = S;
2238 Op->EndLoc = S;
2239 return Op;
2240 }
2241
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002242 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002243 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002244 Op->Tok.Data = Str.data();
2245 Op->Tok.Length = Str.size();
2246 Op->StartLoc = S;
2247 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002248 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002249 }
2250
Bill Wendling2063b842010-11-18 23:43:05 +00002251 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002252 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002253 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002254 Op->StartLoc = S;
2255 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002256 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002257 }
2258
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002259 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2260 unsigned SrcReg,
2261 unsigned ShiftReg,
2262 unsigned ShiftImm,
2263 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002264 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002265 Op->RegShiftedReg.ShiftTy = ShTy;
2266 Op->RegShiftedReg.SrcReg = SrcReg;
2267 Op->RegShiftedReg.ShiftReg = ShiftReg;
2268 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002269 Op->StartLoc = S;
2270 Op->EndLoc = E;
2271 return Op;
2272 }
2273
Owen Andersonb595ed02011-07-21 18:54:16 +00002274 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2275 unsigned SrcReg,
2276 unsigned ShiftImm,
2277 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002278 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002279 Op->RegShiftedImm.ShiftTy = ShTy;
2280 Op->RegShiftedImm.SrcReg = SrcReg;
2281 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002282 Op->StartLoc = S;
2283 Op->EndLoc = E;
2284 return Op;
2285 }
2286
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002287 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002288 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002289 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002290 Op->ShifterImm.isASR = isASR;
2291 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002292 Op->StartLoc = S;
2293 Op->EndLoc = E;
2294 return Op;
2295 }
2296
Jim Grosbach833b9d32011-07-27 20:15:40 +00002297 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002298 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002299 Op->RotImm.Imm = Imm;
2300 Op->StartLoc = S;
2301 Op->EndLoc = E;
2302 return Op;
2303 }
2304
Jim Grosbach864b6092011-07-28 21:34:26 +00002305 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2306 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002307 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002308 Op->Bitfield.LSB = LSB;
2309 Op->Bitfield.Width = Width;
2310 Op->StartLoc = S;
2311 Op->EndLoc = E;
2312 return Op;
2313 }
2314
Bill Wendling2cae3272010-11-09 22:44:22 +00002315 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002316 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002317 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002318 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002319 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002320
Chad Rosierfa705ee2013-07-01 20:49:23 +00002321 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002322 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002323 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002324 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002325 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002326
Chad Rosierfa705ee2013-07-01 20:49:23 +00002327 // Sort based on the register encoding values.
2328 array_pod_sort(Regs.begin(), Regs.end());
2329
Bill Wendling9898ac92010-11-17 04:32:08 +00002330 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002331 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002332 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002333 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002334 Op->StartLoc = StartLoc;
2335 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002336 return Op;
2337 }
2338
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002339 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002340 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002341 ARMOperand *Op = new ARMOperand(k_VectorList);
2342 Op->VectorList.RegNum = RegNum;
2343 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002344 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002345 Op->StartLoc = S;
2346 Op->EndLoc = E;
2347 return Op;
2348 }
2349
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002350 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002351 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002352 SMLoc S, SMLoc E) {
2353 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2354 Op->VectorList.RegNum = RegNum;
2355 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002356 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002357 Op->StartLoc = S;
2358 Op->EndLoc = E;
2359 return Op;
2360 }
2361
Jim Grosbach04945c42011-12-02 00:35:16 +00002362 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002363 unsigned Index,
2364 bool isDoubleSpaced,
2365 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002366 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2367 Op->VectorList.RegNum = RegNum;
2368 Op->VectorList.Count = Count;
2369 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002370 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002371 Op->StartLoc = S;
2372 Op->EndLoc = E;
2373 return Op;
2374 }
2375
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002376 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2377 MCContext &Ctx) {
2378 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2379 Op->VectorIndex.Val = Idx;
2380 Op->StartLoc = S;
2381 Op->EndLoc = E;
2382 return Op;
2383 }
2384
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002385 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002386 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002387 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002388 Op->StartLoc = S;
2389 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002390 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002391 }
2392
Jim Grosbachd3595712011-08-03 23:50:40 +00002393 static ARMOperand *CreateMem(unsigned BaseRegNum,
2394 const MCConstantExpr *OffsetImm,
2395 unsigned OffsetRegNum,
2396 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002397 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002398 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002399 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002400 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002401 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002402 Op->Memory.BaseRegNum = BaseRegNum;
2403 Op->Memory.OffsetImm = OffsetImm;
2404 Op->Memory.OffsetRegNum = OffsetRegNum;
2405 Op->Memory.ShiftType = ShiftType;
2406 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002407 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002408 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002409 Op->StartLoc = S;
2410 Op->EndLoc = E;
2411 return Op;
2412 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002413
Jim Grosbachc320c852011-08-05 21:28:30 +00002414 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2415 ARM_AM::ShiftOpc ShiftTy,
2416 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002417 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002418 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002419 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002420 Op->PostIdxReg.isAdd = isAdd;
2421 Op->PostIdxReg.ShiftTy = ShiftTy;
2422 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002423 Op->StartLoc = S;
2424 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002425 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002426 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002427
2428 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002429 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002430 Op->MBOpt.Val = Opt;
2431 Op->StartLoc = S;
2432 Op->EndLoc = S;
2433 return Op;
2434 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002435
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002436 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2437 SMLoc S) {
2438 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2439 Op->ISBOpt.Val = Opt;
2440 Op->StartLoc = S;
2441 Op->EndLoc = S;
2442 return Op;
2443 }
2444
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002445 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002446 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002447 Op->IFlags.Val = IFlags;
2448 Op->StartLoc = S;
2449 Op->EndLoc = S;
2450 return Op;
2451 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002452
2453 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002454 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002455 Op->MMask.Val = MMask;
2456 Op->StartLoc = S;
2457 Op->EndLoc = S;
2458 return Op;
2459 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002460};
2461
2462} // end anonymous namespace.
2463
Jim Grosbach602aa902011-07-13 15:34:57 +00002464void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002465 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002466 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002467 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002468 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002469 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002470 OS << "<ccout " << getReg() << ">";
2471 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002472 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002473 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002474 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2475 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2476 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002477 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2478 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2479 break;
2480 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002481 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002482 OS << "<coprocessor number: " << getCoproc() << ">";
2483 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002484 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002485 OS << "<coprocessor register: " << getCoproc() << ">";
2486 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002487 case k_CoprocOption:
2488 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2489 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002490 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002491 OS << "<mask: " << getMSRMask() << ">";
2492 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002493 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002494 getImm()->print(OS);
2495 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002496 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002497 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2498 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002499 case k_InstSyncBarrierOpt:
2500 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2501 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002502 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002503 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002504 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002505 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002506 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002507 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002508 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2509 << PostIdxReg.RegNum;
2510 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2511 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2512 << PostIdxReg.ShiftImm;
2513 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002514 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002515 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002516 OS << "<ARM_PROC::";
2517 unsigned IFlags = getProcIFlags();
2518 for (int i=2; i >= 0; --i)
2519 if (IFlags & (1 << i))
2520 OS << ARM_PROC::IFlagsToString(1 << i);
2521 OS << ">";
2522 break;
2523 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002524 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002525 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002526 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002527 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002528 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2529 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002530 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002531 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002532 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002533 << RegShiftedReg.SrcReg << " "
2534 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2535 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002536 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002537 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002538 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002539 << RegShiftedImm.SrcReg << " "
2540 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2541 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002542 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002543 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002544 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2545 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002546 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002547 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2548 << ", width: " << Bitfield.Width << ">";
2549 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002550 case k_RegisterList:
2551 case k_DPRRegisterList:
2552 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002553 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002554
Bill Wendlingbed94652010-11-09 23:28:44 +00002555 const SmallVectorImpl<unsigned> &RegList = getRegList();
2556 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002557 I = RegList.begin(), E = RegList.end(); I != E; ) {
2558 OS << *I;
2559 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002560 }
2561
2562 OS << ">";
2563 break;
2564 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002565 case k_VectorList:
2566 OS << "<vector_list " << VectorList.Count << " * "
2567 << VectorList.RegNum << ">";
2568 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002569 case k_VectorListAllLanes:
2570 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2571 << VectorList.RegNum << ">";
2572 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002573 case k_VectorListIndexed:
2574 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2575 << VectorList.Count << " * " << VectorList.RegNum << ">";
2576 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002577 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002578 OS << "'" << getToken() << "'";
2579 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002580 case k_VectorIndex:
2581 OS << "<vectorindex " << getVectorIndex() << ">";
2582 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002583 }
2584}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002585
2586/// @name Auto-generated Match Functions
2587/// {
2588
2589static unsigned MatchRegisterName(StringRef Name);
2590
2591/// }
2592
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002593bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2594 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002595 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002596 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002597 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002598
2599 return (RegNo == (unsigned)-1);
2600}
2601
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002602/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002603/// and if it is a register name the token is eaten and the register number is
2604/// returned. Otherwise return -1.
2605///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002606int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002607 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002608 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002609
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002610 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002611 unsigned RegNum = MatchRegisterName(lowerCase);
2612 if (!RegNum) {
2613 RegNum = StringSwitch<unsigned>(lowerCase)
2614 .Case("r13", ARM::SP)
2615 .Case("r14", ARM::LR)
2616 .Case("r15", ARM::PC)
2617 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002618 // Additional register name aliases for 'gas' compatibility.
2619 .Case("a1", ARM::R0)
2620 .Case("a2", ARM::R1)
2621 .Case("a3", ARM::R2)
2622 .Case("a4", ARM::R3)
2623 .Case("v1", ARM::R4)
2624 .Case("v2", ARM::R5)
2625 .Case("v3", ARM::R6)
2626 .Case("v4", ARM::R7)
2627 .Case("v5", ARM::R8)
2628 .Case("v6", ARM::R9)
2629 .Case("v7", ARM::R10)
2630 .Case("v8", ARM::R11)
2631 .Case("sb", ARM::R9)
2632 .Case("sl", ARM::R10)
2633 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002634 .Default(0);
2635 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002636 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002637 // Check for aliases registered via .req. Canonicalize to lower case.
2638 // That's more consistent since register names are case insensitive, and
2639 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2640 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002641 // If no match, return failure.
2642 if (Entry == RegisterReqs.end())
2643 return -1;
2644 Parser.Lex(); // Eat identifier token.
2645 return Entry->getValue();
2646 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002647
Chris Lattner44e5981c2010-10-30 04:09:10 +00002648 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002649
Chris Lattner44e5981c2010-10-30 04:09:10 +00002650 return RegNum;
2651}
Jim Grosbach99710a82010-11-01 16:44:21 +00002652
Jim Grosbachbb24c592011-07-13 18:49:30 +00002653// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2654// If a recoverable error occurs, return 1. If an irrecoverable error
2655// occurs, return -1. An irrecoverable error is one where tokens have been
2656// consumed in the process of trying to parse the shifter (i.e., when it is
2657// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002658int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002659 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2660 SMLoc S = Parser.getTok().getLoc();
2661 const AsmToken &Tok = Parser.getTok();
2662 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2663
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002664 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002665 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002666 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002667 .Case("lsl", ARM_AM::lsl)
2668 .Case("lsr", ARM_AM::lsr)
2669 .Case("asr", ARM_AM::asr)
2670 .Case("ror", ARM_AM::ror)
2671 .Case("rrx", ARM_AM::rrx)
2672 .Default(ARM_AM::no_shift);
2673
2674 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002675 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002676
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002677 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002678
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002679 // The source register for the shift has already been added to the
2680 // operand list, so we need to pop it off and combine it into the shifted
2681 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002682 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002683 if (!PrevOp->isReg())
2684 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2685 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002686
2687 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002688 int64_t Imm = 0;
2689 int ShiftReg = 0;
2690 if (ShiftTy == ARM_AM::rrx) {
2691 // RRX Doesn't have an explicit shift amount. The encoder expects
2692 // the shift register to be the same as the source register. Seems odd,
2693 // but OK.
2694 ShiftReg = SrcReg;
2695 } else {
2696 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002697 if (Parser.getTok().is(AsmToken::Hash) ||
2698 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002699 Parser.Lex(); // Eat hash.
2700 SMLoc ImmLoc = Parser.getTok().getLoc();
2701 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002702 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002703 Error(ImmLoc, "invalid immediate shift value");
2704 return -1;
2705 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002706 // The expression must be evaluatable as an immediate.
2707 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002708 if (!CE) {
2709 Error(ImmLoc, "invalid immediate shift value");
2710 return -1;
2711 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002712 // Range check the immediate.
2713 // lsl, ror: 0 <= imm <= 31
2714 // lsr, asr: 0 <= imm <= 32
2715 Imm = CE->getValue();
2716 if (Imm < 0 ||
2717 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2718 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002719 Error(ImmLoc, "immediate shift value out of range");
2720 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002721 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002722 // shift by zero is a nop. Always send it through as lsl.
2723 // ('as' compatibility)
2724 if (Imm == 0)
2725 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002726 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002727 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002728 EndLoc = Parser.getTok().getEndLoc();
2729 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002730 if (ShiftReg == -1) {
2731 Error (L, "expected immediate or register in shift operand");
2732 return -1;
2733 }
2734 } else {
2735 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002736 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002737 return -1;
2738 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002739 }
2740
Owen Andersonb595ed02011-07-21 18:54:16 +00002741 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2742 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002743 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002744 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002745 else
2746 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002747 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002748
Jim Grosbachbb24c592011-07-13 18:49:30 +00002749 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002750}
2751
2752
Bill Wendling2063b842010-11-18 23:43:05 +00002753/// Try to parse a register name. The token must be an Identifier when called.
2754/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2755/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002756///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002757/// TODO this is likely to change to allow different register types and or to
2758/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002759bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002760tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002761 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002762 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002763 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002764 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002765
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002766 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2767 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002768
Chris Lattner44e5981c2010-10-30 04:09:10 +00002769 const AsmToken &ExclaimTok = Parser.getTok();
2770 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002771 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2772 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002773 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002774 return false;
2775 }
2776
2777 // Also check for an index operand. This is only legal for vector registers,
2778 // but that'll get caught OK in operand matching, so we don't need to
2779 // explicitly filter everything else out here.
2780 if (Parser.getTok().is(AsmToken::LBrac)) {
2781 SMLoc SIdx = Parser.getTok().getLoc();
2782 Parser.Lex(); // Eat left bracket token.
2783
2784 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002785 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002786 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002787 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002788 if (!MCE)
2789 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002790
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002791 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002792 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002793
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002794 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002795 Parser.Lex(); // Eat right bracket token.
2796
2797 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2798 SIdx, E,
2799 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002800 }
2801
Bill Wendling2063b842010-11-18 23:43:05 +00002802 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002803}
2804
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002805/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2806/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2807/// "c5", ...
2808static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002809 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2810 // but efficient.
2811 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002812 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002813 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002814 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002815 return -1;
2816 switch (Name[1]) {
2817 default: return -1;
2818 case '0': return 0;
2819 case '1': return 1;
2820 case '2': return 2;
2821 case '3': return 3;
2822 case '4': return 4;
2823 case '5': return 5;
2824 case '6': return 6;
2825 case '7': return 7;
2826 case '8': return 8;
2827 case '9': return 9;
2828 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002829 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002830 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002831 return -1;
2832 switch (Name[2]) {
2833 default: return -1;
2834 case '0': return 10;
2835 case '1': return 11;
2836 case '2': return 12;
2837 case '3': return 13;
2838 case '4': return 14;
2839 case '5': return 15;
2840 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002841 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002842}
2843
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002844/// parseITCondCode - Try to parse a condition code for an IT instruction.
2845ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2846parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2847 SMLoc S = Parser.getTok().getLoc();
2848 const AsmToken &Tok = Parser.getTok();
2849 if (!Tok.is(AsmToken::Identifier))
2850 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002851 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002852 .Case("eq", ARMCC::EQ)
2853 .Case("ne", ARMCC::NE)
2854 .Case("hs", ARMCC::HS)
2855 .Case("cs", ARMCC::HS)
2856 .Case("lo", ARMCC::LO)
2857 .Case("cc", ARMCC::LO)
2858 .Case("mi", ARMCC::MI)
2859 .Case("pl", ARMCC::PL)
2860 .Case("vs", ARMCC::VS)
2861 .Case("vc", ARMCC::VC)
2862 .Case("hi", ARMCC::HI)
2863 .Case("ls", ARMCC::LS)
2864 .Case("ge", ARMCC::GE)
2865 .Case("lt", ARMCC::LT)
2866 .Case("gt", ARMCC::GT)
2867 .Case("le", ARMCC::LE)
2868 .Case("al", ARMCC::AL)
2869 .Default(~0U);
2870 if (CC == ~0U)
2871 return MatchOperand_NoMatch;
2872 Parser.Lex(); // Eat the token.
2873
2874 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2875
2876 return MatchOperand_Success;
2877}
2878
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002879/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002880/// token must be an Identifier when called, and if it is a coprocessor
2881/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002882ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002883parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002884 SMLoc S = Parser.getTok().getLoc();
2885 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002886 if (Tok.isNot(AsmToken::Identifier))
2887 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002888
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002889 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002890 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002891 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002892
2893 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002894 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002895 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002896}
2897
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002898/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002899/// token must be an Identifier when called, and if it is a coprocessor
2900/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00002901ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002902parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002903 SMLoc S = Parser.getTok().getLoc();
2904 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00002905 if (Tok.isNot(AsmToken::Identifier))
2906 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002907
2908 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2909 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00002910 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002911
2912 Parser.Lex(); // Eat identifier token.
2913 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00002914 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002915}
2916
Jim Grosbach48399582011-10-12 17:34:41 +00002917/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2918/// coproc_option : '{' imm0_255 '}'
2919ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2920parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2921 SMLoc S = Parser.getTok().getLoc();
2922
2923 // If this isn't a '{', this isn't a coprocessor immediate operand.
2924 if (Parser.getTok().isNot(AsmToken::LCurly))
2925 return MatchOperand_NoMatch;
2926 Parser.Lex(); // Eat the '{'
2927
2928 const MCExpr *Expr;
2929 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002930 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00002931 Error(Loc, "illegal expression");
2932 return MatchOperand_ParseFail;
2933 }
2934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2935 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2936 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2937 return MatchOperand_ParseFail;
2938 }
2939 int Val = CE->getValue();
2940
2941 // Check for and consume the closing '}'
2942 if (Parser.getTok().isNot(AsmToken::RCurly))
2943 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002944 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00002945 Parser.Lex(); // Eat the '}'
2946
2947 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2948 return MatchOperand_Success;
2949}
2950
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002951// For register list parsing, we need to map from raw GPR register numbering
2952// to the enumeration values. The enumeration values aren't sorted by
2953// register number due to our using "sp", "lr" and "pc" as canonical names.
2954static unsigned getNextRegister(unsigned Reg) {
2955 // If this is a GPR, we need to do it manually, otherwise we can rely
2956 // on the sort ordering of the enumeration since the other reg-classes
2957 // are sane.
2958 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2959 return Reg + 1;
2960 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00002961 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002962 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2963 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2964 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2965 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2966 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2967 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2968 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2969 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2970 }
2971}
2972
Jim Grosbach85a23432011-11-11 21:27:40 +00002973// Return the low-subreg of a given Q register.
2974static unsigned getDRegFromQReg(unsigned QReg) {
2975 switch (QReg) {
2976 default: llvm_unreachable("expected a Q register!");
2977 case ARM::Q0: return ARM::D0;
2978 case ARM::Q1: return ARM::D2;
2979 case ARM::Q2: return ARM::D4;
2980 case ARM::Q3: return ARM::D6;
2981 case ARM::Q4: return ARM::D8;
2982 case ARM::Q5: return ARM::D10;
2983 case ARM::Q6: return ARM::D12;
2984 case ARM::Q7: return ARM::D14;
2985 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00002986 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00002987 case ARM::Q10: return ARM::D20;
2988 case ARM::Q11: return ARM::D22;
2989 case ARM::Q12: return ARM::D24;
2990 case ARM::Q13: return ARM::D26;
2991 case ARM::Q14: return ARM::D28;
2992 case ARM::Q15: return ARM::D30;
2993 }
2994}
2995
Jim Grosbach3ac26b12011-09-14 18:08:35 +00002996/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00002997bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002998parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00002999 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003000 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003001 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003002 Parser.Lex(); // Eat '{' token.
3003 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003004
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003005 // Check the first register in the list to see what register class
3006 // this is a list of.
3007 int Reg = tryParseRegister();
3008 if (Reg == -1)
3009 return Error(RegLoc, "register expected");
3010
Jim Grosbach85a23432011-11-11 21:27:40 +00003011 // The reglist instructions have at most 16 registers, so reserve
3012 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003013 int EReg = 0;
3014 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003015
3016 // Allow Q regs and just interpret them as the two D sub-registers.
3017 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3018 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003019 EReg = MRI->getEncodingValue(Reg);
3020 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003021 ++Reg;
3022 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003023 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003024 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3025 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3026 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3027 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3028 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3029 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3030 else
3031 return Error(RegLoc, "invalid register in register list");
3032
Jim Grosbach85a23432011-11-11 21:27:40 +00003033 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003034 EReg = MRI->getEncodingValue(Reg);
3035 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003036
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003037 // This starts immediately after the first register token in the list,
3038 // so we can see either a comma or a minus (range separator) as a legal
3039 // next token.
3040 while (Parser.getTok().is(AsmToken::Comma) ||
3041 Parser.getTok().is(AsmToken::Minus)) {
3042 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003043 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003044 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003045 int EndReg = tryParseRegister();
3046 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003047 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003048 // Allow Q regs and just interpret them as the two D sub-registers.
3049 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3050 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003051 // If the register is the same as the start reg, there's nothing
3052 // more to do.
3053 if (Reg == EndReg)
3054 continue;
3055 // The register must be in the same register class as the first.
3056 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003057 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003058 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003059 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003060 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003061
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003062 // Add all the registers in the range to the register list.
3063 while (Reg != EndReg) {
3064 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003065 EReg = MRI->getEncodingValue(Reg);
3066 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003067 }
3068 continue;
3069 }
3070 Parser.Lex(); // Eat the comma.
3071 RegLoc = Parser.getTok().getLoc();
3072 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003073 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003074 Reg = tryParseRegister();
3075 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003076 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003077 // Allow Q regs and just interpret them as the two D sub-registers.
3078 bool isQReg = false;
3079 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3080 Reg = getDRegFromQReg(Reg);
3081 isQReg = true;
3082 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003083 // The register must be in the same register class as the first.
3084 if (!RC->contains(Reg))
3085 return Error(RegLoc, "invalid register in register list");
3086 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003087 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003088 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3089 Warning(RegLoc, "register list not in ascending order");
3090 else
3091 return Error(RegLoc, "register list not in ascending order");
3092 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003093 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003094 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3095 ") in register list");
3096 continue;
3097 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003098 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003099 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3100 Reg != OldReg + 1)
3101 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003102 EReg = MRI->getEncodingValue(Reg);
3103 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3104 if (isQReg) {
3105 EReg = MRI->getEncodingValue(++Reg);
3106 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3107 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003108 }
3109
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003110 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003111 return Error(Parser.getTok().getLoc(), "'}' expected");
3112 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003113 Parser.Lex(); // Eat '}' token.
3114
Jim Grosbach18bf3632011-12-13 21:48:29 +00003115 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003116 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003117
3118 // The ARM system instruction variants for LDM/STM have a '^' token here.
3119 if (Parser.getTok().is(AsmToken::Caret)) {
3120 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3121 Parser.Lex(); // Eat '^' token.
3122 }
3123
Bill Wendling2063b842010-11-18 23:43:05 +00003124 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003125}
3126
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003127// Helper function to parse the lane index for vector lists.
3128ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003129parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003130 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003131 if (Parser.getTok().is(AsmToken::LBrac)) {
3132 Parser.Lex(); // Eat the '['.
3133 if (Parser.getTok().is(AsmToken::RBrac)) {
3134 // "Dn[]" is the 'all lanes' syntax.
3135 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003136 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003137 Parser.Lex(); // Eat the ']'.
3138 return MatchOperand_Success;
3139 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003140
3141 // There's an optional '#' token here. Normally there wouldn't be, but
3142 // inline assemble puts one in, and it's friendly to accept that.
3143 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003144 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003145
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003146 const MCExpr *LaneIndex;
3147 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003148 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003149 Error(Loc, "illegal expression");
3150 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003151 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003152 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3153 if (!CE) {
3154 Error(Loc, "lane index must be empty or an integer");
3155 return MatchOperand_ParseFail;
3156 }
3157 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3158 Error(Parser.getTok().getLoc(), "']' expected");
3159 return MatchOperand_ParseFail;
3160 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003161 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003162 Parser.Lex(); // Eat the ']'.
3163 int64_t Val = CE->getValue();
3164
3165 // FIXME: Make this range check context sensitive for .8, .16, .32.
3166 if (Val < 0 || Val > 7) {
3167 Error(Parser.getTok().getLoc(), "lane index out of range");
3168 return MatchOperand_ParseFail;
3169 }
3170 Index = Val;
3171 LaneKind = IndexedLane;
3172 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003173 }
3174 LaneKind = NoLanes;
3175 return MatchOperand_Success;
3176}
3177
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003178// parse a vector register list
3179ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3180parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003181 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003182 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003183 SMLoc S = Parser.getTok().getLoc();
3184 // As an extension (to match gas), support a plain D register or Q register
3185 // (without encosing curly braces) as a single or double entry list,
3186 // respectively.
3187 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003188 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003189 int Reg = tryParseRegister();
3190 if (Reg == -1)
3191 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003192 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003193 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003194 if (Res != MatchOperand_Success)
3195 return Res;
3196 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003197 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003198 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003199 break;
3200 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003201 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3202 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003203 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003204 case IndexedLane:
3205 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003206 LaneIndex,
3207 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003208 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003209 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003210 return MatchOperand_Success;
3211 }
3212 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3213 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003214 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003215 if (Res != MatchOperand_Success)
3216 return Res;
3217 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003218 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003219 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003220 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003221 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003222 break;
3223 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003224 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3225 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003226 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3227 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003228 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003229 case IndexedLane:
3230 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003231 LaneIndex,
3232 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003233 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003234 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003235 return MatchOperand_Success;
3236 }
3237 Error(S, "vector register expected");
3238 return MatchOperand_ParseFail;
3239 }
3240
3241 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003242 return MatchOperand_NoMatch;
3243
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003244 Parser.Lex(); // Eat '{' token.
3245 SMLoc RegLoc = Parser.getTok().getLoc();
3246
3247 int Reg = tryParseRegister();
3248 if (Reg == -1) {
3249 Error(RegLoc, "register expected");
3250 return MatchOperand_ParseFail;
3251 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003252 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003253 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003254 unsigned FirstReg = Reg;
3255 // The list is of D registers, but we also allow Q regs and just interpret
3256 // them as the two D sub-registers.
3257 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3258 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003259 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3260 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003261 ++Reg;
3262 ++Count;
3263 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003264
3265 SMLoc E;
3266 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003267 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003268
Jim Grosbache891fe82011-11-15 23:19:15 +00003269 while (Parser.getTok().is(AsmToken::Comma) ||
3270 Parser.getTok().is(AsmToken::Minus)) {
3271 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003272 if (!Spacing)
3273 Spacing = 1; // Register range implies a single spaced list.
3274 else if (Spacing == 2) {
3275 Error(Parser.getTok().getLoc(),
3276 "sequential registers in double spaced list");
3277 return MatchOperand_ParseFail;
3278 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003279 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003280 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003281 int EndReg = tryParseRegister();
3282 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003283 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003284 return MatchOperand_ParseFail;
3285 }
3286 // Allow Q regs and just interpret them as the two D sub-registers.
3287 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3288 EndReg = getDRegFromQReg(EndReg) + 1;
3289 // If the register is the same as the start reg, there's nothing
3290 // more to do.
3291 if (Reg == EndReg)
3292 continue;
3293 // The register must be in the same register class as the first.
3294 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003295 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003296 return MatchOperand_ParseFail;
3297 }
3298 // Ranges must go from low to high.
3299 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003300 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003301 return MatchOperand_ParseFail;
3302 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003303 // Parse the lane specifier if present.
3304 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003305 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003306 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3307 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003308 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003309 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003310 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003311 return MatchOperand_ParseFail;
3312 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003313
3314 // Add all the registers in the range to the register list.
3315 Count += EndReg - Reg;
3316 Reg = EndReg;
3317 continue;
3318 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003319 Parser.Lex(); // Eat the comma.
3320 RegLoc = Parser.getTok().getLoc();
3321 int OldReg = Reg;
3322 Reg = tryParseRegister();
3323 if (Reg == -1) {
3324 Error(RegLoc, "register expected");
3325 return MatchOperand_ParseFail;
3326 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003327 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003328 // It's OK to use the enumeration values directly here rather, as the
3329 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003330 //
3331 // The list is of D registers, but we also allow Q regs and just interpret
3332 // them as the two D sub-registers.
3333 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003334 if (!Spacing)
3335 Spacing = 1; // Register range implies a single spaced list.
3336 else if (Spacing == 2) {
3337 Error(RegLoc,
3338 "invalid register in double-spaced list (must be 'D' register')");
3339 return MatchOperand_ParseFail;
3340 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003341 Reg = getDRegFromQReg(Reg);
3342 if (Reg != OldReg + 1) {
3343 Error(RegLoc, "non-contiguous register range");
3344 return MatchOperand_ParseFail;
3345 }
3346 ++Reg;
3347 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003348 // Parse the lane specifier if present.
3349 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003350 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003351 SMLoc LaneLoc = Parser.getTok().getLoc();
3352 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3353 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003354 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003355 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003356 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003357 return MatchOperand_ParseFail;
3358 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003359 continue;
3360 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003361 // Normal D register.
3362 // Figure out the register spacing (single or double) of the list if
3363 // we don't know it already.
3364 if (!Spacing)
3365 Spacing = 1 + (Reg == OldReg + 2);
3366
3367 // Just check that it's contiguous and keep going.
3368 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003369 Error(RegLoc, "non-contiguous register range");
3370 return MatchOperand_ParseFail;
3371 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003372 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003373 // Parse the lane specifier if present.
3374 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003375 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003376 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003377 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003378 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003379 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003380 Error(EndLoc, "mismatched lane index in register list");
3381 return MatchOperand_ParseFail;
3382 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003383 }
3384
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003385 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003386 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003387 return MatchOperand_ParseFail;
3388 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003389 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003390 Parser.Lex(); // Eat '}' token.
3391
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003392 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003393 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003394 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003395 // composite register classes.
3396 if (Count == 2) {
3397 const MCRegisterClass *RC = (Spacing == 1) ?
3398 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3399 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3400 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3401 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003402
Jim Grosbach2f50e922011-12-15 21:44:33 +00003403 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3404 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003405 break;
3406 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003407 // Two-register operands have been converted to the
3408 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003409 if (Count == 2) {
3410 const MCRegisterClass *RC = (Spacing == 1) ?
3411 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3412 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003413 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3414 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003415 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003416 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003417 S, E));
3418 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003419 case IndexedLane:
3420 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003421 LaneIndex,
3422 (Spacing == 2),
3423 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003424 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003425 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003426 return MatchOperand_Success;
3427}
3428
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003429/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003430ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003431parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003432 SMLoc S = Parser.getTok().getLoc();
3433 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003434 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003435
Jiangning Liu288e1af2012-08-02 08:21:27 +00003436 if (Tok.is(AsmToken::Identifier)) {
3437 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003438
Jiangning Liu288e1af2012-08-02 08:21:27 +00003439 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3440 .Case("sy", ARM_MB::SY)
3441 .Case("st", ARM_MB::ST)
3442 .Case("sh", ARM_MB::ISH)
3443 .Case("ish", ARM_MB::ISH)
3444 .Case("shst", ARM_MB::ISHST)
3445 .Case("ishst", ARM_MB::ISHST)
3446 .Case("nsh", ARM_MB::NSH)
3447 .Case("un", ARM_MB::NSH)
3448 .Case("nshst", ARM_MB::NSHST)
3449 .Case("unst", ARM_MB::NSHST)
3450 .Case("osh", ARM_MB::OSH)
3451 .Case("oshst", ARM_MB::OSHST)
3452 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003453
Jiangning Liu288e1af2012-08-02 08:21:27 +00003454 if (Opt == ~0U)
3455 return MatchOperand_NoMatch;
3456
3457 Parser.Lex(); // Eat identifier token.
3458 } else if (Tok.is(AsmToken::Hash) ||
3459 Tok.is(AsmToken::Dollar) ||
3460 Tok.is(AsmToken::Integer)) {
3461 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003462 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003463 SMLoc Loc = Parser.getTok().getLoc();
3464
3465 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003466 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003467 Error(Loc, "illegal expression");
3468 return MatchOperand_ParseFail;
3469 }
3470
3471 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3472 if (!CE) {
3473 Error(Loc, "constant expression expected");
3474 return MatchOperand_ParseFail;
3475 }
3476
3477 int Val = CE->getValue();
3478 if (Val & ~0xf) {
3479 Error(Loc, "immediate value out of range");
3480 return MatchOperand_ParseFail;
3481 }
3482
3483 Opt = ARM_MB::RESERVED_0 + Val;
3484 } else
3485 return MatchOperand_ParseFail;
3486
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003487 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003488 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003489}
3490
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003491/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3492ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3493parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3494 SMLoc S = Parser.getTok().getLoc();
3495 const AsmToken &Tok = Parser.getTok();
3496 unsigned Opt;
3497
3498 if (Tok.is(AsmToken::Identifier)) {
3499 StringRef OptStr = Tok.getString();
3500
3501 if (OptStr.lower() == "sy")
3502 Opt = ARM_ISB::SY;
3503 else
3504 return MatchOperand_NoMatch;
3505
3506 Parser.Lex(); // Eat identifier token.
3507 } else if (Tok.is(AsmToken::Hash) ||
3508 Tok.is(AsmToken::Dollar) ||
3509 Tok.is(AsmToken::Integer)) {
3510 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003511 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003512 SMLoc Loc = Parser.getTok().getLoc();
3513
3514 const MCExpr *ISBarrierID;
3515 if (getParser().parseExpression(ISBarrierID)) {
3516 Error(Loc, "illegal expression");
3517 return MatchOperand_ParseFail;
3518 }
3519
3520 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3521 if (!CE) {
3522 Error(Loc, "constant expression expected");
3523 return MatchOperand_ParseFail;
3524 }
3525
3526 int Val = CE->getValue();
3527 if (Val & ~0xf) {
3528 Error(Loc, "immediate value out of range");
3529 return MatchOperand_ParseFail;
3530 }
3531
3532 Opt = ARM_ISB::RESERVED_0 + Val;
3533 } else
3534 return MatchOperand_ParseFail;
3535
3536 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3537 (ARM_ISB::InstSyncBOpt)Opt, S));
3538 return MatchOperand_Success;
3539}
3540
3541
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003542/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003543ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003544parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003545 SMLoc S = Parser.getTok().getLoc();
3546 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003547 if (!Tok.is(AsmToken::Identifier))
3548 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003549 StringRef IFlagsStr = Tok.getString();
3550
Owen Anderson10c5b122011-10-05 17:16:40 +00003551 // An iflags string of "none" is interpreted to mean that none of the AIF
3552 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003553 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003554 if (IFlagsStr != "none") {
3555 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3556 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3557 .Case("a", ARM_PROC::A)
3558 .Case("i", ARM_PROC::I)
3559 .Case("f", ARM_PROC::F)
3560 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003561
Owen Anderson10c5b122011-10-05 17:16:40 +00003562 // If some specific iflag is already set, it means that some letter is
3563 // present more than once, this is not acceptable.
3564 if (Flag == ~0U || (IFlags & Flag))
3565 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003566
Owen Anderson10c5b122011-10-05 17:16:40 +00003567 IFlags |= Flag;
3568 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003569 }
3570
3571 Parser.Lex(); // Eat identifier token.
3572 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3573 return MatchOperand_Success;
3574}
3575
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003576/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003577ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003578parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003579 SMLoc S = Parser.getTok().getLoc();
3580 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003581 if (!Tok.is(AsmToken::Identifier))
3582 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003583 StringRef Mask = Tok.getString();
3584
James Molloy21efa7d2011-09-28 14:21:38 +00003585 if (isMClass()) {
3586 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003587 std::string Name = Mask.lower();
3588 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003589 // Note: in the documentation:
3590 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3591 // for MSR APSR_nzcvq.
3592 // but we do make it an alias here. This is so to get the "mask encoding"
3593 // bits correct on MSR APSR writes.
3594 //
3595 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3596 // should really only be allowed when writing a special register. Note
3597 // they get dropped in the MRS instruction reading a special register as
3598 // the SYSm field is only 8 bits.
3599 //
3600 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3601 // includes the DSP extension but that is not checked.
3602 .Case("apsr", 0x800)
3603 .Case("apsr_nzcvq", 0x800)
3604 .Case("apsr_g", 0x400)
3605 .Case("apsr_nzcvqg", 0xc00)
3606 .Case("iapsr", 0x801)
3607 .Case("iapsr_nzcvq", 0x801)
3608 .Case("iapsr_g", 0x401)
3609 .Case("iapsr_nzcvqg", 0xc01)
3610 .Case("eapsr", 0x802)
3611 .Case("eapsr_nzcvq", 0x802)
3612 .Case("eapsr_g", 0x402)
3613 .Case("eapsr_nzcvqg", 0xc02)
3614 .Case("xpsr", 0x803)
3615 .Case("xpsr_nzcvq", 0x803)
3616 .Case("xpsr_g", 0x403)
3617 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003618 .Case("ipsr", 0x805)
3619 .Case("epsr", 0x806)
3620 .Case("iepsr", 0x807)
3621 .Case("msp", 0x808)
3622 .Case("psp", 0x809)
3623 .Case("primask", 0x810)
3624 .Case("basepri", 0x811)
3625 .Case("basepri_max", 0x812)
3626 .Case("faultmask", 0x813)
3627 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003628 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003629
James Molloy21efa7d2011-09-28 14:21:38 +00003630 if (FlagsVal == ~0U)
3631 return MatchOperand_NoMatch;
3632
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003633 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003634 // basepri, basepri_max and faultmask only valid for V7m.
3635 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003636
James Molloy21efa7d2011-09-28 14:21:38 +00003637 Parser.Lex(); // Eat identifier token.
3638 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3639 return MatchOperand_Success;
3640 }
3641
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003642 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3643 size_t Start = 0, Next = Mask.find('_');
3644 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003645 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003646 if (Next != StringRef::npos)
3647 Flags = Mask.slice(Next+1, Mask.size());
3648
3649 // FlagsVal contains the complete mask:
3650 // 3-0: Mask
3651 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3652 unsigned FlagsVal = 0;
3653
3654 if (SpecReg == "apsr") {
3655 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003656 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003657 .Case("g", 0x4) // same as CPSR_s
3658 .Case("nzcvqg", 0xc) // same as CPSR_fs
3659 .Default(~0U);
3660
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003661 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003662 if (!Flags.empty())
3663 return MatchOperand_NoMatch;
3664 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003665 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003666 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003667 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003668 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3669 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003670 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003671 for (int i = 0, e = Flags.size(); i != e; ++i) {
3672 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3673 .Case("c", 1)
3674 .Case("x", 2)
3675 .Case("s", 4)
3676 .Case("f", 8)
3677 .Default(~0U);
3678
3679 // If some specific flag is already set, it means that some letter is
3680 // present more than once, this is not acceptable.
3681 if (FlagsVal == ~0U || (FlagsVal & Flag))
3682 return MatchOperand_NoMatch;
3683 FlagsVal |= Flag;
3684 }
3685 } else // No match for special register.
3686 return MatchOperand_NoMatch;
3687
Owen Anderson03a173e2011-10-21 18:43:28 +00003688 // Special register without flags is NOT equivalent to "fc" flags.
3689 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3690 // two lines would enable gas compatibility at the expense of breaking
3691 // round-tripping.
3692 //
3693 // if (!FlagsVal)
3694 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003695
3696 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3697 if (SpecReg == "spsr")
3698 FlagsVal |= 16;
3699
3700 Parser.Lex(); // Eat identifier token.
3701 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3702 return MatchOperand_Success;
3703}
3704
Jim Grosbach27c1e252011-07-21 17:23:04 +00003705ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3706parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3707 int Low, int High) {
3708 const AsmToken &Tok = Parser.getTok();
3709 if (Tok.isNot(AsmToken::Identifier)) {
3710 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3711 return MatchOperand_ParseFail;
3712 }
3713 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003714 std::string LowerOp = Op.lower();
3715 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003716 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3717 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3718 return MatchOperand_ParseFail;
3719 }
3720 Parser.Lex(); // Eat shift type token.
3721
3722 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003723 if (Parser.getTok().isNot(AsmToken::Hash) &&
3724 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003725 Error(Parser.getTok().getLoc(), "'#' expected");
3726 return MatchOperand_ParseFail;
3727 }
3728 Parser.Lex(); // Eat hash token.
3729
3730 const MCExpr *ShiftAmount;
3731 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003732 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003733 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003734 Error(Loc, "illegal expression");
3735 return MatchOperand_ParseFail;
3736 }
3737 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3738 if (!CE) {
3739 Error(Loc, "constant expression expected");
3740 return MatchOperand_ParseFail;
3741 }
3742 int Val = CE->getValue();
3743 if (Val < Low || Val > High) {
3744 Error(Loc, "immediate value out of range");
3745 return MatchOperand_ParseFail;
3746 }
3747
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003748 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003749
3750 return MatchOperand_Success;
3751}
3752
Jim Grosbach0a547702011-07-22 17:44:50 +00003753ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3754parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3755 const AsmToken &Tok = Parser.getTok();
3756 SMLoc S = Tok.getLoc();
3757 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003758 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003759 return MatchOperand_ParseFail;
3760 }
Tim Northover4d141442013-05-31 15:58:45 +00003761 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003762 .Case("be", 1)
3763 .Case("le", 0)
3764 .Default(-1);
3765 Parser.Lex(); // Eat the token.
3766
3767 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003768 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003769 return MatchOperand_ParseFail;
3770 }
3771 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3772 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003773 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003774 return MatchOperand_Success;
3775}
3776
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003777/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3778/// instructions. Legal values are:
3779/// lsl #n 'n' in [0,31]
3780/// asr #n 'n' in [1,32]
3781/// n == 32 encoded as n == 0.
3782ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3783parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3784 const AsmToken &Tok = Parser.getTok();
3785 SMLoc S = Tok.getLoc();
3786 if (Tok.isNot(AsmToken::Identifier)) {
3787 Error(S, "shift operator 'asr' or 'lsl' expected");
3788 return MatchOperand_ParseFail;
3789 }
3790 StringRef ShiftName = Tok.getString();
3791 bool isASR;
3792 if (ShiftName == "lsl" || ShiftName == "LSL")
3793 isASR = false;
3794 else if (ShiftName == "asr" || ShiftName == "ASR")
3795 isASR = true;
3796 else {
3797 Error(S, "shift operator 'asr' or 'lsl' expected");
3798 return MatchOperand_ParseFail;
3799 }
3800 Parser.Lex(); // Eat the operator.
3801
3802 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003803 if (Parser.getTok().isNot(AsmToken::Hash) &&
3804 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003805 Error(Parser.getTok().getLoc(), "'#' expected");
3806 return MatchOperand_ParseFail;
3807 }
3808 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003809 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003810
3811 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003812 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003813 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003814 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003815 return MatchOperand_ParseFail;
3816 }
3817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3818 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003819 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003820 return MatchOperand_ParseFail;
3821 }
3822
3823 int64_t Val = CE->getValue();
3824 if (isASR) {
3825 // Shift amount must be in [1,32]
3826 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003827 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003828 return MatchOperand_ParseFail;
3829 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003830 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3831 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003832 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003833 return MatchOperand_ParseFail;
3834 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003835 if (Val == 32) Val = 0;
3836 } else {
3837 // Shift amount must be in [1,32]
3838 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003839 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003840 return MatchOperand_ParseFail;
3841 }
3842 }
3843
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003844 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003845
3846 return MatchOperand_Success;
3847}
3848
Jim Grosbach833b9d32011-07-27 20:15:40 +00003849/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3850/// of instructions. Legal values are:
3851/// ror #n 'n' in {0, 8, 16, 24}
3852ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3853parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3854 const AsmToken &Tok = Parser.getTok();
3855 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003856 if (Tok.isNot(AsmToken::Identifier))
3857 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003858 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003859 if (ShiftName != "ror" && ShiftName != "ROR")
3860 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003861 Parser.Lex(); // Eat the operator.
3862
3863 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003864 if (Parser.getTok().isNot(AsmToken::Hash) &&
3865 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003866 Error(Parser.getTok().getLoc(), "'#' expected");
3867 return MatchOperand_ParseFail;
3868 }
3869 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003870 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00003871
3872 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003873 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003874 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003875 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003876 return MatchOperand_ParseFail;
3877 }
3878 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3879 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003880 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003881 return MatchOperand_ParseFail;
3882 }
3883
3884 int64_t Val = CE->getValue();
3885 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3886 // normally, zero is represented in asm by omitting the rotate operand
3887 // entirely.
3888 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003889 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00003890 return MatchOperand_ParseFail;
3891 }
3892
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003893 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00003894
3895 return MatchOperand_Success;
3896}
3897
Jim Grosbach864b6092011-07-28 21:34:26 +00003898ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3899parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3900 SMLoc S = Parser.getTok().getLoc();
3901 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003902 if (Parser.getTok().isNot(AsmToken::Hash) &&
3903 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003904 Error(Parser.getTok().getLoc(), "'#' expected");
3905 return MatchOperand_ParseFail;
3906 }
3907 Parser.Lex(); // Eat hash token.
3908
3909 const MCExpr *LSBExpr;
3910 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003911 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003912 Error(E, "malformed immediate expression");
3913 return MatchOperand_ParseFail;
3914 }
3915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3916 if (!CE) {
3917 Error(E, "'lsb' operand must be an immediate");
3918 return MatchOperand_ParseFail;
3919 }
3920
3921 int64_t LSB = CE->getValue();
3922 // The LSB must be in the range [0,31]
3923 if (LSB < 0 || LSB > 31) {
3924 Error(E, "'lsb' operand must be in the range [0,31]");
3925 return MatchOperand_ParseFail;
3926 }
3927 E = Parser.getTok().getLoc();
3928
3929 // Expect another immediate operand.
3930 if (Parser.getTok().isNot(AsmToken::Comma)) {
3931 Error(Parser.getTok().getLoc(), "too few operands");
3932 return MatchOperand_ParseFail;
3933 }
3934 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003935 if (Parser.getTok().isNot(AsmToken::Hash) &&
3936 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003937 Error(Parser.getTok().getLoc(), "'#' expected");
3938 return MatchOperand_ParseFail;
3939 }
3940 Parser.Lex(); // Eat hash token.
3941
3942 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003943 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003944 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00003945 Error(E, "malformed immediate expression");
3946 return MatchOperand_ParseFail;
3947 }
3948 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3949 if (!CE) {
3950 Error(E, "'width' operand must be an immediate");
3951 return MatchOperand_ParseFail;
3952 }
3953
3954 int64_t Width = CE->getValue();
3955 // The LSB must be in the range [1,32-lsb]
3956 if (Width < 1 || Width > 32 - LSB) {
3957 Error(E, "'width' operand must be in the range [1,32-lsb]");
3958 return MatchOperand_ParseFail;
3959 }
Jim Grosbach864b6092011-07-28 21:34:26 +00003960
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003961 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00003962
3963 return MatchOperand_Success;
3964}
3965
Jim Grosbachd3595712011-08-03 23:50:40 +00003966ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3967parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3968 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00003969 // postidx_reg := '+' register {, shift}
3970 // | '-' register {, shift}
3971 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00003972
3973 // This method must return MatchOperand_NoMatch without consuming any tokens
3974 // in the case where there is no match, as other alternatives take other
3975 // parse methods.
3976 AsmToken Tok = Parser.getTok();
3977 SMLoc S = Tok.getLoc();
3978 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003979 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00003980 if (Tok.is(AsmToken::Plus)) {
3981 Parser.Lex(); // Eat the '+' token.
3982 haveEaten = true;
3983 } else if (Tok.is(AsmToken::Minus)) {
3984 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00003985 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00003986 haveEaten = true;
3987 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003988
3989 SMLoc E = Parser.getTok().getEndLoc();
3990 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00003991 if (Reg == -1) {
3992 if (!haveEaten)
3993 return MatchOperand_NoMatch;
3994 Error(Parser.getTok().getLoc(), "register expected");
3995 return MatchOperand_ParseFail;
3996 }
Jim Grosbachd3595712011-08-03 23:50:40 +00003997
Jim Grosbachc320c852011-08-05 21:28:30 +00003998 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3999 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004000 if (Parser.getTok().is(AsmToken::Comma)) {
4001 Parser.Lex(); // Eat the ','.
4002 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4003 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004004
4005 // FIXME: Only approximates end...may include intervening whitespace.
4006 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004007 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004008
4009 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4010 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004011
4012 return MatchOperand_Success;
4013}
4014
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004015ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4016parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4017 // Check for a post-index addressing register operand. Specifically:
4018 // am3offset := '+' register
4019 // | '-' register
4020 // | register
4021 // | # imm
4022 // | # + imm
4023 // | # - imm
4024
4025 // This method must return MatchOperand_NoMatch without consuming any tokens
4026 // in the case where there is no match, as other alternatives take other
4027 // parse methods.
4028 AsmToken Tok = Parser.getTok();
4029 SMLoc S = Tok.getLoc();
4030
4031 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004032 if (Parser.getTok().is(AsmToken::Hash) ||
4033 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004034 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004035 // Explicitly look for a '-', as we need to encode negative zero
4036 // differently.
4037 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4038 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004039 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004040 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004041 return MatchOperand_ParseFail;
4042 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4043 if (!CE) {
4044 Error(S, "constant expression expected");
4045 return MatchOperand_ParseFail;
4046 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004047 // Negative zero is encoded as the flag value INT32_MIN.
4048 int32_t Val = CE->getValue();
4049 if (isNegative && Val == 0)
4050 Val = INT32_MIN;
4051
4052 Operands.push_back(
4053 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4054
4055 return MatchOperand_Success;
4056 }
4057
4058
4059 bool haveEaten = false;
4060 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004061 if (Tok.is(AsmToken::Plus)) {
4062 Parser.Lex(); // Eat the '+' token.
4063 haveEaten = true;
4064 } else if (Tok.is(AsmToken::Minus)) {
4065 Parser.Lex(); // Eat the '-' token.
4066 isAdd = false;
4067 haveEaten = true;
4068 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004069
4070 Tok = Parser.getTok();
4071 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004072 if (Reg == -1) {
4073 if (!haveEaten)
4074 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004075 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004076 return MatchOperand_ParseFail;
4077 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004078
4079 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004080 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004081
4082 return MatchOperand_Success;
4083}
4084
Tim Northovereb5e4d52013-07-22 09:06:12 +00004085/// Convert parsed operands to MCInst. Needed here because this instruction
4086/// only has two register operands, but multiplication is commutative so
4087/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004088void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004089cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004090 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004091 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4092 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004093 // If we have a three-operand form, make sure to set Rn to be the operand
4094 // that isn't the same as Rd.
4095 unsigned RegOp = 4;
4096 if (Operands.size() == 6 &&
4097 ((ARMOperand*)Operands[4])->getReg() ==
4098 ((ARMOperand*)Operands[3])->getReg())
4099 RegOp = 5;
4100 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4101 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004102 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004103}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004104
Bill Wendlinge18980a2010-11-06 22:36:58 +00004105/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004106/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004107bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004108parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004109 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004110 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004111 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004112 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004113 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004114
Sean Callanan936b0d32010-01-19 21:44:56 +00004115 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004116 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004117 if (BaseRegNum == -1)
4118 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004119
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004120 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004121 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004122 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4123 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004124 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004125
Jim Grosbachd3595712011-08-03 23:50:40 +00004126 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004127 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004128 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004129
Jim Grosbachd3595712011-08-03 23:50:40 +00004130 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004131 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004132
Jim Grosbach40700e02011-09-19 18:42:21 +00004133 // If there's a pre-indexing writeback marker, '!', just add it as a token
4134 // operand. It's rather odd, but syntactically valid.
4135 if (Parser.getTok().is(AsmToken::Exclaim)) {
4136 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4137 Parser.Lex(); // Eat the '!'.
4138 }
4139
Jim Grosbachd3595712011-08-03 23:50:40 +00004140 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004141 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004142
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004143 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4144 "Lost colon or comma in memory operand?!");
4145 if (Tok.is(AsmToken::Comma)) {
4146 Parser.Lex(); // Eat the comma.
4147 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004148
Jim Grosbacha95ec992011-10-11 17:29:55 +00004149 // If we have a ':', it's an alignment specifier.
4150 if (Parser.getTok().is(AsmToken::Colon)) {
4151 Parser.Lex(); // Eat the ':'.
4152 E = Parser.getTok().getLoc();
4153
4154 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004155 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004156 return true;
4157
4158 // The expression has to be a constant. Memory references with relocations
4159 // don't come through here, as they use the <label> forms of the relevant
4160 // instructions.
4161 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4162 if (!CE)
4163 return Error (E, "constant expression expected");
4164
4165 unsigned Align = 0;
4166 switch (CE->getValue()) {
4167 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004168 return Error(E,
4169 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4170 case 16: Align = 2; break;
4171 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004172 case 64: Align = 8; break;
4173 case 128: Align = 16; break;
4174 case 256: Align = 32; break;
4175 }
4176
4177 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004178 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004179 return Error(Parser.getTok().getLoc(), "']' expected");
4180 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004181 Parser.Lex(); // Eat right bracket token.
4182
4183 // Don't worry about range checking the value here. That's handled by
4184 // the is*() predicates.
4185 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4186 ARM_AM::no_shift, 0, Align,
4187 false, S, E));
4188
4189 // If there's a pre-indexing writeback marker, '!', just add it as a token
4190 // operand.
4191 if (Parser.getTok().is(AsmToken::Exclaim)) {
4192 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4193 Parser.Lex(); // Eat the '!'.
4194 }
4195
4196 return false;
4197 }
4198
4199 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004200 // offset. Be friendly and also accept a plain integer (without a leading
4201 // hash) for gas compatibility.
4202 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004203 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004204 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004205 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004206 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004207 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004208
Owen Anderson967674d2011-08-29 19:36:44 +00004209 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004210 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004211 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004212 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004213
4214 // The expression has to be a constant. Memory references with relocations
4215 // don't come through here, as they use the <label> forms of the relevant
4216 // instructions.
4217 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4218 if (!CE)
4219 return Error (E, "constant expression expected");
4220
Owen Anderson967674d2011-08-29 19:36:44 +00004221 // If the constant was #-0, represent it as INT32_MIN.
4222 int32_t Val = CE->getValue();
4223 if (isNegative && Val == 0)
4224 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4225
Jim Grosbachd3595712011-08-03 23:50:40 +00004226 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004227 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004228 return Error(Parser.getTok().getLoc(), "']' expected");
4229 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004230 Parser.Lex(); // Eat right bracket token.
4231
4232 // Don't worry about range checking the value here. That's handled by
4233 // the is*() predicates.
4234 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004235 ARM_AM::no_shift, 0, 0,
4236 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004237
4238 // If there's a pre-indexing writeback marker, '!', just add it as a token
4239 // operand.
4240 if (Parser.getTok().is(AsmToken::Exclaim)) {
4241 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4242 Parser.Lex(); // Eat the '!'.
4243 }
4244
4245 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004246 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004247
4248 // The register offset is optionally preceded by a '+' or '-'
4249 bool isNegative = false;
4250 if (Parser.getTok().is(AsmToken::Minus)) {
4251 isNegative = true;
4252 Parser.Lex(); // Eat the '-'.
4253 } else if (Parser.getTok().is(AsmToken::Plus)) {
4254 // Nothing to do.
4255 Parser.Lex(); // Eat the '+'.
4256 }
4257
4258 E = Parser.getTok().getLoc();
4259 int OffsetRegNum = tryParseRegister();
4260 if (OffsetRegNum == -1)
4261 return Error(E, "register expected");
4262
4263 // If there's a shift operator, handle it.
4264 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004265 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004266 if (Parser.getTok().is(AsmToken::Comma)) {
4267 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004268 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004269 return true;
4270 }
4271
4272 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004273 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004274 return Error(Parser.getTok().getLoc(), "']' expected");
4275 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004276 Parser.Lex(); // Eat right bracket token.
4277
4278 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004279 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004280 S, E));
4281
Jim Grosbachc320c852011-08-05 21:28:30 +00004282 // If there's a pre-indexing writeback marker, '!', just add it as a token
4283 // operand.
4284 if (Parser.getTok().is(AsmToken::Exclaim)) {
4285 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4286 Parser.Lex(); // Eat the '!'.
4287 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004288
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004289 return false;
4290}
4291
Jim Grosbachd3595712011-08-03 23:50:40 +00004292/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004293/// ( lsl | lsr | asr | ror ) , # shift_amount
4294/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004295/// return true if it parses a shift otherwise it returns false.
4296bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4297 unsigned &Amount) {
4298 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004299 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004300 if (Tok.isNot(AsmToken::Identifier))
4301 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004302 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004303 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4304 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004305 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004306 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004307 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004308 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004309 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004310 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004311 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004312 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004313 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004314 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004315 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004316 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004317
Jim Grosbachd3595712011-08-03 23:50:40 +00004318 // rrx stands alone.
4319 Amount = 0;
4320 if (St != ARM_AM::rrx) {
4321 Loc = Parser.getTok().getLoc();
4322 // A '#' and a shift amount.
4323 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004324 if (HashTok.isNot(AsmToken::Hash) &&
4325 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004326 return Error(HashTok.getLoc(), "'#' expected");
4327 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004328
Jim Grosbachd3595712011-08-03 23:50:40 +00004329 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004330 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004331 return true;
4332 // Range check the immediate.
4333 // lsl, ror: 0 <= imm <= 31
4334 // lsr, asr: 0 <= imm <= 32
4335 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4336 if (!CE)
4337 return Error(Loc, "shift amount must be an immediate");
4338 int64_t Imm = CE->getValue();
4339 if (Imm < 0 ||
4340 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4341 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4342 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004343 // If <ShiftTy> #0, turn it into a no_shift.
4344 if (Imm == 0)
4345 St = ARM_AM::lsl;
4346 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4347 if (Imm == 32)
4348 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004349 Amount = Imm;
4350 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004351
4352 return false;
4353}
4354
Jim Grosbache7fbce72011-10-03 23:38:36 +00004355/// parseFPImm - A floating point immediate expression operand.
4356ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4357parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004358 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004359 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004360 // integer only.
4361 //
4362 // This routine still creates a generic Immediate operand, containing
4363 // a bitcast of the 64-bit floating point value. The various operands
4364 // that accept floats can check whether the value is valid for them
4365 // via the standard is*() predicates.
4366
Jim Grosbache7fbce72011-10-03 23:38:36 +00004367 SMLoc S = Parser.getTok().getLoc();
4368
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004369 if (Parser.getTok().isNot(AsmToken::Hash) &&
4370 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004371 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004372
4373 // Disambiguate the VMOV forms that can accept an FP immediate.
4374 // vmov.f32 <sreg>, #imm
4375 // vmov.f64 <dreg>, #imm
4376 // vmov.f32 <dreg>, #imm @ vector f32x2
4377 // vmov.f32 <qreg>, #imm @ vector f32x4
4378 //
4379 // There are also the NEON VMOV instructions which expect an
4380 // integer constant. Make sure we don't try to parse an FPImm
4381 // for these:
4382 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4383 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4384 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4385 TyOp->getToken() != ".f64"))
4386 return MatchOperand_NoMatch;
4387
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004388 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004389
4390 // Handle negation, as that still comes through as a separate token.
4391 bool isNegative = false;
4392 if (Parser.getTok().is(AsmToken::Minus)) {
4393 isNegative = true;
4394 Parser.Lex();
4395 }
4396 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004397 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004398 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004399 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004400 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4401 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004402 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004403 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004404 Operands.push_back(ARMOperand::CreateImm(
4405 MCConstantExpr::Create(IntVal, getContext()),
4406 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004407 return MatchOperand_Success;
4408 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004409 // Also handle plain integers. Instructions which allow floating point
4410 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004411 if (Tok.is(AsmToken::Integer)) {
4412 int64_t Val = Tok.getIntVal();
4413 Parser.Lex(); // Eat the token.
4414 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004415 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004416 return MatchOperand_ParseFail;
4417 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004418 double RealVal = ARM_AM::getFPImmFloat(Val);
4419 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4420 Operands.push_back(ARMOperand::CreateImm(
4421 MCConstantExpr::Create(Val, getContext()), S,
4422 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004423 return MatchOperand_Success;
4424 }
4425
Jim Grosbach235c8d22012-01-19 02:47:30 +00004426 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004427 return MatchOperand_ParseFail;
4428}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004429
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004430/// Parse a arm instruction operand. For now this parses the operand regardless
4431/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004432bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004433 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004434 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004435
4436 // Check if the current operand has a custom associated parser, if so, try to
4437 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004438 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4439 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004440 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004441 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4442 // there was a match, but an error occurred, in which case, just return that
4443 // the operand parsing failed.
4444 if (ResTy == MatchOperand_ParseFail)
4445 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004446
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004447 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004448 default:
4449 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004450 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004451 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004452 // If we've seen a branch mnemonic, the next operand must be a label. This
4453 // is true even if the label is a register name. So "br r1" means branch to
4454 // label "r1".
4455 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4456 if (!ExpectLabel) {
4457 if (!tryParseRegisterWithWriteBack(Operands))
4458 return false;
4459 int Res = tryParseShiftRegister(Operands);
4460 if (Res == 0) // success
4461 return false;
4462 else if (Res == -1) // irrecoverable error
4463 return true;
4464 // If this is VMRS, check for the apsr_nzcv operand.
4465 if (Mnemonic == "vmrs" &&
4466 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4467 S = Parser.getTok().getLoc();
4468 Parser.Lex();
4469 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4470 return false;
4471 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004472 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004473
4474 // Fall though for the Identifier case that is not a register or a
4475 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004476 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004477 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004478 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004479 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004480 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004481 // This was not a register so parse other operands that start with an
4482 // identifier (like labels) as expressions and create them as immediates.
4483 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004484 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004485 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004486 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004487 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004488 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4489 return false;
4490 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004491 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004492 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004493 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004494 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004495 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004496 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004497 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004498 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004499 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004500
4501 if (Parser.getTok().isNot(AsmToken::Colon)) {
4502 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4503 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004504 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004505 return true;
4506 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4507 if (CE) {
4508 int32_t Val = CE->getValue();
4509 if (isNegative && Val == 0)
4510 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4511 }
4512 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4513 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004514
4515 // There can be a trailing '!' on operands that we want as a separate
4516 // '!' Token operand. Handle that here. For example, the compatibilty
4517 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4518 if (Parser.getTok().is(AsmToken::Exclaim)) {
4519 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4520 Parser.getTok().getLoc()));
4521 Parser.Lex(); // Eat exclaim token
4522 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004523 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004524 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004525 // w/ a ':' after the '#', it's just like a plain ':'.
4526 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004527 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004528 case AsmToken::Colon: {
4529 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004530 // FIXME: Check it's an expression prefix,
4531 // e.g. (FOO - :lower16:BAR) isn't legal.
4532 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004533 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004534 return true;
4535
Evan Cheng965b3c72011-01-13 07:58:56 +00004536 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004537 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004538 return true;
4539
Evan Cheng965b3c72011-01-13 07:58:56 +00004540 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004541 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004542 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004543 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004544 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004545 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004546 }
4547}
4548
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004549// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004550// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004551bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004552 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004553
4554 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004555 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004556 Parser.Lex(); // Eat ':'
4557
4558 if (getLexer().isNot(AsmToken::Identifier)) {
4559 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4560 return true;
4561 }
4562
4563 StringRef IDVal = Parser.getTok().getIdentifier();
4564 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004565 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004566 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004567 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004568 } else {
4569 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4570 return true;
4571 }
4572 Parser.Lex();
4573
4574 if (getLexer().isNot(AsmToken::Colon)) {
4575 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4576 return true;
4577 }
4578 Parser.Lex(); // Eat the last ':'
4579 return false;
4580}
4581
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004582/// \brief Given a mnemonic, split out possible predication code and carry
4583/// setting letters to form a canonical mnemonic and flags.
4584//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004585// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004586// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004587StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004588 unsigned &PredicationCode,
4589 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004590 unsigned &ProcessorIMod,
4591 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004592 PredicationCode = ARMCC::AL;
4593 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004594 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004595
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004596 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004597 //
4598 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004599 if ((Mnemonic == "movs" && isThumb()) ||
4600 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4601 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4602 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4603 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Jim Grosbach9b81a4f2013-04-15 22:42:50 +00004604 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004605 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4606 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004607 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004608 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004609 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4610 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4611 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004612 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004613
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004614 // First, split out any predication code. Ignore mnemonics we know aren't
4615 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004616 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004617 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004618 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004619 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004620 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4621 .Case("eq", ARMCC::EQ)
4622 .Case("ne", ARMCC::NE)
4623 .Case("hs", ARMCC::HS)
4624 .Case("cs", ARMCC::HS)
4625 .Case("lo", ARMCC::LO)
4626 .Case("cc", ARMCC::LO)
4627 .Case("mi", ARMCC::MI)
4628 .Case("pl", ARMCC::PL)
4629 .Case("vs", ARMCC::VS)
4630 .Case("vc", ARMCC::VC)
4631 .Case("hi", ARMCC::HI)
4632 .Case("ls", ARMCC::LS)
4633 .Case("ge", ARMCC::GE)
4634 .Case("lt", ARMCC::LT)
4635 .Case("gt", ARMCC::GT)
4636 .Case("le", ARMCC::LE)
4637 .Case("al", ARMCC::AL)
4638 .Default(~0U);
4639 if (CC != ~0U) {
4640 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4641 PredicationCode = CC;
4642 }
Bill Wendling193961b2010-10-29 23:50:21 +00004643 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004644
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004645 // Next, determine if we have a carry setting bit. We explicitly ignore all
4646 // the instructions we know end in 's'.
4647 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004648 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004649 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4650 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4651 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004652 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004653 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004654 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004655 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004656 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004657 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004658 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4659 CarrySetting = true;
4660 }
4661
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004662 // The "cps" instruction can have a interrupt mode operand which is glued into
4663 // the mnemonic. Check if this is the case, split it and parse the imod op
4664 if (Mnemonic.startswith("cps")) {
4665 // Split out any imod code.
4666 unsigned IMod =
4667 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4668 .Case("ie", ARM_PROC::IE)
4669 .Case("id", ARM_PROC::ID)
4670 .Default(~0U);
4671 if (IMod != ~0U) {
4672 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4673 ProcessorIMod = IMod;
4674 }
4675 }
4676
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004677 // The "it" instruction has the condition mask on the end of the mnemonic.
4678 if (Mnemonic.startswith("it")) {
4679 ITMask = Mnemonic.slice(2, Mnemonic.size());
4680 Mnemonic = Mnemonic.slice(0, 2);
4681 }
4682
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004683 return Mnemonic;
4684}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004685
4686/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4687/// inclusion of carry set or predication code operands.
4688//
4689// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004690void ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004691getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004692 bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004693 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4694 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004695 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004696 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004697 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004698 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004699 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004700 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004701 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004702 Mnemonic == "mla" || Mnemonic == "smlal" ||
4703 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004704 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004705 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004706 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004707
Tim Northover2c45a382013-06-26 16:52:40 +00004708 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4709 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4710 Mnemonic == "trap" || Mnemonic == "setend" ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004711 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4712 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004713 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4714 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4715 Mnemonic == "vrintm") {
Tim Northover2c45a382013-06-26 16:52:40 +00004716 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004717 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004718 } else if (!isThumb()) {
4719 // Some instructions are only predicable in Thumb mode
4720 CanAcceptPredicationCode
4721 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4722 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4723 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4724 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4725 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4726 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4727 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4728 } else if (isThumbOne()) {
4729 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004730 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004731 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004732}
4733
Jim Grosbach7283da92011-08-16 21:12:37 +00004734bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4735 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004736 // FIXME: This is all horribly hacky. We really need a better way to deal
4737 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004738
4739 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4740 // another does not. Specifically, the MOVW instruction does not. So we
4741 // special case it here and remove the defaulted (non-setting) cc_out
4742 // operand if that's the instruction we're trying to match.
4743 //
4744 // We do this as post-processing of the explicit operands rather than just
4745 // conditionally adding the cc_out in the first place because we need
4746 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004747 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004748 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4749 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4750 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4751 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004752
4753 // Register-register 'add' for thumb does not have a cc_out operand
4754 // when there are only two register operands.
4755 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4756 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4757 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4758 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4759 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004760 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004761 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4762 // have to check the immediate range here since Thumb2 has a variant
4763 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004764 if (((isThumb() && Mnemonic == "add") ||
4765 (isThumbTwo() && Mnemonic == "sub")) &&
4766 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004767 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4768 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4769 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004770 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004771 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004772 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004773 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004774 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4775 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004776 // selecting via the generic "add" mnemonic, so to know that we
4777 // should remove the cc_out operand, we have to explicitly check that
4778 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004779 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4780 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004781 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4782 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4783 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4784 // Nest conditions rather than one big 'if' statement for readability.
4785 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004786 // If both registers are low, we're in an IT block, and the immediate is
4787 // in range, we should use encoding T1 instead, which has a cc_out.
4788 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004789 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004790 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4791 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4792 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00004793 // Check against T3. If the second register is the PC, this is an
4794 // alternate form of ADR, which uses encoding T4, so check for that too.
4795 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4796 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4797 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004798
4799 // Otherwise, we use encoding T4, which does not have a cc_out
4800 // operand.
4801 return true;
4802 }
4803
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004804 // The thumb2 multiply instruction doesn't have a CCOut register, so
4805 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4806 // use the 16-bit encoding or not.
4807 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4808 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4809 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4810 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4811 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4812 // If the registers aren't low regs, the destination reg isn't the
4813 // same as one of the source regs, or the cc_out operand is zero
4814 // outside of an IT block, we have to use the 32-bit encoding, so
4815 // remove the cc_out operand.
4816 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4817 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00004818 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004819 !inITBlock() ||
4820 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4821 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4822 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4823 static_cast<ARMOperand*>(Operands[4])->getReg())))
4824 return true;
4825
Jim Grosbachefa7e952011-11-15 19:55:16 +00004826 // Also check the 'mul' syntax variant that doesn't specify an explicit
4827 // destination register.
4828 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4829 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4830 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4831 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4832 // If the registers aren't low regs or the cc_out operand is zero
4833 // outside of an IT block, we have to use the 32-bit encoding, so
4834 // remove the cc_out operand.
4835 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4836 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4837 !inITBlock()))
4838 return true;
4839
Jim Grosbach9c8b9932011-09-14 21:00:40 +00004840
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004841
Jim Grosbach4b701af2011-08-24 21:42:27 +00004842 // Register-register 'add/sub' for thumb does not have a cc_out operand
4843 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4844 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4845 // right, this will result in better diagnostics (which operand is off)
4846 // anyway.
4847 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4848 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004849 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4850 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004851 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4852 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4853 (Operands.size() == 6 &&
4854 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004855 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004856
Jim Grosbach7283da92011-08-16 21:12:37 +00004857 return false;
4858}
4859
Joey Goulye8602552013-07-19 16:34:16 +00004860bool ARMAsmParser::shouldOmitPredicateOperand(
4861 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4862 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4863 unsigned RegIdx = 3;
4864 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4865 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4866 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4867 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4868 RegIdx = 4;
4869
4870 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4871 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4872 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4873 ARMMCRegisterClasses[ARM::QPRRegClassID]
4874 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4875 return true;
4876 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00004877 return false;
Joey Goulye8602552013-07-19 16:34:16 +00004878}
4879
Joey Gouly5d0564d2013-08-02 19:18:12 +00004880bool ARMAsmParser::isDeprecated(MCInst &Inst, StringRef &Info) {
4881 if (hasV8Ops() && Inst.getOpcode() == ARM::SETEND) {
4882 Info = "armv8";
4883 return true;
4884 }
4885}
4886
Jim Grosbach12952fe2011-11-11 23:08:10 +00004887static bool isDataTypeToken(StringRef Tok) {
4888 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4889 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4890 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4891 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4892 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4893 Tok == ".f" || Tok == ".d";
4894}
4895
4896// FIXME: This bit should probably be handled via an explicit match class
4897// in the .td files that matches the suffix instead of having it be
4898// a literal string token the way it is now.
4899static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4900 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4901}
Chad Rosier9f7a2212013-04-18 22:35:36 +00004902static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4903 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004904/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00004905bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4906 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004907 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00004908 // Apply mnemonic aliases before doing anything else, as the destination
4909 // mnemnonic may include suffices and we want to handle them normally.
4910 // The generic tblgen'erated code does this later, at the start of
4911 // MatchInstructionImpl(), but that's too late for aliases that include
4912 // any sort of suffix.
4913 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00004914 unsigned AssemblerDialect = getParser().getAssemblerDialect();
4915 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00004916
Jim Grosbachab5830e2011-12-14 02:16:11 +00004917 // First check for the ARM-specific .req directive.
4918 if (Parser.getTok().is(AsmToken::Identifier) &&
4919 Parser.getTok().getIdentifier() == ".req") {
4920 parseDirectiveReq(Name, NameLoc);
4921 // We always return 'error' for this, as we're done with this
4922 // statement and don't need to match the 'instruction."
4923 return true;
4924 }
4925
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004926 // Create the leading tokens for the mnemonic, split by '.' characters.
4927 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004928 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004929
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004930 // Split out the predication code and carry setting flag from the mnemonic.
4931 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004932 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004933 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004934 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004935 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004936 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004937
Jim Grosbach1c171b12011-08-25 17:23:55 +00004938 // In Thumb1, only the branch (B) instruction can be predicated.
4939 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004940 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00004941 return Error(NameLoc, "conditional execution not supported in Thumb1");
4942 }
4943
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004944 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4945
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004946 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4947 // is the mask as it will be for the IT encoding if the conditional
4948 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4949 // where the conditional bit0 is zero, the instruction post-processing
4950 // will adjust the mask accordingly.
4951 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00004952 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4953 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004954 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00004955 return Error(Loc, "too many conditions on IT instruction");
4956 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004957 unsigned Mask = 8;
4958 for (unsigned i = ITMask.size(); i != 0; --i) {
4959 char pos = ITMask[i - 1];
4960 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004961 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00004962 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004963 }
4964 Mask >>= 1;
4965 if (ITMask[i - 1] == 't')
4966 Mask |= 8;
4967 }
Jim Grosbached16ec42011-08-29 22:24:09 +00004968 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004969 }
4970
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004971 // FIXME: This is all a pretty gross hack. We should automatically handle
4972 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00004973
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004974 // Next, add the CCOut and ConditionCode operands, if needed.
4975 //
4976 // For mnemonics which can ever incorporate a carry setting bit or predication
4977 // code, our matching model involves us always generating CCOut and
4978 // ConditionCode operands to match the mnemonic "as written" and then we let
4979 // the matcher deal with finding the right instruction or generating an
4980 // appropriate error.
4981 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004982 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004983
Jim Grosbach03a8a162011-07-14 22:04:21 +00004984 // If we had a carry-set on an instruction that can't do that, issue an
4985 // error.
4986 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004987 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00004988 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00004989 "' can not set flags, but 's' suffix specified");
4990 }
Jim Grosbach0a547702011-07-22 17:44:50 +00004991 // If we had a predication code on an instruction that can't do that, issue an
4992 // error.
4993 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004994 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00004995 return Error(NameLoc, "instruction '" + Mnemonic +
4996 "' is not predicable, but condition code specified");
4997 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00004998
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004999 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005000 if (CanAcceptCarrySet) {
5001 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005002 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005003 Loc));
5004 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005005
5006 // Add the predication code operand, if necessary.
5007 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005008 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5009 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005010 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005011 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005012 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005013
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005014 // Add the processor imod operand, if necessary.
5015 if (ProcessorIMod) {
5016 Operands.push_back(ARMOperand::CreateImm(
5017 MCConstantExpr::Create(ProcessorIMod, getContext()),
5018 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005019 }
5020
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005021 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005022 while (Next != StringRef::npos) {
5023 Start = Next;
5024 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005025 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005026
Jim Grosbach12952fe2011-11-11 23:08:10 +00005027 // Some NEON instructions have an optional datatype suffix that is
5028 // completely ignored. Check for that.
5029 if (isDataTypeToken(ExtraToken) &&
5030 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5031 continue;
5032
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005033 // For for ARM mode generate an error if the .n qualifier is used.
5034 if (ExtraToken == ".n" && !isThumb()) {
5035 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5036 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5037 "arm mode");
5038 }
5039
5040 // The .n qualifier is always discarded as that is what the tables
5041 // and matcher expect. In ARM mode the .w qualifier has no effect,
5042 // so discard it to avoid errors that can be caused by the matcher.
5043 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005044 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5045 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5046 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005047 }
5048
5049 // Read the remaining operands.
5050 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005051 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005052 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005053 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005054 return true;
5055 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005056
5057 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005058 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005059
5060 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005061 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005062 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005063 return true;
5064 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005065 }
5066 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005067
Chris Lattnera2a9d162010-09-11 16:18:25 +00005068 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005069 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005070 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005071 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005072 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005073
Chris Lattner91689c12010-09-08 05:10:46 +00005074 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005075
Jim Grosbach7283da92011-08-16 21:12:37 +00005076 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5077 // do and don't have a cc_out optional-def operand. With some spot-checks
5078 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005079 // parse and adjust accordingly before actually matching. We shouldn't ever
5080 // try to remove a cc_out operand that was explicitly set on the the
5081 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5082 // table driven matcher doesn't fit well with the ARM instruction set.
5083 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005084 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5085 Operands.erase(Operands.begin() + 1);
5086 delete Op;
5087 }
5088
Joey Goulye8602552013-07-19 16:34:16 +00005089 // Some instructions have the same mnemonic, but don't always
5090 // have a predicate. Distinguish them here and delete the
5091 // predicate if needed.
5092 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5093 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5094 Operands.erase(Operands.begin() + 1);
5095 delete Op;
5096 }
5097
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005098 // ARM mode 'blx' need special handling, as the register operand version
5099 // is predicable, but the label operand version is not. So, we can't rely
5100 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005101 // a k_CondCode operand in the list. If we're trying to match the label
5102 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005103 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5104 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5105 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5106 Operands.erase(Operands.begin() + 1);
5107 delete Op;
5108 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005109
Weiming Zhao8f56f882012-11-16 21:55:34 +00005110 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5111 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5112 // a single GPRPair reg operand is used in the .td file to replace the two
5113 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5114 // expressed as a GPRPair, so we have to manually merge them.
5115 // FIXME: We would really like to be able to tablegen'erate this.
5116 if (!isThumb() && Operands.size() > 4 &&
5117 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5118 bool isLoad = (Mnemonic == "ldrexd");
5119 unsigned Idx = isLoad ? 2 : 3;
5120 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5121 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5122
5123 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5124 // Adjust only if Op1 and Op2 are GPRs.
5125 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5126 MRC.contains(Op2->getReg())) {
5127 unsigned Reg1 = Op1->getReg();
5128 unsigned Reg2 = Op2->getReg();
5129 unsigned Rt = MRI->getEncodingValue(Reg1);
5130 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5131
5132 // Rt2 must be Rt + 1 and Rt must be even.
5133 if (Rt + 1 != Rt2 || (Rt & 1)) {
5134 Error(Op2->getStartLoc(), isLoad ?
5135 "destination operands must be sequential" :
5136 "source operands must be sequential");
5137 return true;
5138 }
5139 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5140 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5141 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5142 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5143 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5144 delete Op1;
5145 delete Op2;
5146 }
5147 }
5148
Kevin Enderby78f95722013-07-31 21:05:30 +00005149 // FIXME: As said above, this is all a pretty gross hack. This instruction
5150 // does not fit with other "subs" and tblgen.
5151 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5152 // so the Mnemonic is the original name "subs" and delete the predicate
5153 // operand so it will match the table entry.
5154 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5155 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5156 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5157 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5158 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5159 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5160 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5161 Operands.erase(Operands.begin());
5162 delete Op0;
5163 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5164
5165 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5166 Operands.erase(Operands.begin() + 1);
5167 delete Op1;
5168 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005169 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005170}
5171
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005172// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005173
5174// return 'true' if register list contains non-low GPR registers,
5175// 'false' otherwise. If Reg is in the register list or is HiReg, set
5176// 'containsReg' to true.
5177static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5178 unsigned HiReg, bool &containsReg) {
5179 containsReg = false;
5180 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5181 unsigned OpReg = Inst.getOperand(i).getReg();
5182 if (OpReg == Reg)
5183 containsReg = true;
5184 // Anything other than a low register isn't legal here.
5185 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5186 return true;
5187 }
5188 return false;
5189}
5190
Jim Grosbacha31f2232011-09-07 18:05:34 +00005191// Check if the specified regisgter is in the register list of the inst,
5192// starting at the indicated operand number.
5193static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5194 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5195 unsigned OpReg = Inst.getOperand(i).getReg();
5196 if (OpReg == Reg)
5197 return true;
5198 }
5199 return false;
5200}
5201
Jim Grosbached16ec42011-08-29 22:24:09 +00005202// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5203// the ARMInsts array) instead. Getting that here requires awkward
5204// API changes, though. Better way?
5205namespace llvm {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005206extern const MCInstrDesc ARMInsts[];
Jim Grosbached16ec42011-08-29 22:24:09 +00005207}
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005208static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005209 return ARMInsts[Opcode];
5210}
5211
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005212// FIXME: We would really like to be able to tablegen'erate this.
5213bool ARMAsmParser::
5214validateInstruction(MCInst &Inst,
5215 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00005216 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005217 SMLoc Loc = Operands[0]->getStartLoc();
5218 // Check the IT block state first.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005219 // NOTE: BKPT instruction has the interesting property of being
5220 // allowed in IT blocks, but not being predicable. It just always
Owen Anderson44ae2da2011-09-13 17:59:19 +00005221 // executes.
Jim Grosbach82f76d12012-01-25 19:52:01 +00005222 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5223 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005224 unsigned bit = 1;
5225 if (ITState.FirstCond)
5226 ITState.FirstCond = false;
5227 else
Jim Grosbacha0d34d32011-09-02 23:22:08 +00005228 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005229 // The instruction must be predicable.
5230 if (!MCID.isPredicable())
5231 return Error(Loc, "instructions in IT block must be predicable");
5232 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5233 unsigned ITCond = bit ? ITState.Cond :
5234 ARMCC::getOppositeCondition(ITState.Cond);
5235 if (Cond != ITCond) {
5236 // Find the condition code Operand to get its SMLoc information.
5237 SMLoc CondLoc;
5238 for (unsigned i = 1; i < Operands.size(); ++i)
5239 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5240 CondLoc = Operands[i]->getStartLoc();
5241 return Error(CondLoc, "incorrect condition in IT block; got '" +
5242 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5243 "', but expected '" +
5244 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5245 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005246 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005247 } else if (isThumbTwo() && MCID.isPredicable() &&
5248 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson29cfe6c2011-09-09 21:48:23 +00005249 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5250 Inst.getOpcode() != ARM::t2B)
Jim Grosbached16ec42011-08-29 22:24:09 +00005251 return Error(Loc, "predicated instructions must be in IT block");
5252
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005253 switch (Inst.getOpcode()) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005254 case ARM::LDRD:
5255 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005256 case ARM::LDRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005257 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005258 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5259 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005260 if (Rt2 != Rt + 1)
5261 return Error(Operands[3]->getStartLoc(),
5262 "destination operands must be sequential");
5263 return false;
5264 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005265 case ARM::STRD: {
5266 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005267 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5268 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005269 if (Rt2 != Rt + 1)
5270 return Error(Operands[3]->getStartLoc(),
5271 "source operands must be sequential");
5272 return false;
5273 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005274 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005275 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005276 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005277 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5278 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005279 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005280 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005281 "source operands must be sequential");
5282 return false;
5283 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005284 case ARM::SBFX:
5285 case ARM::UBFX: {
5286 // width must be in range [1, 32-lsb]
5287 unsigned lsb = Inst.getOperand(2).getImm();
5288 unsigned widthm1 = Inst.getOperand(3).getImm();
5289 if (widthm1 >= 32 - lsb)
5290 return Error(Operands[5]->getStartLoc(),
5291 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005292 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005293 }
Jim Grosbach90103cc2011-08-18 21:50:53 +00005294 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005295 // If we're parsing Thumb2, the .w variant is available and handles
5296 // most cases that are normally illegal for a Thumb1 LDM
5297 // instruction. We'll make the transformation in processInstruction()
5298 // if necessary.
5299 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005300 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005301 // in the register list.
5302 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach139acd22011-08-22 23:01:07 +00005303 bool hasWritebackToken =
5304 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5305 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbach169b2be2011-08-23 18:13:04 +00005306 bool listContainsBase;
Jim Grosbacha31f2232011-09-07 18:05:34 +00005307 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005308 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5309 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005310 // If we should have writeback, then there should be a '!' token.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005311 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005312 return Error(Operands[2]->getStartLoc(),
5313 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005314 // If we should not have writeback, there must not be a '!'. This is
5315 // true even for the 32-bit wide encodings.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005316 if (listContainsBase && hasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005317 return Error(Operands[3]->getStartLoc(),
5318 "writeback operator '!' not allowed when base register "
5319 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005320
5321 break;
5322 }
Jim Grosbacha31f2232011-09-07 18:05:34 +00005323 case ARM::t2LDMIA_UPD: {
5324 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5325 return Error(Operands[4]->getStartLoc(),
5326 "writeback operator '!' not allowed when base register "
5327 "in register list");
5328 break;
5329 }
Chad Rosier8513ffb2012-08-30 23:20:38 +00005330 case ARM::tMUL: {
5331 // The second source operand must be the same register as the destination
5332 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005333 //
5334 // In this case, we must directly check the parsed operands because the
5335 // cvtThumbMultiply() function is written in such a way that it guarantees
5336 // this first statement is always true for the new Inst. Essentially, the
5337 // destination is unconditionally copied into the second source operand
5338 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005339 if (Operands.size() == 6 &&
5340 (((ARMOperand*)Operands[3])->getReg() !=
5341 ((ARMOperand*)Operands[5])->getReg()) &&
5342 (((ARMOperand*)Operands[3])->getReg() !=
5343 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005344 return Error(Operands[3]->getStartLoc(),
5345 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005346 }
5347 break;
5348 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005349 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5350 // so only issue a diagnostic for thumb1. The instructions will be
5351 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005352 case ARM::tPOP: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005353 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005354 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5355 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005356 return Error(Operands[2]->getStartLoc(),
5357 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005358 break;
5359 }
5360 case ARM::tPUSH: {
Jim Grosbach169b2be2011-08-23 18:13:04 +00005361 bool listContainsBase;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005362 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5363 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005364 return Error(Operands[2]->getStartLoc(),
5365 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005366 break;
5367 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005368 case ARM::tSTMIA_UPD: {
5369 bool listContainsBase;
Jim Grosbach099c9762011-09-16 20:50:13 +00005370 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005371 return Error(Operands[4]->getStartLoc(),
5372 "registers must be in range r0-r7");
5373 break;
5374 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005375 case ARM::tADDrSP: {
5376 // If the non-SP source operand and the destination operand are not the
5377 // same, we need thumb2 (for the wide encoding), or we have an error.
5378 if (!isThumbTwo() &&
5379 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5380 return Error(Operands[4]->getStartLoc(),
5381 "source register must be the same as destination");
5382 }
5383 break;
5384 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005385 }
5386
Joey Gouly5d0564d2013-08-02 19:18:12 +00005387 StringRef DepInfo;
5388 if (isDeprecated(Inst, DepInfo))
5389 Warning(Loc, "deprecated on " + DepInfo);
5390
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005391 return false;
5392}
5393
Jim Grosbach1a747242012-01-23 23:45:44 +00005394static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005395 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005396 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005397 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005398 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5399 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5400 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5401 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5402 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5403 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5404 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5405 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5406 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005407
5408 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005409 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5410 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5411 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5412 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5413 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005414
Jim Grosbach1e946a42012-01-24 00:43:12 +00005415 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5416 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5417 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5418 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5419 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005420
Jim Grosbach1e946a42012-01-24 00:43:12 +00005421 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5422 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5423 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5424 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5425 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005426
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005427 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005428 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5429 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5430 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5431 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5432 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5433 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5434 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5435 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5436 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5437 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5438 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5439 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5440 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5441 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5442 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005443
Jim Grosbach1a747242012-01-23 23:45:44 +00005444 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005445 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5446 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5447 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5448 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5449 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5450 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5451 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5452 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5453 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5454 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5455 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5456 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5457 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5458 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5459 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5460 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5461 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5462 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005463
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005464 // VST4LN
5465 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5466 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5467 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5468 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5469 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5470 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5471 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5472 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5473 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5474 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5475 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5476 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5477 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5478 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5479 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5480
Jim Grosbachda70eac2012-01-24 00:58:13 +00005481 // VST4
5482 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5483 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5484 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5485 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5486 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5487 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5488 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5489 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5490 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5491 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5492 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5493 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5494 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5495 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5496 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5497 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5498 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5499 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005500 }
5501}
5502
Jim Grosbach1a747242012-01-23 23:45:44 +00005503static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005504 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005505 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005506 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005507 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5508 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5509 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5510 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5511 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5512 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5513 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5514 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5515 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005516
5517 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005518 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5519 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5520 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5521 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5522 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5523 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5524 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5525 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5526 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5527 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5528 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5529 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5530 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5531 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5532 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005533
Jim Grosbachb78403c2012-01-24 23:47:04 +00005534 // VLD3DUP
5535 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5536 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5537 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5538 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5539 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5540 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5541 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5542 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5543 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5544 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5545 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5546 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5547 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5548 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5549 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5550 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5551 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5552 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5553
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005554 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005555 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5556 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5557 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5558 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5559 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5560 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5561 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5562 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5563 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5564 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5565 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5566 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5567 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5568 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5569 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005570
5571 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005572 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5573 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5574 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5575 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5576 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5577 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5578 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5579 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5580 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5581 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5582 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5583 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5584 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5585 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5586 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5587 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5588 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5589 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005590
Jim Grosbach14952a02012-01-24 18:37:25 +00005591 // VLD4LN
5592 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5593 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5594 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5595 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5596 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5597 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5598 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5599 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5600 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5601 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5602 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5603 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5604 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5605 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5606 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5607
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005608 // VLD4DUP
5609 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5610 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5611 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5612 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5613 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5614 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5615 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5616 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5617 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5618 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5619 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5620 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5621 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5622 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5623 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5624 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5625 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5626 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5627
Jim Grosbached561fc2012-01-24 00:43:17 +00005628 // VLD4
5629 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5630 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5631 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5632 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5633 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5634 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5635 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5636 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5637 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5638 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5639 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5640 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5641 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5642 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5643 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5644 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5645 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5646 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005647 }
5648}
5649
Jim Grosbachafad0532011-11-10 23:42:14 +00005650bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005651processInstruction(MCInst &Inst,
5652 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5653 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005654 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5655 case ARM::ADDri: {
5656 if (Inst.getOperand(1).getReg() != ARM::PC ||
5657 Inst.getOperand(5).getReg() != 0)
5658 return false;
5659 MCInst TmpInst;
5660 TmpInst.setOpcode(ARM::ADR);
5661 TmpInst.addOperand(Inst.getOperand(0));
5662 TmpInst.addOperand(Inst.getOperand(2));
5663 TmpInst.addOperand(Inst.getOperand(3));
5664 TmpInst.addOperand(Inst.getOperand(4));
5665 Inst = TmpInst;
5666 return true;
5667 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005668 // Aliases for alternate PC+imm syntax of LDR instructions.
5669 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005670 // Select the narrow version if the immediate will fit.
5671 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005672 Inst.getOperand(1).getImm() <= 0xff &&
5673 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5674 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005675 Inst.setOpcode(ARM::tLDRpci);
5676 else
5677 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005678 return true;
5679 case ARM::t2LDRBpcrel:
5680 Inst.setOpcode(ARM::t2LDRBpci);
5681 return true;
5682 case ARM::t2LDRHpcrel:
5683 Inst.setOpcode(ARM::t2LDRHpci);
5684 return true;
5685 case ARM::t2LDRSBpcrel:
5686 Inst.setOpcode(ARM::t2LDRSBpci);
5687 return true;
5688 case ARM::t2LDRSHpcrel:
5689 Inst.setOpcode(ARM::t2LDRSHpci);
5690 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005691 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005692 case ARM::VST1LNdWB_register_Asm_8:
5693 case ARM::VST1LNdWB_register_Asm_16:
5694 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005695 MCInst TmpInst;
5696 // Shuffle the operands around so the lane index operand is in the
5697 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005698 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005699 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005700 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5701 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5702 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5703 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5704 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5705 TmpInst.addOperand(Inst.getOperand(1)); // lane
5706 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5707 TmpInst.addOperand(Inst.getOperand(6));
5708 Inst = TmpInst;
5709 return true;
5710 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005711
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005712 case ARM::VST2LNdWB_register_Asm_8:
5713 case ARM::VST2LNdWB_register_Asm_16:
5714 case ARM::VST2LNdWB_register_Asm_32:
5715 case ARM::VST2LNqWB_register_Asm_16:
5716 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005717 MCInst TmpInst;
5718 // Shuffle the operands around so the lane index operand is in the
5719 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005720 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005721 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005722 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5723 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5724 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5725 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5726 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005727 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5728 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005729 TmpInst.addOperand(Inst.getOperand(1)); // lane
5730 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5731 TmpInst.addOperand(Inst.getOperand(6));
5732 Inst = TmpInst;
5733 return true;
5734 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005735
5736 case ARM::VST3LNdWB_register_Asm_8:
5737 case ARM::VST3LNdWB_register_Asm_16:
5738 case ARM::VST3LNdWB_register_Asm_32:
5739 case ARM::VST3LNqWB_register_Asm_16:
5740 case ARM::VST3LNqWB_register_Asm_32: {
5741 MCInst TmpInst;
5742 // Shuffle the operands around so the lane index operand is in the
5743 // right place.
5744 unsigned Spacing;
5745 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5746 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5747 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5748 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5749 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5750 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5751 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5752 Spacing));
5753 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5754 Spacing * 2));
5755 TmpInst.addOperand(Inst.getOperand(1)); // lane
5756 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5757 TmpInst.addOperand(Inst.getOperand(6));
5758 Inst = TmpInst;
5759 return true;
5760 }
5761
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005762 case ARM::VST4LNdWB_register_Asm_8:
5763 case ARM::VST4LNdWB_register_Asm_16:
5764 case ARM::VST4LNdWB_register_Asm_32:
5765 case ARM::VST4LNqWB_register_Asm_16:
5766 case ARM::VST4LNqWB_register_Asm_32: {
5767 MCInst TmpInst;
5768 // Shuffle the operands around so the lane index operand is in the
5769 // right place.
5770 unsigned Spacing;
5771 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5772 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5773 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5774 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5775 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5776 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5778 Spacing));
5779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5780 Spacing * 2));
5781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5782 Spacing * 3));
5783 TmpInst.addOperand(Inst.getOperand(1)); // lane
5784 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5785 TmpInst.addOperand(Inst.getOperand(6));
5786 Inst = TmpInst;
5787 return true;
5788 }
5789
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005790 case ARM::VST1LNdWB_fixed_Asm_8:
5791 case ARM::VST1LNdWB_fixed_Asm_16:
5792 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005793 MCInst TmpInst;
5794 // Shuffle the operands around so the lane index operand is in the
5795 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005796 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005797 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005798 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5799 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5800 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5801 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5802 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5803 TmpInst.addOperand(Inst.getOperand(1)); // lane
5804 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5805 TmpInst.addOperand(Inst.getOperand(5));
5806 Inst = TmpInst;
5807 return true;
5808 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005809
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005810 case ARM::VST2LNdWB_fixed_Asm_8:
5811 case ARM::VST2LNdWB_fixed_Asm_16:
5812 case ARM::VST2LNdWB_fixed_Asm_32:
5813 case ARM::VST2LNqWB_fixed_Asm_16:
5814 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005815 MCInst TmpInst;
5816 // Shuffle the operands around so the lane index operand is in the
5817 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005818 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005819 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005820 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5821 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5822 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5823 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5824 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005825 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5826 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005827 TmpInst.addOperand(Inst.getOperand(1)); // lane
5828 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5829 TmpInst.addOperand(Inst.getOperand(5));
5830 Inst = TmpInst;
5831 return true;
5832 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005833
5834 case ARM::VST3LNdWB_fixed_Asm_8:
5835 case ARM::VST3LNdWB_fixed_Asm_16:
5836 case ARM::VST3LNdWB_fixed_Asm_32:
5837 case ARM::VST3LNqWB_fixed_Asm_16:
5838 case ARM::VST3LNqWB_fixed_Asm_32: {
5839 MCInst TmpInst;
5840 // Shuffle the operands around so the lane index operand is in the
5841 // right place.
5842 unsigned Spacing;
5843 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5844 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5845 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5846 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5847 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5848 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5849 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5850 Spacing));
5851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5852 Spacing * 2));
5853 TmpInst.addOperand(Inst.getOperand(1)); // lane
5854 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5855 TmpInst.addOperand(Inst.getOperand(5));
5856 Inst = TmpInst;
5857 return true;
5858 }
5859
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005860 case ARM::VST4LNdWB_fixed_Asm_8:
5861 case ARM::VST4LNdWB_fixed_Asm_16:
5862 case ARM::VST4LNdWB_fixed_Asm_32:
5863 case ARM::VST4LNqWB_fixed_Asm_16:
5864 case ARM::VST4LNqWB_fixed_Asm_32: {
5865 MCInst TmpInst;
5866 // Shuffle the operands around so the lane index operand is in the
5867 // right place.
5868 unsigned Spacing;
5869 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5870 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5871 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5872 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5873 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5874 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5875 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5876 Spacing));
5877 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5878 Spacing * 2));
5879 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5880 Spacing * 3));
5881 TmpInst.addOperand(Inst.getOperand(1)); // lane
5882 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5883 TmpInst.addOperand(Inst.getOperand(5));
5884 Inst = TmpInst;
5885 return true;
5886 }
5887
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005888 case ARM::VST1LNdAsm_8:
5889 case ARM::VST1LNdAsm_16:
5890 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005891 MCInst TmpInst;
5892 // Shuffle the operands around so the lane index operand is in the
5893 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005894 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005895 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005896 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5897 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5898 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5899 TmpInst.addOperand(Inst.getOperand(1)); // lane
5900 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5901 TmpInst.addOperand(Inst.getOperand(5));
5902 Inst = TmpInst;
5903 return true;
5904 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005905
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005906 case ARM::VST2LNdAsm_8:
5907 case ARM::VST2LNdAsm_16:
5908 case ARM::VST2LNdAsm_32:
5909 case ARM::VST2LNqAsm_16:
5910 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005911 MCInst TmpInst;
5912 // Shuffle the operands around so the lane index operand is in the
5913 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005914 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005915 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005916 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5917 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5918 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00005919 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5920 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005921 TmpInst.addOperand(Inst.getOperand(1)); // lane
5922 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5923 TmpInst.addOperand(Inst.getOperand(5));
5924 Inst = TmpInst;
5925 return true;
5926 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005927
5928 case ARM::VST3LNdAsm_8:
5929 case ARM::VST3LNdAsm_16:
5930 case ARM::VST3LNdAsm_32:
5931 case ARM::VST3LNqAsm_16:
5932 case ARM::VST3LNqAsm_32: {
5933 MCInst TmpInst;
5934 // Shuffle the operands around so the lane index operand is in the
5935 // right place.
5936 unsigned Spacing;
5937 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5938 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5939 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5940 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5941 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5942 Spacing));
5943 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5944 Spacing * 2));
5945 TmpInst.addOperand(Inst.getOperand(1)); // lane
5946 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5947 TmpInst.addOperand(Inst.getOperand(5));
5948 Inst = TmpInst;
5949 return true;
5950 }
5951
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005952 case ARM::VST4LNdAsm_8:
5953 case ARM::VST4LNdAsm_16:
5954 case ARM::VST4LNdAsm_32:
5955 case ARM::VST4LNqAsm_16:
5956 case ARM::VST4LNqAsm_32: {
5957 MCInst TmpInst;
5958 // Shuffle the operands around so the lane index operand is in the
5959 // right place.
5960 unsigned Spacing;
5961 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5962 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5963 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5964 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5965 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5966 Spacing));
5967 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5968 Spacing * 2));
5969 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5970 Spacing * 3));
5971 TmpInst.addOperand(Inst.getOperand(1)); // lane
5972 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5973 TmpInst.addOperand(Inst.getOperand(5));
5974 Inst = TmpInst;
5975 return true;
5976 }
5977
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005978 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005979 case ARM::VLD1LNdWB_register_Asm_8:
5980 case ARM::VLD1LNdWB_register_Asm_16:
5981 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00005982 MCInst TmpInst;
5983 // Shuffle the operands around so the lane index operand is in the
5984 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00005985 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005986 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00005987 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5988 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5989 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5990 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5991 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5992 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5993 TmpInst.addOperand(Inst.getOperand(1)); // lane
5994 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5995 TmpInst.addOperand(Inst.getOperand(6));
5996 Inst = TmpInst;
5997 return true;
5998 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005999
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006000 case ARM::VLD2LNdWB_register_Asm_8:
6001 case ARM::VLD2LNdWB_register_Asm_16:
6002 case ARM::VLD2LNdWB_register_Asm_32:
6003 case ARM::VLD2LNqWB_register_Asm_16:
6004 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006005 MCInst TmpInst;
6006 // Shuffle the operands around so the lane index operand is in the
6007 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006008 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006009 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006010 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006011 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6012 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006013 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6014 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6015 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6016 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6017 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006018 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6019 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006020 TmpInst.addOperand(Inst.getOperand(1)); // lane
6021 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6022 TmpInst.addOperand(Inst.getOperand(6));
6023 Inst = TmpInst;
6024 return true;
6025 }
6026
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006027 case ARM::VLD3LNdWB_register_Asm_8:
6028 case ARM::VLD3LNdWB_register_Asm_16:
6029 case ARM::VLD3LNdWB_register_Asm_32:
6030 case ARM::VLD3LNqWB_register_Asm_16:
6031 case ARM::VLD3LNqWB_register_Asm_32: {
6032 MCInst TmpInst;
6033 // Shuffle the operands around so the lane index operand is in the
6034 // right place.
6035 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006036 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006037 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6038 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6039 Spacing));
6040 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006041 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006042 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6043 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6044 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6045 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6046 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6047 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6048 Spacing));
6049 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006050 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006051 TmpInst.addOperand(Inst.getOperand(1)); // lane
6052 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6053 TmpInst.addOperand(Inst.getOperand(6));
6054 Inst = TmpInst;
6055 return true;
6056 }
6057
Jim Grosbach14952a02012-01-24 18:37:25 +00006058 case ARM::VLD4LNdWB_register_Asm_8:
6059 case ARM::VLD4LNdWB_register_Asm_16:
6060 case ARM::VLD4LNdWB_register_Asm_32:
6061 case ARM::VLD4LNqWB_register_Asm_16:
6062 case ARM::VLD4LNqWB_register_Asm_32: {
6063 MCInst TmpInst;
6064 // Shuffle the operands around so the lane index operand is in the
6065 // right place.
6066 unsigned Spacing;
6067 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6068 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6069 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6070 Spacing));
6071 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6072 Spacing * 2));
6073 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6074 Spacing * 3));
6075 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6076 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6077 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6078 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6079 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6081 Spacing));
6082 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6083 Spacing * 2));
6084 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6085 Spacing * 3));
6086 TmpInst.addOperand(Inst.getOperand(1)); // lane
6087 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6088 TmpInst.addOperand(Inst.getOperand(6));
6089 Inst = TmpInst;
6090 return true;
6091 }
6092
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006093 case ARM::VLD1LNdWB_fixed_Asm_8:
6094 case ARM::VLD1LNdWB_fixed_Asm_16:
6095 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006096 MCInst TmpInst;
6097 // Shuffle the operands around so the lane index operand is in the
6098 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006099 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006100 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006101 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6102 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6103 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6104 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6105 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6106 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6107 TmpInst.addOperand(Inst.getOperand(1)); // lane
6108 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6109 TmpInst.addOperand(Inst.getOperand(5));
6110 Inst = TmpInst;
6111 return true;
6112 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006113
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006114 case ARM::VLD2LNdWB_fixed_Asm_8:
6115 case ARM::VLD2LNdWB_fixed_Asm_16:
6116 case ARM::VLD2LNdWB_fixed_Asm_32:
6117 case ARM::VLD2LNqWB_fixed_Asm_16:
6118 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006119 MCInst TmpInst;
6120 // Shuffle the operands around so the lane index operand is in the
6121 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006122 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006123 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006124 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006125 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6126 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006127 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6128 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6129 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6130 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6131 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006132 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6133 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006134 TmpInst.addOperand(Inst.getOperand(1)); // lane
6135 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6136 TmpInst.addOperand(Inst.getOperand(5));
6137 Inst = TmpInst;
6138 return true;
6139 }
6140
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006141 case ARM::VLD3LNdWB_fixed_Asm_8:
6142 case ARM::VLD3LNdWB_fixed_Asm_16:
6143 case ARM::VLD3LNdWB_fixed_Asm_32:
6144 case ARM::VLD3LNqWB_fixed_Asm_16:
6145 case ARM::VLD3LNqWB_fixed_Asm_32: {
6146 MCInst TmpInst;
6147 // Shuffle the operands around so the lane index operand is in the
6148 // right place.
6149 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006150 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006151 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6152 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6153 Spacing));
6154 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006155 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006156 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6157 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6158 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6159 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6160 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6161 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6162 Spacing));
6163 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006164 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006165 TmpInst.addOperand(Inst.getOperand(1)); // lane
6166 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6167 TmpInst.addOperand(Inst.getOperand(5));
6168 Inst = TmpInst;
6169 return true;
6170 }
6171
Jim Grosbach14952a02012-01-24 18:37:25 +00006172 case ARM::VLD4LNdWB_fixed_Asm_8:
6173 case ARM::VLD4LNdWB_fixed_Asm_16:
6174 case ARM::VLD4LNdWB_fixed_Asm_32:
6175 case ARM::VLD4LNqWB_fixed_Asm_16:
6176 case ARM::VLD4LNqWB_fixed_Asm_32: {
6177 MCInst TmpInst;
6178 // Shuffle the operands around so the lane index operand is in the
6179 // right place.
6180 unsigned Spacing;
6181 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6182 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6183 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6184 Spacing));
6185 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6186 Spacing * 2));
6187 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6188 Spacing * 3));
6189 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6190 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6191 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6192 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6193 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6194 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6195 Spacing));
6196 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6197 Spacing * 2));
6198 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6199 Spacing * 3));
6200 TmpInst.addOperand(Inst.getOperand(1)); // lane
6201 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6202 TmpInst.addOperand(Inst.getOperand(5));
6203 Inst = TmpInst;
6204 return true;
6205 }
6206
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006207 case ARM::VLD1LNdAsm_8:
6208 case ARM::VLD1LNdAsm_16:
6209 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006210 MCInst TmpInst;
6211 // Shuffle the operands around so the lane index operand is in the
6212 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006213 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006214 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006215 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6216 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6217 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6218 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6219 TmpInst.addOperand(Inst.getOperand(1)); // lane
6220 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6221 TmpInst.addOperand(Inst.getOperand(5));
6222 Inst = TmpInst;
6223 return true;
6224 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006225
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006226 case ARM::VLD2LNdAsm_8:
6227 case ARM::VLD2LNdAsm_16:
6228 case ARM::VLD2LNdAsm_32:
6229 case ARM::VLD2LNqAsm_16:
6230 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006231 MCInst TmpInst;
6232 // Shuffle the operands around so the lane index operand is in the
6233 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006234 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006235 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006236 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006237 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6238 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006239 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6240 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6241 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006242 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6243 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006244 TmpInst.addOperand(Inst.getOperand(1)); // lane
6245 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6246 TmpInst.addOperand(Inst.getOperand(5));
6247 Inst = TmpInst;
6248 return true;
6249 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006250
6251 case ARM::VLD3LNdAsm_8:
6252 case ARM::VLD3LNdAsm_16:
6253 case ARM::VLD3LNdAsm_32:
6254 case ARM::VLD3LNqAsm_16:
6255 case ARM::VLD3LNqAsm_32: {
6256 MCInst TmpInst;
6257 // Shuffle the operands around so the lane index operand is in the
6258 // right place.
6259 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006260 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006261 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6262 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6263 Spacing));
6264 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006265 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006266 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6267 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6268 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6269 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6270 Spacing));
6271 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006272 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006273 TmpInst.addOperand(Inst.getOperand(1)); // lane
6274 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6275 TmpInst.addOperand(Inst.getOperand(5));
6276 Inst = TmpInst;
6277 return true;
6278 }
6279
Jim Grosbach14952a02012-01-24 18:37:25 +00006280 case ARM::VLD4LNdAsm_8:
6281 case ARM::VLD4LNdAsm_16:
6282 case ARM::VLD4LNdAsm_32:
6283 case ARM::VLD4LNqAsm_16:
6284 case ARM::VLD4LNqAsm_32: {
6285 MCInst TmpInst;
6286 // Shuffle the operands around so the lane index operand is in the
6287 // right place.
6288 unsigned Spacing;
6289 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6290 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6292 Spacing));
6293 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6294 Spacing * 2));
6295 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6296 Spacing * 3));
6297 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6298 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6299 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6301 Spacing));
6302 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6303 Spacing * 2));
6304 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6305 Spacing * 3));
6306 TmpInst.addOperand(Inst.getOperand(1)); // lane
6307 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6308 TmpInst.addOperand(Inst.getOperand(5));
6309 Inst = TmpInst;
6310 return true;
6311 }
6312
Jim Grosbachb78403c2012-01-24 23:47:04 +00006313 // VLD3DUP single 3-element structure to all lanes instructions.
6314 case ARM::VLD3DUPdAsm_8:
6315 case ARM::VLD3DUPdAsm_16:
6316 case ARM::VLD3DUPdAsm_32:
6317 case ARM::VLD3DUPqAsm_8:
6318 case ARM::VLD3DUPqAsm_16:
6319 case ARM::VLD3DUPqAsm_32: {
6320 MCInst TmpInst;
6321 unsigned Spacing;
6322 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6323 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6324 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6325 Spacing));
6326 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6327 Spacing * 2));
6328 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6329 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6330 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6331 TmpInst.addOperand(Inst.getOperand(4));
6332 Inst = TmpInst;
6333 return true;
6334 }
6335
6336 case ARM::VLD3DUPdWB_fixed_Asm_8:
6337 case ARM::VLD3DUPdWB_fixed_Asm_16:
6338 case ARM::VLD3DUPdWB_fixed_Asm_32:
6339 case ARM::VLD3DUPqWB_fixed_Asm_8:
6340 case ARM::VLD3DUPqWB_fixed_Asm_16:
6341 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6342 MCInst TmpInst;
6343 unsigned Spacing;
6344 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6345 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6346 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6347 Spacing));
6348 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6349 Spacing * 2));
6350 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6351 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6352 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6353 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6354 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6355 TmpInst.addOperand(Inst.getOperand(4));
6356 Inst = TmpInst;
6357 return true;
6358 }
6359
6360 case ARM::VLD3DUPdWB_register_Asm_8:
6361 case ARM::VLD3DUPdWB_register_Asm_16:
6362 case ARM::VLD3DUPdWB_register_Asm_32:
6363 case ARM::VLD3DUPqWB_register_Asm_8:
6364 case ARM::VLD3DUPqWB_register_Asm_16:
6365 case ARM::VLD3DUPqWB_register_Asm_32: {
6366 MCInst TmpInst;
6367 unsigned Spacing;
6368 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6369 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6370 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6371 Spacing));
6372 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6373 Spacing * 2));
6374 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6375 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6376 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6377 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6378 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6379 TmpInst.addOperand(Inst.getOperand(5));
6380 Inst = TmpInst;
6381 return true;
6382 }
6383
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006384 // VLD3 multiple 3-element structure instructions.
6385 case ARM::VLD3dAsm_8:
6386 case ARM::VLD3dAsm_16:
6387 case ARM::VLD3dAsm_32:
6388 case ARM::VLD3qAsm_8:
6389 case ARM::VLD3qAsm_16:
6390 case ARM::VLD3qAsm_32: {
6391 MCInst TmpInst;
6392 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006393 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006394 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6395 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6396 Spacing));
6397 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6398 Spacing * 2));
6399 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6400 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6401 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6402 TmpInst.addOperand(Inst.getOperand(4));
6403 Inst = TmpInst;
6404 return true;
6405 }
6406
6407 case ARM::VLD3dWB_fixed_Asm_8:
6408 case ARM::VLD3dWB_fixed_Asm_16:
6409 case ARM::VLD3dWB_fixed_Asm_32:
6410 case ARM::VLD3qWB_fixed_Asm_8:
6411 case ARM::VLD3qWB_fixed_Asm_16:
6412 case ARM::VLD3qWB_fixed_Asm_32: {
6413 MCInst TmpInst;
6414 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006415 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006416 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6417 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6418 Spacing));
6419 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6420 Spacing * 2));
6421 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6422 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6423 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6424 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6425 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6426 TmpInst.addOperand(Inst.getOperand(4));
6427 Inst = TmpInst;
6428 return true;
6429 }
6430
6431 case ARM::VLD3dWB_register_Asm_8:
6432 case ARM::VLD3dWB_register_Asm_16:
6433 case ARM::VLD3dWB_register_Asm_32:
6434 case ARM::VLD3qWB_register_Asm_8:
6435 case ARM::VLD3qWB_register_Asm_16:
6436 case ARM::VLD3qWB_register_Asm_32: {
6437 MCInst TmpInst;
6438 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006439 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006440 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6441 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6442 Spacing));
6443 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6444 Spacing * 2));
6445 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6446 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6447 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6448 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6449 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6450 TmpInst.addOperand(Inst.getOperand(5));
6451 Inst = TmpInst;
6452 return true;
6453 }
6454
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006455 // VLD4DUP single 3-element structure to all lanes instructions.
6456 case ARM::VLD4DUPdAsm_8:
6457 case ARM::VLD4DUPdAsm_16:
6458 case ARM::VLD4DUPdAsm_32:
6459 case ARM::VLD4DUPqAsm_8:
6460 case ARM::VLD4DUPqAsm_16:
6461 case ARM::VLD4DUPqAsm_32: {
6462 MCInst TmpInst;
6463 unsigned Spacing;
6464 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6465 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6466 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6467 Spacing));
6468 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6469 Spacing * 2));
6470 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6471 Spacing * 3));
6472 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6473 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6474 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6475 TmpInst.addOperand(Inst.getOperand(4));
6476 Inst = TmpInst;
6477 return true;
6478 }
6479
6480 case ARM::VLD4DUPdWB_fixed_Asm_8:
6481 case ARM::VLD4DUPdWB_fixed_Asm_16:
6482 case ARM::VLD4DUPdWB_fixed_Asm_32:
6483 case ARM::VLD4DUPqWB_fixed_Asm_8:
6484 case ARM::VLD4DUPqWB_fixed_Asm_16:
6485 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6486 MCInst TmpInst;
6487 unsigned Spacing;
6488 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6489 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6490 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6491 Spacing));
6492 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6493 Spacing * 2));
6494 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6495 Spacing * 3));
6496 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6497 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6498 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6499 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6500 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6501 TmpInst.addOperand(Inst.getOperand(4));
6502 Inst = TmpInst;
6503 return true;
6504 }
6505
6506 case ARM::VLD4DUPdWB_register_Asm_8:
6507 case ARM::VLD4DUPdWB_register_Asm_16:
6508 case ARM::VLD4DUPdWB_register_Asm_32:
6509 case ARM::VLD4DUPqWB_register_Asm_8:
6510 case ARM::VLD4DUPqWB_register_Asm_16:
6511 case ARM::VLD4DUPqWB_register_Asm_32: {
6512 MCInst TmpInst;
6513 unsigned Spacing;
6514 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6515 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6516 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6517 Spacing));
6518 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6519 Spacing * 2));
6520 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6521 Spacing * 3));
6522 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6523 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6524 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6525 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6526 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6527 TmpInst.addOperand(Inst.getOperand(5));
6528 Inst = TmpInst;
6529 return true;
6530 }
6531
6532 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006533 case ARM::VLD4dAsm_8:
6534 case ARM::VLD4dAsm_16:
6535 case ARM::VLD4dAsm_32:
6536 case ARM::VLD4qAsm_8:
6537 case ARM::VLD4qAsm_16:
6538 case ARM::VLD4qAsm_32: {
6539 MCInst TmpInst;
6540 unsigned Spacing;
6541 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6542 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(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6548 Spacing * 3));
6549 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6550 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6551 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6552 TmpInst.addOperand(Inst.getOperand(4));
6553 Inst = TmpInst;
6554 return true;
6555 }
6556
6557 case ARM::VLD4dWB_fixed_Asm_8:
6558 case ARM::VLD4dWB_fixed_Asm_16:
6559 case ARM::VLD4dWB_fixed_Asm_32:
6560 case ARM::VLD4qWB_fixed_Asm_8:
6561 case ARM::VLD4qWB_fixed_Asm_16:
6562 case ARM::VLD4qWB_fixed_Asm_32: {
6563 MCInst TmpInst;
6564 unsigned Spacing;
6565 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6566 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6567 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6568 Spacing));
6569 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6570 Spacing * 2));
6571 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6572 Spacing * 3));
6573 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6574 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6575 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6576 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6577 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6578 TmpInst.addOperand(Inst.getOperand(4));
6579 Inst = TmpInst;
6580 return true;
6581 }
6582
6583 case ARM::VLD4dWB_register_Asm_8:
6584 case ARM::VLD4dWB_register_Asm_16:
6585 case ARM::VLD4dWB_register_Asm_32:
6586 case ARM::VLD4qWB_register_Asm_8:
6587 case ARM::VLD4qWB_register_Asm_16:
6588 case ARM::VLD4qWB_register_Asm_32: {
6589 MCInst TmpInst;
6590 unsigned Spacing;
6591 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6592 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6593 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6594 Spacing));
6595 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6596 Spacing * 2));
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6598 Spacing * 3));
6599 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6600 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6601 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6602 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6603 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6604 TmpInst.addOperand(Inst.getOperand(5));
6605 Inst = TmpInst;
6606 return true;
6607 }
6608
Jim Grosbach1a747242012-01-23 23:45:44 +00006609 // VST3 multiple 3-element structure instructions.
6610 case ARM::VST3dAsm_8:
6611 case ARM::VST3dAsm_16:
6612 case ARM::VST3dAsm_32:
6613 case ARM::VST3qAsm_8:
6614 case ARM::VST3qAsm_16:
6615 case ARM::VST3qAsm_32: {
6616 MCInst TmpInst;
6617 unsigned Spacing;
6618 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6619 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6620 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6621 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6622 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6623 Spacing));
6624 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6625 Spacing * 2));
6626 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6627 TmpInst.addOperand(Inst.getOperand(4));
6628 Inst = TmpInst;
6629 return true;
6630 }
6631
6632 case ARM::VST3dWB_fixed_Asm_8:
6633 case ARM::VST3dWB_fixed_Asm_16:
6634 case ARM::VST3dWB_fixed_Asm_32:
6635 case ARM::VST3qWB_fixed_Asm_8:
6636 case ARM::VST3qWB_fixed_Asm_16:
6637 case ARM::VST3qWB_fixed_Asm_32: {
6638 MCInst TmpInst;
6639 unsigned Spacing;
6640 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6641 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6642 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6643 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6644 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6645 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6646 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6647 Spacing));
6648 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6649 Spacing * 2));
6650 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6651 TmpInst.addOperand(Inst.getOperand(4));
6652 Inst = TmpInst;
6653 return true;
6654 }
6655
6656 case ARM::VST3dWB_register_Asm_8:
6657 case ARM::VST3dWB_register_Asm_16:
6658 case ARM::VST3dWB_register_Asm_32:
6659 case ARM::VST3qWB_register_Asm_8:
6660 case ARM::VST3qWB_register_Asm_16:
6661 case ARM::VST3qWB_register_Asm_32: {
6662 MCInst TmpInst;
6663 unsigned Spacing;
6664 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6665 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6666 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6667 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6668 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6669 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6670 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6671 Spacing));
6672 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6673 Spacing * 2));
6674 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6675 TmpInst.addOperand(Inst.getOperand(5));
6676 Inst = TmpInst;
6677 return true;
6678 }
6679
Jim Grosbachda70eac2012-01-24 00:58:13 +00006680 // VST4 multiple 3-element structure instructions.
6681 case ARM::VST4dAsm_8:
6682 case ARM::VST4dAsm_16:
6683 case ARM::VST4dAsm_32:
6684 case ARM::VST4qAsm_8:
6685 case ARM::VST4qAsm_16:
6686 case ARM::VST4qAsm_32: {
6687 MCInst TmpInst;
6688 unsigned Spacing;
6689 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6690 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6691 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6692 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6693 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6694 Spacing));
6695 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6696 Spacing * 2));
6697 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6698 Spacing * 3));
6699 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6700 TmpInst.addOperand(Inst.getOperand(4));
6701 Inst = TmpInst;
6702 return true;
6703 }
6704
6705 case ARM::VST4dWB_fixed_Asm_8:
6706 case ARM::VST4dWB_fixed_Asm_16:
6707 case ARM::VST4dWB_fixed_Asm_32:
6708 case ARM::VST4qWB_fixed_Asm_8:
6709 case ARM::VST4qWB_fixed_Asm_16:
6710 case ARM::VST4qWB_fixed_Asm_32: {
6711 MCInst TmpInst;
6712 unsigned Spacing;
6713 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6714 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6715 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6716 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6717 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6718 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6719 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6720 Spacing));
6721 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6722 Spacing * 2));
6723 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6724 Spacing * 3));
6725 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6726 TmpInst.addOperand(Inst.getOperand(4));
6727 Inst = TmpInst;
6728 return true;
6729 }
6730
6731 case ARM::VST4dWB_register_Asm_8:
6732 case ARM::VST4dWB_register_Asm_16:
6733 case ARM::VST4dWB_register_Asm_32:
6734 case ARM::VST4qWB_register_Asm_8:
6735 case ARM::VST4qWB_register_Asm_16:
6736 case ARM::VST4qWB_register_Asm_32: {
6737 MCInst TmpInst;
6738 unsigned Spacing;
6739 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6740 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6741 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6742 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6743 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6744 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6745 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6746 Spacing));
6747 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6748 Spacing * 2));
6749 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6750 Spacing * 3));
6751 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6752 TmpInst.addOperand(Inst.getOperand(5));
6753 Inst = TmpInst;
6754 return true;
6755 }
6756
Jim Grosbachad66de12012-04-11 00:15:16 +00006757 // Handle encoding choice for the shift-immediate instructions.
6758 case ARM::t2LSLri:
6759 case ARM::t2LSRri:
6760 case ARM::t2ASRri: {
6761 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6762 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6763 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6764 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6765 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6766 unsigned NewOpc;
6767 switch (Inst.getOpcode()) {
6768 default: llvm_unreachable("unexpected opcode");
6769 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6770 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6771 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6772 }
6773 // The Thumb1 operands aren't in the same order. Awesome, eh?
6774 MCInst TmpInst;
6775 TmpInst.setOpcode(NewOpc);
6776 TmpInst.addOperand(Inst.getOperand(0));
6777 TmpInst.addOperand(Inst.getOperand(5));
6778 TmpInst.addOperand(Inst.getOperand(1));
6779 TmpInst.addOperand(Inst.getOperand(2));
6780 TmpInst.addOperand(Inst.getOperand(3));
6781 TmpInst.addOperand(Inst.getOperand(4));
6782 Inst = TmpInst;
6783 return true;
6784 }
6785 return false;
6786 }
6787
Jim Grosbach485e5622011-12-13 22:45:11 +00006788 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00006789 case ARM::t2MOVsr:
6790 case ARM::t2MOVSsr: {
6791 // Which instruction to expand to depends on the CCOut operand and
6792 // whether we're in an IT block if the register operands are low
6793 // registers.
6794 bool isNarrow = false;
6795 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6796 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6797 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6798 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6799 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6800 isNarrow = true;
6801 MCInst TmpInst;
6802 unsigned newOpc;
6803 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6804 default: llvm_unreachable("unexpected opcode!");
6805 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6806 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6807 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6808 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6809 }
6810 TmpInst.setOpcode(newOpc);
6811 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6812 if (isNarrow)
6813 TmpInst.addOperand(MCOperand::CreateReg(
6814 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6815 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6816 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6817 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6818 TmpInst.addOperand(Inst.getOperand(5));
6819 if (!isNarrow)
6820 TmpInst.addOperand(MCOperand::CreateReg(
6821 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6822 Inst = TmpInst;
6823 return true;
6824 }
Jim Grosbach485e5622011-12-13 22:45:11 +00006825 case ARM::t2MOVsi:
6826 case ARM::t2MOVSsi: {
6827 // Which instruction to expand to depends on the CCOut operand and
6828 // whether we're in an IT block if the register operands are low
6829 // registers.
6830 bool isNarrow = false;
6831 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6832 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6833 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6834 isNarrow = true;
6835 MCInst TmpInst;
6836 unsigned newOpc;
6837 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6838 default: llvm_unreachable("unexpected opcode!");
6839 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6840 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6841 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6842 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006843 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00006844 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00006845 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6846 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00006847 TmpInst.setOpcode(newOpc);
6848 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6849 if (isNarrow)
6850 TmpInst.addOperand(MCOperand::CreateReg(
6851 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6852 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00006853 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00006854 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00006855 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6856 TmpInst.addOperand(Inst.getOperand(4));
6857 if (!isNarrow)
6858 TmpInst.addOperand(MCOperand::CreateReg(
6859 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6860 Inst = TmpInst;
6861 return true;
6862 }
6863 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00006864 case ARM::ASRr:
6865 case ARM::LSRr:
6866 case ARM::LSLr:
6867 case ARM::RORr: {
6868 ARM_AM::ShiftOpc ShiftTy;
6869 switch(Inst.getOpcode()) {
6870 default: llvm_unreachable("unexpected opcode!");
6871 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6872 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6873 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6874 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6875 }
Jim Grosbachabcac562011-11-16 18:31:45 +00006876 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6877 MCInst TmpInst;
6878 TmpInst.setOpcode(ARM::MOVsr);
6879 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6880 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6881 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6882 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6883 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6884 TmpInst.addOperand(Inst.getOperand(4));
6885 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6886 Inst = TmpInst;
6887 return true;
6888 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00006889 case ARM::ASRi:
6890 case ARM::LSRi:
6891 case ARM::LSLi:
6892 case ARM::RORi: {
6893 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006894 switch(Inst.getOpcode()) {
6895 default: llvm_unreachable("unexpected opcode!");
6896 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6897 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6898 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6899 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6900 }
6901 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006902 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00006903 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00006904 // A shift by 32 should be encoded as 0 when permitted
6905 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6906 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006907 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006908 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00006909 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00006910 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6911 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00006912 if (Opc == ARM::MOVsi)
6913 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00006914 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6915 TmpInst.addOperand(Inst.getOperand(4));
6916 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6917 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006918 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00006919 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00006920 case ARM::RRXi: {
6921 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6922 MCInst TmpInst;
6923 TmpInst.setOpcode(ARM::MOVsi);
6924 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6925 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6926 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6927 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6928 TmpInst.addOperand(Inst.getOperand(3));
6929 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6930 Inst = TmpInst;
6931 return true;
6932 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00006933 case ARM::t2LDMIA_UPD: {
6934 // If this is a load of a single register, then we should use
6935 // a post-indexed LDR instruction instead, per the ARM ARM.
6936 if (Inst.getNumOperands() != 5)
6937 return false;
6938 MCInst TmpInst;
6939 TmpInst.setOpcode(ARM::t2LDR_POST);
6940 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6941 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6942 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6943 TmpInst.addOperand(MCOperand::CreateImm(4));
6944 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6945 TmpInst.addOperand(Inst.getOperand(3));
6946 Inst = TmpInst;
6947 return true;
6948 }
6949 case ARM::t2STMDB_UPD: {
6950 // If this is a store of a single register, then we should use
6951 // a pre-indexed STR instruction instead, per the ARM ARM.
6952 if (Inst.getNumOperands() != 5)
6953 return false;
6954 MCInst TmpInst;
6955 TmpInst.setOpcode(ARM::t2STR_PRE);
6956 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6957 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6958 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6959 TmpInst.addOperand(MCOperand::CreateImm(-4));
6960 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6961 TmpInst.addOperand(Inst.getOperand(3));
6962 Inst = TmpInst;
6963 return true;
6964 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006965 case ARM::LDMIA_UPD:
6966 // If this is a load of a single register via a 'pop', then we should use
6967 // a post-indexed LDR instruction instead, per the ARM ARM.
6968 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6969 Inst.getNumOperands() == 5) {
6970 MCInst TmpInst;
6971 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6972 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6973 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6974 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6975 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6976 TmpInst.addOperand(MCOperand::CreateImm(4));
6977 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6978 TmpInst.addOperand(Inst.getOperand(3));
6979 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00006980 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006981 }
6982 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00006983 case ARM::STMDB_UPD:
6984 // If this is a store of a single register via a 'push', then we should use
6985 // a pre-indexed STR instruction instead, per the ARM ARM.
6986 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6987 Inst.getNumOperands() == 5) {
6988 MCInst TmpInst;
6989 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6990 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6991 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6992 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6993 TmpInst.addOperand(MCOperand::CreateImm(-4));
6994 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6995 TmpInst.addOperand(Inst.getOperand(3));
6996 Inst = TmpInst;
6997 }
6998 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00006999 case ARM::t2ADDri12:
7000 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7001 // mnemonic was used (not "addw"), encoding T3 is preferred.
7002 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7003 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7004 break;
7005 Inst.setOpcode(ARM::t2ADDri);
7006 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7007 break;
7008 case ARM::t2SUBri12:
7009 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7010 // mnemonic was used (not "subw"), encoding T3 is preferred.
7011 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7012 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7013 break;
7014 Inst.setOpcode(ARM::t2SUBri);
7015 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7016 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007017 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007018 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007019 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7020 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7021 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007022 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007023 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007024 return true;
7025 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007026 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007027 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007028 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007029 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7030 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7031 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007032 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007033 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007034 return true;
7035 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007036 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007037 case ARM::t2ADDri:
7038 case ARM::t2SUBri: {
7039 // If the destination and first source operand are the same, and
7040 // the flags are compatible with the current IT status, use encoding T2
7041 // instead of T3. For compatibility with the system 'as'. Make sure the
7042 // wide encoding wasn't explicit.
7043 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007044 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007045 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7046 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7047 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7048 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7049 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7050 break;
7051 MCInst TmpInst;
7052 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7053 ARM::tADDi8 : ARM::tSUBi8);
7054 TmpInst.addOperand(Inst.getOperand(0));
7055 TmpInst.addOperand(Inst.getOperand(5));
7056 TmpInst.addOperand(Inst.getOperand(0));
7057 TmpInst.addOperand(Inst.getOperand(2));
7058 TmpInst.addOperand(Inst.getOperand(3));
7059 TmpInst.addOperand(Inst.getOperand(4));
7060 Inst = TmpInst;
7061 return true;
7062 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007063 case ARM::t2ADDrr: {
7064 // If the destination and first source operand are the same, and
7065 // there's no setting of the flags, use encoding T2 instead of T3.
7066 // Note that this is only for ADD, not SUB. This mirrors the system
7067 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7068 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7069 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007070 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7071 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007072 break;
7073 MCInst TmpInst;
7074 TmpInst.setOpcode(ARM::tADDhirr);
7075 TmpInst.addOperand(Inst.getOperand(0));
7076 TmpInst.addOperand(Inst.getOperand(0));
7077 TmpInst.addOperand(Inst.getOperand(2));
7078 TmpInst.addOperand(Inst.getOperand(3));
7079 TmpInst.addOperand(Inst.getOperand(4));
7080 Inst = TmpInst;
7081 return true;
7082 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007083 case ARM::tADDrSP: {
7084 // If the non-SP source operand and the destination operand are not the
7085 // same, we need to use the 32-bit encoding if it's available.
7086 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7087 Inst.setOpcode(ARM::t2ADDrr);
7088 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7089 return true;
7090 }
7091 break;
7092 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007093 case ARM::tB:
7094 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007095 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007096 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007097 return true;
7098 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007099 break;
7100 case ARM::t2B:
7101 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007102 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007103 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007104 return true;
7105 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007106 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007107 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007108 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007109 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007110 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007111 return true;
7112 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007113 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007114 case ARM::tBcc:
7115 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007116 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007117 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007118 return true;
7119 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007120 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007121 case ARM::tLDMIA: {
7122 // If the register list contains any high registers, or if the writeback
7123 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7124 // instead if we're in Thumb2. Otherwise, this should have generated
7125 // an error in validateInstruction().
7126 unsigned Rn = Inst.getOperand(0).getReg();
7127 bool hasWritebackToken =
7128 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7129 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7130 bool listContainsBase;
7131 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7132 (!listContainsBase && !hasWritebackToken) ||
7133 (listContainsBase && hasWritebackToken)) {
7134 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7135 assert (isThumbTwo());
7136 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7137 // If we're switching to the updating version, we need to insert
7138 // the writeback tied operand.
7139 if (hasWritebackToken)
7140 Inst.insert(Inst.begin(),
7141 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007142 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007143 }
7144 break;
7145 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007146 case ARM::tSTMIA_UPD: {
7147 // If the register list contains any high registers, we need to use
7148 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7149 // should have generated an error in validateInstruction().
7150 unsigned Rn = Inst.getOperand(0).getReg();
7151 bool listContainsBase;
7152 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7153 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7154 assert (isThumbTwo());
7155 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007156 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007157 }
7158 break;
7159 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007160 case ARM::tPOP: {
7161 bool listContainsBase;
7162 // If the register list contains any high registers, we need to use
7163 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7164 // should have generated an error in validateInstruction().
7165 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007166 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007167 assert (isThumbTwo());
7168 Inst.setOpcode(ARM::t2LDMIA_UPD);
7169 // Add the base register and writeback operands.
7170 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7171 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007172 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007173 }
7174 case ARM::tPUSH: {
7175 bool listContainsBase;
7176 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007177 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007178 assert (isThumbTwo());
7179 Inst.setOpcode(ARM::t2STMDB_UPD);
7180 // Add the base register and writeback operands.
7181 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7182 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007183 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007184 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007185 case ARM::t2MOVi: {
7186 // If we can use the 16-bit encoding and the user didn't explicitly
7187 // request the 32-bit variant, transform it here.
7188 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007189 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007190 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7191 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7192 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007193 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7194 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7195 // The operands aren't in the same order for tMOVi8...
7196 MCInst TmpInst;
7197 TmpInst.setOpcode(ARM::tMOVi8);
7198 TmpInst.addOperand(Inst.getOperand(0));
7199 TmpInst.addOperand(Inst.getOperand(4));
7200 TmpInst.addOperand(Inst.getOperand(1));
7201 TmpInst.addOperand(Inst.getOperand(2));
7202 TmpInst.addOperand(Inst.getOperand(3));
7203 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007204 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007205 }
7206 break;
7207 }
7208 case ARM::t2MOVr: {
7209 // If we can use the 16-bit encoding and the user didn't explicitly
7210 // request the 32-bit variant, transform it here.
7211 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7212 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7213 Inst.getOperand(2).getImm() == ARMCC::AL &&
7214 Inst.getOperand(4).getReg() == ARM::CPSR &&
7215 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7216 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7217 // The operands aren't the same for tMOV[S]r... (no cc_out)
7218 MCInst TmpInst;
7219 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7220 TmpInst.addOperand(Inst.getOperand(0));
7221 TmpInst.addOperand(Inst.getOperand(1));
7222 TmpInst.addOperand(Inst.getOperand(2));
7223 TmpInst.addOperand(Inst.getOperand(3));
7224 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007225 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007226 }
7227 break;
7228 }
Jim Grosbach82213192011-09-19 20:29:33 +00007229 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007230 case ARM::t2SXTB:
7231 case ARM::t2UXTH:
7232 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007233 // If we can use the 16-bit encoding and the user didn't explicitly
7234 // request the 32-bit variant, transform it here.
7235 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7236 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7237 Inst.getOperand(2).getImm() == 0 &&
7238 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7239 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007240 unsigned NewOpc;
7241 switch (Inst.getOpcode()) {
7242 default: llvm_unreachable("Illegal opcode!");
7243 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7244 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7245 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7246 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7247 }
Jim Grosbach82213192011-09-19 20:29:33 +00007248 // The operands aren't the same for thumb1 (no rotate operand).
7249 MCInst TmpInst;
7250 TmpInst.setOpcode(NewOpc);
7251 TmpInst.addOperand(Inst.getOperand(0));
7252 TmpInst.addOperand(Inst.getOperand(1));
7253 TmpInst.addOperand(Inst.getOperand(3));
7254 TmpInst.addOperand(Inst.getOperand(4));
7255 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007256 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007257 }
7258 break;
7259 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007260 case ARM::MOVsi: {
7261 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007262 // rrx shifts and asr/lsr of #32 is encoded as 0
7263 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7264 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007265 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7266 // Shifting by zero is accepted as a vanilla 'MOVr'
7267 MCInst TmpInst;
7268 TmpInst.setOpcode(ARM::MOVr);
7269 TmpInst.addOperand(Inst.getOperand(0));
7270 TmpInst.addOperand(Inst.getOperand(1));
7271 TmpInst.addOperand(Inst.getOperand(3));
7272 TmpInst.addOperand(Inst.getOperand(4));
7273 TmpInst.addOperand(Inst.getOperand(5));
7274 Inst = TmpInst;
7275 return true;
7276 }
7277 return false;
7278 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007279 case ARM::ANDrsi:
7280 case ARM::ORRrsi:
7281 case ARM::EORrsi:
7282 case ARM::BICrsi:
7283 case ARM::SUBrsi:
7284 case ARM::ADDrsi: {
7285 unsigned newOpc;
7286 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7287 if (SOpc == ARM_AM::rrx) return false;
7288 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007289 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007290 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7291 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7292 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7293 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7294 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7295 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7296 }
7297 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007298 // The exception is for right shifts, where 0 == 32
7299 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7300 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007301 MCInst TmpInst;
7302 TmpInst.setOpcode(newOpc);
7303 TmpInst.addOperand(Inst.getOperand(0));
7304 TmpInst.addOperand(Inst.getOperand(1));
7305 TmpInst.addOperand(Inst.getOperand(2));
7306 TmpInst.addOperand(Inst.getOperand(4));
7307 TmpInst.addOperand(Inst.getOperand(5));
7308 TmpInst.addOperand(Inst.getOperand(6));
7309 Inst = TmpInst;
7310 return true;
7311 }
7312 return false;
7313 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007314 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007315 case ARM::t2IT: {
7316 // The mask bits for all but the first condition are represented as
7317 // the low bit of the condition code value implies 't'. We currently
7318 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007319 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007320 MCOperand &MO = Inst.getOperand(1);
7321 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007322 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007323 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007324 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007325 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007326 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007327 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007328 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007329
7330 // Set up the IT block state according to the IT instruction we just
7331 // matched.
7332 assert(!inITBlock() && "nested IT blocks?!");
7333 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7334 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7335 ITState.CurPosition = 0;
7336 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007337 break;
7338 }
Richard Bartona39625e2012-07-09 16:12:24 +00007339 case ARM::t2LSLrr:
7340 case ARM::t2LSRrr:
7341 case ARM::t2ASRrr:
7342 case ARM::t2SBCrr:
7343 case ARM::t2RORrr:
7344 case ARM::t2BICrr:
7345 {
Richard Bartond5660372012-07-09 16:14:28 +00007346 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007347 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7348 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7349 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007350 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7351 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007352 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7353 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7354 unsigned NewOpc;
7355 switch (Inst.getOpcode()) {
7356 default: llvm_unreachable("unexpected opcode");
7357 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7358 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7359 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7360 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7361 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7362 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7363 }
7364 MCInst TmpInst;
7365 TmpInst.setOpcode(NewOpc);
7366 TmpInst.addOperand(Inst.getOperand(0));
7367 TmpInst.addOperand(Inst.getOperand(5));
7368 TmpInst.addOperand(Inst.getOperand(1));
7369 TmpInst.addOperand(Inst.getOperand(2));
7370 TmpInst.addOperand(Inst.getOperand(3));
7371 TmpInst.addOperand(Inst.getOperand(4));
7372 Inst = TmpInst;
7373 return true;
7374 }
7375 return false;
7376 }
7377 case ARM::t2ANDrr:
7378 case ARM::t2EORrr:
7379 case ARM::t2ADCrr:
7380 case ARM::t2ORRrr:
7381 {
Richard Bartond5660372012-07-09 16:14:28 +00007382 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007383 // These instructions are special in that they are commutable, so shorter encodings
7384 // are available more often.
7385 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7386 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7387 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7388 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007389 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7390 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007391 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7392 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7393 unsigned NewOpc;
7394 switch (Inst.getOpcode()) {
7395 default: llvm_unreachable("unexpected opcode");
7396 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7397 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7398 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7399 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7400 }
7401 MCInst TmpInst;
7402 TmpInst.setOpcode(NewOpc);
7403 TmpInst.addOperand(Inst.getOperand(0));
7404 TmpInst.addOperand(Inst.getOperand(5));
7405 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7406 TmpInst.addOperand(Inst.getOperand(1));
7407 TmpInst.addOperand(Inst.getOperand(2));
7408 } else {
7409 TmpInst.addOperand(Inst.getOperand(2));
7410 TmpInst.addOperand(Inst.getOperand(1));
7411 }
7412 TmpInst.addOperand(Inst.getOperand(3));
7413 TmpInst.addOperand(Inst.getOperand(4));
7414 Inst = TmpInst;
7415 return true;
7416 }
7417 return false;
7418 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007419 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007420 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007421}
7422
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007423unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7424 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7425 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007426 unsigned Opc = Inst.getOpcode();
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00007427 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007428 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7429 assert(MCID.hasOptionalDef() &&
7430 "optionally flag setting instruction missing optional def operand");
7431 assert(MCID.NumOperands == Inst.getNumOperands() &&
7432 "operand count mismatch!");
7433 // Find the optional-def operand (cc_out).
7434 unsigned OpNo;
7435 for (OpNo = 0;
7436 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7437 ++OpNo)
7438 ;
7439 // If we're parsing Thumb1, reject it completely.
7440 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7441 return Match_MnemonicFail;
7442 // If we're parsing Thumb2, which form is legal depends on whether we're
7443 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007444 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7445 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007446 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007447 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7448 inITBlock())
7449 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007450 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007451 // Some high-register supporting Thumb1 encodings only allow both registers
7452 // to be from r0-r7 when in Thumb2.
7453 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7454 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7455 isARMLowRegister(Inst.getOperand(2).getReg()))
7456 return Match_RequiresThumb2;
7457 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007458 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007459 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7460 isARMLowRegister(Inst.getOperand(1).getReg()))
7461 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007462 return Match_Success;
7463}
7464
Jim Grosbach5117ef72012-04-24 22:40:08 +00007465static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007466bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007467MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007468 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007469 MCStreamer &Out, unsigned &ErrorInfo,
7470 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007471 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007472 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007473
Chad Rosier2f480a82012-10-12 22:53:36 +00007474 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007475 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007476 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007477 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007478 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007479 // Context sensitive operand constraints aren't handled by the matcher,
7480 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007481 if (validateInstruction(Inst, Operands)) {
7482 // Still progress the IT block, otherwise one wrong condition causes
7483 // nasty cascading errors.
7484 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007485 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007486 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007487
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007488 // Some instructions need post-processing to, for example, tweak which
Jim Grosbachafad0532011-11-10 23:42:14 +00007489 // encoding is selected. Loop on it while changes happen so the
7490 // individual transformations can chain off each other. E.g.,
7491 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7492 while (processInstruction(Inst, Operands))
7493 ;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007494
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007495 // Only move forward at the very end so that everything in validate
7496 // and process gets a consistent answer about whether we're in an IT
7497 // block.
7498 forwardITPosition();
7499
Jim Grosbach82f76d12012-01-25 19:52:01 +00007500 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7501 // doesn't actually encode.
7502 if (Inst.getOpcode() == ARM::ITasm)
7503 return false;
7504
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007505 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007506 Out.EmitInstruction(Inst);
7507 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007508 case Match_MissingFeature: {
7509 assert(ErrorInfo && "Unknown missing feature!");
7510 // Special case the error message for the very common case where only
7511 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7512 std::string Msg = "instruction requires:";
7513 unsigned Mask = 1;
7514 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7515 if (ErrorInfo & Mask) {
7516 Msg += " ";
7517 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7518 }
7519 Mask <<= 1;
7520 }
7521 return Error(IDLoc, Msg);
7522 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007523 case Match_InvalidOperand: {
7524 SMLoc ErrorLoc = IDLoc;
7525 if (ErrorInfo != ~0U) {
7526 if (ErrorInfo >= Operands.size())
7527 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007528
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007529 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7530 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7531 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007532
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007533 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007534 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007535 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007536 return Error(IDLoc, "invalid instruction",
7537 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007538 case Match_RequiresNotITBlock:
7539 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007540 case Match_RequiresITBlock:
7541 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007542 case Match_RequiresV6:
7543 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7544 case Match_RequiresThumb2:
7545 return Error(IDLoc, "instruction variant requires Thumb2");
Quentin Colombeta83d5e92013-04-26 17:54:54 +00007546 case Match_ImmRange0_4: {
7547 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7548 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7549 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7550 }
Jim Grosbach087affe2012-06-22 23:56:48 +00007551 case Match_ImmRange0_15: {
7552 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7553 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7554 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7555 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007556 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007557
Eric Christopher91d7b902010-10-29 09:26:59 +00007558 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007559}
7560
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007561/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007562bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7563 StringRef IDVal = DirectiveID.getIdentifier();
7564 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007565 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007566 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007567 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007568 else if (IDVal == ".arm")
7569 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007570 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007571 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007572 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007573 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007574 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007575 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007576 else if (IDVal == ".unreq")
7577 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007578 else if (IDVal == ".arch")
7579 return parseDirectiveArch(DirectiveID.getLoc());
7580 else if (IDVal == ".eabi_attribute")
7581 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007582 else if (IDVal == ".fnstart")
7583 return parseDirectiveFnStart(DirectiveID.getLoc());
7584 else if (IDVal == ".fnend")
7585 return parseDirectiveFnEnd(DirectiveID.getLoc());
7586 else if (IDVal == ".cantunwind")
7587 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7588 else if (IDVal == ".personality")
7589 return parseDirectivePersonality(DirectiveID.getLoc());
7590 else if (IDVal == ".handlerdata")
7591 return parseDirectiveHandlerData(DirectiveID.getLoc());
7592 else if (IDVal == ".setfp")
7593 return parseDirectiveSetFP(DirectiveID.getLoc());
7594 else if (IDVal == ".pad")
7595 return parseDirectivePad(DirectiveID.getLoc());
7596 else if (IDVal == ".save")
7597 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7598 else if (IDVal == ".vsave")
7599 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007600 return true;
7601}
7602
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007603/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007604/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007605bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007606 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7607 for (;;) {
7608 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007609 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007610 return true;
7611
Eric Christopherbf7bc492013-01-09 03:52:05 +00007612 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007613
7614 if (getLexer().is(AsmToken::EndOfStatement))
7615 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007616
Kevin Enderbyccab3172009-09-15 00:27:25 +00007617 // FIXME: Improve diagnostic.
7618 if (getLexer().isNot(AsmToken::Comma))
7619 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007620 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007621 }
7622 }
7623
Sean Callanana83fd7d2010-01-19 20:27:46 +00007624 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007625 return false;
7626}
7627
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007628/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007629/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007630bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007631 if (getLexer().isNot(AsmToken::EndOfStatement))
7632 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007633 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007634
Tim Northovera2292d02013-06-10 23:20:58 +00007635 if (!hasThumb())
7636 return Error(L, "target does not support Thumb mode");
7637
Jim Grosbach7f882392011-12-07 18:04:19 +00007638 if (!isThumb())
7639 SwitchMode();
7640 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7641 return false;
7642}
7643
7644/// parseDirectiveARM
7645/// ::= .arm
7646bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7647 if (getLexer().isNot(AsmToken::EndOfStatement))
7648 return Error(L, "unexpected token in directive");
7649 Parser.Lex();
7650
Tim Northovera2292d02013-06-10 23:20:58 +00007651 if (!hasARM())
7652 return Error(L, "target does not support ARM mode");
7653
Jim Grosbach7f882392011-12-07 18:04:19 +00007654 if (isThumb())
7655 SwitchMode();
7656 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007657 return false;
7658}
7659
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007660/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007661/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007662bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007663 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7664 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007665 StringRef Name;
Jim Grosbach1152cc02011-12-21 22:30:16 +00007666 bool needFuncName = true;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007667
Jim Grosbach1152cc02011-12-21 22:30:16 +00007668 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007669 // ELF doesn't
7670 if (isMachO) {
7671 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007672 if (Tok.isNot(AsmToken::EndOfStatement)) {
7673 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7674 return Error(L, "unexpected token in .thumb_func directive");
7675 Name = Tok.getIdentifier();
7676 Parser.Lex(); // Consume the identifier token.
7677 needFuncName = false;
7678 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007679 }
7680
Jim Grosbach1152cc02011-12-21 22:30:16 +00007681 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00007682 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00007683
7684 // Eat the end of statement and any blank lines that follow.
7685 while (getLexer().is(AsmToken::EndOfStatement))
7686 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007687
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007688 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbach1152cc02011-12-21 22:30:16 +00007689 // We really should be checking the next symbol definition even if there's
7690 // stuff in between.
7691 if (needFuncName) {
Jim Grosbach42ba6282011-11-10 20:48:53 +00007692 Name = Parser.getTok().getIdentifier();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007693 }
7694
Jim Grosbachc6db8ce2010-11-05 22:33:53 +00007695 // Mark symbol as a thumb symbol.
7696 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7697 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007698 return false;
7699}
7700
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007701/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00007702/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007703bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007704 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007705 if (Tok.isNot(AsmToken::Identifier))
7706 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00007707 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00007708 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00007709 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007710 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00007711 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00007712 else
7713 return Error(L, "unrecognized syntax mode in .syntax directive");
7714
7715 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007716 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007717 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007718
7719 // TODO tell the MC streamer the mode
7720 // getParser().getStreamer().Emit???();
7721 return false;
7722}
7723
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007724/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00007725/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007726bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00007727 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007728 if (Tok.isNot(AsmToken::Integer))
7729 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00007730 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00007731 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007732 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00007733 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00007734 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007735 else
7736 return Error(L, "invalid operand to .code directive");
7737
7738 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00007739 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007740 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007741
Evan Cheng284b4672011-07-08 22:36:29 +00007742 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00007743 if (!hasThumb())
7744 return Error(L, "target does not support Thumb mode");
7745
Jim Grosbachf471ac32011-09-06 18:46:23 +00007746 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007747 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007748 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00007749 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00007750 if (!hasARM())
7751 return Error(L, "target does not support ARM mode");
7752
Jim Grosbachf471ac32011-09-06 18:46:23 +00007753 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00007754 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00007755 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00007756 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00007757
Kevin Enderby146dcf22009-10-15 20:48:48 +00007758 return false;
7759}
7760
Jim Grosbachab5830e2011-12-14 02:16:11 +00007761/// parseDirectiveReq
7762/// ::= name .req registername
7763bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7764 Parser.Lex(); // Eat the '.req' token.
7765 unsigned Reg;
7766 SMLoc SRegLoc, ERegLoc;
7767 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007768 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007769 return Error(SRegLoc, "register name expected");
7770 }
7771
7772 // Shouldn't be anything else.
7773 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007774 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007775 return Error(Parser.getTok().getLoc(),
7776 "unexpected input in .req directive.");
7777 }
7778
7779 Parser.Lex(); // Consume the EndOfStatement
7780
7781 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7782 return Error(SRegLoc, "redefinition of '" + Name +
7783 "' does not match original.");
7784
7785 return false;
7786}
7787
7788/// parseDirectiveUneq
7789/// ::= .unreq registername
7790bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7791 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007792 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00007793 return Error(L, "unexpected input in .unreq directive.");
7794 }
7795 RegisterReqs.erase(Parser.getTok().getIdentifier());
7796 Parser.Lex(); // Eat the identifier.
7797 return false;
7798}
7799
Jason W Kim135d2442011-12-20 17:38:12 +00007800/// parseDirectiveArch
7801/// ::= .arch token
7802bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7803 return true;
7804}
7805
7806/// parseDirectiveEabiAttr
7807/// ::= .eabi_attribute int, int
7808bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7809 return true;
7810}
7811
Logan Chien4ea23b52013-05-10 16:17:24 +00007812/// parseDirectiveFnStart
7813/// ::= .fnstart
7814bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7815 if (FnStartLoc.isValid()) {
7816 Error(L, ".fnstart starts before the end of previous one");
7817 Error(FnStartLoc, "previous .fnstart starts here");
7818 return true;
7819 }
7820
7821 FnStartLoc = L;
7822 getParser().getStreamer().EmitFnStart();
7823 return false;
7824}
7825
7826/// parseDirectiveFnEnd
7827/// ::= .fnend
7828bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7829 // Check the ordering of unwind directives
7830 if (!FnStartLoc.isValid())
7831 return Error(L, ".fnstart must precede .fnend directive");
7832
7833 // Reset the unwind directives parser state
7834 resetUnwindDirectiveParserState();
7835
7836 getParser().getStreamer().EmitFnEnd();
7837 return false;
7838}
7839
7840/// parseDirectiveCantUnwind
7841/// ::= .cantunwind
7842bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7843 // Check the ordering of unwind directives
7844 CantUnwindLoc = L;
7845 if (!FnStartLoc.isValid())
7846 return Error(L, ".fnstart must precede .cantunwind directive");
7847 if (HandlerDataLoc.isValid()) {
7848 Error(L, ".cantunwind can't be used with .handlerdata directive");
7849 Error(HandlerDataLoc, ".handlerdata was specified here");
7850 return true;
7851 }
7852 if (PersonalityLoc.isValid()) {
7853 Error(L, ".cantunwind can't be used with .personality directive");
7854 Error(PersonalityLoc, ".personality was specified here");
7855 return true;
7856 }
7857
7858 getParser().getStreamer().EmitCantUnwind();
7859 return false;
7860}
7861
7862/// parseDirectivePersonality
7863/// ::= .personality name
7864bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7865 // Check the ordering of unwind directives
7866 PersonalityLoc = L;
7867 if (!FnStartLoc.isValid())
7868 return Error(L, ".fnstart must precede .personality directive");
7869 if (CantUnwindLoc.isValid()) {
7870 Error(L, ".personality can't be used with .cantunwind directive");
7871 Error(CantUnwindLoc, ".cantunwind was specified here");
7872 return true;
7873 }
7874 if (HandlerDataLoc.isValid()) {
7875 Error(L, ".personality must precede .handlerdata directive");
7876 Error(HandlerDataLoc, ".handlerdata was specified here");
7877 return true;
7878 }
7879
7880 // Parse the name of the personality routine
7881 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7882 Parser.eatToEndOfStatement();
7883 return Error(L, "unexpected input in .personality directive.");
7884 }
7885 StringRef Name(Parser.getTok().getIdentifier());
7886 Parser.Lex();
7887
7888 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
7889 getParser().getStreamer().EmitPersonality(PR);
7890 return false;
7891}
7892
7893/// parseDirectiveHandlerData
7894/// ::= .handlerdata
7895bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
7896 // Check the ordering of unwind directives
7897 HandlerDataLoc = L;
7898 if (!FnStartLoc.isValid())
7899 return Error(L, ".fnstart must precede .personality directive");
7900 if (CantUnwindLoc.isValid()) {
7901 Error(L, ".handlerdata can't be used with .cantunwind directive");
7902 Error(CantUnwindLoc, ".cantunwind was specified here");
7903 return true;
7904 }
7905
7906 getParser().getStreamer().EmitHandlerData();
7907 return false;
7908}
7909
7910/// parseDirectiveSetFP
7911/// ::= .setfp fpreg, spreg [, offset]
7912bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
7913 // Check the ordering of unwind directives
7914 if (!FnStartLoc.isValid())
7915 return Error(L, ".fnstart must precede .setfp directive");
7916 if (HandlerDataLoc.isValid())
7917 return Error(L, ".setfp must precede .handlerdata directive");
7918
7919 // Parse fpreg
7920 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
7921 int NewFPReg = tryParseRegister();
7922 if (NewFPReg == -1)
7923 return Error(NewFPRegLoc, "frame pointer register expected");
7924
7925 // Consume comma
7926 if (!Parser.getTok().is(AsmToken::Comma))
7927 return Error(Parser.getTok().getLoc(), "comma expected");
7928 Parser.Lex(); // skip comma
7929
7930 // Parse spreg
7931 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
7932 int NewSPReg = tryParseRegister();
7933 if (NewSPReg == -1)
7934 return Error(NewSPRegLoc, "stack pointer register expected");
7935
7936 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
7937 return Error(NewSPRegLoc,
7938 "register should be either $sp or the latest fp register");
7939
7940 // Update the frame pointer register
7941 FPReg = NewFPReg;
7942
7943 // Parse offset
7944 int64_t Offset = 0;
7945 if (Parser.getTok().is(AsmToken::Comma)) {
7946 Parser.Lex(); // skip comma
7947
7948 if (Parser.getTok().isNot(AsmToken::Hash) &&
7949 Parser.getTok().isNot(AsmToken::Dollar)) {
7950 return Error(Parser.getTok().getLoc(), "'#' expected");
7951 }
7952 Parser.Lex(); // skip hash token.
7953
7954 const MCExpr *OffsetExpr;
7955 SMLoc ExLoc = Parser.getTok().getLoc();
7956 SMLoc EndLoc;
7957 if (getParser().parseExpression(OffsetExpr, EndLoc))
7958 return Error(ExLoc, "malformed setfp offset");
7959 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
7960 if (!CE)
7961 return Error(ExLoc, "setfp offset must be an immediate");
7962
7963 Offset = CE->getValue();
7964 }
7965
7966 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
7967 static_cast<unsigned>(NewSPReg),
7968 Offset);
7969 return false;
7970}
7971
7972/// parseDirective
7973/// ::= .pad offset
7974bool ARMAsmParser::parseDirectivePad(SMLoc L) {
7975 // Check the ordering of unwind directives
7976 if (!FnStartLoc.isValid())
7977 return Error(L, ".fnstart must precede .pad directive");
7978 if (HandlerDataLoc.isValid())
7979 return Error(L, ".pad must precede .handlerdata directive");
7980
7981 // Parse the offset
7982 if (Parser.getTok().isNot(AsmToken::Hash) &&
7983 Parser.getTok().isNot(AsmToken::Dollar)) {
7984 return Error(Parser.getTok().getLoc(), "'#' expected");
7985 }
7986 Parser.Lex(); // skip hash token.
7987
7988 const MCExpr *OffsetExpr;
7989 SMLoc ExLoc = Parser.getTok().getLoc();
7990 SMLoc EndLoc;
7991 if (getParser().parseExpression(OffsetExpr, EndLoc))
7992 return Error(ExLoc, "malformed pad offset");
7993 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
7994 if (!CE)
7995 return Error(ExLoc, "pad offset must be an immediate");
7996
7997 getParser().getStreamer().EmitPad(CE->getValue());
7998 return false;
7999}
8000
8001/// parseDirectiveRegSave
8002/// ::= .save { registers }
8003/// ::= .vsave { registers }
8004bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8005 // Check the ordering of unwind directives
8006 if (!FnStartLoc.isValid())
8007 return Error(L, ".fnstart must precede .save or .vsave directives");
8008 if (HandlerDataLoc.isValid())
8009 return Error(L, ".save or .vsave must precede .handlerdata directive");
8010
8011 // Parse the register list
8012 SmallVector<MCParsedAsmOperand*, 1> Operands;
8013 if (parseRegisterList(Operands))
8014 return true;
8015 ARMOperand *Op = (ARMOperand*)Operands[0];
8016 if (!IsVector && !Op->isRegList())
8017 return Error(L, ".save expects GPR registers");
8018 if (IsVector && !Op->isDPRRegList())
8019 return Error(L, ".vsave expects DPR registers");
8020
8021 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8022 return false;
8023}
8024
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008025/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008026extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008027 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8028 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008029}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008030
Chris Lattner3e4582a2010-09-06 19:11:01 +00008031#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008032#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008033#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008034#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008035
8036// Define this matcher function after the auto-generated include so we
8037// have the match class enum definitions.
8038unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8039 unsigned Kind) {
8040 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8041 // If the kind is a token for a literal immediate, check if our asm
8042 // operand matches. This is for InstAliases which have a fixed-value
8043 // immediate in the syntax.
8044 if (Kind == MCK__35_0 && Op->isImm()) {
8045 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8046 if (!CE)
8047 return Match_InvalidOperand;
8048 if (CE->getValue() == 0)
8049 return Match_Success;
8050 }
8051 return Match_InvalidOperand;
8052}